admin管理员组文章数量:1430923
I am using Storefront theme with woocommerce and I want to create a custom layout in the shop page.
This custom layout has no product thumbnail the title and price must be inside the same div so I can easily customize it with css.
However when I try to get the price inside the h2 tags it doesn't has the result I expected. It appears but above the Title and outside the custom div. What am I doing wrong?
See image for reference
remove_action( 'woocommerce_shop_loop_item_title', 'woocommerce_template_loop_product_title', 10 );
add_filter( 'woocommerce_shop_loop_item_title' , 'custom_woocommerce_template_loop_product_title', 10);
function custom_woocommerce_template_loop_product_title () {
echo '
<div class="custom-title-wrapper">
<h1 class="woocommerce-loop-product__title custom-loop-product-title">' . get_the_title() . '</h1>
<h2>' . woocommerce_template_loop_price() . '</h2>
</div>'
;
}
I am using Storefront theme with woocommerce and I want to create a custom layout in the shop page.
This custom layout has no product thumbnail the title and price must be inside the same div so I can easily customize it with css.
However when I try to get the price inside the h2 tags it doesn't has the result I expected. It appears but above the Title and outside the custom div. What am I doing wrong?
See image for reference
remove_action( 'woocommerce_shop_loop_item_title', 'woocommerce_template_loop_product_title', 10 );
add_filter( 'woocommerce_shop_loop_item_title' , 'custom_woocommerce_template_loop_product_title', 10);
function custom_woocommerce_template_loop_product_title () {
echo '
<div class="custom-title-wrapper">
<h1 class="woocommerce-loop-product__title custom-loop-product-title">' . get_the_title() . '</h1>
<h2>' . woocommerce_template_loop_price() . '</h2>
</div>'
;
}
Share
Improve this question
asked Apr 17, 2019 at 11:18
João TeixeiraJoão Teixeira
1087 bronze badges
1 Answer
Reset to default 3It appears but above the Title and outside the custom div. What am I doing wrong?
It's because woocommerce_template_loop_price()
echoes the output.
So to fix the problem, just use ?> HTML here <?php
instead of echo 'HTML here';
:
function custom_woocommerce_template_loop_product_title() {
?>
<div class="custom-title-wrapper">
<h1 class="woocommerce-loop-product__title custom-loop-product-title"><?php the_title(); ?></h1>
<h2><?php woocommerce_template_loop_price(); ?></h2>
</div>
<?php
}
And (although this isn't a big issue,) you should use add_action()
and not add_filter()
because woocommerce_shop_loop_item_title
is an action and not a filter:
add_action( 'woocommerce_shop_loop_item_title', 'custom_woocommerce_template_loop_product_title', 10 );
本文标签: Woocommerce Shop Price Position
版权声明:本文标题:Woocommerce Shop Price Position 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745578032a2664450.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论