Support » Plugin: WooCommerce » add custom discount message to price area

  • Resolved Benjamin Rothman

    (@brothman01)


    Screenshot 1

    I have this product page for a woocommerce product. My client is having a sale that ends on May 31, and there is a red text price reduction note that is part of the product description. The client wants that red text right under the price without space.

    Using the inspector I can see that what I need to do is have woocommerce put a note into p.price. How can I move that red text into p.price? I know I can use css to make the red text APPEAR that it is in p.price but I am trying not to use css hacks to just temp fix this, I want to do this correctly with woocommerce. Is there a way to tell woocommerce to include the red text in p.price?

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Support Joey Ricketts

    (@jricketts4)

    Hi @brothman01 – you can add a string to the default WooCommerce price using the woocommerce_get_price_html filter. The only problem is this will then alter all products in your store. In order to differentiate between which product this should display on, you can use an if statement to define the product ID number.

    Here’s something I put together that should work:

    
    function wc_add_string_to_price_newline( $price, $product ) {
        $product_id = $product->get_id();
        
        if ($product_id == '1190') {
            $price .= "<br>(15% off until May 31, 2020)";
        }
        
        return $price;
    }
    add_filter( 'woocommerce_get_price_html', 'wc_add_string_to_price_newline', 10, 2 );
    

    You’ll want to change 1190 within the if statement for $product_id to the applicable product.
    You can then place this in your theme’s functions.php file.

    – Joey

    Thread Starter Benjamin Rothman

    (@brothman01)

    yes, thank you Joey!

    Plugin Support Joey Ricketts

    (@jricketts4)

    No problem @brothman01! Let me know if you need anything else. 😁

    – Joey

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘add custom discount message to price area’ is closed to new replies.