我正在try 在 checkout 页面上强制填写订单/发货备注字段,以用于特定的发货方式.
在这个帖子后面:Make Order notes required if shipping method is local pickup in Woocommerce,我使用以下代码:
add_action( 'woocommerce_checkout_process', 'danskefragtmand_order_comment_validation', 20 );
function danskefragtmand_order_comment_validation() {
$chosen_shipping = WC()->session->get( 'chosen_shipping_methods' )[0];
$chosen_shipping = explode(':', $chosen_shipping);
if ( $chosen_shipping[0] == 'shipmondo:26' && empty($_POST['order_comments']) ){
wc_add_notice( __( "Please tell the courier where he can leave your package in case you are not at home during time of delivery.", "woocommerce" ), 'error' );
}
}
如果我使用标准的WooCommerce发货术语,如local_pickup
和free_shipping
,并且如果您将我自己的发货术语shipmondo:26
更改为shipmondo
,则上面的代码工作得很好,但随后通知将显示为所有其他shipmondo
种发货方式.我正试图锁定特定的ID 26
.
任何建议都会受到重视.
其他有用的帖子:Disable only specific flat rate shipping method when free shipping is available in WooCommerce