Quantcast
Channel: WordPress.org Forums » All Topics
Viewing all articles
Browse latest Browse all 59525

Programmatically change shipping cost

$
0
0

Replies: 0

Hello

i am changing programmatically the cost for pickup store based on the items weight using the below code

but the shipping costs does not change on the order review page. I can see that in the cart section the price is update correctly but in order review it shows the default value defined in plugin settings

`function kmchild_update_wps_shipping_costs($cost) {
$calculate_costs=get_calculate_shipping();
return get_calculate_shipping();
}
add_filter(‘wps_shipping_costs’, ‘kmchild_update_wps_shipping_costs’, 100);

function kmchild_wps_formatted_shipping_title( $formatted_title, $title, $calculated_costs ) {
$calculate_costs=get_calculate_shipping();
return $title . ” €” . get_calculate_shipping();
}

add_filter(‘wps_formatted_shipping_title’, ‘kmchild_wps_formatted_shipping_title’, 10, 3);

function get_calculate_shipping() {
$total_weight=0;
foreach ( WC()->cart->get_cart() as $key => $values ) {
$p_id = $values[‘data’]->get_id();
$p_quantity = $values[‘quantity’];
$weight=get_post_meta($p_id,’_weight’);
$weight=($weight[0])*$p_quantity;
$total_weight=$total_weight+$weight;
}
if ($total_weight>0 && $total_weight<=10)
{return 5;}
if ($total_weight>10 && $total_weight<=15)
{return 6;}
if ($total_weight>15 && $total_weight<=25)
{return 8;}
if ($total_weight>25 && $total_weight<=30)
{return 10;}
if ($total_weight>30 && $total_weight<=35)
{return 15;}
if ($total_weight>35 && $total_weight<=40)
{return 20;}
if ($total_weight>40)
{return 25;}

}

can you please assist as why on order review page the shipping fee does not change?


Viewing all articles
Browse latest Browse all 59525

Trending Articles