我正在尝试找到以下问题的解决方案。我一直在使用 Woocommerce 动态定价,以便为特定产品类别应用 25% 的折扣。然后,如果运输选项为 local_pickup,我需要删除该折扣。我想我可以调整以下代码。它在某个地方丢失了一些东西,所以我向您寻求帮助。
function discount_table(){
// Set $cat_in_cart to false
$cat_in_cart = false;
// Loop through all products in the Cart
foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) {
if ( has_term( 'category_1', 'product_cat', $cart_item['product_id'] ) ) {
$cat_in_cart = true;
break;
}
}
$total = WC()->cart->subtotal;
$sconto_label = "";
if($total >= 300){
$sconto_label=15;
}elseif($total >= 220){
$sconto_label=10;
}elseif($total >= 150){
$sconto_label=8;
}elseif($total >= 100){
$sconto_label=4;
}
$chosen_methods = WC()->session->get( 'chosen_shipping_methods' );
$chosen_shipping = explode(':',$chosen_methods[0]);
if($chosen_shipping[0]=='local_pickup' && !$cat_in_cart){
$sconto_label=25;
}
else if ($chosen_shipping[0]=='local_pickup' && $cat_in_cart){
$sconto_label=25;
// there should be something here or not?
}
$sconto_cliente = (($total*$sconto_label)/100);
if($sconto_label!="")
$sconto_cliente_net = ($sconto_loison/1.1);
WC()->cart->add_fee( "Discount ($sconto_label%)", -$sconto_cliente_net, false );
}
add_action( 'woocommerce_cart_calculate_fees','discount_table' );
有没有办法恢复购物车中已经打折的特定类别的一件或多件商品的原始价格?