Hello @twogunrosie,
If I understand you correctly, you want to hide certain product variations unless a certain product is in the cart.
At the time being, there’s no plugin in our store for this as it’s a very specific scenario. Please note custom solutions are not within our scope of support.
That said, I found the a similar question on StackOverflow.
I’ve added the snippet to match what you’re trying to do, here’s the end result.
add_filter( 'woocommerce_variation_is_visible', 'hide_specific_product_variation', 10, 4 );
function hide_specific_product_variation( $is_visible, $variation_id, $variable_product, $variation ) {
// Here define the variation(s) ID(s) to hide
$variations_ids_to_hide = array('481');
// Here enter the product ID or IDs that needs to be in the cart otherwise the the variation will be hidden. If 1 of two products need to me in cart you can do 343 or 334;
$product_id = 343;
// All the magic happens here ??
if( !in_array( $product_id, array_column( WC()->cart->get_cart(), 'product_id' ) ) && in_array($variation_id, $variations_ids_to_hide ) ) {
return false;
}
return $is_visible;
}
You can find comments in the code, please replace the numbers with your variation and product ID.
You can find the product ID here: https://d.pr/i/IWlvOF
Variation ID here: https://d.pr/i/M87ZkY
If you need more help, I highly recommend working with a WooExpert.
Hope this helps!