Find out if there are products in a woocommerce category


I need to check if there are products in a WooCommerce category to show one message or another in the body of a page in WordPress. For example: if there are products in the category with ID 61, show "I have these courses right now". In case you do not, show "there are no scheduled courses on this subject".

EDIT: I have found the solution through the WP loop, although I do not know if it is the most correct way.

$args = array( 'post_type' => 'product', 'product_cat' => 'master' ); $loop = new WP_Query( $args ); if ( $loop->have_posts() ) { echo '<p>Actualmente, tenemos programados...</p>'; } else { echo '<p>Actualmente no tenemos...</p>'; }

asked by lk2_89 04.01.2019 в 10:35

0 answers