Pourriez-vous ajouter un hook filtre après le calcul du total du poids, afin de pouvoir ajouter du poids additionnel d’emballages selon des règles spécifiques ?
Fichier /includes/shipping/lpc_abstract_shipping.php
Méthode calculate_shipping()
foreach ($package['contents'] as $item) {
$product = $item['data'];
$totalWeight += (float) $product->get_weight() * $item['quantity'];
$cartShippingClasses[] = $product->get_shipping_class_id();
}
// Modification par dahive
$totalWeight = apply_filters( 'lpc_cart_total_weight', $totalWeight, $package );
Merci d’avance,
]]>I’d like to add the total order weight on the invoice, how can I do this via hook or editing the template? I’m currently using the free version ^^
Thank you!
]]>And thanks for providing a PDF invoice which actually works with custom-fields from checkout manager.
I miss total weight though and I have seen one ‘solved issue’ here – but it didn’t work for me.
How do I show total weight?
Thanks in advance
Mick, Denmark
]]>I have been playing around with this template and got some code working in it. However I’m not sure if this “Total Weight code” needs a child theme template or not. Otherwise next update it will be gone. Is there a way to add this to the Functions.php, or is creating another template in a Child Theme better?
wp-content/plugins/kadence-woocommerce-email-designer/templates/woo/emails/email-order-details.php
if ( ‘new_order’ != $email->id ) return;
$total_weight = 0;
foreach( $order->get_items() as $item_id => $product_item ){
$quantity = $product_item->get_quantity(); // get quantity
$product = $product_item->get_product(); // get the WC_Product object
$product_weight = $product->get_weight(); // get the product weight
// Add the line item weight to the total weight calculation
$total_weight += floatval( $product_weight * $quantity );
?>
<tr>
<th class=”td” scope=”row” colspan=”2″ style=”text-align:<?php echo esc_attr( $text_align ); ?>;”><?php esc_html_e( ‘Note:’, ‘woocommerce’ ); ?></th>
<td class=”td” style=”text-align:<?php echo esc_attr( $text_align ); ?>;”><?php echo wp_kses_post( nl2br( wptexturize( $order->get_customer_note() ) ) ); ?></td>
</tr>
<?php
}
I would like to add the total weight per product.
So if someone ordered 2 items it will show the weight of 2 products.
Right now it is showing the weight of only 1 product.
Kind regards,
Olga
For example – if I send 1 book, the shipping cost should be calculated on the weight of the book + the weight of the packaging. But if I send 2 books, the shipping cost is the weight of 2 books + the same weight of the packaging.
If I add the weight of the packaging to the product weight on the product page then the the total weight is overestimated if two or more copies of the book are added to the basket.
If it’s not possible to do this in the current version, would it be possible to add a “Packaging Weight” on the APG Shipping tabs of Shipping Zones ? This could function similar to the handling fee or additional fee categories, and be added to the total sum of the product weights.
]]>function order_custom_field_function_name($order)
{
$order_id = $order->id;
$items = $order->get_items();
$total_weight = 0;
foreach ($items as $item) {
$item_metas = get_post_meta($item['product_id']);
$weight = $item_metas['_weight']['0'];
$quantity = $item['qty'];
$item_weight = ($weight * $quantity);
$total_weight += $item_weight;
}
$total_weight = $total_weight / 1000;
echo "<p><strong>Total Weight: <span style='color:green;'>" . $total_weight . "</span></strong> kg</p>";
}
add_action('woocommerce_admin_order_data_after_billing_address', 'order_custom_field_function_name', 10, 1);
]]>