Open dajer93 opened 6 years ago
Hi Dajer,
Thanks for reaching out. I haven't looked into the WooCommerce fees API yet, and it's hard to tell what the issue is based on a single line. Would you mind sharing the full function/part of your code so that I can better understand the situation?
If you're not comfortable sharing the code publicly send me a private email at szelpeter@szelpeter.hu
Thanks, Peter
Sure, here you go:
add_action( 'woocommerce_cart_calculate_fees','jam_custom_delivery_charge' );
function jam_custom_delivery_charge() {
global $woocommerce;
if ( is_admin() && ! defined( 'DOING_AJAX' ) )
return;
// Milyen szállítási módot választott?
$chosen_shipping_rates = WC()->session->get( 'chosen_shipping_methods' );
// Milyen fizetési mód van kiválasztva?
$payment_method = WC()->session->get("chosen_payment_method");
// Mekkora a kosár össztömege?
$weight = $woocommerce->cart->cart_contents_weight;
// Mekkora a kosár összértéke?
$total = $woocommerce->cart->cart_contents_total;
if ( in_array( 'local_pickup:4', $chosen_shipping_rates ) ){
$delivery_charge = 0;
} else {
if ($weight < 2){
$based_on_weight = 1250;
} else if ($weight < 15){
$based_on_weight = 1500;
} else {
$based_on_weight = 2000;
}
switch ($payment_method) {
case 'cod':
# code...
if ($total < 10000){
$based_on_price = 550;
} else if ($total < 20000){
$based_on_price = 600;
} else if ($total < 50000){
$based_on_price = 800;
} else if ($total < 100000){
$based_on_price = 1100;
} else if ($total < 150000){
$based_on_price = 1350;
} else {
$based_on_price = $total * 0.01;
}
break;
default:
$based_on_price = 0;
break;
}
$delivery_charge = $based_on_weight + $based_on_price;
}
$woocommerce->cart->add_fee( 'Szállítási díj', $delivery_charge, true, '' );
}
The point of this code is to calculate shipping fee based on the selected shipping and payment method and the cart's sum weight and total. The last line $woocommerce->cart->add_fee( 'Szállítási díj', $delivery_charge, true, '' );
adds the calculated value as an additional fee to the order.
Thanks, Martin
Hi,
I'm opening this issue because: Additional fee charges are not showing up on the Barion Payment page.
I've added additional fee charges to the cart like this: $woocommerce->cart->add_fee( 'Szállítási díj', $delivery_charge, true, '' ); Everything works well, except on the Barion page within the details it shows "Szállítási díj" with a value of 0.
What's going wrong here?
Thanks