У меня очень специфический вопрос.
Прежде всего, я разделил элементы корзины, когда их количество превышает 1, и заставил рассматривать их как отдельные элементы.
Все работает отличнопока с разделением, только мне нужно передать дополнительные опции продукта, которые у меня есть, к продукту.Вот скриншот того, что я хочу http://prntscr.com/nmfuty
Вот код разделения элементов:
function bbloomer_split_product_individual_cart_items( $cart_item_data, $product_id ){
$unique_cart_item_key = uniqid();
$cart_item_data['unique_key'] = $unique_cart_item_key;
return $cart_item_data;
}
add_filter( 'woocommerce_add_cart_item_data', 'bbloomer_split_product_individual_cart_items', 10, 2 );
add_action( 'woocommerce_after_cart_item_quantity_update', 'limit_cart_item_quantity', 20, 4 );
function limit_cart_item_quantity( $cart_item_key, $quantity, $old_quantity, $cart ){
// Here the quantity limit
$limit = 1;
$orders_added = $quantity - $limit;
if( $quantity > $limit ){
//Set existing line item quantity to the limit of 1
$cart->cart_contents[ $cart_item_key ]['quantity'] = $limit;
//get product id of item that was updated
$product_id = $cart->cart_contents[ $cart_item_key ][ 'product_id' ];
for( $i = 0; $i< $orders_added; $i++ ){
//iterate over the number of orders you must as with quantity one
$unique_cart_item_key = uniqid();
//create unique cart item ID, this is what breaks it out as a separate line item
$cart_item_data = array();
//initialize cart_item_data array where the unique_cart_item_key will be stored
$cart_item_data['unique_key'] = $unique_cart_item_key;
//set the cart_item_data at unique_key = to the newly created unique_key
//add that shit! this does not take into account variable products
$cart->add_to_cart( $product_id, 1, 0, 0, $cart_item_data );
}
// Add a custom notice
wc_add_notice( __('Notice!'), 'notice' );
}
}
Я использую плагин TM Extra Product Options, который в основном сохраняет информацию втаблица woocommerce_order_itemmeta в БД с meta_key [_tmcartepo_data], если это поможет.
Большое спасибо заранее:)