简体   繁体   中英

WP + ACF How to retrieve data in front end product page

As it said in the title I'm trying to retrieve the data from my ACF's fields.

Better than an explanation, please see the following screenshot: 在此处输入图片说明

So as you can see I've created under my attribute ' pa_size ' the 2 following text fields: uk-size and us-size . Which is giving the following result in my Products->attributes backend: 在此处输入图片说明

Until there, everything's ok but the next step is to retrieve these data to the following single-product (variable) screen: 在此处输入图片说明

I tried with this documentation from ACF to do it but impossible. I also tried to place different part of code under /public_html/wp-content/themes/atelier-child/woocommerce/single-product/add-to-cart/variable.php but no way to figure it out. It's been days I am struggling on it and it's driving me super crazy.

I would like if I click on "UK" or "US" to display sizes like on this link.

If anyone could help even just a little bit, I would be really grateful!!

Thanks in advance guys.

Could you provide the code that you tried?

All of the objects that are not a post type use a special "post id syntax": https://www.advancedcustomfields.com/resources/get-values-from-a-taxonomy-term/

In your example you have the taxonomy pa_size, and let's pretend the term you are editing is number 352.

$term_id = 352;
$us_size = get_field( 'us_size', 'pa_size_' . $term_id, );
$uk_size = get_field( 'uk_size', 'pa_size_' . $term_id, );

Is this what you are looking for? Or are you wondering about tying it in to toggle the values of the dropdown menu?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM