cedricdc
Forum Replies Created
-
Absolutely no idea?
I have the same problem:
See my website
Testimonials are below the corksWhen I use the code in my first post (with $country and $shipping_country, the country is not correct when I execute my function.
So now I am trying to find tot correct function to get thema chosen countrycode, and to make my if-function work ??Regards,
CedricForum: Plugins
In reply to: [WooCommerce] Subtotal cart variable phpTo be clear, I want to use following rules:
When you chose to pick up to items: extra fee = 0
When you chose to deliver the items:
– Amount (subtotal before discount) is below €250:
– between 1 – 6 items: extra fee = 8,7
– between 7 – 12 items: extra fee = 10,6
– …
– Amount (subtotal before discount) is above €250: extra fee = 0I have following code:
add_action('woocommerce_cart_calculate_fees' , 'add_custom_fees'); function add_custom_fees( WC_Cart $cart ){ $fees = 0; $aantal_items = 0; $min_order = 250.00; $country_shipping = WC()->countries->countries[ $order->shipping_country ]; $country = $country_shipping[0]; $chosen_methods = WC()->session->get( 'chosen_shipping_methods' ); $chosen_shipping = $chosen_methods[0]; foreach( $cart->get_cart() as $item ){ $aantal_items = $aantal_items + $item['quantity']; } $session_cart = $woocommerce->session->cart; if(count($session_cart) > 0) { $total = 0; foreach($session_cart as $cart_product) $total = $total + $cart_product['line_subtotal']; } //PICKUP if ($chosen_shipping == 'local_pickup') {$fees = 0;} //DELIVERY elseif ($chosen_shipping == 'woocommerce_flatrate_percountry') { if ($total < $min_order and $aantal_items >= 1 and $aantal_items <= 6) {$fees = 8.7;} elseif ($total < $min_order and $aantal_items >= 7 and $aantal_items <= 12) {$fees = 10.6;} elseif ($total < $min_order and $aantal_items >= 13 and $aantal_items <= 18) {$fees = 11.8;} elseif ($total < $min_order and $aantal_items >= 19 and $aantal_items <= 24) {$fees = 20.5;} elseif ($total < $min_order and $aantal_items >= 25 and $aantal_items <= 30) {$fees = 22.4;} elseif ($total < $min_order and $aantal_items >= 31 and $aantal_items <= 36) {$fees = 23.6;} elseif ($total < $min_order and $aantal_items >= 37 and $aantal_items <= 42) {$fees = 32.3;} elseif ($total < $min_order and $aantal_items >= 43 and $aantal_items <= 48) {$fees = 34.2;} elseif ($total < $min_order and $aantal_items >= 49 and $aantal_items <= 54) {$fees = 35.4;} elseif ($total >= $min_order) {$fees = 0;} else {$fees = 60;} } $cart->add_fee( 'Verpakkingskosten', $fees); }
Forum: Plugins
In reply to: [WooCommerce] Subtotal cart variable phpI found something like this, be it doesn’t seem to work..
$session_cart = $woocommerce->session->cart; if(count($session_cart) > 0) { $total = 0; foreach($session_cart as $cart_product) $total = $total + $cart_product['line_subtotal']; }