Skip to content

Instantly share code, notes, and snippets.

@jeffreyvr
Created June 9, 2020 12:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jeffreyvr/f8f1ffe7ceb349e82347a87eaeef1acd to your computer and use it in GitHub Desktop.
Save jeffreyvr/f8f1ffe7ceb349e82347a87eaeef1acd to your computer and use it in GitHub Desktop.
Simply switching a WooCommerce coupon-code if a user is logged in.
<?php
add_action( 'woocommerce_before_calculate_totals', function () {
if ( is_user_logged_in() ) {
if ( in_array( 'highdiscount', WC()->cart->get_applied_coupons() ) ) {
WC()->cart->remove_coupon( 'highdiscount' );
WC()->cart->add_discount( 'lowdiscount' );
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment