doulang1945 2019-05-11 00:35
浏览 20

我需要覆盖Woocommerce购物车购物车内容的重量

I have updated the functions.php file in my child theme with custom code to calculate the weight of items in the shopping cart based on what pallet they can fit on for delivery via truck.

Now I just need to update/override the cart weight with the $kilo_rate which is the value created by my script?

How do I set the shopping cart weight to $kilo_rate ??

<?php
add_filter( 'woocommerce_cart_item_name', 'showing_sku_in_cart_items', 99, 3 );
    $item_count  = 0;
    $volume = 0;
    $max_length = 0; 
    $max_width = 0; 
    $max_length_cart = 0; 
    $max_width_cart = 0; 
    $sample_count = 0; 
    $sample_count = 0; 
    $sample_count = "Short"; 

    
function showing_sku_in_cart_items( $item_name, $cart_item, $cart_item_key  ) {
    global $volume;
    global $max_length;
    global $max_width;
    global $max_length_cart;
    global $max_width_cart; 
    global $item_count ;
    global $pallet_size;
    global $cubic_rate;
    global $kilo_rate;

    
    // The WC_Product object
    $product = $cart_item['data'];
    // Get the  SKU
    $sku = $product->get_sku();
    //IGNORE samples from this list
    $sku_pref = substr($sku,0,2);
    
    
    // When sku doesn't exist
    if(empty($sku)) return $item_name;

    // Add the sku
    $item_name .= '<br><small class="product-sku">' . __( "SKU: ", "woocommerce") . $sku . '</small></br>';

    //if ($sku_pref != 'SM') $sku_num = substr($sku,-3);
    if ($sku_pref != 'SM'){ 
    $sku_num = substr($sku,-3);
    }else{
     $sample_count = $sample_count + 1; 
    }
    
    //get max pallet vol by product SKU
    if ($sku_num == '001'){ $max_length = 2.6; $max_width = 0.7; $pallet_size = "Long";}
    if ($sku_num == '002'){ $max_length = 2.6; $max_width = 0.8; $pallet_size = "Long";}
    if ($sku_num == '003'){ $max_length = 2.6; $max_width = 1.0; $pallet_size = "Long";}
    if ($sku_num == '004'){ $max_length = 3.2; $max_width = 0.7; $pallet_size = "Long";}
    if ($sku_num == '005'){ $max_length = 3.2; $max_width = 0.9; $pallet_size = "Long";}
    if ($sku_num == '006'){ $max_length = 3.2; $max_width = 1.0; $pallet_size = "Long";}
    if ($sku_num == '007'){ $max_length = 2.6; $max_width = 0.7; $pallet_size = "Long";}
    if ($sku_num == '008'){ $max_length = 3.2; $max_width = 0.7; $pallet_size = "Long";}
    if ($sku_num == '009'){ $max_length = 3.2; $max_width = 1.0; $pallet_size = "Long";}
    
    if ($sku_num == '010'){ $max_length = 1.2; $max_width = 0.7; }
    if ($sku_num == '011'){ $max_length = 1.2; $max_width = 0.9; }
    if ($sku_num == '012'){ $max_length = 1.2; $max_width = 1.0; }

    if ($sku_num == '013'){ $max_length = 2.6; $max_width = 1.0; $pallet_size = "Long";}
    
    if ($pallet_size != "Long") $max_width = 1.2;   
    
    //SET Max Volume to largest pallet based on largest piece selected
    if ($max_length_cart < $max_length) $max_length_cart =  $max_length;
    if ($max_width_cart < $max_width) $max_width_cart =  $max_width;
    

    
    $pallet_area = ($max_length_cart * $max_width_cart);
    

    global $woocommerce;
    $cart_items = $woocommerce->cart->cart_contents_count;

    $cart_less_samples = $cart_items - $sample_count;
    $cubic_rate = ($pallet_area *(($cart_less_samples * 0.06)+ 0.14));  
    
    $kilo_rate = 250 * $cubic_rate; 
    
    return $item_name."<strong> Cubic Rate: ".$cubic_rate." - Kilo Rate: ".$kilo_rate."</br>Pallet Size W: ".$max_width_cart."m L: ".$max_length_cart."m</strong>";
   
}

?>

</div>
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
    • ¥500 火焰左右视图、视差(基于双目相机)
    • ¥100 set_link_state
    • ¥15 虚幻5 UE美术毛发渲染
    • ¥15 CVRP 图论 物流运输优化
    • ¥15 Tableau online 嵌入ppt失败
    • ¥100 支付宝网页转账系统不识别账号
    • ¥15 基于单片机的靶位控制系统
    • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
    • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?