php – 我需要在woocommerce中添加自定义查询并添加到购物车按钮动态代码?
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了php – 我需要在woocommerce中添加自定义查询并添加到购物车按钮动态代码?,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含3552字,纯文字阅读大概需要6分钟。
内容图文
![php – 我需要在woocommerce中添加自定义查询并添加到购物车按钮动态代码?](/upload/InfoBanner/zyjiaocheng/733/70a86807b67542e09f5b2391c75f041e.jpg)
我为我的WordPress网站制作了自定义模板.所以我需要动态地在我的自定义模板中显示我的产品.我怎样才能做到这一点?
这是我的HTML代码 – >
<div class="all_content_shop">
<div class="col-md-3 single_all_c_s">
<div class="shop_product_inner">
<a href="<?php echo get_permalink( $loop->post->ID ) ?>">
<img src="http://jetsetbabies.com/wp-content/uploads/2006/07/100Juice_Organic_Apple_MAIN_v2.jpg" alt="Prduct Image" />
<div class="shop_product_inner_caption">
<h2>Product Title</h2>
<p>$200</p>
<a href="">Add to Cart</a>
</div>
</a>
</div>
</div>
</div>
================================================
另外我是简单的查询,但我没有找到添加到购物车按钮动态代码???
这是我的查询代码—->
<div class="all_content_shop">
<?php $new_posts = new WP_Query(array(
'post_type' => 'product', //post of page of my post type
'cat' => 0, // category id, 0 for all categories.
'posts_per_page' => 12,
'offset' => 0, //how many posts you want to eliminate from the query
'orderby' => '', // order by title or date ?
'order' => 'DESC') // order as ASC or DESC
); ?>
<?php if ($new_posts->have_posts()) :
while ($new_posts->have_posts()) :
$new_posts->the_post(); ?>
<div class="col-md-3 single_all_c_s">
<div class="shop_product_inner">
<a href="<?php echo get_permalink( $loop->post->ID ) ?>">
<?php if (has_post_thumbnail( $loop->post->ID )) echo get_the_post_thumbnail($loop->post->ID, 'shop_single'); else echo '<img src="'.woocommerce_placeholder_img_src().'" alt="Placeholder" />'; ?>
<div class="shop_product_inner_caption">
<h2><?php the_title(); ?></h2>
<p><?php if ( ! defined( 'ABSPATH' ) ) exit; global $post, $product; ?> <?php echo $product->get_price_html(); ?></p>
<a href="">Add to Cart</a>
</div>
</a>
</div>
</div>
<?php endwhile;//Possibility to add else statement ?>
<?php wp_reset_postdata(); ?>
<?php else:?>
<p class="not_found">Sorry, The post you are looking is unavailable!</p>
<?php endif; wp_reset_query(); ?>
</div>
所以我的问题是—>
>我的查询是对还是错?如果我的查询错误,请给我正确的查询…另外,如果我的查询几乎正确所以请给我“添加到购物车”(http://prntscr.com/439lxj)按钮动态Ajax代码…
请帮我…
请帮我…
谢谢 !!!
解决方法:
我已经对代码进行了必要的更改以使其工作.确保将woocommerce add-to-cart.js或add-to-cart.min.js排入页面.
<div class="all_content_shop">
<?php wc_print_notices(); ?>
<?php $new_posts = new WP_Query( array(
'post_type' => 'product', //post of page of my post type
'cat' => 0, // category id, 0 for all categories.
'posts_per_page' => 12,
'offset' => 0, //how many posts you want to eliminate from the query
'orderby' => '', // order by title or date ?
'order' => 'DESC'
) // order as ASC or DESC
); ?>
<?php if ( $new_posts->have_posts() ) :
while ( $new_posts->have_posts() ) :
$new_posts->the_post();
global $product;
$product = get_product( get_the_ID() ); //set the global product object?>
<div class="col-md-3 single_all_c_s">
<div class="shop_product_inner">
<a href="<?php the_permalink() ?>">
<?php if ( has_post_thumbnail( get_the_ID() ) ) {
echo get_the_post_thumbnail( get_the_ID(), 'shop_single' );
} else {
echo '<img src="' . woocommerce_placeholder_img_src() . '" alt="Placeholder" />';
} ?>
<div class="shop_product_inner_caption">
<h2><?php the_title(); ?></h2>
<p><?php echo $product->get_price_html(); ?></p>
<?php woocommerce_template_loop_add_to_cart(); //ouptput the woocommerce loop add to cart button ?>
</div>
</a>
</div>
</div>
<?php endwhile;//Possibility to add else statement ?>
<?php wp_reset_postdata(); ?>
<?php else: ?>
<p class="not_found">Sorry, The post you are looking is unavailable!</p>
<?php endif;
wp_reset_query(); ?>
内容总结
以上是互联网集市为您收集整理的php – 我需要在woocommerce中添加自定义查询并添加到购物车按钮动态代码?全部内容,希望文章能够帮你解决php – 我需要在woocommerce中添加自定义查询并添加到购物车按钮动态代码?所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。