Last active
March 26, 2021 08:38
-
-
Save wooexperte/9c8fc3bd862034283f67e8dda2016489 to your computer and use it in GitHub Desktop.
WooCommerce Gutschein und Coupon automatisch in den Warenkorb legen
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Das Snippet fügt im Warenkorb automatisch einen WooCommerce Gutschein hinzu und zeigt einen Hinweistext an. | |
Für das Snippet ist einen Gutschein mit dem Titel "COUPON" in WooCommerce notwendig. | |
*/ | |
add_action( 'woocommerce_before_cart' , 'add_coupon_notice' ); | |
add_action( 'woocommerce_before_checkout_form' , 'add_coupon_notice' ); | |
function add_coupon_notice() { | |
$cart_total = WC()->cart->get_subtotal(); | |
$minimum_amount = 50; | |
$currency_code = get_woocommerce_currency(); | |
wc_clear_notices(); | |
if ( $cart_total < $minimum_amount ) { | |
WC()->cart->remove_coupon( 'COUPON' ); | |
wc_print_notice( "Erhalten Sie 3% Rabatt bei einem Mindestbestellwert von $minimum_amount $currency_code!", 'notice' ); | |
} else { | |
WC()->cart->apply_coupon( 'COUPON' ); | |
wc_print_notice( 'Sie bekommen 3% Rabatt auf Ihre Bestellung!', 'notice' ); | |
} | |
wc_clear_notices(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment