woocommerce_upsell_display

Output product up sells.

Description

woocommerce_upsell_display( (string) $limit = '-1', (int) $columns = 4, (string) $orderby = 'rand', (string) $order = 'desc' ); 

Parameters (4)

0. $limit — Optional. (string) => '-1'
(default: -1)
1. $columns — Optional. (int) => 4
The columns.
2. $orderby — Optional. (string) => 'rand'
Supported values - rand, title, ID, date, modified, menu_order, price.
3. $order — Optional. (string) => 'desc'
Sort direction.

Usage

  1. if ( !function_exists( 'woocommerce_upsell_display' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'woocommerce/includes/wc-template-functions.php'; 
  3.  
  4. // (default: -1) 
  5. $limit = '-1'; 
  6.  
  7. // The columns. 
  8. $columns = 4; 
  9.  
  10. // Supported values - rand, title, ID, date, modified, menu_order, price. 
  11. $orderby = 'rand'; 
  12.  
  13. // Sort direction. 
  14. $order = 'desc'; 
  15.  
  16. // NOTICE! Understand what this does before running. 
  17. $result = woocommerce_upsell_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_upsell_display( $limit = '-1', $columns = 4, $orderby = 'rand', $order = 'desc' ) { 
  2. global $product, $woocommerce_loop; 
  3.  
  4. if ( ! $product ) { 
  5. return; 
  6.  
  7. // Handle the legacy filter which controlled posts per page etc. 
  8. $args = apply_filters( 'woocommerce_upsell_display_args', array( 
  9. 'posts_per_page' => $limit,  
  10. 'orderby' => $orderby,  
  11. 'columns' => $columns,  
  12. ) ); 
  13. $woocommerce_loop['name'] = 'up-sells'; 
  14. $woocommerce_loop['columns'] = apply_filters( 'woocommerce_upsells_columns', isset( $args['columns'] ) ? $args['columns'] : $columns ); 
  15. $orderby = apply_filters( 'woocommerce_upsells_orderby', isset( $args['orderby'] ) ? $args['orderby'] : $orderby ); 
  16. $limit = apply_filters( 'woocommerce_upsells_total', isset( $args['posts_per_page'] ) ? $args['posts_per_page'] : $limit ); 
  17.  
  18. // Get visble upsells then sort them at random, then limit result set. 
  19. $upsells = wc_products_array_orderby( array_filter( array_map( 'wc_get_product', $product->get_upsell_ids() ), 'wc_products_array_filter_visible' ), $orderby, $order ); 
  20. $upsells = $limit > 0 ? array_slice( $upsells, 0, $limit ) : $upsells; 
  21.  
  22. wc_get_template( 'single-product/up-sells.php', array( 
  23. 'upsells' => $upsells,  
  24.  
  25. // Not used now, but used in previous version of up-sells.php. 
  26. 'posts_per_page' => $limit,  
  27. 'orderby' => $orderby,  
  28. 'columns' => $columns,  
  29. ) );