I’ve used a snippet to display the weight of jewellery in shop page of woocommerce. I’ve inserted the snippet in function.php file. But its displaying the weight below add to cart button. It must be displayed above the button.
here is the snippet
add_action( 'woocommerce_after_shop_loop_item', 'bbloomer_show_product_dimensions_loop', 20 );
function bbloomer_show_product_dimensions_loop() {
global $product;
$dimensions = $product->get_dimensions();
if ( ! empty( $dimensions ) ) {
echo '<div class="dimensions">';
echo '<br><b>Weight:</b> ' . $product->get_weight() . get_option( 'woocommerce_weight_unit' );
echo '</div>';
}
}
the weight must be printed above the add to cart button, what i’ve to change here.
2
Answers
You have to use the filter tag
woocommerce_loop_add_to_cart_link
and prepend your weight component HTML like this. Since it’s filter hook no need to echo the output just return the output HTML the tagwoocommerce_loop_add_to_cart_link
will handle that.Based on my own blog tutorial: How To Add Quantity Input In Shop Page
Visit source code if you want to learn how this filter
woocommerce_loop_add_to_cart_link
works internally.You can take the help of flex css for example: