Posted on

Display “no results” message when there are no results in shortcode

To add message if there are no results in shortcode please use code snippet below:

function afw_action_woocommerce_shortcode_products_loop_no_results( $attributes ) {
    echo __( 'No auction(s) found.', 'my-custom-language-domain' );
}
add_action( 'woocommerce_shortcode_ending_soon_auctions_loop_no_results', 'afw_action_woocommerce_shortcode_products_loop_no_results', 10, 1 );
add_action( 'woocommerce_shortcode_all_user_auctions_loop_no_results', 'afw_action_woocommerce_shortcode_products_loop_no_results', 10, 1 );

For ending_soon_auctions shortcode hook is woocommerce_shortcode_ending_soon_auctions_loop_no_results, in general hook is woocommerce_shortcode_[shortcode_name]_loop_no_results. This is applicable for both Auctions for Woo and Competitions for Woo plugins.