这是一件复杂的事情……你可以做的是检查购物车项目的允许装运国家,显示错误通知,并避免在客户国家与所有其他产品变体的允许国家不匹配时结帐。
下面为您的其他产品变体定义允许的可发货变体ID(国际)和允许的基本国家代码:
add_action( \'woocommerce_check_cart_items\', \'check_cart_items_for_shipping\' );
function check_cart_items_for_shipping() {
$allowed_variation_id = \'513\'; // Here defined the allowed Variation ID
$allowed_country = \'US\'; // Here define the allowed shipping country for all variations
$shipping_country = WC()->customer->get_shipping_country();
$countries = WC()->countries->get_countries();
// Loop through cart items
foreach(WC()->cart->get_cart() as $cart_item ) {
// Check cart item for defined product Ids and applied coupon
if( $shipping_country !== $allowed_country && $cart_item[\'variation_id\'] !== $allowed_variation_id ) {
wc_clear_notices(); // Clear all other notices
// Avoid checkout displaying an error notice
wc_add_notice( sprintf( __(\'The product "%s" can not be shipped to %s.\'),
$cart_item[\'data\']->get_name(),
$countries[$shipping_country]
), \'error\' );
break; // stop the loop
}
}
}
代码进入函数。活动子主题(或活动主题)的php文件。已测试并正常工作。