【问题标题】:How to output added to cart messsage or add to cart error on the current page Woocommerce?如何在当前页面 Woocommerce 上输出添加到购物车消息或添加到购物车错误?
【发布时间】:2015-06-23 04:23:05
【问题描述】:

添加到购物车按钮被触发后,如何在当前页面 Woocommerce 上输出添加到购物车消息或添加到购物车错误消息?由于错误消息通常在 class-wc-cart.php 中重定向? 因为我允许在 content-product.php 页面上添加到购物车按钮。 class-wc-cart AJAX 上 add to car 后的重定向代码如下:

           // If there was an error adding to the cart, redirect to the product page to show any errors
            $data = array(
                'error'       => true,
                'product_url' => apply_filters( 'woocommerce_cart_redirect_after_error', get_permalink( $product_id ), $product_id )
            );// it's redirect link to individual product page

            wp_send_json( $data );

网站链接是: http://gotheelz.com

【问题讨论】:

    标签: php wordpress woocommerce


    【解决方案1】:

    尝试更改 woocommerce 的设置,

    WooCommerce > 设置 > 产品 > 显示选项卡 > 添加到购物车行为 -- 取消勾选成功添加后重定向到购物车页面 和 [✓] 启用 AJAX 添加到存档上的购物车按钮。

    这个解决方案对我有用。 让我知道这是否对您有用。

    【讨论】:

      【解决方案2】:
                //Redirect any other role to the previous visited page or current on page
                $redirect = wp_get_referer() ? wp_get_referer() : home_url();
                $data = array(
                  'error'       => true,
                  'product_url' => apply_filters( 'woocommerce_cart_redirect_after_error', $redirect, $product_id )
                );// it's redirect link to individual product page
              wp_send_json( $data );
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2018-08-29
        • 2012-08-13
        • 2015-10-10
        • 1970-01-01
        • 2020-10-28
        • 2015-08-18
        • 2014-02-25
        相关资源
        最近更新 更多