Skip to content

Instantly share code, notes, and snippets.

@braddalton
Created June 10, 2024 04:50
Show Gist options
  • Save braddalton/d50ee624495720656913b530df5e54e1 to your computer and use it in GitHub Desktop.
Save braddalton/d50ee624495720656913b530df5e54e1 to your computer and use it in GitHub Desktop.
WooCommerce set % discount when 2 or more products are in shopping cart
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