• [ Moderator note: moved to How-to and Troubleshooting. ]

    We are developing the webpage for our e-commerce business and encounter the following problem. We sell teas and allow customers to choose to have their order in tea bag form for an added fee. Somehow the added fee is separated from the subtotal and thus excluded when applying coupons or calculating free shipping threshold. The code that governs the fee is as below in the functions.php file:

    [ Moderator note: code fixed. Please wrap code in the backtick character or use the code button. ]

    add_action( 'woocommerce_cart_calculate_fees', 'woo_add_cart_fee' );
    function woo_add_cart_fee() {

    global $woocommerce;

    $qtytotal = 0;
    $cnt = 0;
    $curr_cost = 0;
    foreach ($woocommerce->cart->get_cart() as $item) {

    $qty = $item['quantity'];
    $cost = get_post_meta($item['product_id'], 'customer_wants_tea_bag', false);

    if (!empty($cost)) {
    $qtytotal = $qty + $qtytotal;
    $curr_cost = $cost[0];
    }
    }
    $woocommerce->cart->add_fee( __('Packing', 'woocommerce'), $qtytotal * 6, TRUE);
    }

    Any idea as to how to change the fee as part of subtotal? Thank you very much in advance.

    Kirby

Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)

The topic ‘Checkout Coding – Fees Counting Towards Subtotal’ is closed to new replies.