简体   繁体   English

将折扣复选框添加到 Woocommerce 购物车页面

[英]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).我需要在 Woocommerce 购物车页面添加一个复选框,以便当用户选中该复选框时,会对购物车总数应用固定折扣(当用户再次取消选中该复选框时,应将其删除)。 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然后你应该能够触发 js 调用并添加折扣

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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