Woocommerce ngày nay là plugin miễn phí tương trợ khiến website bán hàng trên WordPress rất rộng rãi. Ở bài viết này mình sẽ chỉ dẫn Cả nhà hiển thị số lượng sản phẩm đã bán trong Woocommerce. Ngay hiện nay, hãy thực hiện ngay thôi nào.
Hiển thị số lượng sản phẩm đã bán trong Woocommerce
- Bước 1: Các bạn đăng nhập vào trang quản trị của website.
- Bước 2: Vào mục
Giao diện →
Sửa giao diện →
function.php. - Bước 3: Anh chị thêm đoạn code bên dưới vào
function.php.
1. Này đang hiện thị ở trang sản phẩm dùng code sau :
<br /> add_action( 'woocommerce_single_product_summary', 'wc_product_sold_count', 11 );<br /> function wc_product_sold_count() <br /> global $product;<br /> $units_sold = get_post_meta( $product->get_id(), 'total_sales', true );<br /> echo '<p class="da-ban">' . Sprintf( __( 'Đã bán: %s', 'woocommerce' ), $units_sold ) . '≪/P>';<br />
|
1
hai
3
4
5
6
|
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 class="da-ban">' . Sprintf( __( 'Đã bán: %s', 'woocommerce' ), $units_sold ) . '≪/P>';
|
Hiển thị số lượng sản phẩm đã bán trong Woocommerce wordpress
2 . Nếu như hiện ở trang chủ thì tiêu dùng code
<br /> add_action( 'woocommerce_after_shop_loop_item_title', 'wc_product_sold_count' );<br /> function wc_product_sold_count() <br /> global $product;<br /> $units_sold = get_post_meta( $product->get_id(), 'total_sales', true );<br /> echo '<p class="da-ban">' . Sprintf( __( 'Đã bán: %s', 'woocommerce' ), $units_sold ) . '≪/P>';<br />
|
một
hai
3
4
5
6
|
add_action( 'woocommerce_after_shop_loop_item_title', 'wc_product_sold_count' );
function wc_product_sold_count()
global $product;
$units_sold = get_post_meta( $product->get_id(), 'total_sales', true );
echo '<p class="da-ban">' . Sprintf( __( 'Đã bán: %s', 'woocommerce' ), $units_sold ) . '≪/P>';
|
có THỂ BẠN để ý
- chỉ dẫn sử dụng Font Awesome 5 bản miễn phí
- bí quyết chặn ko cho user cài đặt thêm Plugin giúp website bảo mật hơn
- Thêm Block Share cho web theme Flatsome
- Lightbox Flatsome – Thêm form đăng ký newsletter
- Coupon mới giảm giá 80% Hosting tại StableHost
- Fix lỗi No URLs waiting lớn be saved trong Content crawler
3. Còn nếu như muốn hiện thị hai vị trí cộng 1 khi thì sử dụng code này
<br /> add_action( 'woocommerce_after_shop_loop_item_title', 'wc_product_sold_count' );<br /> add_action( 'woocommerce_single_product_summary', 'wc_product_sold_count', 11 );<br /> function wc_product_sold_count() <br /> global $product;<br /> $units_sold = get_post_meta( $product->get_id(), 'total_sales', true );<br /> echo '<p class="da-ban">' . Sprintf( __( 'Đã bán: %s', 'woocommerce' ), $units_sold ) . '≪/P>';<br />
|
1
2
3
4
5
6
7
|
add_action( 'woocommerce_after_shop_loop_item_title', 'wc_product_sold_count' );
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 class="da-ban">' . Sprintf( __( 'Đã bán: %s', 'woocommerce' ), $units_sold ) . '≪/P>';
|
note : chỉ là thêm hook vào vị trí ( hai vị trí ) thôi nhé
OK rồi nhé , css cho đẹp hơn nè bà con
<br /> p.da-ban <br /> border-radius: 20px;<br /> margin-bottom: 0;<br /> text-align: center;<br /> margin-top: 5px;<br /> background-color: rgba(210,33,33,.4);<br /> background-image: none;<br /> margin-left: 10px;<br /> margin-right: 10px;<br /> position: relative;<br /> height: 25px;<br /> margin-bottom: 10px;<br /> color: #fff;<br /> -webkit-box-shadow: none;<br /> box-shadow: none;<br />
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
|
p.da-ban
border-radius: 20px;
margin-bottom: 0;
text-align: center;
margin-top: 5px;
background-color: rgba(210,33,33,.4);
background-image: none;
margin-left: 10px;
margin-right: 10px;
position: relative;
height: 25px;
margin-bottom: 10px;
color: #fff;
-webkit-box-shadow: none;
box-shadow: none;
|
Note : do minh đặt class da-ban , name class của bạn có thể khác nhé
Chúc bạn thành công !