• Resolved nivsp

    (@spektorniv)


    ???? ?? ???? ?? ???????? ????? ?? ?????? ????? ????? ????? ?-XML ???? ???.
    ?? ??? ???? ????? ???? ??????? ???? ?? ???? ????? ???? ???? ???????? ????? ?? Zap Mirror ????? ????? ?????.
    ??? ?? ?? ????? ?-XML. ?? ??? ???? ?? ???

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author Ido Friedlander

    (@idofri)

    Try using the following filter-hook, it’ll remove the main variable product and display it’s variations instead:

    add_filter( 'wc_zap_mirror_wp_query', function( $args ) {
        // Include product variations
        $args['post_type'] = [ 'product', 'product_variation' ];
    
        // Exclude the main variable product
        $args['tax_query'][] = [
            'taxonomy'         => 'product_type',
            'field'            => 'name',
            'terms'            => 'variable',
            'include_children' => false,
            'operator'         => 'NOT IN'
        ];
    
        // Quick fix: variations are not assigned to product categories
        add_filter( 'posts_join', function( $join, $query ) {
            global $wpdb;
    
            $table = $query->tax_query->primary_table;
            $column = $query->tax_query->primary_id_column;
    
            $search = "{$table}.{$column} = {$wpdb->term_relationships}.object_id";
            $replace = "{$search} OR {$table}.post_parent = {$wpdb->term_relationships}.object_id";
    
            return str_replace($search, $replace, $join);
        }, 10, 2 );
    
        return $args;
    } );

    Just paste in your theme’s functions.php file.

    Thread Starter nivsp

    (@spektorniv)

    Worked perfectly but now it shows “out of stock” products.
    Is there a way to fix this?

    Plugin Author Ido Friedlander

    (@idofri)

    That should do the trick:

    add_filter( 'wc_zap_mirror_wp_query', function( $args ) {
    	// Include product variations
    	$args['post_type'] = [ 'product', 'product_variation' ];
    
    	// Exclude the main variable product
    	$args['tax_query'][] = [
    		'taxonomy'         => 'product_type',
    		'field'            => 'name',
    		'terms'            => 'variable',
    		'include_children' => false,
    		'operator'         => 'NOT IN'
    	];
    
    	// Include only in-stock products
    	$args['meta_query'] = [
    		'relation' => 'AND',
    		[
    			'key'     => '_stock_status',
    			'value'   => 'instock',
    			'compare' => '='
    		],
    		$args['meta_query']
    	];
    
    	// Quick fix: variations are not assigned to product categories
    	add_filter( 'posts_join', function( $join, $query ) {
    		global $wpdb;
    
    		$table = $query->tax_query->primary_table;
    		$column = $query->tax_query->primary_id_column;
    
    		$search = "{$table}.{$column} = {$wpdb->term_relationships}.object_id";
    		$replace = "{$search} OR {$table}.post_parent = {$wpdb->term_relationships}.object_id";
    
    		return str_replace($search, $replace, $join);
    	}, 10, 2 );
    
    	return $args;
    } );
    Thread Starter nivsp

    (@spektorniv)

    Perfect. Thank you so much!

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Override price’ is closed to new replies.