How To Remove Sale From Woocommerce Product Page

How to Remove the “Sale” Badge from WooCommerce Product Pages: A Comprehensive Guide

Introduction:

WooCommerce is a powerful and flexible platform for building online stores. One of its standard features is the “Sale” badge, automatically displayed on product pages when you apply a discount or set a sale price. While this badge can effectively attract attention to discounted items, there might be situations where you want to remove it. Perhaps you want a more minimalist design, the sale is permanent, or the badge clashes with your overall brand aesthetic. This article provides a step-by-step guide on how to remove the “Sale” badge from your WooCommerce product pages, offering several methods to suit different technical skill levels. We’ll cover everything from simple CSS solutions to code snippets that you can add to your theme.

Main Part:

There are several ways to remove the “Sale” badge from your WooCommerce product pages. Choose the method that best suits your technical expertise and comfort level.

Method 1: Using CSS (Simplest Method)

This is the easiest and recommended method for most users. It involves adding a simple CSS rule to hide the badge.

1. Access the WordPress Customizer: Go to your WordPress dashboard, then navigate to Appearance > Customize.

2. Find the “Additional CSS” Section: In the Customizer, locate and click on the “Additional CSS” section.

3. Add the CSS Code: Paste the following CSS code into the text area:

.woocommerce span.onsale {

display: none !important;

}

Important: The `!important` declaration ensures that this style overrides any other conflicting styles in your theme.

4. Publish Your Changes: Click the “Publish” button at the top of the Customizer to save your changes.

This method will globally hide the “Sale” badge from all product pages on your WooCommerce store.

Method 2: Using a Code Snippet (For More Control)

If you prefer a code-based solution or need more control over where the badge is removed, you can use a code snippet. This involves adding a PHP function to your theme’s `functions.php` file or using a code snippet plugin.

1. Access Your Theme’s `functions.php` File: You can access this file either through your WordPress dashboard (Appearance > Theme Editor, then select `functions.php` in the right-hand sidebar) or by using an FTP client and navigating to your theme’s directory. Caution: Modifying the `functions.php` file directly can break your site. Always back up your file before making changes. Using a child theme is highly recommended.

2. OR, Use a Code Snippet Plugin: Install and activate a plugin like “Code Snippets.” This allows you to add PHP code without directly modifying your theme files, reducing the risk of errors.

3. Add the Code Snippet: Paste the following code into your `functions.php` file (or the Code Snippets plugin):

 add_filter( 'woocommerce_sale_flash', '__return_empty_string' ); 

4. Save Changes: Save the changes to your `functions.php` file or activate the code snippet in the Code Snippets plugin.

This snippet uses a filter to completely remove the HTML output for the sale flash (the “Sale” badge). This is a more efficient solution than CSS because it prevents the badge from being generated in the first place.

Method 3: Removing the Badge from Specific Product Types

If you only want to remove the “Sale” badge from certain product types (e.g., variable products), you can modify the code snippet in Method 2 to add conditional logic.

 add_filter( 'woocommerce_sale_flash', 'remove_sale_badge_conditional' ); 

function remove_sale_badge_conditional( $html ) {

global $product;

if ( $product->is_type( ‘variable’ ) ) {

return ”; // Remove for variable products

}

return $html; // Keep for other product types

}

This example removes the badge only from variable products. You can adjust the `if` condition to target different product types like `simple`, `grouped`, or `external`.

Method 4: Editing WooCommerce Template Files (Advanced)

This is the most advanced method and generally not recommended unless you have significant experience with WooCommerce templates. It involves directly editing the template file responsible for displaying the “Sale” badge.

1. Locate the Template File: The file responsible is typically located at: `woocommerce/templates/loop/sale-flash.php`. Important: Do not edit this file directly within the WooCommerce plugin folder. Doing so will make it extremely difficult to upgrade WooCommerce without losing your changes. Instead, copy this file to your theme’s WooCommerce folder (e.g., `yourtheme/woocommerce/loop/sale-flash.php`). If the `woocommerce` folder doesn’t exist in your theme directory, create it.

2. Edit the Copied Template File: Open the copied file in your theme’s WooCommerce directory. You can either completely remove the code within the file or comment it out:

 <?php /** 
  • Product loop sale flash
  • * @author WooThemes
  • @package WooCommerce/Templates
  • @version 1.6.4
*/

// if ( ! defined( ‘ABSPATH’ ) ) {

// exit; // Exit if accessed directly

// }

// global $post, $product;

// return ‘‘ . esc_html__( ‘Sale!’, ‘woocommerce’ ) . ‘‘;

3. Save Changes: Save the changes to the copied template file.

Conclusion:

Removing the “Sale” badge from your WooCommerce product pages is a simple process that can be achieved through various methods. The easiest and most recommended approach is using CSS. For more control and flexibility, consider using a code snippet. Editing WooCommerce template files is only recommended for experienced developers. By choosing the method that best Explore this article on How To Do A Buy One Get One Half Woocommerce suits your needs and technical expertise, you can customize your WooCommerce store’s appearance to align perfectly with your brand and desired user experience. Remember to always back up your website before making significant changes, especially when dealing with code.

Comments

No comments yet. Why don’t you start the discussion?

Leave a Reply

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