WooCommerce购物车数量基数折扣显示在迷你购物车(.php)

时间:2018-03-20 16:43:47

标签: wordpress woocommerce cart discount

相关:WooCommerce Cart Quantity Base Discount

在WooCommerce中,如何根据购物车中的商品总数设置购物车折扣?

## Tested and works on WooCommerce 2.6.x and 3.0+
add_action( 'woocommerce_cart_calculate_fees','wc_cart_quantity_discount', 10, 1 );
function wc_cart_quantity_discount( $cart_object ) {
    if ( is_admin() && ! defined( 'DOING_AJAX' ) )
        return;

    ## -------------- DEFINIG VARIABLES ------------- ##
    $discount = 0;
    $cart_item_count = $cart_object->get_cart_contents_count();
    $cart_total_excl_tax = $cart_object->subtotal_ex_tax;

    ## ----------- CONDITIONAL PERCENTAGE ----------- ##
    if( $cart_item_count <= 4 )
        $percent = 0;
    elseif( $cart_item_count >= 5 && $cart_item_count <= 10 )
        $percent = 5;
    elseif( $cart_item_count > 10 && $cart_item_count <= 15 )
        $percent = 10;
    elseif( $cart_item_count > 15 && $cart_item_count <= 20 )
        $percent = 15;
    elseif( $cart_item_count > 20 && $cart_item_count <= 25 )
        $percent = 20;
    elseif( $cart_item_count > 25 )
        $percent = 25;


    ## ------------------ CALCULATION ---------------- ##
    $discount -= ($cart_total_excl_tax / 100) * $percent;

    ## ----  APPLYING CALCULATED DISCOUNT TAXABLE ---- ##
    if( $percent > 0 )
        $cart_object->add_fee( __( "Quantity discount $percent%", "woocommerce" ), $discount, true);
}

对购物车页面有好处,没关系!

问题:

可以集成此功能,以便在迷你购物车中显示折扣小计,

形式:

....-&gt; add_fee(__(“数量折扣$百分比%”,“woocommerce”),$折扣,真);

提前致谢。

的Dom

0 个答案:

没有答案