【发布时间】:2018-08-28 21:49:19
【问题描述】:
我正在尝试为哥伦比亚国家/地区专门应用 20 公斤的强制性最低重量,如果购物车总重量低于此最低重量,则避免结账。
这是我的实际代码,可以让我确定最小重量:
add_action( 'woocommerce_check_cart_items', 'cldws_set_weight_requirements' );
function cldws_set_weight_requirements() {
// Only run in the Cart or Checkout pages
if( is_cart() || is_checkout() ) {
global $woocommerce;
// Set the minimum weight before checking out
$minimum_weight = 30;
// Get the Cart's content total weight
$cart_contents_weight = WC()->cart->cart_contents_weight;
// Compare values and add an error is Cart's total weight
if( $cart_contents_weight < $minimum_weight ) {
// Display our error message
wc_add_notice( sprintf('<strong>A Minimum Weight of %s%s is required before checking out.</strong>'
. '<br />Current cart weight: %s%s',
$minimum_weight,
get_option( 'woocommerce_weight_unit' ),
$cart_contents_weight,
get_option( 'woocommerce_weight_unit' ),
get_permalink( wc_get_page_id( 'shop' ) )
),
'error' );
}
}
}
如何使它仅适用于哥伦比亚国家/地区?
【问题讨论】:
标签: php woocommerce cart checkout country