Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save msulaimanmisri/9667b918c02b5eb3405163903b1ec019 to your computer and use it in GitHub Desktop.
Save msulaimanmisri/9667b918c02b5eb3405163903b1ec019 to your computer and use it in GitHub Desktop.
This will turn Shipping fee based on Cart total
/**
* @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