WC_Cart::get_cross_sells()
Gets cross sells based on the items in the cart.
Method of the class: WC_Cart{}
Hooks from the method
Return
Array
. cross_sells (item ids)
Usage
$WC_Cart = new WC_Cart(); $WC_Cart->get_cross_sells();
WC_Cart::get_cross_sells() WC Cart::get cross sells code WC 9.6.1
public function get_cross_sells() { $cross_sells = array(); $in_cart = array(); if ( ! $this->is_empty() ) { foreach ( $this->get_cart() as $values ) { if ( $values['quantity'] > 0 ) { $cross_sells = array_merge( $values['data']->get_cross_sell_ids(), $cross_sells ); $in_cart[] = $values['product_id']; // Add variations to the in cart array. if ( $values['data']->is_type( 'variation' ) ) { $in_cart[] = $values['variation_id']; } } } } $cross_sells = array_diff( $cross_sells, $in_cart ); return apply_filters( 'woocommerce_cart_crosssell_ids', wp_parse_id_list( $cross_sells ), $this ); }