How to Remove On Sale Badges on WooCommerce Shop and Product Pages

In this comprehensive tutorial, we’ll guide you through the process of customizing the “On Sale” badge and concurrently removing it from your WooCommerce shop and product pages. This tutorial is designed for all WordPress users and ensures a clean, plugin-free approach to customization. The provided steps adhere to WordPress coding standards. Additionally, a bonus function to rename the sale badge will be introduced.

Before proceeding with any customizations in WordPress, it’s essential to set up a child theme. A child theme acts as a safe and efficient way to make modifications without affecting the parent theme. If you haven’t set up a child theme yet, follow this tutorial on How to Create a Child Theme for Customization. It will guide you through the process and ensure that your customizations remain intact even after theme updates.

Identify the Hooks and Priorities

Start by identifying the actions responsible for displaying the “On Sale” badges, located in files such as class-wc-template-loader.php. Look for lines like:

add_action( 'woocommerce_before_shop_loop_item_title', 'woocommerce_show_product_loop_sale_flash', 10 );
add_action( 'woocommerce_before_single_product_summary', 'woocommerce_show_product_sale_flash', 10 );
Code language: PHP (php)

Remove the Actions for Both Pages

Remove the “On Sale” badge from both the shop and single product pages with the following code in your child theme’s functions.php file:

/**
 * Remove WooCommerce On Sale Badge
 *
 * Remove the On Sale badge from both shop and single product pages.
 */
remove_action( 'woocommerce_before_shop_loop_item_title', 'woocommerce_show_product_loop_sale_flash', 10 );
remove_action( 'woocommerce_before_single_product_summary', 'woocommerce_show_product_sale_flash', 10 );
Code language: PHP (php)

Review and Save

After inserting the code into your child theme’s functions.php file, review the changes, and save the file. Ensure you clear any site cache for immediate effect.

That’s it! You’ve not only successfully removed the “On Sale” badges from your WooCommerce shop and single product pages but also customized the sale badge text with a unique function. Enjoy the flexibility of WordPress customization without relying on additional plugins.

Leave your feedback and help us improve ๐Ÿถ

We hope you found this article helpful! If you have any questions, feedback, or spot any errors, please let us know in the comments. Your input is valuable and helps us improve. If you liked this article, please consider sharing it with others. And if you really enjoyed it, you can show your support by buying us a cup of coffee โ˜•๏ธ or donating via PayPal ๐Ÿ’ฐ.

More free knowledge, because why not?

Your thoughts matter, leave a reply ๐Ÿ’ฌ

Your email address will not be published. Required fields are marked *