1 回答

TA貢獻1776條經驗 獲得超12個贊
您的代碼$roles中存在一些錯誤,例如該鉤子參數(shù)不存在變量,還有一些其他錯誤……請嘗試以下操作:
add_filter( 'woocommerce_quantity_input_args', 'quantity_input_args_filter_callback', 10, 2 );
function quantity_input_args_filter_callback( $args, $product ) {
// HERE define the user role:
$user_role = 'customer_roles';
$user = wp_get_current_user(); // Get the WP_Use Object
// For a specific user role, we keep default woocommerce quantity settings
if( in_array( $user_role, $user->roles ) )
return $args; // Exit to default
// For the others as following
if ( is_singular( 'product' ) ) {
if( $product->get_id() == 85 ) {
$args['input_value'] = 30;
} else {
$args['input_value'] = 5;
}
}
if( $product->get_id() == 85 ) {
$args['min_value'] = 30;
$args['step'] = 5;
} else {
$args['min_value'] = 5;
$args['step'] = 5;
}
return $args;
}
代碼進入您的活動子主題(或活動主題)的function.php文件中。它應該工作。
- 1 回答
- 0 關注
- 172 瀏覽
添加回答
舉報