【发布时间】:2018-12-13 20:37:07
【问题描述】:
使用Hide shipping method for specific shipping classes in woocommerce 回答代码,我试图隐藏基于运输类别的运输选项。
大件和小件在我们的网站上都有自己的运输类别,我们只想为小件提供快递。
add_filter( 'woocommerce_package_rates', 'hide_shipping_method_based_on_shipping_class', 10, 2 );
function hide_shipping_method_based_on_shipping_class( $rates, $package )
{
if ( is_admin() && ! defined( 'DOING_AJAX' ) )
return;
// HERE define your shipping class to find
$class = 92;
// HERE define the shipping method to hide
$method_key_id = 'flat_rate:7';
// Checking in cart items
foreach( WC()->cart->get_cart() as $cart_item ){
// If we find the shipping class
if( $cart_item['data']->get_shipping_class_id() == $class ){
unset($rates[$method_key_id]); // Remove the targeted method
break; // Stop the loop
}
}
return $rates;
}
我了解如何实现代码,但是我不知道在哪里可以找到运输类 id,我只能找到 slug 和运输类名称
// HERE define your shipping class to find
$class = 92;
在上面的示例中,我在哪里可以找到替换 92 的 Id?
提前致谢。
会
【问题讨论】:
标签: php wordpress woocommerce