I’ve set up an ACF SELECT type field that “classifies” my products into groups.
I want to be able to create a page that lists only products for a specific group.
I’ve tried to search for ways to do this in various different places – here, WooCommerce, Elementor…
However I’ve not seen anyone mention a way to do it.
Can anyone point me in the right direction?
Hi there,
I’m trying to get this code to work in my functions.php, but I’m missing something where I get the posts I guess.
Products have a few ACF field, including one called ‘date_of_event’. That’s a datepicker field. I want to hide all products that are out of stock and the date has past. For the products where the stock is 0, but the date in the future I want to display them (don’t hide).
Can anyone check my code and tell me what I am missing?
add_filter( 'pre_option_woocommerce_hide_out_of_stock_items', 'bbloomer_hide_out_of_stock_exception_page' );
function bbloomer_hide_out_of_stock_exception_page( $hide ) {
$sDate = get_field('date_of_event');
$currendDate = date('Ymd');
if($sDate > $currendDate){
$hide = 'no';
}
return $hide;
}
I’m managing a WooCommerce webshop, and have the need to display various attributes for the different products, from simple things like “color” and “country of origin” to whether or not the item is assembled or not. But also things like weight, length, height etc (for the product, not the box it is shipped in). So some of these attributes will be different for each product.
I have previously done this both using the native product attributes in WP, but also with ACF. What are you guys thoughts here, what would be advantages/disadvantages with each? Anyone else setup something similar?
For now, the product info will need to be imported via csv on a regular basis (whenever new stock is added) but in the future we hope to expand this to pushing via API.
Hi,
I have a conceptual question. Think about the example books and authors. I made a webshop that sells books. BOOKS (WooCommerce products) have different attributes for description and filtering.
They also have a bidirectional relationship with AUTHORS. So there is also the CPT author, that also comes with some fields and images to describe them.
Now, I realize I could also create a custom taxonomy for the WooCommerce product (book). I was not aware that I can add custom fields to a custom taxonomy, i.e. it will server like a category but at the same time describe the category in more detail with custom fields.
I am asking myself now: would it be better to assign the custom taxonomy to the books, instead of creating a separate CPT author and bidirectional relationship?
(actually, it’s composers and musical pieces but easier to comprehend with books and authors)
best regards
Markus
Hello there,
I have browsed many threads and different sides to get this solved but with no solution so far.
We have a wordpress installation working with WooCommerce and Dokan.
Within our marketplace we want to seperate 2 different main categories with ACF PRO.
So basically we want to add different fields for each category.
If a vendor chooses for example category “Industry” then 3 new fields should appear in the product creation page as well as on the product page itself after publishing the product.
If the vendor chooses category “Private” there should be 3 different fields than there would be when using category “Industry”.
Vendor Edits are allowed.
Right now, only in our backend this is working. When we as the admin create/edit a product the condition works perfectly fine and is also displayed on the page correctly.
Where it is not working is when the vendor creates/edits a product on front end. In the product creation page there are all fields shown no matter what category is chosen.
This is the code we used for displaying the fields on the product page:
add_action( ‘woocommerce_product_meta_end’, ‘acf_dokan_display_product_fields4’ );
function acf_dokan_display_product_fields4(){
echo ‘<p class=”productpdf”> <b>Model:</b> ‘ . get_field(‘model’, $post_id, true) . ‘ </p>’;
}
add_action( ‘woocommerce_product_meta_end’, ‘acf_dokan_display_product_fields5’ );
function acf_dokan_display_product_fields5(){
echo ‘<p class=”productpdf”> <b>Kategorie:</b> ‘ . get_field(‘kategorie’, $post_id, true) . ‘ </p>’;
}
add_action( ‘woocommerce_product_meta_end’, ‘acf_dokan_display_product_fields’ );
function acf_dokan_display_product_fields(){
echo ‘Produkt PDF Herunterladen‘;
}
Hello everyone,
I’m stuck with this problem and I will really appreciate any kind of help.
For woocommerce products I have created a custom field “date_end” and I like to order the products based on that value. The custom field type is Date Picker with Display Format: d/F/Y and Save Format: dd/MM/yy.
I’m using this function to order the products:
add_filter('woocommerce_get_catalog_ordering_args', 'woocommerce_catalog_orderby');
function woocommerce_catalog_orderby( $args ) {
$args['order'] = 'ASC';
$args['meta_key'] = 'date_end';
$args['orderby'] = 'meta_value';
return $args;
}
But this is not ordering correctly. For example, I have products with dates: 3 September 2021, 22 February 2022, 01 April 2022.
Instead of that correct ordering, I have: 01 April 2022, 03 September 2021, 22 February 2022
So I guess that the ordering is made only based on the day ( 1,3,22) and the month and the year are not considered. I really don’t know what’s causing this issue. Thanks.
I can get my acf fields using the GET api rest web service, but I can not achieve update the fields, I don’t know if I’m doing something wrong or there a bug.
I’m trying to make a POST to https://www.example.com/wc/v3/products/{postId}
with
{“acf”: {“field1”: “value1”, “field2”: “value2”}}
the API response contains all the information of {postId} product, but the acf fields are both empty.
Could someone help me?
Hi, Has anyone managed to import variation images from CSV using a ACF image field? Or otherwise – any ideas welcome!
Hello,
Thank you for this great job of Advanced Custom Fields.
I’m Looking for a solution to map CSV filed
Currently when I try to import products from CSV files some fields do not exist in our woocommerce website, so I want to make them available for admin only so for this reason I installed Advanced Custom Fields and I’m trying to use it.
I’ve created a new filed group with administrator permission because I want to make them available for admin only.
I’ve added new fields as showing the following screenshot:
https://prnt.sc/26vj5e7
Now after trying to map fields when I import products CSV files I’m unable to find them
Here is the loom video from my desktop
https://www.loom.com/share/4ce19f9ba5c74bfbb58027f132081d5b
Please have a look and help me how can I add the created fields to the CSV map fields
Thank You!
Hi! Let’s say there was a “Professors” post type, and classes are WooCommerce products. Creating a new class, the professor is selected, so it’s tied into the database.
If I give admin access to Professors, and they can view their name in the post type, is there a field I can use to show all the students registered into this professor’s class?
I know the message field can be used to show general data in the backend. What about for a list showing all students? Maybe even a table, would inserting a table into a Message field work?
Wondering if anyone has ideas or thoughts on showing data for a user in the back-end.
Thanks!
Hi,
I am trying to add a custom parameter via ACF field to my Woocommerce product images, for example selecting “Rose Gold” from a dropdown on the Woocommerce Product Page Gallery upload/select section.
I have managed to do this via ACF Location -> Attachments. It shows up in the correct place, and saves the value I set.
I then call this via product-image.php child theme override, and it doesn’t work. I have entered a simple string, and the override works correctly, however the ACF field will not display.
Is ACF initialised on the product-image.php page?
I’ve attached the code.
Thanks,
H
hello i use acf to post pickup time for delivery…
i get the value from the default woocommerce order detail page with this code
$timepicker = get_field('timepicker', $order_id);
and it work fine but i want to but this form
from the default order detail page to another custom page how can i do this with php?
So… I have been using ACF fields on my WooCommerce pages for more than a year now (December 2020 to be exact). And everything has been working perfectly.
But since this week, the ACF field displays on the product pages have simply gone.
Nothing has changed (apart from auto-updates of plugins). But some reason the product pages are not displaying the values from the ACF fields in WooCommerce.
Can anyone offer any advice?
Hello,
I’m curious if there’s a way to use the built in REST API to query a WooCommerce product based on it’s ACF custom fields, and (hopefully) only respond with those custom fields.
Either the WC API, WC Legacy API, or the WP API is fine in this case.
The reason I mention that is because if I hit: /wp-json/wc/v3/products it doesn’t display the custom fields, but if I hit /wp-json/wp/v2/product it does, although it excludes some information in the response that’s specific to WooCommerce, but hopefully that won’t matter because I can pass in _fields=acf with the WordPress route.
I can also hit the WC legacy API like /wc-api/v3/products/?filter[meta]=true to return a product_meta object that contains the acf fields but can’t structure a query based on what’s in there.
Basically, I have custom fields set up so that if I hit /wp-json/wp/v2/product?_fields=acf, I receive a response object that looks like:
acf: {
id: "367fh9378ahr89h2r",
name: "Chair (Single Leg)"
entity_type: "Furniture",
category: "Chairs",
price: 543.21,
manufacturer: "Home Depot",
},
acf: {
id: "234898172983712dj",
name: "Dishwasher (Steel)"
entity_type: "Appliance",
category: "Dishwasher",
price: 123.45,
manufacturer: "Wayfair",
}
So my question is, is there someway that I can make a GET request to any of these APIs so that I can structure the query with parameters or filters to retrieve products, as well as retrieve a specific product, using a queries like this:
All products marked as appliances:
/wp-json/wp/v2/product/?_fields=acf&entity_type=Appliance
A specific product:
/wp-json/wp-v2/product/?_fields=acf&id=2hi3kuah82h2
All products marked as either furniture or appliances
/wp-json/wp/v2/product/?_fields=acf&filter[entity_type]=Appliance,Furniture
or (since I know filters were deprecated, but you can use the rest filter plugin to bring em back)
/wp-json/wp/v2/product/?_fields=acf&entity_type=Appliance,Furniture
doesn’t matter which way obviously.
All products made by Wayfair marked appliances:
/wp-json/wp/v2/product/?_fields=acf&entity_type=Appliance&manufacturer=Wayfair
I think that’s enough for you all to get the point. I haven’t even found a way to filter by the ACF fields specifically, let alone only return the acf object. I’ve seen a few posts about adding some functions or extending the API, but after experimenting with it (for someone like myself who is mostly a Javascript developer and doesn’t deal with too much PHP), I can’t seem to get a solution to work that fits another app developer’s specifications.
Let me add that querying based on any type of WordPress/WooCommerce id is not possible in this circumstance.
I have tried using the REST filter plugin. I’ve tried using the ACF to REST API plugin. I’ve tried using the WooCommerce legacy API to with ?filter[meta]=true, but can’t filter through the returned product_meta object.
Any input on this or a point in the right direction would be much appreciated.
Thanks,
Nathan.
–
Just after typing out this post I found a lovely and very small plugin that appears to be just two functions called ACF-REST-Query (by sts24 here: https://github.com/sts24/ACF-REST-Query) which is almost exactly what I’m looking to do, but it doesn’t have support for multiple arguments, or querying multiple acf parameters, so making requests like these don’t work (and it just accepts the last parameter):
?_fields=acf&acf_entity_type=Furniture,Appliance
or
?_fields=acf&acf_category=Dishwasher&acf_manufacturer=Wayfair
So yeah, almost there.
Again, if anyone could help me out, it’d be much appreciated.
Thanks,
Nathan.
Hi everyone,
I have searched a bit around but I couldn’t find much about this.
Is it possible to include ACF options field to custom WooCommerce Settings Tab?
Thanks,
A.
I have a fully working code to collect the data of 2 meta fields (title and description) on all pages in case the auto generated meta is not suitable. It works on every page exact 2:
– The WordPress blog overview (archive)
– The WooCommerce shop page (also archive page)
The 2 ACF fields within the pages look like to be totally ignored.
Any reason for that? And how to overwrite this behavior?
I understand that both pages are like kinda system pages where I can’t directly edit the content but I do want to edit the generated meta data.
Here’s the working code (except for the 2 archive pages):
// Add social media friendly meta tags
function yl_add_meta_tags_to_wp_head() {
setup_postdata( $post );
$custom_meta_title = get_field('yl_meta_title' );
$custom_meta_description = get_field( 'yl_meta_description' );
if ($custom_meta_title) {
$meta_title = $custom_meta_title;
} else {
$meta_title = get_the_title();
}
if ($custom_meta_description) {
$meta_description = $custom_meta_description;
} else {
$meta_description = substr(wp_strip_all_tags(get_the_excerpt()),0,150) . '...';
}
if ( class_exists( 'woocommerce' ) && is_product() ) {
$meta_type = 'product';
} elseif ( is_single() ) {
$meta_type = 'article';
} else {
$meta_type = 'website';
}
echo '
<meta name="meta_name" content="' . $meta_title . '" />
<meta name="description" content="' . $meta_description . '" />
';
}
add_action( 'wp_head', 'yl_add_meta_tags_to_wp_head', 1, 1 );
Hi all, newbie question incoming:
I’m using ACF for measurements, and currently outputing these like so on frontend (WooCommerce):
Lenght: [acf field="lenght"] cm
Width: [acf field="width"] cm
Depth: [acf field="depth"] cm
Height: [acf field="height"] cm
But most products only have 2 or 3 of these fields, so you end up with half-empty lines like “Height cm”.
What is the best way to go about hiding the entire lines where there is no data?
Cross post from wordpress support page
In a shop I am working on, I created a few custom fields associated to the product post type. I have a strange issue that cannot debug further. When I publish or update the product, some of the custom fields stay empty (not updating).
What I did for debugging:
– Disabled all the plugins except Woocommerce and ACF
– Changed theme to storefront
– Disable server and website cache
– Check server logs (nothing there)
– Enable wp_debug and also nothing
– Disable every custom code I had in the child theme
What I also found:
– The name doesn’t matter. I created a field called “Box Quantity” and I couldn’t save it. Then I delete all the custom fields and create just this one and it worked. Adding more kept this one working but not the new fields
– Checked the database on the postmeta table and the fields values are not there. So not saved at all.
Those are some of the server settings that might affected it. As you see, values are big enough and I even tried to increase them more with no success.
PHP version 7.2.34
PHP max input variables 6500
PHP time limit 3600
PHP memory limit 3072M
Max input time 1000
PHP post max size 260M
WordPress Version 5.8.2
Advanced Custom Fields Version 5.11.4
WooCommerce Version 6.0.0
I just started out with ACF Pro a couple of weeks ago, not learning yet to custom code it but work with some ACF plugins.
I am building a WooCommerce store (think books & authors) and want to add the country to the author.
As far as I see it, I have several options
1. Add country as a custom field / select and just list each country per line in ACF backend
2. Add a custom taxonomy and connect it to the author. Next, add the taxonomy as an ACF field
For my use case, the 1st attempt would probably be sufficient.
However, when would it be better to create a custom taxonomy instead?
Hello! Thanks to you I have achieved good things, but I am stagnant:
I have a website with ACF in which, I have a role called parent which buys a (PRODUCT “PLAN”), with the purchase of 1 product or plan, you can add 1 new user with the child role.
At first I could not do that if I bought 5 products of the same memebresia or example plan (basic plan * 5) it would allow me to create 5 new users but this has already been solved, with some problems but that’s it.
Now I need to make it work but I can’t do it, it is that if someone buys:
plan 1
plan 2
plan 3, that is, several plans at once, this generates the permissions to add a new user for each plan or for the amount of each plan.
this is my role
add_action (‘woocommerce_order_status_completed’, ‘c7_order_completed’);
function c7_order_completed ($ order_id) {
$ order = wc_get_order ($ order_id);
$ user_id = $ order-> get_customer_id ();
$ plans = get_user_meta ($ user_id, ‘plans’, true);
if (empty ($ plans)) $ plans = 0;
foreach ($ order-> get_items () as $ item_id => $ item) {
$ product_id = $ item [‘product_id’]; // product id
$ product_qty = $ item [‘qty’]; // product quantity
$ product_id = $ item-> get_product ();
update_user_meta ($ user_id, ‘plans _’. $ plans .’_ order ‘, $ order_id);
update_user_meta ($ user_id, ‘_planes _’. $ plans .’_ order ‘,’ field_615a9e10ec6b6 ‘);
update_user_meta ($ user_id, ‘plans _’. $ plans .’_ plan ‘, $ product_id-> get_id ());
update_user_meta ($ user_id, ‘_planes _’. $ plans .’_ plan ‘,’ field_615a9b29093b2 ‘);
update_user_meta ($ user_id, ‘plans _’. $ plans .’_ child ‘, 0);
update_user_meta ($ user_id, ‘_planes _’. $ plans .’_ child ‘,’ field_615a9c1f093b3 ‘);
wp_insert_post ([‘post_title’ => ‘test’. $ order_id. ‘-‘. $ product_id-> get_id ()]);
}
update_user_meta ($ user_id, ‘plans’, ($ plans + (1 * $ product_qty)));
update_user_meta ($ user_id, ‘_planes’, ‘field_615a9a13a26bf’);
}
I’ve this code below copying acf gallery to woocommerce _product_image_gallery. runs perfectly.
but when I choose field type as “Justified Image Grid” it shops working. how can I solve this problem ???
any idea ?
function use_acf_fields_for_product_photos($post_id) {
if(‘product’ != get_post_type($post_id)) {
return false;
}
$product_gallery = get_field(‘proimages’, $post_id);
if($product_gallery) {
$product_gallery_ids_string = implode(‘,’, wp_list_pluck($product_gallery, ‘ID’));
update_post_meta($post_id, ‘_product_image_gallery’, $product_gallery_ids_string);
}
}
add_action(‘acf/save_post’, ‘use_acf_fields_for_product_photos’, 20);
I’m trying to integrate Woo products into Custom Post Type Fields. I’m creating a Recipe CPT with tons of custom fields, but the essential ones will be “Ingredients”, on the frontend those fields will have a button to take the user to the corresponding product that the Ingredient is mentioning. Example: In a Salad, I’m using Olive Oil as an ingredient, then in the ingredients list a button will take the user to the Olive Oil product page.
How can I achieve something like that?
Has anyone figured out how to add a ACF fields into the existing “Product data” back-end metabox which displays Woocommerce’s fields in a tabbed interface. I don’t like having 2 different boxes in the back-end, this is weird for editors.
I know you can add fields manually using Woo hooks/php, but I’d rather manage them through ACF.
Hi,
I am not really a developer and have been doing a lot of research and trial and error but can’t seem to figure out my problem.
I would like to add a field (datepicker and is added to woocommerce products) to the invoices that are generated and attached to emails.
The field that I would like to add is called “Begindatum”.
Any idea if this is possible or not?
Thanks!
Hi
I’m trying to create a front-end form where is possible to edit woocommerces product properties.
I have been able to create form where is possible to edit all the custom fields created by the acf, but I’m struggling with the products default fields witch are created by the woocommerce( price, product image, etc ). My question is: Is it even possible to edit these values via acf:form and if it is what is the correct way to do that?