Created
May 17, 2020 10:06
-
-
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/
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
<?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