Title: Programmatically change shipping cost
Last modified: September 29, 2021

---

# Programmatically change shipping cost

 *  [yiangosv](https://wordpress.org/support/users/yiangosv/)
 * (@yiangosv)
 * [4 years, 8 months ago](https://wordpress.org/support/topic/programmatically-change-shipping-cost/)
 * 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?
 * The page I need help with: _[[log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fwordpress.org%2Fsupport%2Ftopic%2Fprogrammatically-change-shipping-cost%2F%3Foutput_format%3Dmd&locale=en_US)
   to see the link]_

Viewing 1 replies (of 1 total)

 *  Plugin Author [Keylor Mendoza](https://wordpress.org/support/users/keylorcr/)
 * (@keylorcr)
 * [4 years, 8 months ago](https://wordpress.org/support/topic/programmatically-change-shipping-cost/#post-14954859)
 * Hey [@yiangosv](https://wordpress.org/support/users/yiangosv/)
 * Checking out your code, the filters are working fine. What’s not, is how you 
   get the cart contents weight. Use this **foreach** instead
 *     ```
       foreach ( WC()->cart->get_cart() as $key => $cart_item ) {
       	$weight = $cart_item['data']->get_weight();
       	$total_weight += ( $cart_item['quantity'] * $weight );
       }
       ```
   
 * Let me know if it works for you
 * Regards

Viewing 1 replies (of 1 total)

The topic ‘Programmatically change shipping cost’ is closed to new replies.

 * ![](https://ps.w.org/wc-pickup-store/assets/icon-256x256.jpg?rev=2011755)
 * [WC Pickup Store](https://wordpress.org/plugins/wc-pickup-store/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/wc-pickup-store/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/wc-pickup-store/)
 * [Active Topics](https://wordpress.org/support/plugin/wc-pickup-store/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/wc-pickup-store/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/wc-pickup-store/reviews/)

 * 1 reply
 * 2 participants
 * Last reply from: [Keylor Mendoza](https://wordpress.org/support/users/keylorcr/)
 * Last activity: [4 years, 8 months ago](https://wordpress.org/support/topic/programmatically-change-shipping-cost/#post-14954859)
 * Status: not resolved