matep05
So ändern Sie eine WooCommerce-Schaltfläche zum Hinzufügen zum Warenkorb in der Produktlistenschleife, jedoch abhängig vom Produkttyp, wie zum Beispiel:
Für Produkte mit Variationen möchte ich einen Text im Warenkorb-Button zu: “Produkt anzeigen”
Für einfache Produkte “Produkt anzeigen”
Für Produkte, die nicht auf Lager sind: “Nicht verfügbar”
Ich habe es mit folgendem Code versucht, aber es funktioniert nicht:
add_filter( 'woocommerce_loop_add_to_cart_link', 'replace_loop_add_to_cart_button', 10, 2 );
function replace_loop_add_to_cart_button( $button, $product ) {
$button_text = __( "Out of stock", "woocommerce" );
return '<a class="view-product" href="' . $product->get_permalink() . '">' . $button_text . '</a>';
if( ! $product->managing_stock() && ! $product->is_in_stock() ) {
return $button;
}
if( $product->is_type( 'variable' ) ) return $button;
}
LoicTheAztec
Versuchen Sie stattdessen Folgendes:
add_filter( 'woocommerce_loop_add_to_cart_link', 'replace_loop_add_to_cart_button', 10, 2 );
function replace_loop_add_to_cart_button( $button, $product ) {
// Out of stock products
if( ! $product->is_in_stock() ) {
$button_text = __( "Unavailable", "woocommerce" );
}
// Simple and Variable products
elseif( $product->is_type( 'simple' ) || $product->is_type( 'variable' ) ) {
$button_text = __( "Show product", "woocommerce" );
}
// Other product types
else {
$button_text = add_to_cart_text();
}
return '<a class="view-product button" href="' . $product->get_permalink() . '">' . $button_text . '</a>';
}
Der Code wird in die Datei functions.php des aktiven untergeordneten Designs (oder aktiven Designs) eingefügt. Es sollte funktionieren
Sascha Kuzmenko
Um die WooCommerce-Schaltfläche Jetzt buchen zu ändern, habe ich dieses Plugin installiert https://wordpress.org/plugins/button-customizer-for-woocommerce/ und fügte 2 Filter zu functions.php hinzu und endlich funktioniert es
add_filter( 'woocommerce_booking_single_check_availability_text', 'wooninja_booking_check_availability_text' );
function wooninja_booking_check_availability_text() {
return "your text";
}
add_filter( 'woocommerce_booking_single_add_to_cart_text', 'wooninja_woocommerce_booking_single_add_to_cart_text' );
function wooninja_woocommerce_booking_single_add_to_cart_text() {
return "your text";
}
142654 0 0 cookie-check Ändern Sie die Schaltfläche „Zum Warenkorb hinzufügen“ und den Text basierend auf dem WooCommerce-Produkttyp yes