向Woocommerce产品页面添加自定义按钮

时间:2018-08-25 01:26:48

标签: wordpress woocommerce

在Woocommerce产品页面中,我添加了一个额外的按钮,该按钮使用以下代码重定向到“添加到购物车”按钮下的另一个页面:

 add_action( 'woocommerce_after_add_to_cart_button','content_after_addtocart_button' );

function content_after_addtocart_button() {
echo '<br><div class="content-section">
<br><br> Cannot find the specs you need? Order your customized product! <br> 
<br>
<button type="submit" formaction="https://xxxx.com/custom- 
product/">Demand a custom product</button><br>
</div>';
}

单击按钮然后将其重定向到该页面没有问题,但是再次打开产品页面会显示以下错误警报:     请选择产品选项。 或此错误警报:     抱歉,无法购买该产品。 单击自定义按钮之前,不会显示此错误。我该如何解决?提前谢谢。

1 个答案:

答案 0 :(得分:0)

我通过解决方法解决了该问题。我将按钮包含在链接中,然后将其引用到另一页的URL,如下所示:

<a href="https://xxxx.com/custom-product/"><button type="button" style="border:2;">Order a custom product</button></a>

我将按钮的type属性分配给“按钮”,它现在可以正常工作,但是我不确定将其保留为“提交”是否会导致任何错误。而是将其更改为“按钮”。

相关问题