【发布时间】:2016-06-30 09:09:04
【问题描述】:
我创建了一个自定义页面模板,在该模板中我使用 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(); ?>
【问题讨论】:
标签: php wordpress templates woocommerce