-
-
Save xlplugins/f98d27307b41e26ce2bb000988539f03 to your computer and use it in GitHub Desktop.
Apply Discount on Regular price instead of sale price. if sale price configured at product level then we not apply sublium discount on Subscribe and save
This file contains hidden or 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
| /** | |
| * Force Sublium Subscribe & Save discount to calculate against | |
| * the product's regular price, not the sale price. | |
| * | |
| * Works on product page, cart, and checkout. | |
| * Place in your child theme's functions.php or a site-specific plugin. | |
| */ | |
| add_filter( 'sublium_wcs_plan_price', 'sublium_sns_discount_on_regular_price', 10, 3 ); | |
| function sublium_sns_discount_on_regular_price( $price, $product, $plan ) { | |
| // Only act on Subscribe & Save plans (type 1). | |
| if ( ! is_object( $plan ) || $plan->get_type() !== 1 ) { | |
| return $price; | |
| } | |
| // Only act when the product is on sale. | |
| if ( ! $product->is_on_sale() ) { | |
| return $price; | |
| } | |
| // Recalculate the discount from regular price instead. | |
| $regular_price = (float) $product->get_regular_price(); | |
| if ( $regular_price <= 0 ) { | |
| return $price; | |
| } | |
| return \Sublium_WCS\Includes\Helpers\Discount::calculate( | |
| $regular_price, | |
| $plan->get_plan_data(), | |
| $product | |
| ); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment