35 Comments

  • Thanks Perry,
    Do you also know how to remove the strikethrough from the original price?
    Steve

  • My bad – sorry Terry!

  • MarTy says:

    Thaks for tutorial, can you advise how to add a countdown ?

  • Marius says:

    Hi, thanks for tutorial. I wonder how are you getting discount value and outputting it?

    Thanks,

  • pipdig says:

    Awesome, thanks Terry!

  • gopi says:

    Hi Terry,

    Thanks for the code. but unfortunately it’s not working for me. When put that code into function.php. my site is going down and my getting blank white pages.but i really want to show this expiration date just beside to my product price. Any help ?

    cheers

  • King Soft says:

    Hi Terry,
    Can you talk about Countdown for a single product?
    Ex: I want Product name “ABC” with sale $19 & sale off $15 in 3 days (show countdown hours/minutes/seconds).

    Thanks,
    King

  • arianna says:

    Dear Terry
    I’d love to use your code but text appaears near price Tag in my product page.
    Can you help me please?

    All the bests!

    • terrytsang says:

      Hi arianna, you can put extra spaces between price and the text. Do try the code below:

      add_filter( 'woocommerce_get_price_html', 'custom_price_html', 100, 2 );
      function custom_price_html( $price, $product ){
          global $post;
          $sales_price_to = get_post_meta($post->ID, '_sale_price_dates_to', true);
          if(is_single() && $sales_price_to != "")
          {
              $sales_price_date_to = date("j M y", $sales_price_to);
       
              return str_replace( '</ins>', ' </ins> &nbsp;&nbsp;&nbsp;<b>(Offer till '.$sales_price_date_to.')</b>', $price );
          }
          else
          {
              return apply_filters( 'woocommerce_get_price', $price );
          }
      }
      
  • Terry, Hi!
    My question pertains to the schedule area of the:
    woo-product/product-data/general (back-end)
    Where we can schedule (via the calender) YY-MM-DD of the sale.
    Can I add HH:MM to that code to get hours and minutes?
    Sorry if this is a little off base, I’ve been searching everywhere for documentation and this is the closest I’ve found on the subject.
    Any ideas would be helpful, thank you again.

  • Troglos says:

    hi Terry,
    I am using the Variable product type, and your code is not working with it.
    Any suggestion? That would be really helpful.

  • Lee says:

    Thaks for tutorial, can you advise how to add a countdown ,too ^_^
    Waitting …

  • Lee says:

    Hi, “related products” display too (i dont want it ) , can only display product page ?

    • terrytsang says:

      Hi Lee, you can put below code at functions.php in your them folder:

      function wc_remove_related_products( $args ) {
      return array();
      }
      add_filter('woocommerce_related_products_args','wc_remove_related_products', 10);

  • Lee says:

    Thanks, but you misunderstood what I meant -.-

    I mean, your function (Add Sales End Date) will be displayed in the above related merchandise.

    Can be displayed only in one place ?

  • Ron says:

    thanks so much! worked like a charm. Appreciate the help. i’ve never seen code inserted through a function file.

  • Thong Tran says:

    There is a timer plugin to do that more fancy and out of the box, take a look: http://codecanyon.net/item/woocommerce-sales-countdown/7906953

  • Elena says:

    Great code! How can I display the date for variable products on sale?

  • Angel says:

    Yes, can you please help us out… Just like Elena we want this to work with Variable Products…. Please! Help us out.. lol

  • Giovanni says:

    It’s possible to add more than one schedule?
    I have to sell a course by October 20.
    Registering before August 31 pay 300.
    Registering before September 31 pay 400.
    Enrolling in October pay 500 (regular price)
    So I should add two dates sale price.
    Maybe I have to use some custom field?

  • Chonathun says:

    Thanks, for the code. I’m grateful. It works for single product. But once I use variation products, it doesn’t show the end date.

  • kerala says:

    Exactly what i looking for..Thank you so much for your time.

  • ashraf says:

    Hi sir,
    Please
    I added your code:
    add_filter( ‘woocommerce_get_price_html’, ‘custom_price_html’, 100, 2 );
    function custom_price_html( $price, $product ){
    global $post;
    $sales_price_to = get_post_meta($post->ID, ‘_sale_price_dates_to’, true);
    if(is_single() && $sales_price_to != “”)
    {
    $sales_price_date_to = date(“j M y”, $sales_price_to);

    return str_replace( ”, ‘    (Offer till ‘.$sales_price_date_to.’)‘, $price );
    }
    else
    {
    return apply_filters( ‘woocommerce_get_price’, $price );
    }
    }

    On my functions.php file, but it is not working !!!

    Please, Help!!!

    Best regards
    A.J.

  • ashraf says:

    Hi sir,
    Your code is working very fins,
    Please,
    Do you know , how can i view a schedule time for a regular price ?

    Best regards
    A.J.

  • Vicsabi says:

    Hello Terry,
    Thanks this code ! And how to display Sales End Date on the variable products page ? Can you help for me?
    Thanks

  • Denis says:

    Hey Terry,
    woocommerce_get_price_html is not being fired for products with variation. So your code only works for single products.
    Any idea how to fix that?
    Thank you!

  • Andrei says:

    Thank you for the sale of code!
    How can I remove the date of designation of the year?

  • kolo says:

    Can We do also “from date”?

  • Tayo Banjo says:

    Hi, your code works like magic. However,

    1. kindly what the code will be if it were to show days to end of the sale instead? E.g Sale ends in 1day/2days/3days etc.

    2. I need it to display on the Sale Products page too.

    I will really appreciate a response, please.

    Thank you.

    Much love,
    from Africa.

  • Alan Krum says:

    Is this still valid for WP 4.9 and WC 3.2.4 ?
    I am using a child theme and put the filter below the setup for the Child Theme Plug-in and it does not work. Any clue as to what I’m doing wrong?:

    ID, ‘_sale_price_dates_to’, true);
    if(is_single() && $sales_price_to != “”)
    {
    $sales_price_date_to = date(“j M y”, $sales_price_to);

    return str_replace( ”, ‘    (Offer till ‘.$sales_price_date_to.’)‘, $price );
    }
    else
    {
    return apply_filters( ‘woocommerce_get_price’, $price );
    }
    }
    // AMK – 171121 End
    //

Leave a Reply

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

WhatsApp chat Talk to Me