Merge pull request #13440 from woocommerce/woocommerce_upsell_display_args
WC upsell display args
This commit is contained in:
commit
bc6e68b29c
|
@ -295,13 +295,14 @@ function wc_get_product_cat_class( $class = '', $category = null ) {
|
|||
* @return array
|
||||
*/
|
||||
function wc_product_post_class( $classes, $class = '', $post_id = '' ) {
|
||||
if ( ! $post_id || 'product' !== get_post_type( $post_id ) ) {
|
||||
if ( ! $post_id || ! in_array( get_post_type( $post_id ), array( 'product', 'product_variation' ) ) ) {
|
||||
return $classes;
|
||||
}
|
||||
|
||||
$product = wc_get_product( $post_id );
|
||||
|
||||
if ( $product ) {
|
||||
$classes[] = 'product';
|
||||
$classes[] = wc_get_loop_class();
|
||||
$classes[] = $product->get_stock_status();
|
||||
|
||||
|
@ -1315,27 +1316,29 @@ if ( ! function_exists( 'woocommerce_upsell_display' ) ) {
|
|||
function woocommerce_upsell_display( $limit = '-1', $columns = 4, $orderby = 'rand', $order = 'desc' ) {
|
||||
global $product, $woocommerce_loop;
|
||||
|
||||
// Get visble upsells then sort them at random.
|
||||
$upsells = array_filter( array_map( 'wc_get_product', $product->get_upsell_ids() ), 'wc_products_array_filter_visible' );
|
||||
// Handle the legacy filter which controlled posts per page etc.
|
||||
$args = apply_filters( 'woocommerce_upsell_display_args', array(
|
||||
'posts_per_page' => $limit,
|
||||
'orderby' => $orderby,
|
||||
'columns' => $columns,
|
||||
) );
|
||||
$woocommerce_loop['name'] = 'up-sells';
|
||||
$woocommerce_loop['columns'] = apply_filters( 'woocommerce_upsells_columns', isset( $args['columns'] ) ? $args['columns'] : $columns );
|
||||
$orderby = apply_filters( 'woocommerce_upsells_orderby', isset( $args['orderby'] ) ? $args['orderby'] : $orderby );
|
||||
$limit = apply_filters( 'woocommerce_upsells_total', isset( $args['posts_per_page'] ) ? $args['posts_per_page'] : $limit );
|
||||
|
||||
// Handle orderby and limit results.
|
||||
$orderby = apply_filters( 'woocommerce_upsells_orderby', $orderby );
|
||||
$upsells = wc_products_array_orderby( $upsells, $orderby, $order );
|
||||
$limit = apply_filters( 'woocommerce_upsells_total', $limit );
|
||||
// Get visble upsells then sort them at random, then limit result set.
|
||||
$upsells = wc_products_array_orderby( array_filter( array_map( 'wc_get_product', $product->get_upsell_ids() ), 'wc_products_array_filter_visible' ), $orderby, $order );
|
||||
$upsells = $limit > 0 ? array_slice( $upsells, 0, $limit ) : $upsells;
|
||||
|
||||
// Set global loop values.
|
||||
$woocommerce_loop['name'] = 'up-sells';
|
||||
$woocommerce_loop['columns'] = apply_filters( 'woocommerce_up_sells_columns', $columns );
|
||||
|
||||
wc_get_template( 'single-product/up-sells.php', apply_filters( 'woocommerce_upsell_display_args', array(
|
||||
'upsells' => $upsells,
|
||||
wc_get_template( 'single-product/up-sells.php', array(
|
||||
'upsells' => $upsells,
|
||||
|
||||
// Not used now, but used in previous version of up-sells.php.
|
||||
'posts_per_page' => $limit,
|
||||
'orderby' => $orderby,
|
||||
'columns' => $columns,
|
||||
) ) );
|
||||
'posts_per_page' => $limit,
|
||||
'orderby' => $orderby,
|
||||
'columns' => $columns,
|
||||
) );
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue