Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save emanueljacob/c671d0c7ea0167602c019e0fd24612a7 to your computer and use it in GitHub Desktop.
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
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