Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save damiencarbery/d7c1b6abef625f2300d73169c20b6aa6 to your computer and use it in GitHub Desktop.
Save damiencarbery/d7c1b6abef625f2300d73169c20b6aa6 to your computer and use it in GitHub Desktop.
Change the 'No products were found matching your selection' message - Change the text without modifying the template file. https://www.damiencarbery.com/2020/05/change-the-no-products-were-found-matching-your-selection-message/
<?php
/*
Plugin Name: Change the 'No products were found matching your selection' message
Plugin URI: https://www.damiencarbery.com/2020/05/change-the-no-products-were-found-matching-your-selection-message/
Description: Change the text without modifying the template file.
Author: Damien Carbery
Author URI: https://www.damiencarbery.com
Version: 0.1
*/
// Customise the message when no products found.
add_action( 'wp_head', 'dcwd_change_no_products_found_text' );
function dcwd_change_no_products_found_text() {
// Remove the original code that uses the no-products-found.php template.
remove_action( 'woocommerce_no_products_found', 'wc_no_products_found' );
// and add in my own code.
add_action( 'woocommerce_no_products_found', 'dcwd_no_products_found' );
}
function dcwd_no_products_found() {
// Use the original message in case one of the conditions below is not met.
$message = 'No products were found matching your selection.';
if ( is_product_category() ) {
$message = sprintf( 'We do not currently have any <strong>%s</strong> products for sale.', single_term_title('', false) );
}
?>
<p class="woocommerce-info"><?php echo $message; ?></p>
<?php
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment