1

Add Advanced Custom Fields to WooCommerce Product Variation

Hello, we are having issues trying to add a unique ACF per each variable product.

Our product: "Product A - Variable Product." This product has 4 different variations, and we would like to add unique ACF depending on that product variation.

Within our custom fields tab I created a new custom field, field group, and label, I then selected; "Show this field group if post is equal to product_variation Product A - Variable Product." Doing so did NOT add the custom field to our products admin page. Previously we have used; "post type is equal to product" which works great, but can not be used in the variable product situation.


More background: Currently, we are using ACF to aid in our WooCommerce Email customizer, and it is working great. The email is printing out ACF data in accordance to the product that is purchased (see code below).

<?php
$product_idMe = $item->get_product_id();
$fields = get_field_objects($product_idMe);
if( $fields )
{
    foreach( $fields as $field_name => $field )
    {   
            echo $field['label']; 
            echo $field['value'];  
    }
}
?>

Goal: To add unique ACF to variable products, and print out the data into an email (like we are doing already doing, but now with the variable products unique ACF).

Please let me know if you need any clarification, a client of ours is trying to launch their website with this feature working. -Thanks, Michael P.

Michael
  • 61
  • 1
  • 4

1 Answers1

1

There seems not to be a solution with ACF.

But have a look at this discussion. It points you to a workaround: https://support.advancedcustomfields.com/forums/topic/custom-fields-on-woocommerce-product-variations/

Aleksandar
  • 1,496
  • 1
  • 18
  • 35
  • Ah, alright I will look into that. I'm just not sure if I will then be able to use those custom variables in the emails (like I did with advanced custom fields). If i can reference those custom fields in the email, I'm sure the code will look different than what I used. Also, I do not want to add any of this data to the front-end. These variables are just to appear in the admin email... I have to decide if this solution is worth pursuing before finding out at the end, that it is not possible to add the code into my email template. – Michael Jun 06 '17 at 12:20