Alright the issue that I am having is that I need to get multiple lines into a variable to output later in the code. my $pieces variable is not returning anything, much less missing parts of it, but even the text code is not returning.
foreach($packages as $pack)
{
$weight+=$pack->weight;
$items_no++;
$singleweight=$pack->weight;
$length=$pack->length;
$height=$pack->height;
$width=$pack->width;
$pieces .= '<piece actual_weight="'.$singleweight.'" length="'.$length.'" height="'.$height.'" width="'.$width.'">';
}
if(!empty($post_code) && $weight>0 && $items_no>0)
{
$data='?shipment='.urlencode('<shipment weight_system="IMPERIAL" shipper_number="'.$this->shipper_number.'" destination_postal_code="'.$post_code.'" service_type="'.$service.'">'.$pieces.'</shipment>').'&token='.$this->token;
// $woocommerce->add_message('Items No:'.$items_no.'- Postalcode:'.$post_code.'- ');
$resp=file_get_contents($this->canpar_url.$data,false,$context);
If I do this in another method that only requires a single line (getting the total weight and number of items) it works fine, but this does not return the proper shipping cost for low weight items. On a site where higher weight items is shipped the plugin works fine. However I need to modify it to work based on dimensions. The result I am looking for is something like this:
https://www.canpar.com/XML/RatingXML.jsp?shipment=
<shipment weight_system="IMPERIAL" shipper_number="42500047" destination_postal_code="M1M1M1" service_type="1">
<piece actual_wieght="7" length="24" height="24" width="24"/>
<piece actual_wieght="5" length="10" height="12" width="14"/>
</shipment>
&token=WZHBRS4KQYNA
using an output system I can output weight, packs, length, width, height but it does not return anything for $pieces and obviously shipping costs because I am getting an invalid xml response.
$woocommerce->add_message('Weight: '.$weight.' Packs: '.$items_no.' Shipping cost : '.$atts['total_charge'].' Pieces: '.$item_box.' Length: '.$length.' Width: '.$width.' Height: '.$height);