Hiển thị số sản phẩm đã bán trong woocommerce

Code dưới đây sẽ cho chúng ta số lượng sản phẩm đã bán ra của 1 sản phẩm nào đó trong trang single product.

Các bạn chỉ cần thêm đoạn code vào file functions.php của theme đang sử dụng là được

unit_sold

 

add_action( 'woocommerce_single_product_summary', 'wc_product_sold_count', 11 );
function wc_product_sold_count() {
 global $product;
 $units_sold = get_post_meta( $product->get_id(), 'total_sales', true );
 echo '<p>' . sprintf( __( 'Units Sold: %s', 'woocommerce' ), $units_sold ) . '</p>';
}

Xem thêm: http://gerhardpotgieter.com/2013/10/14/woocommerce-number-of-products-sold/

3.9/5 - (7 votes)
Từ khóa:
  • Bình luận
Sản phẩm nổi bật của Toản
x