简体   繁体   English

Woocommerce-在添加到购物车按钮下添加链接

[英]Woocommerce - adding link under add to cart button

Good afternoon, 下午好,

I have been searching the internet all morning trying to find away to add a 'view cart' link under my 'add to cart' button on the single product page. 我整个上午都在搜索互联网,试图找到一个产品页面上“添加到购物车”按钮下的“查看购物车”链接。

I am trying to do this as I only want a link to the cart to be visible when there are items in the cart, without adding it to the main site menu. 我正在尝试执行此操作,因为我只希望在购物车中有物品时可以看到指向购物车的链接,而无需将其添加到主站点菜单中。

I tried this snippet but it did nothing: 我尝试了此代码段,但没有执行任何操作:

add_action( 'woocommerce_after_single_product_summary', 'add_cart_link', 0   );

function add_custom_field() {
global $post;

echo "something here";

return true;
}

I am not sure what the best solution is... has anyone come across a solution that may work? 我不确定最好的解决方案是什么...是否有人遇到了可行的解决方案?

Add below code to your theme's functions.php . 将以下代码添加到主题的functions.php

add_action('woocommerce_after_add_to_cart_button','view_cart_text');

function view_cart_text(){
    echo '<button type="submit" class="single_add_to_cart_button button alt">View cart</button>';
}

Obviously you need to do some CSS or styling according to your theme.But it will give you the result what you want to achieve. 显然,您需要根据主题进行一些CSS或样式设置,但这将为您提供想要实现的结果。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM