我正在使用带有wordpress的woocommerce。我需要按类别在购物车中展示产品。如果用户从category1中选择一个产品并添加到购物车,然后从category2中添加购物车中的产品,然后再添加category1中的任何其他产品。然后我需要category1的产品,然后是category2。我需要在购物车中以这种方式显示产品。我正在尝试更改cart.php文件中的代码。
车
Category1
product name category qty price
aaa category1 2 50
bbb category1 1 10
Category2
product name category qty price
test1 category2 2 40
test2 category2 1 10
$taxonomies = get_terms( array(
'taxonomy' => 'product-cat',
'hide_empty' => false,
) );
foreach ( $taxonomies as $_tax )
{
$allfactories[] = $_tax->name;
}
foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) {
//print_r($cart_item);
$cart_cat = $cart_item['wdm_user_custom_data_value'];
$terms = wp_get_object_terms($cart_item['product_id'], 'product-cat');
foreach ($terms as $term) {
$product_cat = $term->name;
$factory[] = $term->name;
}
if($product_cat==$cart_cat)
{
$_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 );
}
}