【问题标题】:WooCommerce and hooks in thank you pageWooCommerce 和感谢页面中的挂钩
【发布时间】:2018-11-05 01:50:52
【问题描述】:

我在我的网站中设置了一些 php 代码以限制最小订单量,因此,我还添加了一个“返回购物车”按钮以显示在“结帐”页面中以改善用户体验(基于在这个例子中:Back to cart button on checkout page)。问题是,当客户被重定向到“谢谢”页面时,当订单有效(匹配最小订单数量)时,“返回购物车”按钮不断出现,在这个页面中没有任何意义,因为图片显示: thank you message with get back to cart button

有什么方法可以阻止它出现在感谢页面中,并在结帐页面中保持其行为?

到目前为止,在我的子主题中添加到函数文件中的 PHP 代码是:

// back to cart button
add_action ( 'woocommerce_checkout_process', 'return_to_cart_notice_button', 20 );
function return_to_cart_notice_button(){

    //Set the messages for notice and button
    $message = __( 'Do you want to go back to shopping cart?', 'woocommerce' );
    $button_text = __( 'Go to shopping cart', 'woocommerce' );

    $cart_link = WC()->cart->get_cart_url();

    wc_add_notice( '<a href="' . $cart_link . '" class="button wc-forward">' . $button_text . '</a>' . $message, 'notice' );
}

【问题讨论】:

    标签: php wordpress woocommerce checkout hook-woocommerce


    【解决方案1】:

    您可以同时使用这 2 个条件 woocommerce 标签只定位结帐页面,而不是订单收到(谢谢)页面:

    if( is_checkout() && ! is_wc_endpoint_url( 'order-received' ) ){ }
    

    所以在你的代码中:

    // back to cart button
    add_action ( 'woocommerce_checkout_process', 'return_to_cart_notice_button', 20 );
    function return_to_cart_notice_button(){
    
        if( is_checkout() && ! is_wc_endpoint_url( 'order-received' ) ){
    
            //Set the messages for notice and button
            $message = __( 'Do you want to go back to shopping cart?', 'woocommerce' );
            $button_text = __( 'Go to shopping cart', 'woocommerce' );
    
            $cart_link = WC()->cart->get_cart_url();
    
            wc_add_notice( '<a href="' . $cart_link . '" class="button wc-forward">' . $button_text . '</a>' . $message, 'notice' );
        }
    }
    

    【讨论】:

      猜你喜欢
      • 2014-09-26
      • 2023-03-20
      • 1970-01-01
      • 1970-01-01
      • 2020-11-03
      • 2021-09-12
      • 2021-01-27
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多