Sau đây là một số code ví dụ cách sử dụng wc_get_products để lấy sản phẩm trong woocommerce:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
<?php $args = array( 'featured' => true, 'status' => 'publish', 'limit' => 5 ); $product_featureds = wc_get_products( $args ); ?> <?php if($product_featureds){ foreach($product_featureds as $product_featured){ $link = get_permalink($product_featured->get_id()); ?> <div class="item-product col-lg-12 col-md-12 col-sm-12 col-xs-12"> <div class="products-entry clearfix product-wapper"> <div class="products-thumb"> <div class="product-thumb-hover"><a href="<?php echo $link; ?>" class="woocommerce-LoopProduct-link"> <?php echo $product_featured->get_image('thumbnail');; ?> </a></div> </div> <div class="products-content"> <h3 class="product-title"><a href="<?php echo $link; ?>"><?php echo $product_featured->get_title(); ?></a></h3> <span class="price"> <?php echo $product_featured->get_price_html(); ?> </span> </div> </div> </div> <?php } }?> |
1 2 3 4 |
$product->get_regular_price(); $product->get_sale_price(); $product->get_price(); // gets current active price. Can be sale or regular price. $product->get_price_html(); // gets formatted pric |
Mọi sự sao chép xin ghi rõ nguồn là fcwordpress.net
Chuyên trang về wordpress: hướng dẫn thiết kế theme, plugin, thủ thuật wordpress