小编Sea*_*nns的帖子

Woocommerce,隐藏基于运输类的运输方式

我试图隐藏基于货运类的所有货运方法,当选择属于特定类的产品时,基本上强制采用FedEx隔夜方法.

我从这段代码开始,并按如下所示进行修改:

add_filter( 'woocommerce_available_shipping_methods', 'hide_shipping_based_on_class' ,    10, 1 );

function check_cart_for_share() {

// load the contents of the cart into an array.
global $woocommerce;
$cart = $woocommerce->cart->cart_contents;

$found = false;

// loop through the array looking for the tag you set. Switch to true if the tag is     found.
foreach ($cart as $array_item) {
$term_list = wp_get_post_terms( $array_item['product_id'], 'product_shipping_class', array( "fields" => "names" ) );

if (in_array("Frozen",$term_list)) {

      $found = true;
      break;
    }
}

return $found;

}

function …
Run Code Online (Sandbox Code Playgroud)

php wordpress fedex shipping woocommerce

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

标签 统计

fedex ×1

php ×1

shipping ×1

woocommerce ×1

wordpress ×1