php - 在 WooCommerce 中设置最低未折扣订单金额

标签 php wordpress woocommerce cart discount

我使用“Minimum Order Amount”来要求最低订购量。

如果我有一篮子 50 欧元的商品并且我应用了 10% 的折扣代码,我无法订购我的购物车,因为总计 45 欧元。

但我想订购 < 50 欧元 ONLY with a discount code

最佳答案

更新:使用以下重新访问和压缩的代码,使用未折扣的总数:

add_action( 'woocommerce_checkout_process', 'wc_minimum_order_amount' );
add_action( 'woocommerce_before_cart' , 'wc_minimum_order_amount' );

function wc_minimum_order_amount() {
    // Set this variable to specify a minimum order value
    $minimum = 50;

    $total = WC()->cart->total;
    $discount_total = WC()->cart->get_discount_total(); // updated thanks to 7uc1f3r
    $maximized_total = $total + $discount_total;

    if ( $maximized_total < $minimum ) {

        $notice = sprintf( __('Your current order total is %s — you must have an order with a minimum of %s to place your order '), 
            wc_price( $maximized_total ), 
            wc_price( $minimum )
        );

        if( is_cart() ) {
            wc_print_notice( $notice , 'error' );
        } else {
            wc_add_notice( $notice , 'error' );
        }
    }
}

代码进入事件子主题(或事件主题)的 functions.php 文件。经过测试并有效。

关于php - 在 WooCommerce 中设置最低未折扣订单金额,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62404924/

相关文章:

php - 需要帮助为 select 语句编写 SQL 查询

php - WooCommerce 从当前类别页面获取父类别

php - 如何更改 Woocommerce 星级评分的位置

php - $getJSON 未被识别为数组

javascript - 谷歌地图,在标记信息窗口中显示mysql信息

php - 用户 'dbtsorder' @'localhost' 的访问被拒绝(使用密码 : YES)

wordpress - WooCommerce REST API 通过 ID 获取多个产品

php - 如何在 codeigniter 中加载 css

php - 尝试使用 Google SQL Cloud 在 Google App Engine 上运行 Wordpress

php - 如何使用数据库字段调用 PHP 文件?