我需要覆盖Woocomerce购物车推车内容物重量

时间:2019-05-11 00:35:09

标签: php woocommerce hook-woocommerce

我已经用自定义代码更新了子主题中的functions.php文件,以根据购物车上适合通过卡车运送的货盘计算购物车中的物品重量。

现在我只需要用$ kilo_rate更新/覆盖购物车重量,这是我的脚本创建的值?

如何将购物车重量设置为$ 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>";
   
}

?>

0 个答案:

没有答案