so I got a working shortcode that outputs the selected product attribute name and id alongside, however, I have no idea how to obtain the same product variable name and id which is essentially from the same attribute.
This means that my current product form URL slug cannot add to cart the selected variable e.g. ( ?add-to-cart=18395&quantity=1&?variation_id=407 ) because the variation id is fetched from the attribute, and it is wrong I know.
add_shortcode ('color_attribute', function (){
$color_attributes = get_the_terms($post->ID, 'pa_pla_color', array(
'hide_empty' => false,
));
foreach ($color_attributes as $k => $color_attribute):
if( $k > 0 ) echo "n";
echo $color_attribute->name . ' | ' . $color_attribute->term_id;
endforeach;
} );
Any help is really appreciated!
2
Answers
For anyone else looking for similar solutions, this is how I achieved to solve my problem:
Check this out