Issue
I have the following code which works very well, it shows me the text (CARRIER) only if the meta field of the order has a value, otherwise it doesn't show the text:
<?php
$text_order_meta = get_post_meta($order->get_order_number(), 'carrier_name', true);
if( ! empty($text_order_meta) )
{ ?> <p> <?php printf( '<b>CARRIER:</b> ' . esc_html( '%s', 'woocommerce' ), esc_html($text_order_meta) );?>
</p> <?php
}
?>
I want to do the something similar to display order items weight.
I know how to get the weight of each product, and to display it only if it has a value:
<?php $product; $attributes = $product->get_attributes(); if ( $product->has_weight() ) { echo $product->get_weight(); } ?>
How I get and display order items weight in WooCommerce?
Solution
You need to use wc_format_weight()
function to get the formatted weight, so just replace:
echo $product->get_weight();
with:
echo wc_format_weight($product->get_weight());
Answered By - LoicTheAztec Answer Checked By - Mary Flores (PHPFixing Volunteer)
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.