【问题标题】:Remove “Place order” button for specific shipping method, except on the Order-Pay endpoint删除特定运输方式的“下订单”按钮,除了 Order-Pay 端点
【发布时间】:2021-06-22 12:15:24
【问题描述】:

我想在选择特定运输方式时删除“下订单”按钮,使用优秀的LoicTheAztecDisable “Place order” button for specific shipping method in WooCommerce”的代码,但不包括订单支付端点。

我尝试了以下解决方案,但它不起作用,Place Order 按钮也消失在 order-pay 端点上。

add_filter('woocommerce_order_button_html', 'disable_place_order_button_html' );
function disable_place_order_button_html( $button ) {
    if ( is_checkout() && ! is_wc_endpoint_url( 'order-pay' ) ) {  
        // HERE define your targeted shipping method id
        $targeted_shipping_method = "table_rate:3";
    
        // Get the chosen shipping method (if it exist)
        $chosen_shipping_methods = WC()->session->get('chosen_shipping_methods');
        
        // If the targeted shipping method is selected, we disable the button
        if( in_array( $targeted_shipping_method, $chosen_shipping_methods ) ) {
            $style  = 'style="background:Silver !important; color:white !important; cursor: not-allowed !important; text-align:center;"';
            $text   = apply_filters( 'woocommerce_order_button_text', __( 'Place order', 'woocommerce' ) );
            $button = '<a class="button" '.$style.'>' . $text . '</a>';
        }
    }
    return $button;
}

感谢任何帮助。

【问题讨论】:

    标签: woocommerce checkout endpoint shipping-method


    【解决方案1】:

    我测试了您的代码,它适用于我。问题与此代码无关。

    支付订单按钮的挂钩是woocommerce_pay_order_button_html,而不是woocommerce_order_button_html。您可以在模板中找到它:/woocommerce/checkout/form-pay.php

    您可以删除 ! is_wc_endpoint_url( 'order-pay' ) 检查 因为它永远不会在那个页面上运行。

    你可以检查几件事:

    • 访问此页面的用户是否已登录?
    • 检查活动主题的 functions.php 文件是否有任何其他使用 woocommerce_pay_order_button_html 挂钩的函数。
    • 您是否安装了任何管理/编辑此页面的插件(WooCommerce 除外)?
    • 最后,检查是否有隐藏元素的 CSS 规则

    【讨论】:

    • 这是一个概念错误,我没有注意到“订单支付”端点中不同的“下订单”挂钩。所以我只是用 ywraq_quote_button_checkout_html 替换了 woocommerce_order_button_html (结帐时报价请求按钮的“Yith Woocommerce Request a Quote”插件的钩子),我需要根据运输方式出现和消失。非常感谢
    • 奇怪的是,woocommerce_order_button_html 钩子也删除了订单支付端点中的“下订单”,可能是由于主题或 jquery 不兼容(我尝试使用默认主题并且它有效)
    猜你喜欢
    • 2018-10-25
    • 2012-04-07
    • 2011-12-06
    • 1970-01-01
    • 1970-01-01
    • 2017-09-20
    • 2019-12-10
    • 1970-01-01
    • 2019-06-09
    相关资源
    最近更新 更多