I am using the below code in functions.php on my WooCommerce store to add a fee at the checkout, when a specific promo code is being used
function conditional_custom_fee( $cart ) {
if ( is_admin() && ! defined( 'DOING_AJAX' ) )
return;
// HERE set your targeted coupon code
$coupon_code = 'ABC123' ;
// Check if our targeted coupon is applied
if( in_array( wc_format_coupon_code( $coupon_code ), $cart->get_applied_coupons() ) ){
$title = __('One-off fee', 'woocommerce'); // The fee title
$cost = 2.5; // The fee amount
// Adding the fee (not taxable)
$cart->add_fee( $title, $cost, false );
}
}
I would like to be able to use this rule on other promo codes, in addition to this one. As a PHP novice, how would I change this code to be able to use the code ABC123, or XYZ789, to apply this 2.5 fee?
Aucun commentaire:
Enregistrer un commentaire