Merge pull request #14273 from woocommerce/fix/14162

Return if there is no product in woocommerce_upsell_display
This commit is contained in:
Claudio Sanches 2017-04-11 17:03:46 -03:00 committed by GitHub
commit 0df920ebde
1 changed files with 8 additions and 4 deletions

View File

@ -1269,6 +1269,10 @@ if ( ! function_exists( 'woocommerce_related_products' ) ) {
function woocommerce_related_products( $args = array() ) {
global $product, $woocommerce_loop;
if ( ! $product ) {
return;
}
$defaults = array(
'posts_per_page' => 2,
'columns' => 2,
@ -1278,10 +1282,6 @@ if ( ! function_exists( 'woocommerce_related_products' ) ) {
$args = wp_parse_args( $args, $defaults );
if ( ! $product ) {
return;
}
// Get visble related products then sort them at random.
$args['related_products'] = array_filter( array_map( 'wc_get_product', wc_get_related_products( $product->get_id(), $args['posts_per_page'], $product->get_upsell_ids() ) ), 'wc_products_array_filter_visible' );
@ -1309,6 +1309,10 @@ if ( ! function_exists( 'woocommerce_upsell_display' ) ) {
function woocommerce_upsell_display( $limit = '-1', $columns = 4, $orderby = 'rand', $order = 'desc' ) {
global $product, $woocommerce_loop;
if ( ! $product ) {
return;
}
// Handle the legacy filter which controlled posts per page etc.
$args = apply_filters( 'woocommerce_upsell_display_args', array(
'posts_per_page' => $limit,