Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/286.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 只有在商业中使用特定优惠券时,才适用运费_Php_Wordpress_Woocommerce_Coupon - Fatal编程技术网

Php 只有在商业中使用特定优惠券时,才适用运费

Php 只有在商业中使用特定优惠券时,才适用运费,php,wordpress,woocommerce,coupon,Php,Wordpress,Woocommerce,Coupon,我需要创建2000张优惠券进行销售,但我希望使用它们的客户始终支付运费。目前,免费送货的门槛设定在69欧元以上。我尝试使用下面的代码(取自此处:) 但它适用于所有优惠券,我想只适用于前缀为“pd”的优惠券 add_filter( 'woocommerce_package_rates', 'coupons_removes_free_shipping', 10, 2 ); function coupons_removes_free_shipping( $rates, $package ) { if

我需要创建2000张优惠券进行销售,但我希望使用它们的客户始终支付运费。目前,免费送货的门槛设定在69欧元以上。我尝试使用下面的代码(取自此处:)

但它适用于所有优惠券,我想只适用于前缀为“pd”的优惠券

add_filter( 'woocommerce_package_rates', 'coupons_removes_free_shipping', 10, 2 );
function coupons_removes_free_shipping( $rates, $package ) {
if ( is_admin() && ! defined( 'DOING_AJAX' ) )
    return $rates;

$applied_coupons = WC()->cart->get_applied_coupons();

if( sizeof($applied_coupons) > 0 ) {
    // Loop through shipping rates
    foreach ( $rates as $rate_key => $rate ) {
        // Targeting "Free shipping" only
        if( 'free_shipping' === $rate->method_id  ) {
            unset($rates[$rate_key]); // Removing current method
        }
    }
}
return $rates;
}

检查
WC()->cart->get_applicated_优惠券()的输出
并查看您是否可以通过
$applicated\u-coups
访问优惠券名称。谢谢@dmanexe!我试试看!我必须说,我对php了解不多,这可能很难。你可以使用
print\u r
查看数组有什么:然后你可以通过这个完全虚构的示例访问特定优惠券:
$applicated\u-coups[“优惠券”][“名称”]
,完全取决于
$applicated\u-coups
的设置方式。谢谢@dmanexe!我马上试试:)检查
WC()->cart->get_applicated_coups()的输出
并查看您是否可以通过
$applicated\u-coups
访问优惠券名称。谢谢@dmanexe!我试试看!我必须说,我对php了解不多,这可能很难。你可以使用
print\u r
查看数组有什么:然后你可以通过这个完全虚构的示例访问特定优惠券:
$applicated\u-coups[“优惠券”][“名称”]
,完全取决于
$applicated\u-coups
的设置方式。谢谢@dmanexe!我马上试试:)