# 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.

1. Locate `envoimoinscher_model.php` file.
2. 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;
}
```

1. 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'];
   }
}
```

1. 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;
}
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://kb.moomoo.agency/uni-cpo-4-documentation/plugins-compatibility/boxtal-how-to.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
