当我选择了一种特定的送货方式时,我想禁用“下订单”按钮,有点像我先前问题的“ Disable "Place order" button for specific shipping zone in WooCommerce” 回答,但针对特定问题运输方式而不是运输区域。
相关运输方式的名称为“ LATAM”。
感谢您的帮助。
答案 0 :(得分:1)
首先,您需要检查运输方式单选按钮,以找到与“ LATAM”相对应的值的运输方式ID…
要使其适用于特定的送货方式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)
if( $chosen_shipping_methods = WC()->session->get( 'chosen_shipping_methods' ) ){
foreach ( $chosen_shipping_methods as $chosen_shipping_method ) {
// If the targeted shipping method is selected, we disable the button
if( $targeted_shipping_method == $chosen_shipping_method ) {
$style = 'style="background:Silver !important; color:white !important; cursor: not-allowed !important; text-align:center;"';
$button_text = apply_filters( 'woocommerce_order_button_text', __( 'Place order', 'woocommerce' ) );
$button = '<a class="button" '.$style.'>' . $button_text . '</a>';
break;
}
}
}
return $button;
}
代码进入活动子主题(或活动主题)的functions.php文件中。经过测试并可以工作。