首页 文章

如何改变methor免费送货跟随woocommerce中的价格产品

提问于
浏览
0

我尝试在插件woocommerce wordpress中定制统一费率,违约统一费率任何类45美元,但我想要的产品有11美元的价格将免费送货 . 请帮我!

add_filter('woocommerce_shipping_free_shipping_is_available', 'diy_free_delivery');
 function diy_free_delivery($rates, $package){
    $product = new WC_Product();
    $price = $product->regular_price;
    if($price > 11){
        unset( $rates['flat_rate'] );

        $free_shipping = $rates['free_shipping'];
        $rates         = array();
        $rates['free_shipping'] = $free_shipping;
    }
    return $rates;
 }

1 回答

  • 0

    您应该使用woocommerce_package_rates过滤器来确定哪些出货选项可用,具体取决于购物车的 Value . 过滤器将传入 $available_methods ,您可以使用WC()->get_cart_subtotal()根据购物车的 Value 在功能中修改 .

    add_filter( 'woocommerce_package_rates', 'diy_free_delivery' );
    function diy_free_delivery( $available_methods ){
        // check to see if the cart total is more than $11
        if ( WC()->get_cart_subtotal() > 11 ){
            // if it is we *only* want to show the free shipping
            return array( 'free_shipping' => $available_methods['free_shipping'] );
        } else {
            // if not we want to remove free_shipping and return the other methods
            unset( $available_methods['free_shipping'] );
            return $available_methods;
        }
    }
    

相关问题