![](/img/trans.png)
[英]Disable "Place order" button for specific shipping zone in WooCommerce
[英]Disable “Place order” button for specific shipping method in WooCommerce
我想在选择特定运输方式时禁用“下订单”按钮,有点像“ 在 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 文件中。 测试和工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.