dow5001
2018-10-10 18:34
浏览 45
已采纳

隐藏Woocommerce中特定用户角色的特定送货方式

In Woocommerce I am using WooCommerce Wholesale Pro Suite (from IgniteWoo) and Flat Rate Box Shipping plugins to add B2B to our eshop.

I am trying to disable the Flat Rate Box Shipping for specific user roles, guests and customers. I found this code after searching online:

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;
}

What should I use in place of "wholesale_customer" and in place of "table_rate_shipping_free-shipping", so the Flat Rate Box Shipping is not showing, for guests and customers roles?

Any help is appreciated.

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

1条回答 默认 最新

相关推荐 更多相似问题