Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/279.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php woocommerce初始化发货方式,添加到费率_Php_Wordpress_Woocommerce - Fatal编程技术网

Php woocommerce初始化发货方式,添加到费率

Php woocommerce初始化发货方式,添加到费率,php,wordpress,woocommerce,Php,Wordpress,Woocommerce,在Woocommerce中,我有以下情况:100美元之前有配送方式,100美元之后只有一种(免费配送)。因此,当客户以102美元购买产品,然后应用(10%)促销代码时,价格将为91,80美元。因为我在100美元后取消了配送方式,免费配送仅在100美元后出现,因为客户端显示:“没有配送方式可用…” 在促销代码和优惠券应用之前,如果价格>100$,是否可以显示免费送货?我将免费送货设置为显示最低订单金额(100$),但有一种方法可以显示,初始化?其他方法也受到欢迎。问题是。。。。您申请的免费送货受最

在Woocommerce中,我有以下情况:100美元之前有配送方式,100美元之后只有一种
(免费配送)
。因此,当客户以102美元购买
产品,然后
应用(10%)促销代码时,价格将为91,80美元。因为我在100美元后取消了配送方式,免费配送仅在100美元后出现
,因为客户端显示:“没有
配送方式可用…”


在促销代码和优惠券应用之前,如果
价格>100$
,是否可以显示免费送货?我将免费送货设置为显示最低订单
金额(100$)
,但有一种方法可以显示,初始化?其他方法也受到欢迎。

问题是。。。。您申请的免费送货受最小订单限制,这是指订单总额(而非小计)。。。。。 而小计给你的价值没有折扣

所以

从管理员设置中删除条件(最小订单总数)-免费送货。。。。现在它将适用于每个订单

然后修改代码---

add_filter('woocommerce_package_rates','woocommerce_hide_shipping',10,2);
功能:商业、隐藏、运输($rates,$package){
$threshold=100;
如果(WC()->购物车->小计>=$threshold){
未结算($费率['固定费率:45');
未结算($费率['固定费率:75']);
}
如果(WC()->购物车->小计<$threshold){
//代码在这里
未结算($费率['免费送货:45');
未结算($rates['free\u shipping:75']);
}
返回美元汇率;
}
    add_filter( 'woocommerce_package_rates', 'woocommerce_hide_shipping', 10, 2 );
function woocommerce_hide_shipping( $rates, $package ) {

  $threshold = 100;

if ( WC()->cart->subtotal >= $threshold ) {
    unset( $rates['flat_rate:45'] );
    unset( $rates['flat_rate:75'] );
}
if ( WC()->cart->subtotal >= $threshold && !empty(WC()->cart->applied_coupons) ) {
     //code here
}

  return $rates;

}
add_filter( 'woocommerce_package_rates', 'woocommerce_hide_shipping', 10, 2 );
function woocommerce_hide_shipping( $rates, $package ) {

  $threshold = 100;

 if ( WC()->cart->subtotal >= $threshold ) {
    unset( $rates['flat_rate:45'] );
    unset( $rates['flat_rate:75'] );
}
if ( WC()->cart->subtotal < $threshold ) {
     //code here
     unset( $rates['free_shipping:45'] );
     unset( $rates['free_shipping:75'] );
}

  return $rates;

}