Skip to content

Instantly share code, notes, and snippets.

@banna360
Last active August 22, 2020 12:39
Show Gist options
  • Save banna360/8e49a6f365e0ea7a00e2a1a9c8370a7e to your computer and use it in GitHub Desktop.
Save banna360/8e49a6f365e0ea7a00e2a1a9c8370a7e to your computer and use it in GitHub Desktop.
Woocommerce Price + Coupon Based Total Price Set
/// Custome Total Pirce Rule
function custom_calculated_total( $total, $cart ){
if ( is_admin() && ! defined( 'DOING_AJAX' ) ) return;
$coupons_50_price = array('sha001', 'sha002', 'sha003', 'sha004', 'sha005'); // Add add full list here
$coupons_100_price = array('sha301', 'sha302', 'sha303', 'sha304', 'sha305'); // Add add full list here
$coupons_200_price = array('sha601', 'sha602', 'sha603', 'sha604', 'sha605'); // Add add full list here
$applied_coupons = WC()->cart->get_applied_coupons();
if($applied_coupons) {
if(in_array($applied_coupons[0] , $coupons_50_price)) {
if( $total >= 50 && $total <= 100 ){
return 50;
}
}
if(in_array($applied_coupons[0] , $coupons_100_price)) {
if( $total >= 100 && $total <= 200 ){
return 100;
}
}
if(in_array($applied_coupons[0] , $coupons_200_price)) {
if( $total >= 200 && $total <= 300 ){
return 200;
}
}
}
else {
return $total;
}
}
add_filter( 'woocommerce_calculated_total', 'custom_calculated_total', 30, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment