I want to show display a message when a product category has zero products. I want to do this via shortcode please.
I’ve tried searching StackOverflow and search engines for some codes to work off of but have been unsuccessful.
$category = get_queried_object();
$theCount = $category->count;
function farmdish_no_prod_msg_shortcode( $atts ) {
$a = shortcode_atts(array('slug' => ''), $atts );
if( ( is_product_category( '' . $a['slug'] . '' ) ) && ( $theCount > 0 ) ){
}else {
return '<span>No Products!</span>';
}
}
add_shortcode( 'no-prod-msg', 'farmdish_no_prod_msg_shortcode' );
I need to show a simple text message when there are zero products in a WooCommerce product category. Thank your for any help!
3
Answers
Shortcode is a wrong way of doing it.
You can do it by adding a woocommerce template file:
exists)
Create a file called “result-count.php” Add the following code to this file
$total = wc_get_loop_prop( ‘total’ );
if ($total === 0){
echo ‘NO PRODUCTS HERE BUDDY…’;
}
Try this
Try this:-