Show Cross-sell in Related Section
Code
1
add_filter('woocommerce_related_products', 'wooler_change_related_to_cross_sell');
2
3
function wooler_change_related_to_cross_sell($products)
4
{
5
$cross_sells = array_filter(array_map('wc_get_product', WC()->cart->get_cross_sells()), 'wc_products_array_filter_visible');
6
$orderby = apply_filters('woocommerce_cross_sells_orderby', 'rand');
7
$order = apply_filters('woocommerce_cross_sells_order', 'desc');
8
$cross_sells = wc_products_array_orderby($cross_sells, $orderby, $order);
9
$limit = apply_filters('woocommerce_cross_sells_total', 0);
10
$cross_sells = $limit > 0 ? array_slice($cross_sells, 0, $limit) : $cross_sells;
11
12
return $cross_sells;
13
}
Copied!
Copy link