admin管理员组文章数量:1328021
I am trying to add order, sale count next to star rating at single product page, my store is built with WordPress and Woocommerce, I have tried a code but it adds this function before add to cart button/form.
Website URL for reference:
and image
Code:
add_action( 'woocommerce_before_add_to_cart_button', 'product_sold_count', 10 );
function product_sold_count() {
global $product;
$units_sold = $product->get_total_sales();
if ( $units_sold ) echo '<p>' . sprintf( __( 'Sold: %s', 'woocommerce' ), $units_sold ) . '</p>';
I will appreciate if anyone helps me in this matter.
I am trying to add order, sale count next to star rating at single product page, my store is built with WordPress and Woocommerce, I have tried a code but it adds this function before add to cart button/form.
Website URL for reference: https://techcart.pk
and image
Code:
add_action( 'woocommerce_before_add_to_cart_button', 'product_sold_count', 10 );
function product_sold_count() {
global $product;
$units_sold = $product->get_total_sales();
if ( $units_sold ) echo '<p>' . sprintf( __( 'Sold: %s', 'woocommerce' ), $units_sold ) . '</p>';
I will appreciate if anyone helps me in this matter.
Share Improve this question edited Jul 21, 2020 at 0:22 fuxia♦ 107k38 gold badges255 silver badges459 bronze badges asked Jul 20, 2020 at 16:45 Asif MughalAsif Mughal 11 bronze badge1 Answer
Reset to default 0For single product page, I tested it with the themes: ShoppingCart and Storefront and it works fine :
in function.php
:
function shoppingcart_setup(){
add_filter('woocommerce_short_description', function(){
global $product;
$units_sold = $product->get_total_sales();
if ( $units_sold ) return '<p>' . sprintf( __( 'Sold: %s', 'woocommerce' ), $units_sold ) . '</p>';
}, 10, 2);
}
add_action( 'after_setup_theme', 'shoppingcart_setup' );
Note: If you checked: Manage Stock, this code does not work
本文标签: Add sale count next to star rating in woocommerce single product page
版权声明:本文标题:Add sale count next to star rating in woocommerce single product page 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742245821a2439412.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论