Skip to content

Commit

Permalink
mb_substr replacement.
Browse files Browse the repository at this point in the history
  • Loading branch information
dennisnissle committed May 24, 2024
1 parent 4c49d9e commit 62ffa52
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
10 changes: 10 additions & 0 deletions includes/wc-gzd-shipment-functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -1569,3 +1569,13 @@ function wc_gzd_get_shipment_error( $error ) {
return \Vendidero\Germanized\Shipments\ShipmentError::from_wp_error( $error );
}
}

function wc_gzd_shipments_substring( $string, $start, $length = null ) {
if ( function_exists( 'mb_substr' ) ) {
$string = mb_substr( $string, $start, $length );
} else {
$string = substr( $string, $start, $length );
}

return $string;
}
4 changes: 2 additions & 2 deletions src/Labels/Label.php
Original file line number Diff line number Diff line change
Expand Up @@ -826,7 +826,7 @@ public function get_customs_data( $max_desc_length = 255 ) {
$customs_items[ $key ] = apply_filters(
"{$this->get_general_hook_prefix()}customs_item",
array(
'description' => apply_filters( "{$this->get_general_hook_prefix()}item_description", wc_clean( mb_substr( $single_item_description, 0, $max_desc_length ) ), $item, $this, $shipment ),
'description' => apply_filters( "{$this->get_general_hook_prefix()}item_description", wc_clean( wc_gzd_shipments_substring( $single_item_description, 0, $max_desc_length ) ), $item, $this, $shipment ),
'category' => apply_filters( "{$this->get_general_hook_prefix()}item_category", $category, $item, $this, $shipment ),
'origin_code' => ( $shipment_product && $shipment_product->get_manufacture_country() ) ? $shipment_product->get_manufacture_country() : Package::get_base_country(),
'tariff_number' => $shipment_product ? $shipment_product->get_hs_code() : '',
Expand All @@ -850,7 +850,7 @@ public function get_customs_data( $max_desc_length = 255 ) {
$total_value += (float) $customs_items[ $key ]['value'];
}

$item_description = mb_substr( $item_description, 0, $max_desc_length );
$item_description = wc_gzd_shipments_substring( $item_description, 0, $max_desc_length );

$customs_data = apply_filters(
"{$this->get_general_hook_prefix()}customs_data",
Expand Down

0 comments on commit 62ffa52

Please sign in to comment.