This topic has 3 replies, 3 voices, and was last updated 2 months, 3 weeks ago ago by Andrew Mitchell
We have added the below code which is working with other themes but not with the Xstore store theme. Let us know the correct code. We need to display the weight the same as displayed on the homepage categories tabs.
add_action('woocommerce_after_shop_loop_item_title', 'show_weight', 20);
add_action('woocommerce_single_product_summary', 'show_weight', 20);
function show_weight() {
global $product;
// Ensure $product is defined on category/archive pages
if ( ! is_object( $product ) ) {
$product = wc_get_product( get_the_ID() );
}
$weight_unit = get_option('woocommerce_weight_unit');
if ( $product->has_weight() ) {
echo '<p><strong>Weight: ' . esc_html( $product->get_weight() . ' ' . $weight_unit ) . '</strong></p>';
}
}
Looking forward to your response.
best Regards,
Abhijit
Hi @Abhijit,
Please try with this hooks instead:
add_action('after_etheme_product_grid_list_product_element_title', 'show_weight', 20);
add_action('woocommerce_before_add_to_cart_form', 'show_weight', 20);
function show_weight() {
global $product;
// Ensure $product is defined on category/archive pages
if ( ! is_object( $product ) ) {
$product = wc_get_product( get_the_ID() );
}
$weight_unit = get_option('woocommerce_weight_unit');
if ( $product->has_weight() ) {
echo '<p><strong>Weight: ' . esc_html( $product->get_weight() . ' ' . $weight_unit ) . '</strong></p>';
}
}
You can find all the hooks of single product page here: https://www.businessbloomer.com/woocommerce-visual-hook-guide-single-product-page/.
Hope it helps!
Dear Abhijit,
In the spirit of gratitude, we want to express our appreciation for your trust in our products. As a valued customer, your experience matters greatly. Would you consider sharing it by giving our theme a deserving 5-star rating on ThemeForest?
Click here to share your thoughts: https://themeforest.net/downloads
Being part of our community means a lot, and your feedback contributes immensely.
Best Regards,
The 8Theme Team
The issue related to '‘Add action not working for the archive pages wc loop’' has been successfully resolved, and the topic is now closed for further responses