Support » Plugin: WooCommerce » Display custom field for chosen variation

  • Hi,

    I have added a single custom field to my product variations: retailer_url. I should like to display this once the customer has selected his variation from the dropdown – just after the variation price is displayed.

    I think I probably need to add a function to the woocommerce_single_variation hook, and use get_post_meta to retrieve the value of the custom field.

    How how on earth do I know what the selected variation id is?

    I’ve read loads of posts that refer to similar problems, but nothing that exactly answers my question. Will I need JavaScript to access the id of product variation that was selected from the dropdown? Or is it held in a variable – and, if so, what?


Viewing 4 replies - 1 through 4 (of 4 total)
  • I’ve moved on a bit with this, but don’t know whether I’m going down the wrong track….

    If I use Firebug to examine the HTML on my page, I can see this for the ADD TO BASKET button:

    <div class="variations_button">
    <div class="quantity" style="display: block;">
    <button class="single_add_to_cart_button button alt" type="submit">Add to basket</button>
    <input type="hidden" value="42" name="add-to-cart">
    <input type="hidden" value="42" name="product_id">
    <input class="variation_id" type="hidden" value="79" name="variation_id">

    That VARIATION_ID of 79 is what I want to capture.

    So how do I do that?

    I’ve tried:
    $var_id = $_POST[‘variation_id’];
    $var_id = $_GET[‘variation_id’];
    but no luck……..

    I’m possibly barking up the wrong tree with my hidden fields…..

    But one more, related, question:

    As of WooCommerce 2.4, the woocommerce_single_variation hook seems to have two actions:

    woocommerce_single_variation – 10 Empty div for variation data
    woocommerce_single_variation_add_to_cart_button – 20 Qty and cart button

    The first is presumably where I need to be getting and displaying variation metadata – in fact, the comment implies that this is what it was set up for. But I just don’t know how!

    Kahoferj – did you work this out – trying to do the same but can’t find any documentation either.

    Hi. I’m afraid I didn’t, but it is something I’m going to have to revisit soon. I found this article, which I hope might be the solution I need:

    Woocommerce: Display Dynamic Content For Each Product Variation

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Display custom field for chosen variation’ is closed to new replies.