没有优惠券=免费送货,有优惠券=带有送货-WooCommerce

时间:2019-03-07 21:28:35

标签: php wordpress woocommerce

我的WooCommerce商店需要帮助。 满39欧元免运费。 如果我们的客户在使用优惠券后得到的价格低于39欧元,则不再免费送货。

例如:

客户在购物车中,完整的购物车金额为42€=免运费。

使用-15%的优惠券=购物车金额为38,55 =运费<-但这仍然是免费的

在我使用的插件中,我可以将设置设置为“允许免费送货”,但随后客户在获得优惠券的最低金额后即可免费送货,因此这对我们没有用。

我免费使用插件= WooCommerce扩展优惠券功能 Here!

希望你们明白我的意思

1 个答案:

答案 0 :(得分:1)

您可以通过使用简单的代码段来实现。

您需要配置一个免费送货,而没有任何最低订单金额固定费率以显示正常送货。

现在将以下代码段复制并粘贴到functions.php中。如果小计少于39,它将隐藏免费送货,否则将隐藏统一运费

add_filter( 'woocommerce_package_rates',  'modify_shipping_rate', 15, 2 );
function modify_shipping_rate( $available_shipping_methods, $package ){

    global $woocmmerce;
    $total_coast = WC()->cart->get_subtotal();

    if( $total_coast < 39 ){
        unset($available_shipping_methods['free_shipping:4']); // Config the Free Shipping method id properly
    }else{
        unset($available_shipping_methods['flat_rate:1']); //// Config the Flatrate shipping method id properly
    }

    return $available_shipping_methods;
}
相关问题