• Resolved lospeso

    (@lospeso)


    I am using as WooCommerce short-code inserted into page, that draws and displays all products per a single product category.

    The short-code is:
    [product_category category="category-slug-here"]

    The short-code works great, but if there are no products per the category, all I get is a blank page, showing the page title.

    I tried to find a method to show a “message” on the page when there are no products, so the page is not all blank.

    There are no settings in the Customizer for WooCommerce and there are no settings in the Admin area (WooCommerce > Settings).

    I am hoping at least, there is some PHP snippet somewhere that I can use.

    Can anyone help with this?

    Thanks.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Support mcampal – a11n

    (@mcampal)

    Hi there,

    When accessing a category page for an empty category, the following message should display:

    No products were found matching your selection.

    When using Shortcodes, you can use a PHP snippet like the following to add a custom message:

    function woocommerce_shortcode_product_category_loop_no_results( $attributes ) {
        echo __( 'There are no products in this category', 'woocommerce' );
    }
    add_action( 'woocommerce_shortcode_product_category_loop_no_results', 'woocommerce_shortcode_product_category_loop_no_results', 20, 1 );

    Note that customizations are outside the scope of the support we provide, but we can point you in the right direction.

    I hope it helps!

    Best,

    Thread Starter lospeso

    (@lospeso)

    @mcampal

    Perfect!

    The PHP snippet works perfectly! ??

    When I used the Product-Category as a WordPress menu item, then the “No products found…” message shows up when there are no products. It has a “i” icon and the same message.

    …but for some reason, using the short-code to use the same thing (product-category), doesn’t show the “No products…” message at all, which is why I asked for the PHP snippet.

    Customization? – No problem, I got that handled. ~ Thanks

    Suggestion
    Unless I missed it, if I did, I apologize, but it would be nice to have WooCommerce make a documentation page outlining this same snippet you kindly gave.

    Thank-you very much for your help. ??

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘How Do I Create A Message when No Products Are Found?’ is closed to new replies.