Woocommerce 更新购物车按钮操作后哪个挂钩 运行
Which Hook is running after Woocommerce update cart button action
单击购物车页面中的更新购物车按钮后,我需要知道哪个挂钩 运行ning。
在购物车页面我们有 4 个按钮,update cart
,continue shopping
,proceed to checkout
,apply coupon
。
所以我想知道点击更新购物车按钮后 运行 哪个挂钩。当客户在更改数量后单击更新购物车按钮时,我必须 运行 一个可以更改购物车中总价的特殊功能,如果满足某些条件,我将更改购物车中的总价,以及这个总价价格也需要传递到结帐页面 /
请帮忙。
例如
add_filter('after_update_cart_function_finished', 'special_function');
function special_function(){
$applied_coupons= WC()->cart->get_applied_coupons();
if(!empty($applied_coupons)){
$new_value=WC()->cart->get_cart_subtotal();
$discounted=WC()->cart->coupon_discount_totals;
$discounted_value=array_values($discounted)[0];
$new_value=$new_value-$discounted_value+100;
WC()->cart->set_total_price($new_value);
After this update all post_meta value that regarding to order total
}
}
请查看我为更改购物车中的值而编写的以下自定义函数
function action_woocommerce_cart_totals_after_order_total( ) {
$applied_coupons= WC()->cart->get_applied_coupons();
if(!empty($applied_coupons)){
$new_value=WC()->cart->get_cart_subtotal();
$discounted=WC()->cart->coupon_discount_totals;
$discounted_value=array_values($discounted)[0];
$new_value=$new_value-$discounted_value;
if($new_value<100){
$new_value=$new_value+5;
}
?>
<style>
.new-price-new{
color:black;
font-size: 17px;
}
</style>
<script>
jQuery(function($){
$(".order-total .woocommerce-Price-amount.amount").text("£<?php echo $new_value;?>");
$(".order-total .woocommerce-Price-amount.amount").hide();
$(".new-price").remove();
$('.order-total .woocommerce-Price-amount.amount').after('<div class="new-price-new">£<?php echo $new_value;?></div>');;
$(".new-price-new").show();
});
</script>
<?php
}
else{
?>
<script>
jQuery(function($){
$(".new-price-new").remove();
});
</script>
<?php }
};
add_action( 'woocommerce_cart_totals_after_order_total', 'action_woocommerce_cart_totals_after_order_total', 10, 0 );
而且这个函数有很多问题,我写这个函数是因为某些原因或其他一些函数 woocommerce 没有正确计算优惠券价格,所以我写这个函数是为了手动更新购物车中的产品价格。这里如果购物车价值超过 100 我们提供免费送货,否则我们将添加 5。连这个功能都不能正常使用。
Woocommerce Create new discount functionality
您应该尝试 woocommerce_update_cart_action_cart_updated
动作挂钩。我已经重新审视了你的代码。试试这个:
add_action( 'woocommerce_update_cart_action_cart_updated', 'on_action_cart_updated', 20, 1 );
function on_action_cart_updated( $cart_updated ){
$applied_coupons = WC()->cart->get_applied_coupons();
if( count( $applied_coupons ) > 0 ){
$new_value = WC()->cart->get_cart_subtotal();
$discounted = WC()->cart->coupon_discount_totals;
$discounted_value = array_values($discounted)[0];
$new_value = $new_value-$discounted_value + 100;
WC()->cart->set_total( $new_value );
if ( $cart_updated ) {
// Recalc our totals
WC()->cart->calculate_totals();
}
}
}
代码进入您的活动子主题(或活动主题)的 function.php 文件。 未经测试。它可以工作。
更新: WC_Cart
set_total_price()
方法不存在...我已将其替换为现有的 WC_Cart
set_total()
单击购物车页面中的更新购物车按钮后,我需要知道哪个挂钩 运行ning。
在购物车页面我们有 4 个按钮,update cart
,continue shopping
,proceed to checkout
,apply coupon
。
所以我想知道点击更新购物车按钮后 运行 哪个挂钩。当客户在更改数量后单击更新购物车按钮时,我必须 运行 一个可以更改购物车中总价的特殊功能,如果满足某些条件,我将更改购物车中的总价,以及这个总价价格也需要传递到结帐页面 /
请帮忙。
例如
add_filter('after_update_cart_function_finished', 'special_function');
function special_function(){
$applied_coupons= WC()->cart->get_applied_coupons();
if(!empty($applied_coupons)){
$new_value=WC()->cart->get_cart_subtotal();
$discounted=WC()->cart->coupon_discount_totals;
$discounted_value=array_values($discounted)[0];
$new_value=$new_value-$discounted_value+100;
WC()->cart->set_total_price($new_value);
After this update all post_meta value that regarding to order total
}
}
请查看我为更改购物车中的值而编写的以下自定义函数
function action_woocommerce_cart_totals_after_order_total( ) {
$applied_coupons= WC()->cart->get_applied_coupons();
if(!empty($applied_coupons)){
$new_value=WC()->cart->get_cart_subtotal();
$discounted=WC()->cart->coupon_discount_totals;
$discounted_value=array_values($discounted)[0];
$new_value=$new_value-$discounted_value;
if($new_value<100){
$new_value=$new_value+5;
}
?>
<style>
.new-price-new{
color:black;
font-size: 17px;
}
</style>
<script>
jQuery(function($){
$(".order-total .woocommerce-Price-amount.amount").text("£<?php echo $new_value;?>");
$(".order-total .woocommerce-Price-amount.amount").hide();
$(".new-price").remove();
$('.order-total .woocommerce-Price-amount.amount').after('<div class="new-price-new">£<?php echo $new_value;?></div>');;
$(".new-price-new").show();
});
</script>
<?php
}
else{
?>
<script>
jQuery(function($){
$(".new-price-new").remove();
});
</script>
<?php }
};
add_action( 'woocommerce_cart_totals_after_order_total', 'action_woocommerce_cart_totals_after_order_total', 10, 0 );
而且这个函数有很多问题,我写这个函数是因为某些原因或其他一些函数 woocommerce 没有正确计算优惠券价格,所以我写这个函数是为了手动更新购物车中的产品价格。这里如果购物车价值超过 100 我们提供免费送货,否则我们将添加 5。连这个功能都不能正常使用。
Woocommerce Create new discount functionality
您应该尝试 woocommerce_update_cart_action_cart_updated
动作挂钩。我已经重新审视了你的代码。试试这个:
add_action( 'woocommerce_update_cart_action_cart_updated', 'on_action_cart_updated', 20, 1 );
function on_action_cart_updated( $cart_updated ){
$applied_coupons = WC()->cart->get_applied_coupons();
if( count( $applied_coupons ) > 0 ){
$new_value = WC()->cart->get_cart_subtotal();
$discounted = WC()->cart->coupon_discount_totals;
$discounted_value = array_values($discounted)[0];
$new_value = $new_value-$discounted_value + 100;
WC()->cart->set_total( $new_value );
if ( $cart_updated ) {
// Recalc our totals
WC()->cart->calculate_totals();
}
}
}
代码进入您的活动子主题(或活动主题)的 function.php 文件。 未经测试。它可以工作。
更新: WC_Cart
set_total_price()
方法不存在...我已将其替换为现有的 WC_Cart
set_total()