/** * Get component options to display. Fetched using a WP Query wrapper to allow advanced component options filtering / ordering / pagination. * * @param string $component_id * @param array $args * @return array */ public function get_current_component_options($component_id, $args = array()) { $current_options = array(); if (isset($this->current_component_options_query[$component_id])) { $current_options = $this->current_component_options_query[$component_id]->get_component_options(); } else { if (!$this->is_synced()) { $this->sync_composite(); } // Only do paged component options in 'thumbnails' mode if ($this->get_composite_selections_style() === 'dropdowns') { $per_page = false; } else { $per_page = $this->get_component_results_per_page($component_id); } $defaults = array('load_page' => $this->paginate_component_options($component_id) ? 'selected' : 1, 'per_page' => $per_page, 'selected_option' => $this->get_component_default_option($component_id), 'orderby' => $this->get_component_default_ordering_option($component_id), 'query_type' => 'product_ids'); // Component option ids have already been queried without any pages / filters / sorting when initializing the product in 'sync_composite'. // This time, we can speed up our paged / filtered / sorted query by using the stored ids of the first "raw" query. $component_data = $this->get_component_data($component_id); $component_data['assigned_ids'] = $this->get_component_options($component_id); $current_args = apply_filters('woocommerce_composite_component_options_query_args_current', wp_parse_args($args, $defaults), $args, $component_id, $this); // Pass through query to apply filters / ordering $query = new WC_CP_Query($component_data, $current_args); $this->current_component_options_query[$component_id] = $query; $current_options = $query->get_component_options(); } return $current_options; }
/** * Sets up a WP_Query wrapper object to fetch component options. The query is configured based on the data stored in the 'component_data' array. * Note that the query parameters are filterable - @see WC_CP_Query for details. * * @param array $component_data * @param array $query_args * @return array */ public function get_component_options($component_data, $query_args = array()) { $query = new WC_CP_Query($component_data, $query_args); return $query->get_component_options(); }