Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $product = get_product();
- global $variable_id;
- global $color;
- if ($product->product_type == "variable") {
- $variations = $product->get_available_variations();
- foreach ($variations as $variation) {
- $color = $variation["attributes"]["attribute_pa_colour"];
- $variable_id = $variation['variation_id'];
- wc_get_template_part('content', 'product');
- }
- } else {
- $variable_id = null;
- $color = null;
- wc_get_template_part('content', 'product');
- }
- private function query_products( $args ) {
- // Set base query arguments
- $query_args = array(
- 'fields' => 'ids',
- 'post_type' => 'product',
- 'post_status' => 'publish',
- 'meta_query' => array(),
- );
- if ( ! empty( $args['type'] ) ) {
- $types = explode( ',', $args['type'] );
- $query_args['tax_query'] = array(
- array(
- 'taxonomy' => 'product_type',
- 'field' => 'slug',
- 'terms' => $types,
- ),
- );
- unset( $args['type'] );
- }
- // Filter products by category
- if ( ! empty( $args['category'] ) ) {
- $query_args['product_cat'] = $args['category'];
- }
- // Filter by specific sku
- if ( ! empty( $args['sku'] ) ) {
- if ( ! is_array( $query_args['meta_query'] ) ) {
- $query_args['meta_query'] = array();
- }
- $query_args['meta_query'][] = array(
- 'key' => '_sku',
- 'value' => $args['sku'],
- 'compare' => '='
- );
- $query_args['post_type'] = array( 'product', 'product_variation' );
- }
- $query_args = $this->merge_query_args( $query_args, $args );
- return new WP_Query( $query_args );
- }
Add Comment
Please, Sign In to add comment