Created
June 10, 2024 04:50
-
-
Save braddalton/d50ee624495720656913b530df5e54e1 to your computer and use it in GitHub Desktop.
WooCommerce set % discount when 2 or more products are in shopping cart
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
function custom_cart_discount() { | |
$discount_percentage = 10; // Replace with your desired discount percentage | |
$cart = WC()->cart; | |
if ( $cart->get_cart_contents_count() >= 2 ) { | |
$discount = $cart->subtotal * ($discount_percentage / 100); | |
$cart->add_fee( 'Bulk Discount', -$discount ); | |
} | |
} | |
add_action( 'woocommerce_cart_calculate_fees', 'custom_cart_discount' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment