我想在选择特定送货方式时禁用“下订单”按钮,有点像我之前问题的答案“Disable "Place order" button for specific shipping zone in WooCommerce”,但针对的是特定送货方式而不是运输区域。
相关运输方式的名称是“LATAM”。
感谢任何帮助。
最佳答案
首先,您需要检查送货方式单选按钮,找出与“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)
$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 文件中。已测试且有效。
关于php - 禁用 WooCommerce 中特定运输方式的 “Place order” 按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57324907/