Home / Admin / Prevent Discounts on Upgrades
Duplicate Snippet

Embed Snippet on Your Site

Prevent Discounts on Upgrades

Does not allow a discount code to be applied when an license upgrade is present in the cart

Code Preview
php
<?php
function pw_edd_disable_discount_on_upgrade( $return ) {
    $cart_items = edd_get_cart_contents();
    if ( $cart_items ) {
        foreach ( $cart_items as $item ) {
            if ( isset( $item['options']['is_upgrade'] ) ) {
                $error_message = __( 'Discounts are not valid when upgrading.', 'edd' );
                edd_set_error( 'edd-discount-error', $error_message );
                return false;
            }
        }
    }
    return $return;
}
add_filter( 'edd_is_discount_valid', 'pw_edd_disable_discount_on_upgrade', 99, 1 );

Comments

Add a Comment