
Jashar
In Woocommerce versuche ich, die Schaltfläche „In den Warenkorb“ für Variationen mit einem bestimmten ausgewählten Wert für eines der Attribute auszublenden. Es gibt zwei Attribute für jede Variante (pa_color
und pa_size
) Zum Beispiel haben wir für ein variables Produkt diese Optionen:
1) Red - XL
2) Red - XXL
3) Blue - M
4) Blue - XL
Ich möchte die Schaltfläche „In den Einkaufswagen“ ausblenden XL
Benutzer konnten also keine Optionen mit XL zum Einkaufswagen hinzufügen (1 und 4 in diesem Beispiel).
PS: Wir möchten die Variation nicht deaktivieren, daher könnte das Variationsbild angezeigt werden, wenn Sie diese Option auswählen. Daher ist das Deaktivieren der Variation oder das Entfernen des Preises und … keine Lösung für uns.

LoicTheAztec
Hier ist der Weg zu machen Schaltfläche zum Warenkorb hinzufügen inaktiv auf Produktvariationen welches Produktattribut “pa_size” mit einer “XL” Wert:
add_filter( 'woocommerce_variation_is_purchasable', 'conditional_variation_is_purchasable', 20, 2 );
function conditional_variation_is_purchasable( $purchasable, $product ) {
## ---- Your settings ---- ##
$taxonomy = 'pa_size';
$term_name="XL";
## ---- The active code ---- ##
$found = false;
// Loop through all product attributes in the variation
foreach ( $product->get_variation_attributes() as $variation_attribute => $term_slug ){
$attribute_taxonomy = str_replace('attribute_', '', $variation_attribute); // The taxonomy
$term = get_term_by( 'slug', $term_slug, $taxonomy ); // The WP_Term object
// Searching for attribute 'pa_size' with value 'XL'
if($attribute_taxonomy == $taxonomy && $term->name == $term_name ){
$found = true;
break;
}
}
if( $found )
$purchasable = false;
return $purchasable;
}
Der Code wird in die function.php-Datei Ihres aktiven untergeordneten Designs (oder Designs) eingefügt. Getestet und funktioniert.
Verwenden Sie Ihren Slug-Text für term_name
add_filter( 'woocommerce_variation_is_purchasable', 'conditional_variation_is_purchasable', 20, 2 );
function conditional_variation_is_purchasable( $purchasable, $product ) {
## ---- Your settings ---- ##
$taxonomy = 'pa_size';
$term_name="XL";
## ---- The active code ---- ##
$found = false;
// Loop through all product attributes in the variation
foreach ( $product->get_variation_attributes() as $variation_attribute => $term_slug ){
$attribute_taxonomy = str_replace('attribute_', '', $variation_attribute); // The taxonomy
$term = get_term_by( 'slug', $term_slug, $taxonomy ); // The WP_Term object
// Searching for attribute 'pa_size' with value 'XL'
if($attribute_taxonomy == $taxonomy && $term->slug == $term_name ){
$found = true;
break;
}
}
if( $found )
$purchasable = false;
return $purchasable;
}
9175700cookie-checkAusblenden der Schaltfläche „In den Einkaufswagen“ in Woocommerce-Produktvariationen für einen bestimmten Attributwertyes