Hàm lưu tự động lại tất cả bài viết theo post type tùy chỉnh
21/11/2024
02/06/2023 - 437
Tham khảo đoạn code trên
$product_id = get_the_ID(); // Lấy ID của sản phẩm
$product = wc_get_product( $product_id ); // Lấy đối tượng sản phẩm
// Debugging
//var_dump($product);
$upsells = $product->get_upsells();
// Hiển thị các sản phẩm upsell
if ( $upsells ) : ?>
<h2 style="text-transform: uppercase; font-size: 18px;border-bottom: 2px solid #e3e3e3;padding-bottom: 10px;margin-bottom: 20px;">Sản phẩm upsells</h2>
<div class="products row row-small large-columns-3 medium-columns-3 small-columns-1 has-equal-box-heights equalize-box">
<?php foreach ( $upsells as $upsell ) :
//echo $upsell;
setup_postdata( $GLOBALS['post'] =& $upsell );
wc_get_template_part( 'content', 'product' ); ?>
<?php endforeach; ?>
</div>
<?php endif;
wp_reset_postdata();
// Lấy danh sách sản phẩm bán chéo
$cross_sells = $product->get_cross_sells();
// Hiển thị các sản phẩm bán chéo
if ( $cross_sells ) : ?>
<h2 style="text-transform: uppercase; font-size: 18px;border-bottom: 2px solid #e3e3e3;padding-bottom: 10px;margin-bottom: 20px;margin-top: 20px;">Sản phẩm bán chéo</h2>
<div class="products row row-small large-columns-3 medium-columns-3 small-columns-1 has-equal-box-heights equalize-box">
<?php foreach ( $cross_sells as $cross_sell ) :
setup_postdata( $GLOBALS['post'] =& $cross_sell );
wc_get_template_part( 'content', 'product' ); ?>
<?php endforeach; ?>
</div>
<?php endif;
wp_reset_postdata();
