简体   繁体   中英

Add discount checkbox to Woocommerce cart page

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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM