首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在我自己的自定义产品-single.php页面中添加到购物车按钮

如何在我自己的自定义产品-single.php页面中添加到购物车按钮
EN

Stack Overflow用户
提问于 2015-05-07 11:01:29
回答 1查看 1.3K关注 0票数 0

我的问题是,我正在使用我自己的自定义单产品. own页面,它的工作方式是我想要的,因为我使用循环来根据我的需要显示单个产品的内容.但是没有,我唯一面临的问题是,我不能得到“加到车”按钮代码在哪里?现在我的add to cart按钮丢失了,这使我完全无法将产品添加到购物车.这里是我的完整代码<div class="shop-info"> <?php query_posts( array( 'post_type' => product, 'posts_per_page' => 1) ); ?> <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?> <h2> <?php the_title(); ?> </h2> <span class="check"></span> <span class="stock">IN STOCK</span> <span class="right-code"> <span class="code">CODE: </span> <span class="number"><?php echo $product->get_sku(); ?></span> </span> <img src="<?php bloginfo('template_url'); ?>/images/shop-line.png" alt=""/> <span class="price">$<?php $product = new WC_Product( get_the_ID() ); echo $price = $product->price; ?></span> <span class="total">QUANTITY: </span> <span class="select"> <a href="">00</a> <span class="arrow"></span> </span> <img src="<?php bloginfo('template_url'); ?>/images/shop-line.png" alt=""/> <div class="product-single-content"> <p class="product-detail"> <?php the_content(); ?> </p> </div> <div class="add-buttons"> <a class="add-to-cart" href="<?php echo $product->single_add_to_cart_text(); ?>">ADD TO BASKET/ BORROW</a> <a class="add-to-cart pink" href="">ADD TO WISH LIST</a> </div> <div class="social-links"> <ul class="social-networks"> <li><a href="#">facebook</a></li> <li><a class="twitter" href="#">twitter</a></li> <li><a class="play" href="#">play</a></li> </ul> </div> <?php endwhile; endif; ?> </div>,在上面的代码和div类按钮的部分,我自己的按钮被命名为“添加到篮子/借入”放置,我希望一旦单击锚,这个项目应该添加到购物车.有谁能帮我摆脱这件事吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-05-07 11:11:21

替换

<a class="add-to-cart" href="<?php echo $product->single_add_to_cart_text(); ?>">ADD TO BASKET/ BORROW</a>

使用

<?php do_action('woocommerce_simple_add_to_cart'); ?>

如果您想更改add to cart文本,那么将下面的代码添加到主题的functions.php中:

代码语言:javascript
复制
add_filter( 'woocommerce_product_single_add_to_cart_text', 'your_custom_cart_button_text' );

function your_custom_cart_button_text(){
    return __( 'ADD TO BASKET/ BORROW', 'woocommerce' );
}

注意:不会为变量产品添加。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/30099186

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档