Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- add_action( 'woocommerce_cart_calculate_fees', 'custom_handling_fee' );
- function custom_handling_fee ( $cart ) {
- if ( is_admin() && ! defined( 'DOING_AJAX' ) )
- return;
- $chosen_payment_id = WC()->session->get('chosen_payment_method');
- if ( empty( $chosen_payment_id ) )
- return;
- $subtotal = $cart->subtotal;
- // SETTINGS: Here set in the array the (payment Id) / (fee cost) pairs
- $targeted_payment_ids = array(
- 'cod' => 17, // Fixed fee
- );
- $minimum_amount = 500; // Amount needed for free shipping
- // Loop through defined payment Ids array
- if ( $subtotal < $minimum_amount ) {
- foreach ( $targeted_payment_ids as $payment_id => $fee_cost ) {
- if ( $chosen_payment_id === $payment_id) {
- $cart->add_fee( __('Plaćanje pouzećem', 'woocommerce'), $fee_cost, true );
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment