Created
April 15, 2021 10:25
-
-
Save xlplugins/16eccae9ad17bbf59bee1592e94bea33 to your computer and use it in GitHub Desktop.
custom upsell pricing based on order total #Upstroke
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
add_filter( 'wfocu_offer_data', 'wfocu_custom_alter_price', 12, 3 ); | |
function wfocu_custom_alter_price( $output, $offer_data, $is_front ) { | |
$percentage_discount_on_order = 50; //put your dynamic percentage discount amount here | |
if ( true === $is_front ) { | |
foreach ( $output->products as &$product ) { | |
if ( is_a( $product->data, 'WC_Product' ) ) { | |
$get_parent_order = WFOCU_Core()->data->get_parent_order(); | |
if ( ! $get_parent_order instanceof WC_Order ) { | |
continue; | |
} | |
$price_with_tax = $get_parent_order->get_total() - ( $get_parent_order->get_total() * ( $percentage_discount_on_order / 100 ) ); | |
$price_without_tax = $get_parent_order->get_subtotal() - ( $get_parent_order->get_subtotal() * ( $percentage_discount_on_order / 100 ) ); | |
$product->price = $price_with_tax; | |
$product->price_raw = $price_with_tax; | |
$product->sale_price_incl_tax = $price_with_tax; | |
$product->sale_price_excl_tax = $price_without_tax; | |
$product->tax = $product->sale_price_incl_tax - $product->sale_price_excl_tax; | |
} | |
} | |
} | |
return $output; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment