Skip to content

Instantly share code, notes, and snippets.

@WillBrubaker
Created September 4, 2015 02:08
Show Gist options
  • Save WillBrubaker/b87dafe5e17202462bc9 to your computer and use it in GitHub Desktop.
Save WillBrubaker/b87dafe5e17202462bc9 to your computer and use it in GitHub Desktop.
Apply WooCommerce Membership discount to a Subscription sign-up fee
add_filter( 'woocommerce_subscriptions_product_sign_up_fee', 'handsome_bearded_guy_filter_sign_up_fee', 10, 2 );
function handsome_bearded_guy_filter_sign_up_fee( $subscription_sign_up_fee, $product ) {
//this will only work if the necessary object and method are present
if ( class_exists( 'WC_Memberships_Member_Discounts' ) && method_exists( 'WC_Memberships_Member_Discounts', 'get_discounted_price' ) ) {
$discounter = new WC_Memberships_Member_Discounts;
//taken from WooCommerce Memberships
/**
* Get product discounted price for member
*
* @since 1.3.0
* @param int $base_price Original price
* @param int|WC_product $product Product ID or product object
* @param int $user_id Optional. Defaults to current user id.
* @return int|null discounted price, or null if no discount applies
*/
$discounted_fee = $discounter->get_discounted_price( $subscription_sign_up_fee, $product, null );
//see above - check here for null
//because if null, no discount applies but if not null, then set subscription sign up fee
//value to the discounted fee
$subscription_sign_up_fee = ( ! is_null( $discounted_fee ) ) ? $discounted_fee : $subscription_sign_up_fee;
}
return $subscription_sign_up_fee;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment