Editing a function, so it displays PRODUCTS * FEE instead of PRODUCTS + FEE
-
Hello there!
I friend recently helped me and wrote this code for me, and it works great, however, something’s not right.
We added 2 checkboxes to checkout, so a customer can choose if they want us to do the assembly or if they want to do it themselves. The checkboxes do exactly that.
BUT, the problem is if there are more than 1 products. The assembly fee is fixed and it doesn’t matter if I have 1 product or 5 products – the price is still the same.
What I need is the assembly fee to be multiplied by each product.This is the code that I have:
// Part 1 // Display Radio Buttons add_action( 'woocommerce_review_order_before_payment', 'ahirwp_checkout_radio_choice' ); function ahirwp_checkout_radio_choice() { $chosen = WC()->session->get( 'radio_chosen' ); $chosen = empty( $chosen ) ? WC()->checkout->get_value( 'radio_choice' ) : $chosen; $chosen = empty( $chosen ) ? '0' : $chosen; $args = array( 'type' => 'radio', 'class' => array( 'form-row-wide', 'update_totals_on_change' ), 'options' => array( '0' => 'Brez monta?e', '170' => 'Monta?a - 170 €', ), 'default' => $chosen ); echo '<div id="checkout-radio">'; echo '<h3>Monta?a v 14 dneh (prostor mora biti predpripravljen!)</h3>'; woocommerce_form_field( 'radio_choice', $args, $chosen ); echo '</div>'; } // Part 2 // Add Fee and Calculate Total add_action( 'woocommerce_cart_calculate_fees', 'ahirwp_checkout_radio_choice_fee', 20, 1 ); function ahirwp_checkout_radio_choice_fee( $cart ) { if ( is_admin() && ! defined( 'DOING_AJAX' ) ) return; $radio = WC()->session->get( 'radio_chosen' ); if ( $radio ) { $cart->add_fee( 'Monta?a', $radio ); } } // Part 3 // Add Radio Choice to Session add_action( 'woocommerce_checkout_update_order_review', 'ahirwp_checkout_radio_choice_set_session' ); function ahirwp_checkout_radio_choice_set_session( $posted_data ) { parse_str( $posted_data, $output ); if ( isset( $output['radio_choice'] ) ){ WC()->session->set( 'radio_chosen', $output['radio_choice'] ); } }
Please help me out!
Kind regards
The page I need help with: [log in to see the link]
Viewing 5 replies - 1 through 5 (of 5 total)
Viewing 5 replies - 1 through 5 (of 5 total)
- The topic ‘Editing a function, so it displays PRODUCTS * FEE instead of PRODUCTS + FEE’ is closed to new replies.