woocommerce_cross_sell_display

Output the cart cross-sells.

Description

woocommerce_cross_sell_display( (int) $limit = 2, (int) $columns = 2, (string) $orderby = 'rand', (string) $order = 'desc' ); 

Parameters (4)

0. $limit — Optional. (int) => 2
(default: 2)
1. $columns — Optional. (int) => 2
The columns.
2. $orderby — Optional. (string) => 'rand'
(default: rand)
3. $order — Optional. (string) => 'desc'
(default: desc)

Usage

  1. if ( !function_exists( 'woocommerce_cross_sell_display' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'woocommerce/includes/wc-template-functions.php'; 
  3.  
  4. // (default: 2) 
  5. $limit = 2; 
  6.  
  7. // The columns. 
  8. $columns = 2; 
  9.  
  10. // (default: 'rand') 
  11. $orderby = 'rand'; 
  12.  
  13. // (default: 'desc') 
  14. $order = 'desc'; 
  15.  
  16. // NOTICE! Understand what this does before running. 
  17. $result = woocommerce_cross_sell_display($limit, $columns, $orderby, $order); 
  18.  

Defined (1)

The function is defined in the following location(s).

/includes/wc-template-functions.php  
  1. function woocommerce_cross_sell_display( $limit = 2, $columns = 2, $orderby = 'rand', $order = 'desc' ) { 
  2. global $woocommerce_loop; 
  3.  
  4. if ( is_checkout() ) { 
  5. return; 
  6. // Get visble cross sells then sort them at random. 
  7. $cross_sells = array_filter( array_map( 'wc_get_product', WC()->cart->get_cross_sells() ), 'wc_products_array_filter_visible' ); 
  8. $woocommerce_loop['name'] = 'cross-sells'; 
  9. $woocommerce_loop['columns'] = apply_filters( 'woocommerce_cross_sells_columns', $columns ); 
  10.  
  11. // Handle orderby and limit results. 
  12. $orderby = apply_filters( 'woocommerce_cross_sells_orderby', $orderby ); 
  13. $cross_sells = wc_products_array_orderby( $cross_sells, $orderby, $order ); 
  14. $limit = apply_filters( 'woocommerce_cross_sells_total', $limit ); 
  15. $cross_sells = $limit > 0 ? array_slice( $cross_sells, 0, $limit ) : $cross_sells; 
  16.  
  17. wc_get_template( 'cart/cross-sells.php', array( 
  18. 'cross_sells' => $cross_sells,  
  19.  
  20. // Not used now, but used in previous version of up-sells.php. 
  21. 'posts_per_page' => $limit,  
  22. 'orderby' => $orderby,  
  23. 'columns' => $columns,  
  24. ) );