T
T
theyakov172021-06-09 16:46:46
WooCommerce
theyakov17, 2021-06-09 16:46:46

How to remove the inscription of the minimum price from the subcategories?

function wpq_get_min_price_per_product_cat( $term_id ) {

global $wpdb;

$sql = "
SELECT MIN( meta_value+0 ) as minprice
FROM {$wpdb->posts}
INNER JOIN {$wpdb->term_relationships} ON ({$wpdb->posts}.ID = {$wpdb->term_relationships}. object_id)
INNER JOIN {$wpdb->postmeta} ON ({$wpdb->posts}.ID = {$wpdb->postmeta}.post_id)
WHERE
( {$wpdb->term_relationships}.term_taxonomy_id IN (%d) )
AND {$wpdb->posts}.post_type = 'product'
AND {$wpdb->posts}.post_status = 'publish'
AND {$wpdb->postmeta}.meta_key = '_price'
";

return $wpdb->get_var( $wpdb->prepare( $sql, $term_id ) );
}

function wpq_after_subcategory( $category ) {
if( is_product_category() ){
if( function_exists( 'wpq_get_min_price_per_product_cat' ) ) {
echo 'from ' . wpq_get_min_price_per_product_cat( $category->term_id ) . ' ₽/m2';
}
}


}
add_action( 'woocommerce_after_subcategory', 'wpq_after_subcategory' );

This is the code, the essence is this, I have categories of producers, inside which are categories of collections and the task is such that it shows the minimum cost of the collection, but also shows an inscription in the categories of manufacturers, how to remove the inscription from these categories?60c0c634a57c9669798075.png60c0c63b838fd631387713.png

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton Litvinenko, 2021-06-14
@theyakov17

function wpq_after_subcategory( $category ) {

  $queried_object = get_queried_object();

  if( is_product_category() && $queried_object->parent !== 0 ){
    if ( function_exists( 'wpq_get_min_price_per_product_cat' ) ) {
      echo 'от ' . wpq_get_min_price_per_product_cat( $category->term_id ) . ' ₽/м2';
    }
  }

}
add_action( 'woocommerce_after_subcategory', 'wpq_after_subcategory' );

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question