Getting current product attribute pa_color
-
When a user selects a color from a dropdown box on the product page I would like to retrieve that selected color attribute or term to use in a table I’m building. I can get a list of all the colors (red, black, blue, green) for the individual product on the product page using the code listed below but I only want the currently selected color. Example: if a user selects red I would like the $term-> name “red” to be used in my PHP code and not all the colors associated with that product. I’ve tried get_term, get_term_by, has_term, etc.
`$terms = get_the_terms($product->id,’pa_color’ );
foreach( $terms as $term ) {
echo “<option>” . $term->name . “</option>”;}`
The topic ‘Getting current product attribute pa_color’ is closed to new replies.