【问题标题】:Woocommerce Force Sells/Bookings - Snippet to force number of person in a bookingWoocommerce 强制销售/预订 - 强制预订人数的片段
【发布时间】:2019-09-13 16:58:55
【问题描述】:

通过 WooCommerce,我使用 WooCommerce 预订和 WooCommerce 强制销售插件。

我想使用 WooCommerce Force Sells 为预订中的每个人数添加一件强制销售的商品。

Woocommerce 的家伙已经提供了一个 sn-p 来添加到 functions.php 中,它可以修改 Force Sells 的行为。使用此 sn-p,您可以设置要添加的副产品的固定数量 (1):

// only add one force sell item per product no matter how many of the original product are added

function my_wc_force_sell_add_to_cart_product( $product ){

    $product['quantity'] = 1;

    return $product;

}

add_filter( 'wc_force_sell_add_to_cart_product', 'my_wc_force_sell_add_to_cart_product' );


// when a synced force sell product is updated always set it to 1

function my_wc_force_sell_update_quantity( $quantity, $product ){

    return 1;

}

add_filter( 'wc_force_sell_update_quantity', 'my_wc_force_sell_update_quantity' );

我想做的:用一个检索预订中指定人数的函数替换固定数量 (1)。

任何帮助都会很棒。

【问题讨论】:

    标签: php woocommerce woocommerce-bookings


    【解决方案1】:

    我想我找到了!

    function my_wc_force_sell_add_to_cart_product( $product ){
        foreach(WC()->cart->get_cart() as $cart_item) {
        // The item persons count
        $person = array_sum( $cart_item['booking']['_persons'] );
    }
        $product['quantity'] = $person;
        return $product;
    }
    add_filter( 'wc_force_sell_add_to_cart_product', 'my_wc_force_sell_add_to_cart_product' );
    
    // when a synced force sell product is updated always set it to 1
    function my_wc_force_sell_update_quantity( $quantity, $product ){
        return 1;
    }
    add_filter( 'wc_force_sell_update_quantity', 'my_wc_force_sell_update_quantity' );
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-12-13
      • 1970-01-01
      • 2014-12-01
      • 2019-09-19
      相关资源
      最近更新 更多