Created
April 3, 2023 15:58
-
-
Save msulaimanmisri/9667b918c02b5eb3405163903b1ec019 to your computer and use it in GitHub Desktop.
This will turn Shipping fee based on Cart total
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
/** | |
* @author SulaimanMisri | |
* Load the logic | |
*/ | |
function makeShippingChangeBasedOnCartTotal( $cart ) { | |
if ( is_admin() && ! defined( 'DOING_AJAX' ) ) return; | |
$total = WC()->cart->subtotal; | |
if ( $total >= 100 ) { | |
$fee = 10; | |
} else { | |
$fee = 15; | |
} | |
$cart->add_fee( __( 'Shipping Fee', 'woocommerce' ), $fee, true, 'standard' ); | |
} | |
/** | |
* Run the logic | |
*/ | |
add_action( 'woocommerce_cart_calculate_fees', 'makeShippingChangeBasedOnCartTotal', 10, 1 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment