如果选择了特定的运输类别,我正在尝试停用“下订单”按钮。运输类别的名称为“Zone 6”。
基于“针对特定运输类别的“删除 Woocommerce”下订单“按钮”回答线程,我做了一些更改来处理运输区域:
add_filter('woocommerce_order_button_html', 'remove_order_button_html' );
function remove_order_button_html( $button ) {
// HERE define your targeted shipping zone
$targeted_shipping_zone = "Zone 6";
$found = false;
// Loop through cart items
foreach( WC_Shipping_Zones::get_zones() as $shipping_zone ) {
if( $shipping_zone['data']->get_zone_name() == $targeted_shipping_zone ) {
$found = true; // The targeted shipping class is found
break; // We stop the loop
}
}
// If found we remove the button
if( $found ) {
$style = 'style="background:Silver !important; color:white !important; cursor: not-allowed !important;"';
$button_text = apply_filters( 'woocommerce_order_button_text', __( 'Place order', 'woocommerce' ) );
$button = '<a class="button" '.$style.'>' . $button_text . '</a>';
}
return $button;
}
但它不起作用。当$found
手动设置为 true 时,按钮会根据需要停用。我认为行中有错误get_zone()
。
任何帮助表示赞赏。