Sale Price on Variant Products - by seanseansean

This topic has 9 replies, 3 voices, and was last updated 4 years, 10 months ago ago by Olga Barlow

  • Avatar: seanseansean
    seanseansean
    Participant
    June 8, 2019 at 00:08

    Hello, is it possible to display sale price variant products in the same fashion as single product prices on category pages?
    Ex:
    Original Price Sale Price
    Using Numbers:
    $49.99 $15.99

    Please, contact administrator
    for this information.
    8 Answers
    Avatar: Rose Tyler
    Rose Tyler
    Support staff
    June 8, 2019 at 08:44

    Hello,

    Go to Theme Options > Shop elements > Variation swatches > Variation swatches > Off.

    Regards

    Avatar: seanseansean
    seanseansean
    Participant
    June 8, 2019 at 15:47

    That seems to have no effect even after clearing the cache?

    Items with variation opens do not show the original price slashed with sale price in blue but products with no variations do.

    Please contact administrator
    for this information.
    Avatar: Rose Tyler
    Rose Tyler
    Support staff
    June 8, 2019 at 15:55

    Please see screenshot – http://prntscr.com/nz971f

    Regards

    Avatar: seanseansean
    seanseansean
    Participant
    June 10, 2019 at 17:32

    For some reason its not applying to all variant products, is there an option to have it applied only to certain products that I am missing in the theme options?

    http://prnt.sc/o01y8y

    Avatar: seanseansean
    seanseansean
    Participant
    June 10, 2019 at 17:34

    I apologize my description was not succinct of my problem to begin with, its specifically not applying to variant products where the variants have different prices. Would like if the low end or high end could be displayed at sale price, is this possible?

    Avatar: Olga Barlow
    Olga Barlow
    Support staff
    June 10, 2019 at 18:33

    Hello,

    If you want to display sale price for the variable products in the following way http://prntscr.com/o02q7z, unfortunately, WooCommerce does not have such option. You may try to implement this only by additional customization. You can submit customization request here.

    Regards

    Avatar: seanseansean
    seanseansean
    Participant
    June 10, 2019 at 20:29

    Thank you for your response.

    For anyone who comes across this problem, this is the code that worked for me to achieve the results.

    //add variation sale strikethrough with original price on shop and category pages
    function wc_wc20_variation_price_format($price, $product) {
      // Main Price
      $prices = array($product->get_variation_price('min', true), $product->get_variation_price('max', true));
      $price_min = $prices[0] !== $prices[1] ? sprintf(__('%1$s', 'woocommerce'), wc_price($prices[0])) : wc_price($prices[0]);
      $price_max = $prices[0] !== $prices[1] ? sprintf(__('%1$s', 'woocommerce'), wc_price($prices[1])) : wc_price($prices[1]);
      // Sale Price
      $prices = array($product->get_variation_regular_price('min', true), $product->get_variation_regular_price('max', true));
      sort($prices);
      $saleprice_min = $prices[0] !== $prices[1] ? sprintf(__('%1$s', 'woocommerce'), wc_price($prices[0])) : wc_price($prices[0]);
      $saleprice_max = $prices[0] !== $prices[1] ? sprintf(__('%1$s', 'woocommerce'), wc_price($prices[1])) : wc_price($prices[1]);
      if ($price_min !== $saleprice_min || $price_max !== $saleprice_max) {
        $del = $saleprice_min === $saleprice_max ? $saleprice_min : "$saleprice_min - $saleprice_max";
        $ins = $price_min === $price_max ? $price_min : "$price_min - $price_max";
        return "<del>$del</del> <ins>$ins</ins>";
      }
      return $price;
    }
    add_filter('woocommerce_variable_sale_price_html', 'wc_wc20_variation_price_format', 10, 2);
    add_filter('woocommerce_variable_price_html', 'wc_wc20_variation_price_format', 10, 2);
    Avatar: Olga Barlow
    Olga Barlow
    Support staff
    June 11, 2019 at 10:38

    Hello,

    Thank you that you shared your solution. Probably it will be useful for somebody with the same request.

    Regards

  • Viewing 9 results - 1 through 9 (of 9 total)

You must be logged in to reply to this topic.Log in/Sign up

We're using our own and third-party cookies to improve your experience and our website. Keep on browsing to accept our cookie policy.