logo

Pablo Guides

לפעמים אנחנו רוצים להתיג חלק מהומצרים כמוצר לרכישה ולפעמים נרצה שהם לא יופיעו כמוצר לרכישה אלא מעין תצוגת קטלוג.

נניח שיש לנו מותגים באתר המוגדרים כ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;
}


כמובן יש להחליף לפי הצורך

Pablo Guides