-1

I need to add a checkbox to the Woocommerce cart page, so that when a user checks the checkbox, a fixed discount is applied to the cart totals (and it should be removed when the user unchecks the checkbox again). The updated total needs to be displayed ever where correctly (mini-cart, checkout, order emails, admin backend).

This question is similar, but I need to add it the checkbox to the cart page, and the updated total should be displayed correctly everywhere. Ideally, it would also be possible to remove the discount in admin backend on the order detail page.

How can I achieve this?

1 Answers1

0

You already have more information on this question and answers provide great much of information.

Also as alternate, What is you can do is add field on checkout page something like below.

add_action('woocommerce_cart_totals_before_shipping', 'add_check_box')

function add_check_box(){
  echo "<input type="checkbox" id="discount" name="discount" value="discount_price">"
}

Then you should be able trigger js called and added discount

Amila Priyankara
  • 118
  • 1
  • 12
  • The question you linked to is the same that I linked to. And like I mentioned in my question, it does not add the checkbox to the cart page and it also does not apply the discount EVERYWHERE. It only applies it to the checkout page, and cart page still shows the regular total sum. Also, it is percentage based and not fixed. – user10273978 Nov 15 '21 at 17:42
  • @user10273978 So sometimes we need to understand question that we might need altered it as per our needs. Did you try above solution? which should add check field on checkout form. So, then you need run some js function method trigger ajax call which alternately you can add some discount manually to order or using coupon as well – Amila Priyankara Nov 15 '21 at 18:23