Created
July 1, 2018 12:32
-
-
Save emanueljacob/c671d0c7ea0167602c019e0fd24612a7 to your computer and use it in GitHub Desktop.
Filter woocommerce products shortcode and show default message if no product has been found
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function prefix_filter_shortcodes($output, $tag, $attr, $m){ | |
//filter woocommerce "products" shortcode output | |
if($tag == 'products') { | |
$default_output = '<div class="woocommerce columns-3 "></div>'; | |
//show default message if no product has been found | |
if(empty($output) || $output == $default_output ){ | |
?> | |
<div class="no-products-info"> | |
<p class="woocommerce-no-products"><?php _e( 'No products were found matching your selection.', 'woocommerce' ); ?></p> | |
</div> | |
<?php | |
return ''; | |
} | |
} | |
return $output; | |
} | |
add_filter('do_shortcode_tag', 'prefix_filter_shortcodes', 10, 4); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment