Woocommerce ngày nay là plugin miễn phí hỗ trợ khiến cho 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 Anh chị hiển thị số lượng sản phẩm đã bán trong Woocommerce. Ngay hiện giờ, hãy thực hành ngay thôi nào.
Hiển thị số lượng sản phẩm đã bán trong Woocommerce
- Bước một: Các bạn đăng nhập vào trang quản trị của website.
- Bước hai: 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.
một. 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 />
|
một
2
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
hai . Nếu như hiện ở trang chủ thì 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 />
|
1
2
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>';
|
sở hữu THỂ BẠN để ý
- chỉ dẫn sử dụng Font Awesome 5 bản miễn phí
- cách 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 khuyến mại 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ị 2 vị trí cộng 1 khi thì tiêu 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 />
|
một
hai
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
hai
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 sở hữu thể khác nhé
Chúc bạn thành công !