• Resolved rajeshsingh520

    (@rajeshsingh520)


    Hi,

    We are making some dynamic coupon we we are having issue at one point

    our coupon get applied based on the shipping method selected but when the user changes the shipping method the cart and coupon subtotal are not recalculated as the cart total are loaded from the session so our dynamic coupon is applied with 0 cost

    can you tell us if there is a way to bypass the session and force subtotal recalculation when doing shipping method change

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Support B C. a11n

    (@battouly)

    Hi @rajeshsingh520,

    Please share a link to a product and the steps to replicate this behavior. Once we are able to see it in action, we will have a clearer picture of it.

    Best!

    Thread Starter rajeshsingh520

    (@rajeshsingh520)

    Hi,

    Here is the code

    https://gist.github.com/rajeshsingh520/82168a0e7bf8178b4af1df5377bf8508

    step 1: create a Local pickup shipping method in your zone (as script is suppose to add coupon when the local pickup method is selected)

    step 2: add the script in your theme functions.php file

    when you will select other shiopping method no coupon will be applied

    but when you select “Local pikcup” it will apply the coupon but the cost is shown as “0” when you will refresh the page then the coupon original amount is applied that is 10

    Thread Starter rajeshsingh520

    (@rajeshsingh520)

    Hi

    We where able to fix it by replacing the hook

    
    add_action('woocommerce_after_calculate_totals', array($this,'applyDiscountCode'));
    

    with (the below one works properly)

    
    add_action('woocommerce_before_calculate_totals', array($this,'applyDiscountCode'));
    
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘How to force recalculation of cart total when doing shipping method change’ is closed to new replies.