לפעמים אנחנו רוצים להתיג חלק מהומצרים כמוצר לרכישה ולפעמים נרצה שהם לא יופיעו כמוצר לרכישה אלא מעין תצוגת קטלוג.
נניח שיש לנו מותגים באתר המוגדרים כbrands – ברירת מחדל כל attribute שנוסיף יקבל קידומת של pa_ושם
אז לשם הדוגמה אם אנחנו רוצים להסתיר מוצרים ממותג בשם apple
נוסיף את הקוד הנל לתבנית או לתוסף כגון
add_filter( 'woocommerce_variation_is_purchasable', 'conditional_variation_is_purchasable', 20, 2 );
function conditional_variation_is_purchasable( $purchasable, $product ) {
\\כאן התנאי לפי מותג להחליף כמובן אבל אם זה לא השם הנכון..
$taxonomy = 'pa_brand';
$term_name = 'urbrand';
$found = false;
foreach ( $product->get_variation_attributes() as $variation_attribute => $term_slug ){
$attribute_taxonomy = str_replace('attribute_', '', $variation_attribute);
$term = get_term_by( 'slug', $term_slug, $taxonomy );
if($attribute_taxonomy == $taxonomy && $term->name == $term_name ){
$found = true;
break;
}
}
if( $found )
$purchasable = false;
return $purchasable;
}
כמובן יש להחליף לפי הצורך
📊 נתוני צפיות
סה"כ צפיות: 16
מבקרים ייחודיים: 16
- 🧍 172.71.146.230 (
United States)
- 🧍 172.71.151.221 (
United States)
- 🧍 141.101.76.104 (
Netherlands)
- 🧍 172.69.223.146 (
France)
- 🧍 172.71.118.244 (
France)
- 🧍 172.71.134.81 (
France)
- 🧍 172.71.146.200 (
United States)
- 🧍 172.68.23.134 (
United States)
- 🧍 162.158.42.214 (
United States)
- 🧍 172.71.119.51 (
France)
- 🧍 172.68.23.168 (
United States)
- 🧍 172.68.245.120 (
United States)
- 🧍 104.23.213.86 (
United States)
- 🧍 172.71.150.187 (
United States)
- 🧍 172.70.174.12 (
United States)
- 🧍 172.71.131.86 (
France)