Last active
November 21, 2018 20:28
-
-
Save jchristopher/ae8c9de0d9cdecc818c8db2ce1ba98c2 to your computer and use it in GitHub Desktop.
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
| <?php | |
| // Quick and dirty *AUTOMATIC* upgrade-only discount for EDD (no discount code) | |
| class SearchwpUpgradeDiscount { | |
| private $upgrade_discount = 30; // 30% discount | |
| private $applicable = false; | |
| function __construct() { | |
| add_filter( 'edd_get_cart_content_details_item_discount_amount', function( $discount, $item ) { | |
| if ( ! empty( $item['options']['is_upgrade'] ) ) { | |
| $this->applicable = true; | |
| $discount = floatval( $item['options']['cost'] * ( $this->upgrade_discount / 100 ) ); | |
| } | |
| return $discount; | |
| }, 10, 2); | |
| // Output a note next to the Total to reiterate the discount | |
| add_filter( 'edd_cart_total', function( $total ) { | |
| return $this->applicable ? $total . ' (upgrade discount)' : $total; | |
| }, 10, 3 ); | |
| } | |
| } | |
| new SearchwpUpgradeDiscount(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment