0

In woocommerce, I am trying to add a fee using this answer code:
Update fee dynamically based on radio buttons in Woocommerce checkout (credits: LoicTheAztec)

I need to update the code to add third conditional option to the fee like "ribbon" in this hooked function:

// Add a custom dynamic packaging fee
add_action( 'woocommerce_cart_calculate_fees', 'add_packaging_fee', 20, 1 );
function add_packaging_fee( $cart ) {
    if ( is_admin() && ! defined( 'DOING_AJAX' ) )
        return;

    $packing_fee = WC()->session->get( 'chosen_packing' ); // Dynamic packing fee
    $fee = $packing_fee == 'box' ? 9.00 : 3.00;
    $cart->add_fee( __( 'Packaging fee', 'woocommerce' ), $fee );
}

But I am stuck trying to add another entry with this line of code:

$fee = $packing_fee == 'box' ? 9.00 : 3.00;

How can I add an additional fee option?

LoicTheAztec
  • 229,944
  • 23
  • 356
  • 399
Omer
  • 11
  • 3
  • You have literally copied the code from one of my answers, without mentioning anything and without doing any changes… Your question is not clear as you don't explain what do you really want, how that is going to be **(what are the option prices)** … So you should clarify your answer editing it with care and details, as it's really unclear. – LoicTheAztec Apr 05 '18 at 22:42
  • if ($packing_fee == 'box') { $fee = 0.94; } elseif ($packing_fee == 'bag') { $fee = 0.42; } elseif ($packing_fee == 'bag1') { $fee = 2.05; } --- SOLVED – Omer Apr 05 '18 at 22:44
  • Sorry, have added now, I hadn't understood the conditional operator condition ? true : false – Omer Apr 05 '18 at 22:46
  • Next time, always mention the answer thread where you pick the code please… – LoicTheAztec Apr 05 '18 at 22:47
  • 1
    I added a comment, but they removed due to duplicated, I missed the reference - will remember next time, Thankyou Loic for amazing code. Made me turned hoops of that short if condition. – Omer Apr 05 '18 at 22:49

0 Answers0