Skip to content

Instantly share code, notes, and snippets.

@jchristopher
Last active November 21, 2018 20:28
Show Gist options
  • Select an option

  • Save jchristopher/ae8c9de0d9cdecc818c8db2ce1ba98c2 to your computer and use it in GitHub Desktop.

Select an option

Save jchristopher/ae8c9de0d9cdecc818c8db2ce1ba98c2 to your computer and use it in GitHub Desktop.
<?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