【发布时间】:2019-03-15 17:56:08
【问题描述】:
在 Woocommerce 中,我使用 WooCommerce Wholesale Pro Suite (来自 IgniteWoo) 和统一费率 Box Shipping 插件将 B2B 添加到我们的电子商店。
我正在尝试为特定的用户角色、客人和客户禁用统一费率箱式运输。我在网上搜索后找到了这段代码:
add_filter( 'woocommerce_package_rates', 'hide_shipping_for_user_role', 10, 2 );
function hide_shipping_for_user_role( $rates, $package ) {
// Role ID to be excluded
$excluded_role = "wholesale_customer";
// Shipping rate to be excluded
$shipping_id = 'table_rate_shipping_free-shipping';
// Get current user's role
$user = wp_get_current_user();
if ( empty( $user ) ) return false;
if( in_array( $excluded_role, (array) $user->roles ) && isset( $rates[ $shipping_id ] ) )
unset( $rates[ $shipping_id ] );
return $rates;
}
我应该使用什么来代替“wholesale_customer”和“table_rate_shipping_free-shipping”,这样就不会为客人和客户角色显示统一运费箱运费?
感谢任何帮助。
【问题讨论】:
标签: php wordpress woocommerce user-roles shipping-method