小编Pit*_*yer的帖子

隐藏Woocommerce中基于产品类别的送货方式

使用Woocommerce,当购物车中已定义产品类别时,我想隐藏“本地取货”以外的所有运输方式…

下面的代码对其他产品类型(可变产品除外)执行此操作:

add_filter( 'woocommerce_package_rates', 'custom_shipping_methods', 100, 2 );
function custom_shipping_methods( $rates, $package ){

    // Define/replace here your correct category slug (!)
    $cat_slug = 'my_category_slug';
    $prod_cat = false;

    // Going through each item in cart to see if there is anyone of your category
    foreach ( WC()->cart->get_cart() as $values ) {
        $product = $values['data'];

        // compatibility with WC +3
        $product_id = method_exists( $product, 'get_id' ) ? $product->get_id() : $product->id;

        if ( has_term( $cat_slug, 'product_cat', $product_id ) )
            $prod_cat = true;
    } …
Run Code Online (Sandbox Code Playgroud)

php wordpress shipping custom-taxonomy woocommerce

1
推荐指数
1
解决办法
2070
查看次数

标签 统计

custom-taxonomy ×1

php ×1

shipping ×1

woocommerce ×1

wordpress ×1