0

I am using variable products within my store and I want to have the same child product variant show up on multiple parent product pages.

For example if someone were buying letters (eg; "a,b,c ... z" , ie; the alphabet) from my website the same letters would show up for both the English and the German pages however the German page would get ß, ä, ö and ü as well.

1 Answer 1

0

a. If your fine with a plugin dependency, ACF has this kind of functionality built in with the "Relationship" field.

Relationship: https://www.advancedcustomfields.com/resources/relationship/

Reverse Query: https://www.advancedcustomfields.com/resources/querying-relationship-fields/


b. If you want to do this with just WP core, you would use custom fields.

First, on the child product, store the IDs of the product pages it should show on:

enter image description here

Next, on the "Parent" product pages, make a wordpress meta_query, looking for 'show_on':

<?php 
$args = array
(
    'post_type'  => 'page',
    'meta_query' => array
    (
        array
        (
            'key'     => 'show_on',
            'value'   => get_the_ID(),
            'compare' => '=',
        ),
    ),
);

$product_query = new WP_Query( $args );
if($product_query->have_posts()):
    while($product_query->have_posts()): $product_query->the_post();
        echo get_the_title();
    endwhile; wp_reset_postdata();
endif;

WP_Query: https://codex.wordpress.org/Class_Reference/WP_Query

Meta_Query: https://codex.wordpress.org/Class_Reference/WP_Meta_Query

1
  • The variants don't have their own pages as I used attributes to create variations.
    – Zacharoo
    Nov 28, 2017 at 22:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.