Created
February 4, 2019 01:40
-
-
Save CrispDev/dfeef5f75e79ba3ef191c73690ca0832 to your computer and use it in GitHub Desktop.
Adjust Checkout and Recurring Price based on Frequency and Type
This file contains 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
// Adjust Scheduled Order Checkout Price. | |
function xx_adjust_checkout_price( $checkout_price, $product_id, $frequency_type, $frequency ){ | |
// Adjust the checkout price based on the frequency and type | |
if ( ( 'Days' == $frequency_type ) && ( 1 == $frequency ) ){ | |
$discount_pct = .5; | |
} else if ( ( 'Weeks' == $frequency_type ) && ( 1 == $frequency ) ){ | |
$discount_pct = .25; | |
} else if ( ( 'Months' == $frequency_type ) && ( 1 == $frequency ) ){ | |
$discount_pct = .10; | |
} | |
return $checkout_price - round( $checkout_price * $discount_pct , 2 ); | |
} | |
add_filter( 'autoship_checkout_price', 'xx_adjust_checkout_price', 10, 4 ); | |
// Adjust Scheduled Order Recurring Price. | |
function xx_adjust_recurring_price( $scheduled_order_item_data, $frequency_type, $frequency ) { | |
// Adjust the recurring price based on the frequency and type | |
if ( ( 'Days' == $frequency_type ) && ( 1 == $frequency ) ){ | |
$discount_pct = .5; | |
} else if ( ( 'Weeks' == $frequency_type ) && ( 1 == $frequency ) ){ | |
$discount_pct = .25; | |
} else if ( ( 'Months' == $frequency_type ) && ( 1 == $frequency ) ){ | |
$discount_pct = .10; | |
} | |
$scheduled_order_item_data["SalePrice"] = $scheduled_order_item_data["Price"] - round( $scheduled_order_item_data["Price"] * $discount_pct , 2 ); | |
return $scheduled_order_item_data; | |
} | |
add_filter( 'autoship_get_scheduled_order_item_product_data', 'xx_adjust_recurring_price', 11, 3 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment