슬러그가 performance_customer
인 맞춤형 사용자 역할을 설정했습니다. 현재 사용자가 "성과 고객"인지 확인하고 특정 카테고리의 제품에 특정 가격 할인을 적용 할 것인지 확인하고 있습니다.카트에 맞춤형 가격으로 제품을 추가 할 때 오류가 발생했습니다. - WooCommerce
여기 내 코드입니다 :
function return_custom_performance_dealer_price($price, $product) {
global $woocommerce;
global $post;
$terms = wp_get_post_terms($post->ID, 'product_cat');
foreach ($terms as $term) $categories[] = $term->slug;
$origPrice = get_post_meta(get_the_ID(), '_regular_price', true);
$price = $origPrice;
//check if user role is performance dealer
$current_user = wp_get_current_user();
if(in_array('performance_customer', $current_user->roles)){
//if is category performance hard parts
if(in_array('new-hard-parts-150', $categories)){
$price = $origPrice * .85;
}
//if is category performance clutches
elseif(in_array('performance-clutches-and-clutch-packs-150', $categories)){
$price = $origPrice * .75;
}
//if is any other category
else{
$price = $origPrice * .9;
}
}
return $price;
}
add_filter('woocommerce_get_price', 'return_custom_performance_dealer_price', 10, 2);
기능은 제품 루프에서 완벽하게 작동하지만, 나는 그것이 폭발 장바구니에 제품을 추가 if(in_array('CATEGORY_NAME_HERE', $categories)){
을 포함하는 각 줄을 나에게이 오류를 받았습니다.
Error: Warning:
in_array()
expects parameter 2 to be array, null given in…
나는 이것이 내가 각 제품이 속한 카테고리의 배열을 형성 wp_get_post_terms()
를 사용하는 위의 코드의 5 라인과 관련이있다 같은데요. 이 작업을 수행하는 방법을 잘 모르겠습니다.
을 작동합니다. 위대한 작품, 고마워요. –