Boxtal
It is possible to make Boxtal plugin to get weight calculated from Uni CPO and calculate its shipping rate based on this weight. However, some Boxtal functions must be modified prior that. We know that it is not good to do that, but we had no choice as Boxtal plugin does not have enough filters to make the integration in better way.
Locate
envoimoinscher_model.php
file.Replace this function:
static function get_weight_from_order($order) {
$total_weight = 0;
foreach( $order->get_items( 'line_item' ) as $item ) {
$product_id = ( $item['variation_id'] != 0 ? $item['variation_id'] : $item['product_id'] );
$product_weight=self::get_product_weight($product_id);
$total_weight += (int)$item['qty'] * (float)$product_weight;
}
return (float)$total_weight;
}
with this one:
static function get_weight_from_order($order) {
$total_weight = 0;
foreach( $order->get_items( 'line_item' ) as $item ) {
$product_id = ( $item['variation_id'] != 0 ? $item['variation_id'] : $item['product_id'] );
$product_weight=self::get_product_weight($product_id);
$product_weight = apply_filters( 'envoimoinscher_order_line_item_weight', $product_weight, $item );
$total_weight += (int)$item['qty'] * (float)$product_weight;
}
return (float)$total_weight;
}
Find
split_package_get_quotation
function and replace this piece of the code:
foreach($best_fits[$i] as $fit_item){
$product_id = $fit_item['variation_id'] != 0 ? $fit_item['variation_id'] : $fit_item['product_id'];
$fit_weight += (float)self::get_product_weight($product_id) * $fit_item['quantity'];
}
with this one:
foreach($best_fits[$i] as $fit_item){
if ( $fit_item['data']->get_weight() ) { // implementing integration with Uni CPO
$fit_weight += $fit_item['data']->get_weight() * $fit_item['quantity'];
} else {
$product_id = $fit_item['variation_id'] != 0 ? $fit_item['variation_id'] : $fit_item['product_id'];
$fit_weight += (float)self::get_product_weight($product_id) * $fit_item['quantity'];
}
}
Replace this function:
static function get_cart_weight() {
$weight = 0;
foreach ( WC()->cart->get_cart() as $item_id => $item ) {
$_product = $item['data'];
if($item['data']->needs_shipping()){
$product_id = ( $item['variation_id'] != 0 ? $item['variation_id'] : $item['product_id'] );
$weight += self::get_product_weight($product_id)*$item['quantity'];
}
}
return $weight;
}
with this one:
static function get_cart_weight() {
$weight = 0;
foreach ( WC()->cart->get_cart() as $item_id => $item ) {
$_product = $item['data'];
if($item['data']->needs_shipping()){
if ( $item['data']->get_weight() ) {
$weight += $item['data']->get_weight() * $item['quantity'];
} else {
$product_id = ( $item['variation_id'] != 0 ? $item['variation_id'] : $item['product_id'] );
$weight += self::get_product_weight( $product_id ) * $item['quantity'];
}
}
}
return $weight;
}
Last updated
Was this helpful?