• Resolved Bert O

    (@websitehelperberto)


    Trying to display $product->get_sale_price() but it comes back empty.

    How can I fetch the sale price? Is your plugin adding some sort of filter?

Viewing 5 replies - 1 through 5 (of 5 total)
  • sangeethasrinivasan

    (@sangeethasrinivasan)

    Hi,
    Thank you for reaching out.

    We would like to let you know that our plugin does not update the prices in the backend (Sale price for discounts). Our plugin applies discounts on the fly dynamically while adding the product to the cart.

    However, it doesn’t change the price in the back-end.

    To get a discount on a product, you can give it a try using this snippet.
    https://gist.github.com/AshlinRejo/c37a155a42c0e30beafbbad183f0c4e8

    Kindly check with your developer on how you can use this snippet on your site.

    Hope this helps!

    Thanks
    Team Flycart

    Thread Starter Bert O

    (@websitehelperberto)

    The price still comes back as 0.

    This is what I am trying to do:

    add_action( 'woocommerce_review_order_after_order_total', 'show_total_discount_cart_checkout', 9999 );
      
    function how_total_discount_cart_checkout() {   
    	
       $discount_total = 0;  
       foreach ( WC()->cart->get_cart() as $cart_item_key => $values ) {         
          $product = $values['data'];
          if ( $product->is_on_sale() ) {
             $regular_price = $product->get_regular_price();
             //$sale_price = $product->get_sale_price();
    	   $discount_price = apply_filters('advanced_woo_discount_rules_get_product_discount_price_from_custom_price', $price, $product, $quantity, $custom_price, $return_details, $manual_request, $is_cart);
    
             $discount = ( (float)$regular_price - (float)$discount_price  * (int)$values['quantity']) ;
             $discount_total += $discount;
         // }
       }         
           if ( $discount_total > 0 ) {
           echo '<tr><th>You Saved</th><td data-title="You Saved">' . wc_price( $discount_total + WC()->cart->get_discount_total() ) .'</td></tr>';
       }
    
    }

    I tried $discount_price = apply_filters(‘advanced_woo_discount_rules_get_product_discount_price_from_custom_price’, $price, $product, $quantity, $custom_price, $return_details, $manual_request, $is_cart); on its own and still returns 0.

    • This reply was modified 2 years ago by Bert O.
    kowsaliya

    (@kowsaliya)

    Hi

    If you are trying to get you saved amount, you can refer to the following snippet
    https://gist.github.com/AnanthFlycart/f926a0d53921ea0bf5c0d3a19e9c5126.

    Hope this helps!

    Thanks
    Team Flycart

    Thread Starter Bert O

    (@websitehelperberto)

    You have gone above and beyond and I didn’t expect you to write a snippet but thank you. The level of support displayed there is outstanding.

    However, what you have done is what your plugin already does and it is not what I was trying to achieve.

    Testing your snippet, my question is, why does $sale_price still return 0?

    All I want to do is show the customer what they saved based on the difference between the regular price and the sale price.

    Which is just basically $regular_price – $sale_price = the difference
    Regular Price: £500
    Sale Price: £300
    The difference: £200 (you saved)

    This works for me on the product level but not on the cart/checkout journey which is where the problem lies. Your plugin filters $sale_price

    kowsaliya

    (@kowsaliya)

    Hi
    Thanks for reaching out.

    Our plugin calculates and applies the discount on run time so we won’t store discount value in sale_price, so it returns 0.

    Also, it seems in the cart you are trying as below
    $sale_price = $product->get_sale_price();
    We recommend you try by replacing $sale_price = $product->get_price();

    Hope this helps!

    Thanks
    Team Flycart

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Sale Price Empty’ is closed to new replies.