隐藏特定客户角色的特定送货方式

时间:2019-06-21 20:21:30

标签: php woocommerce roles shipping

我在WooCommerce中使用Wholesale Suite Premium Price插件。在15个职位中,我有6个特定的批发角色,我希望对这6个例外情况不加选择两种特定的运输方式。目前,我只是使用我发现并修改为特定条件的代码示例在我的登台服务器上尝试此操作。为此目的,以下工作吗?任何有关如何实现这一目标的见解将不胜感激。溶解

/* Hide specific shipping methods for specific wholesale roles */
add_filter( 'woocommerce_package_rates', function( $shipping_rates ) {
// User role and shipping method ID to hide for the user role
    $role_shipping_method_arr = array(
    'ws_silvia_silver' => array( 'Silvia Premium Standard Shipping (Tracking Service)'),
    'ws_silvia_silver_pst_exempt' => array( 'Silvia Premium Standard Shipping (Tracking Service)'),
    'ws_silvia_silver_tax_exempt' => array( 'Silvia Premium Standard Shipping (Tracking Service)'),
    'ws_silvia_silver' => array( 'Silvia Union Standard Shipping (Tracking Service)'),
    'ws_silvia_silver_pst_exempt' => array( 'Silvia Union Standard Shipping (Tracking Service)'),
    'ws_silvia_silver_tax_exempt' => array( 'Silvia Union Standard Shipping (Tracking Service)'),
    'ws_silvia_gold' =>    array( 'Silvia Premium Standard Shipping (Tracking Service)'),
    'ws_silvia_gold_pst_exempt' => array( 'Silvia Premium Standard Shipping (Tracking Service)'),
    'ws_silvia_gold_tax_exempt' => array( 'Silvia Premium Standard Shipping (Tracking Service)'),
    'ws_silvia_gold' =>    array( 'Silvia Union Standard Shipping (Tracking Service)'),
    'ws_silvia_gold_pst_exempt' => array( 'Silvia Union Standard Shipping (Tracking Service)'),
    'ws_silvia_gold_tax_exempt' => array( 'Silvia Union Standard Shipping (Tracking Service)'),
    );

    // Getting the current user role
    $curr_user = wp_get_current_user(); 
    $curr_user_data = get_userdata($current_user->ID); 

    // Wholesale Suite Roles 
    if (isset($current_user) && class_exists('WWP_Wholesale_Roles')) {
        $wwp_wholesale_roles = WWP_Wholesale_Roles::getInstance();
        $wwp_wholesale_role = $wwp_wholesale_roles->getUserWholesaleRole(); 

// Loop through the user role and shipping method pair
    foreach( $role_shipping_method_arr as $role => $shipping_methods_to_hide ) {

// Check if defined role exist in current user role or not
    if( in_array( $role, $current_user->roles) ) {

// Loop through all the shipping rates
    foreach( $shipping_rates as $shipping_method_key => $shipping_method ) {
$shipping_id = $shipping_method->get_id();

// Unset the shipping method if found
    if( in_array( $shipping_id, $shipping_methods_to_hide) ) {
unset($shipping_rates[$shipping_method_key]);
}
}
}
}
}
    return $shipping_rates;
});

0 个答案:

没有答案