如何使用现有购物车中的选定产品下订单?

问题描述 投票:0回答:0

在 woocommerce 购物车页面上,我们有 3 种类型的购物车列表,我们有以下购物车列表:

  1. 获取报价
  2. 创建订单
  3. 信用卡购买

enter image description here

所以我们使用以下代码过滤购物车,以便每个购物车列表在购物车页面上都有自己的产品。

if ( $_product && $_product->exists() && $listt == $pur_mode && $cart_item['quantity'] > 0 && apply_filters( 'woocommerce_cart_item_visible', true, $cart_item, $cart_item_key ) ) {

//our content here

}

我们还修改了总计和小计挂钩/过滤器(woocommerce_cart_subtotalwoocommerce_cart_total),以便在购物车和结帐页面上具有相同的总计和小计金额。以下是代码:

// Changing Cart final total
add_filter( 'woocommerce_cart_total', 'wc_modify_cart_price' ); 
function wc_modify_cart_price( $price ) {
    global $pur_mode, $line_subtotal;
    $line_subtotal = 0; 
    $pur_mode = WC()->session->get('pur_mode');
    foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) {
        $listt = $cart_item['list-cart-type'];
        
        $_product   = apply_filters( 'woocommerce_cart_item_product', $cart_item['data'], $cart_item, $cart_item_key );
        $product_id = apply_filters( 'woocommerce_cart_item_product_id', $cart_item['product_id'], $cart_item, $cart_item_key );
        if ( $_product && $_product->exists() && $listt == $pur_mode && $cart_item['quantity'] > 0 && apply_filters( 'woocommerce_cart_item_visible', true, $cart_item, $cart_item_key ) ) {
            $line_subtotal += $cart_item['line_total'];             
        }
    }   
    if ( ! WC()->cart->prices_include_tax ) {       
        $x_tax = WC()->cart->tax_total;
    } else {
        $x_tax = WC()->cart->cart_contents_total;       
    }
    
    $price = $line_subtotal + $x_tax;
    
    return get_woocommerce_currency_symbol() . number_format($price, 2, '.', ',');
}


// Changing Cart Sub total
function woocommerce_cart_subtotal(  $cart_subtotal ){
    global $pur_mode, $line_subtotal;
    $line_subtotal = 0;
    $pur_mode = WC()->session->get('pur_mode');
    foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) {
        $listt = $cart_item['list-cart-type'];      
        $_product   = apply_filters( 'woocommerce_cart_item_product', $cart_item['data'], $cart_item, $cart_item_key );
        $product_id = apply_filters( 'woocommerce_cart_item_product_id', $cart_item['product_id'], $cart_item, $cart_item_key );
        if ( $_product && $_product->exists() && $listt == $pur_mode && $cart_item['quantity'] > 0 && apply_filters( 'woocommerce_cart_item_visible', true, $cart_item, $cart_item_key ) ) {
            $line_subtotal += $cart_item['line_total'];                 
        }
    }   
    $cart_subtotal = number_format($line_subtotal, 2, '.', ',');
    
    return get_woocommerce_currency_symbol() . $cart_subtotal;
}

现在我们的问题是,当我们结帐选定的购物车时,假设获取报价列表将其下订单,获取报价列表、创建采购订单列表和使用信用卡购买列表中的所有产品将一起下订单,总金额和小计金额将更改为3个购物车中所有产品加起来的金额。

有人可以帮忙吗?我们只想修改购物车清单,以便结帐订购。就像如果我只检查购物车页面上的获取报价列表,只会被下订单及其总计和小计

谢谢。

wordpress woocommerce cart checkout
© www.soinside.com 2019 - 2024. All rights reserved.