2, 'columns' => 2, 'orderby' => 'rand', // @codingStandardsIgnoreLine. 'order' => 'desc', ]; $args = apply_filters( 'woocommerce_output_related_products_args', [ 'posts_per_page' => 2, 'columns' => 2, ] ); $args = wp_parse_args($args, $defaults); // Get visible 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' ); // Handle orderby. $args['related_products'] = wc_products_array_orderby( $args['related_products'], $args['orderby'], $args['order'] ); // Set global loop values. wc_set_loop_prop('name', 'related'); wc_set_loop_prop('columns', apply_filters('woocommerce_related_products_columns', $args['columns'])); if (blocksy_is_visible(get_theme_mod('related_products_visibility', [ 'desktop' => true, 'tablet' => false, 'mobile' => false, ]))) { if ($args['related_products'] && !empty($args['related_products'])) { echo blocksy_generate_related_output( $args['related_products'], false ); } } if (is_customize_preview()) { blocksy_add_customizer_preview_cache(blocksy_html_tag( 'div', ['data-id' => 'single-related'], blocksy_generate_related_output( $args['related_products'], true ) )); } } } if (! function_exists('blocksy_generate_related_output')) { function blocksy_generate_related_output($related_products, $for_preview = false) { $limit = intval(get_theme_mod('related_products', 4)); $class = 'related products'; $heading = apply_filters('woocommerce_product_related_heading', __('Related products', 'blocksy')); ob_start(); ?>
>

$related_product ) : ?> get_id() ); setup_postdata($GLOBALS['post'] =& $post_object ); // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited, Squiz.PHP.DisallowMultipleAssignments.Found if (! $for_preview && $index + 1 > $limit) { break; } wc_get_template_part( 'content', 'product' ); ?>