1

我想在选择特定运输方式时禁用“下订单”按钮,有点像在为 WooCommerce 中的特定运输区域禁用“下订单”按钮回答我之前的问题,但是针对特定的运输方式一个航运区。

相关运输方式的名称为“LATAM”。

任何帮助表示赞赏。

4

1 回答 1

2

首先,您需要检查运输方式单选按钮,找出与“LATAM”相对应的运输方式 ID ... </p>

在此处输入图像描述

要使其适用于特定的运输方式 ID,您将使用以下内容:

add_filter('woocommerce_order_button_html', 'disable_place_order_button_html' );
function disable_place_order_button_html( $button ) {
    // HERE define your targeted shipping method id
    $targeted_shipping_method = "flat_rate:14";

    // 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;
}

代码位于活动子主题(或活动主题)的 functions.php 文件中。测试和工作。

于 2019-08-02T11:09:46.707 回答