首页 文章

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

提问于
浏览
0

在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

    我用一种解决方法解决了这个问题 . 我将该按钮括在链接中并将其引用到另一页的URL,如下所示:

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

    我将按钮的类型属性分配给“按钮”,它现在工作正常,但我不确定是否保持“提交”将呈现任何错误 . 而是将其更改为“按钮” .

相关问题