首页 文章

如何在自定义页面模板上添加woocommerce的默认产品排序?

提问于
浏览
2

我创建了一个自定义页面模板,在其中我使用WooCommerce函数加载产品列表,但不使用模板 . 但现在我想在我的自定义页面模板上实现默认的WooCommerce排序功能 . 我该如何实现呢?

我不想使用WooCommerce模板 . 我只想使用WooCommerce函数创建类似默认的排序函数 .

这是我的自定义页面模板代码:

<?php
/**
 Template Name: Shop page custom layout template
 */

get_header(); ?>

<?php
    $full_product_list = array();
$loop = new WP_Query( array( 'post_type' =>array( 'product', 'product_variation' ), 'posts_per_page' => -1,) );

while ( $loop->have_posts() ) : $loop->the_post();
    $theid = get_the_ID();
    $product = new WC_Product($theid); ?>
    <?php $product_url=$product->add_to_cart_url(); ?>
    <ul><li><a href="<?php echo get_the_permalink(); ?>">
<?php
   echo '<h3>' . get_the_title() . '</h3>';
    echo woocommerce_get_product_thumbnail();
    if ( $product->is_on_sale() ) : 
       echo apply_filters( 'woocommerce_sale_flash', '<span class="onsale">' . __( 'Sale!', 'woocommerce' ) . '</span>', $post, $product ); 
    endif; 
    if ( $price_html = $product->get_price_html() ) : ?>
    <span class="price"><?php echo $price_html; ?></span>
    <?php endif; 
    if ( $rating_html = $product->get_rating_html() ) : ?>
    <?php echo $rating_html; ?>
<?php endif; ?>

  <?php $cart_url="/construction/shop/?add-to-cart=".$theid; ?>
   <a class="button product_type_simple add_to_cart_button ajax_add_to_cart" data-product_sku="" data-product_id="<?php echo $theid ?>" data-quantity="1" href="<?php echo $cart_url; ?>" rel="nofollow">Add to cart</a>
    </a></li></ul>
<?php
endwhile; wp_reset_query();

?>
<?php get_footer(); ?>

1 回答

  • 0

    没有“默认的Woocommerce排序功能”,因为订单产品的显示取决于附加到显示产品的页面的功能 . 但假设您要按产品 Headers 排序,请将查询更改为:

    $loop = new wp_query(array('post_type' =>array('product', 'product_variation'), 'posts_per_page' => -1, 'orderby' => 'title', 'order' => 'ASC'));

    这将按 Headers 按升序排序,我猜是你想要的 .

相关问题