【问题标题】:Display Contact Button if Woocommerce Product Price is zero else display Add to cart button如果 Woocommerce 产品价格为零,则显示联系按钮,否则显示添加到购物车按钮
【发布时间】:2019-05-02 13:33:47
【问题描述】:

我正在使用 Divi 主题的 Woocommerce 网站。我在 Divi 主题中的商店模块的帮助下展示特色产品。目前 Divi 商店模块不显示添加到购物车按钮。所以我添加了一个实现相同的钩子。

链接:https://intercom.help/elegantthemes/faq-s-and-troubleshooting/how-to-add-add-to-cart-button-in-divi-shop-pages

但问题是“添加到购物车”按钮是 ajax 类型的。我需要将按钮重定向到相应的产品页面。此外,如果 woocommerce 产品价格为零,请删除添加到购物车并显示联系我们按钮。

我尝试了以下解决方案,但无法满足我的要求。

Hide "Add to cart" button when the product price is zero When price is 0 change add to cart button to "request quote"

我需要实现这样的功能:https://imgur.com/a/GaQAgUg

【问题讨论】:

  • 你现在面临什么困难?有什么错误吗?
  • @SudharshanNair : 其实不是错误,请看链接imgur.com/a/qK0iKAX 我已经实现了这么多。我需要的是这个imgur.com/a/GaQAgUg

标签: php wordpress woocommerce hook-woocommerce


【解决方案1】:

把它放在你的主题functions.php 文件中。谢谢!

function replace_add_to_cart() {
   global $product;

   if( $product->get_price() == 0 ) {
     $link = 'YOUR CONTACT PAGE URL';
     $button_text = 'Contact Us';
   } else {
     $link = $product->get_permalink();
     $button_text = 'Buy Now';
   }

   echo do_shortcode('[button link="' . esc_attr($link) . '"]'.$button_text.'[/button]');
}
add_action('woocommerce_after_shop_loop_item','replace_add_to_cart');

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-12-29
    • 2018-09-30
    • 2021-01-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-08-11
    相关资源
    最近更新 更多