2014-02-17 86 views
1

我正在使用woocommerce开发电子商务网站如何在woocommerce的single-product.php页面添加“添加到购物车”按钮?

在single-product.php中,我遇到了问题。

我无法在此页面的产品下显示添加到购物车按钮。

到目前为止我使用这段代码:

<?php 
    //global $post; 
    echo do_shortcode('[add_to_cart id="$post->ID"]'); 
    ?> 

,但没有运气的我呢!

+0

你为什么要使用简码是什么?有内置的模板和钩子。 – ViszinisA

+0

ViszinisA,是的,你是对的,但我正在改变模板的设计..这就是为什么! – user3257003

+1

然后使用woocommerce模板并按照指导原则为如何创建woocommerce设计。尝试阅读http://docs.woothemes.com/document/template-structure/和相关内容。 – ViszinisA

回答

5

也许你犯了一个简单的写错误?试试这个:

<?php 
echo do_shortcode('[add_to_cart id="'.$post->ID.'"]'); 
?> 
2

我会建议使用WooCommerce默认content-single-product.php模板。

默认情况下,通过woocommerce_template_single_add_to_cart()函数添加单个产品的添加到购物车模板,并将其添加到woocommerce_single_product_summary挂钩(优先级30)。

如果您必须从根本上更改单一产品内容,则可以直接致电woocommerce_template_single_add_to_cart()或将其添加到其他挂钩。没有理由在这里使用简码。

0

如果我理解你是正确的,你需要将页面顶部的Add-to-Cart按钮移动到页面底部,这样它就会低于主要产品描述。

下面是我做这个在我的网站:

/* Removing the Add-To-Cart button from right below the product summary. 
*/ 
remove_action('woocommerce_single_product_summary', 'woocommerce_template_single_add_to_cart', 30); 

/* Adding the Add-To-Cart button so that it would go after the main product description. 
*/ 
add_action('woocommerce_after_single_product_summary', 'woocommerce_template_single_add_to_cart', 12); 
相关问题