• Hi there,

    I try to get an extra fee on cart page depending on the delivery method and the subtotal.

    If subtotal is bigger 100 and delivery is flat rate -> 6,00€
    If subtotal is bigger 100 and delivery is international_delivery -> 12,00€
    If none of those = 0

    Now I’ve tried it with this code:

    function add_fee() {
        global $woocommerce;
        $subtotal = (int)$woocommerce->cart->subtotal;
        $versand = WC()->session->get( 'chosen_shipping_methods' );
        if($subtotal > '100' ) {
            if($versand = 'international_delivery') {
                $fee_value = 6;
            }
            else {
                $fee_value = 12;
            }
            $woocommerce->cart->add_fee( 'weiteres Paket (Pauschale)', $fee_value, $taxable = false,'');
    }}
    add_action( 'woocommerce_cart_calculate_fees', 'add_fee' );

    If the subtotal is less 100 it shows nothing. If it is about 100 it shows the 6,00€ fee. But if I change the delivery method to international it shows also 6,00€.

    I think that there is a problem getting the delivery method.

    A var_dump($versand) shows

    array(1) { [0]=> string(22) "international_delivery" }

    Any ideas to get the delivery_method n a good way?

    Thanks and regards

    Thorsten

    https://wordpress.org/plugins/woocommerce/

The topic ‘Get delivery method in if-statement’ is closed to new replies.