我想为WooCommerce增加一个最低订单价格.我找到了有关如何限制订购的说明,除非用户向购物车添加更多产品以满足最低金额(例如15欧元).
But我希望这样,如果购物车中的产品总数少于15欧元,购物车的总金额自动增加到15欧元(+运费).
以下是我目前掌握的情况:
add_action( 'woocommerce_before_cart' , 'total_order_amount' );
add_action( 'woocommerce_review_order_before_order_total' , 'total_order_amount' );
//include the minimum total in the total price in Cart and Checkout pages
function total_order_amount( ) {
// Set this variable to specify a minimum order value
$minimum = get_option( 'cart_minimum_total' );
if ( WC()->cart->subtotal < $minimum ) {
if( is_cart() || is_checkout() ) {
$new_price = (WC()->cart->total - WC()->cart->subtotal) + $minimum;
WC()->cart->total = $new_price;
}
}
}
add_action( 'woocommerce_review_order_after_order_total', 'show_minimum_total');
add_action( 'woocommerce_cart_totals_after_order_total', 'show_minimum_total');
//Show the minimum total included in the final price
function show_minimum_total() {
if ( WC()->cart->subtotal < get_option( 'cart_minimum_total') ) {
echo '<tr class="cart_minimum_total">';
echo '<th>'.esc_html__( 'Includes minimum price', 'myplugin' ).'</th>';
echo '<td data-title="'.esc_attr__( 'Includes minimum price', 'myplugin' ).'">'.get_option( 'cart_minimum_total' ).' €</td>';
echo '</tr>';
}
}
此外还有管理部分,管理员可以将购物车的最低总金额设置为15欧元,但这很好.
我的问题是,我不知道如何在购物车/购物中包含金额,当用户单击"发送订单"时,它也会包含在订单中.
我假设最低金额应该是与装运类似的"项目/产品".