Display Product Weight on Product Page and Shop Page
-
Hi,
I am using this code for products page but it is displaying the incorrect weight. Please advise.
add_action (‘woocommerce_single_product_summary’, ‘show_weight’, 20);
function show_weight() {
global $product;
$attributes = $product->get_attributes();
if ( $product->has_weight() ) {
print ‘<p>Weight: ‘.$product->get_weight().'</p>’.PHP_EOL;
}
}And using this code for shop page and this is also displaying incorrect weight.
/**
* Show product weight on archive pages
*/
add_action( ‘woocommerce_after_shop_loop_item’, ‘rs_show_weights’, 9 );function rs_show_weights() {
global $product;
$weight = $product->get_weight();if ( $product->has_weight() ) {
echo ‘<div class=”product-meta”><span class=”product-meta-label”> </span>’ . $weight . get_option(‘woocommerce_weight_unit’) . ‘</div></br>’;
}
}Thanks in advance
The page I need help with: [log in to see the link]
- The topic ‘Display Product Weight on Product Page and Shop Page’ is closed to new replies.