Returns an array of arguments for ordering products based on the selected values.
public get_catalog_ordering_args ( $orderby = '', $order = '' ) : array | ||
return | array |
/** * Gets sorting options * * @access public * @return array */ public static function getSorting() { $order = array('orderby' => '', 'order' => '', 'meta_key' => ''); if (self::isActive()) { $query = new WC_Query(); $order = $query->get_catalog_ordering_args(); } return $order; }
/** * This method is used to display the output of the element. * @return void */ function element() { // Check if this is a normal page or the Shop archive page if (!is_shop()) { global $paged; $wc_query = new WC_Query(); // Get the proper page - this resolves the pagination on static frontpage if (get_query_var('paged')) { $paged = get_query_var('paged'); } elseif (get_query_var('page')) { $paged = get_query_var('page'); } else { $paged = 1; } $ordering = $wc_query->get_catalog_ordering_args(); $queryArgs = array('post_type' => 'product', 'paged' => $paged, 'orderby' => $ordering['orderby'], 'order' => $ordering['order']); if (isset($ordering['meta_key'])) { $queryArgs['meta_key'] = $ordering['meta_key']; } query_posts($queryArgs); } // Change the number of columns add_filter('loop_shop_columns', array(&$this, 'zn_woo_loop_columns'), 999); $sidebar_tweak = $this->opt('num_columns', '4') == 3 ? 'left_sidebar' : ''; echo '<div class="zn_woo_archive_elemenent woocommerce ' . $this->data['uid'] . ' ' . $sidebar_tweak . ' ' . $this->opt('css_class', '') . '">'; ?> <?php if ($this->opt('show_page_title', 'yes') == 'yes') { ?> <h1 class="page-title"><?php woocommerce_page_title(); ?> </h1> <?php } ?> <?php /** * woocommerce_archive_description hook * * @hooked woocommerce_taxonomy_archive_description - 10 * @hooked woocommerce_product_archive_description - 10 */ do_action('woocommerce_archive_description'); ?> <?php if (have_posts()) { ?> <?php /** * woocommerce_before_shop_loop hook * * @hooked woocommerce_result_count - 20 * @hooked woocommerce_catalog_ordering - 30 */ do_action('woocommerce_before_shop_loop'); ?> <?php woocommerce_product_loop_start(); ?> <?php woocommerce_product_subcategories(); ?> <?php while (have_posts()) { the_post(); ?> <?php wc_get_template_part('content', 'product'); ?> <?php } // end of the loop. ?> <?php woocommerce_product_loop_end(); ?> <?php /** * woocommerce_after_shop_loop hook * * @hooked woocommerce_pagination - 10 */ do_action('woocommerce_after_shop_loop'); ?> <?php } elseif (!woocommerce_product_subcategories(array('before' => woocommerce_product_loop_start(false), 'after' => woocommerce_product_loop_end(false)))) { ?> <?php wc_get_template('loop/no-products-found.php'); ?> <?php } ?> <?php wp_reset_postdata(); wp_reset_query(); echo '</div>'; }