shopp_apply_discount

runs once per active discount when the cart and order totals are being calculated

add_action('shopp_apply_discount', [callback]);

Description

Runs once for each active discount when the cart and order totals are being calculated, so if you have 3 active discounts in your store, this action will run 3 times. The callback function receives two variables: a boolean for whether or not the discount applies to the order, and the Discount object itself. The function should return true or false for whether or not the discount should be applied. You can use this action hook to extend the Discount logic and disable (or enable) discounts in situations they normally would apply.

Example: Removing a Free Shipping Promotion

// This example disables a Free Shipping discount to Alaska and Hawaii
add_action('shopp_apply_discount', 'no_free_shipping', 10, 2);
function no_free_shipping ( $apply, $Discount ) {
// set the ID of the Free Shipping promo
$shipping_promo = 1;
if ($Discount->id == $shipping_promo) {
    $Shipping = ShoppOrder()->Shipping;
    $Billing = ShoppOrder()->Billing;

    // Use the shipping state, with the billing state as a fallback
    $state = isset( $Shipping->state ) ? $Shipping->state : $Billing->state;
    if ( empty($state) || $state == "AK" || $state == "HI" ) return false;
}

return $apply;
}

See Also

You must be logged in to post a comment.

© Ingenesis Limited. Shopp™ is a registered trademark of Ingenesis Limited.

Skip to toolbar