Hello everyone.
I urgently need help and am looking for an ingenious idea for the following problem: How can I retrieve ACF information for variable products when exporting orders from Woocommerce?
Details:
> Orders should be exported from Woocommerce with the plugin “WP ALL EXPORT PRO” and ACF to my fulfillment partner as XML
> ONLY relevant orders or products with necessary information should be filtered, which works well for “simple products” with the following code
> Variable products (T-shirts) are also correctly recognized and exported by the code – BUT all ACF information remains empty and is not retrieved
What have I created?
> Created variable product “T-SHIRT” in the Woocommerce Dashboard
> Woocommerce attribute “SIZE” with the variants S / M / L / XL
> ACF field group “DDF” with desired text fields created to export the necessary ACF information later for orders (in addition to simple products also for product variants e.g. T-SHIRT, SIZE “L”)
> Field group rule: content type -> is equal to -> product
> Do I also have to apply the rule here? Taxonomy -> is equal to -> “SIZE”
Do I have to add or create other settings in ACF?
or is this only possible with ACF Pro?
->
/////CURRENT STATUS CODE IN WP ALL EXPORT
//////XML EDITOR
<?xml version="1.0" encoding="UTF-8"?>
<orders>
<!-- BEGIN LOOP -->
<order>
<commission>{Bestell ID}</commission>
<production>2</production>
<receiver>
<line1>{Shipping First Name} {Shipping Last Name}</line1>
<line2>{Shipping Company}</line2>
<street>{Shipping Address 1}</street>
<streetnumber>{Shipping Address 2}</streetnumber>
<country_code>{Shipping Country}</country_code>
<zip>{Shipping Postcode}</zip>
<city>{Shipping City}</city>
<email>{Customer Account Email Address}</email>
</receiver>
<items>
[my_get_order_items({Bestell ID})]
</items>
</order>
<!-- END LOOP -->
</orders>
/////FUNCTION EDITOR
<?php
function my_get_order_items($Bestell_id) {
// Check if the Bestell ID is valid
if (!$Bestell_id) {
return false;
}
// Fetch the order
$order = wc_get_order($Bestell_id);
if (!$order) {
return false;
}
// Initialize the string to store order details
$order_details = "";
// Loop through each order item
foreach ($order->get_items() as $item_id => $item) {
// Get the product object
$product = $item->get_product();
// Skip if there's no product associated with the item
if (!$product)
{ continue; }
if (!(
strpos($item->get_name(), 'KERAMIKTASSE') !== false ||
strpos($item->get_name(), 'BAUMWOLLTASCHE') !== false ||
strpos($item->get_name(), 'T-SHIRT') !== false))
{ continue; }
$order_details .= "**LT**item**GT**";
$order_details .= "**LT**ID**GT**" . $product->get_sku() . "**LT**/ID**GT**";
$order_details .= "**LT**produktname**GT**" . $item->get_name() . "**LT**/produktname**GT**";
$order_details .= "**LT**amount**GT**" . $item->get_quantity() . "**LT**/amount**GT**";
$order_details .= "**LT**upload**GT**" . maybe_serialize( get_field( 'upload', $product->get_id() ) ) . "**LT**/upload**GT**";
$order_details .= "**LT**size**GT**" . maybe_serialize( get_field( 'size', $product->get_id() ) ) . "**LT**/size**GT**";
$order_details .= "**LT**groesse**GT**" . maybe_serialize( get_field( 'produktgröße', $product->get_id() ) ) . "**LT**/groesse**GT**";
$order_details .= "**LT**material**GT**" . maybe_serialize( get_field( 'material', $product->get_id() ) ) . "**LT**/material**GT**";
$order_details .= "**LT**print**GT**" . maybe_serialize( get_field( 'print', $product->get_id() ) ) . "**LT**/print**GT**";
$order_details .= "**LT**variante**GT**" . maybe_serialize( get_field( 'variante', $product->get_id() ) ) . "**LT**/variante**GT**";
$order_details .= "**LT**category**GT**" . maybe_serialize( get_field( 'category', $product->get_id() ) ) . "**LT**/category**GT**";
//add options to the output
$order_details .= "**LT**Options**GT**";
$order_details .= "**LT**Option**GT****LT**ID**GT**" . "1996" . "**LT**/ID**GT****LT**Value**GT**" . maybe_serialize( get_field( 'value_115', $product->get_id() ) ) . "**LT**/Value**GT****LT**/Option**GT**";
$order_details .= "**LT**Option**GT****LT**ID**GT**" . "2489" . "**LT**/ID**GT****LT**Value**GT**" . maybe_serialize( get_field( 'value_117', $product->get_id() ) ) . "**LT**/Value**GT****LT**/Option**GT**";
$order_details .= "**LT**Option**GT****LT**ID**GT**" . "2056" . "**LT**/ID**GT****LT**Value**GT**" . maybe_serialize( get_field( 'value_118', $product->get_id() ) ) . "**LT**/Value**GT****LT**/Option**GT**";
$order_details .= "**LT**/Options**GT**";
$order_details .= "**LT**/item**GT**";
}
return $order_details;
}
?>
->
Does anyone have an idea?
Many thanks.
I have a content type called testimonial and this holds testimonials for 4 different services. I have created 4 pages each of which describes 1 service and it’s my aim to output the testimonials for each service on the relevant service page. I need to tie the two together. My thought process is to created a taxonomy for each service, add this field to the page and also the testimonial page. I can then do a lookup within the wordpress loop for the relevant term. Is that the best plan?
I have created a custom post type, let’s call that Services.
I have also created a custom Taxonomy called Services type
Now, I’d like to create a custom URL for the cars so it’s domain.com/services/service-type/{service name}
Where, services= custom post type, service-type = custom taxonomy and service name = the specific post name.
By default it’s domain.com/services/{service name}
How can i add taxonomy before service name ?
I use a custom post type and a custom taxonomy that is applied to this custom post type. This post type is published by receiving submissions from the front-end and the taxonomy ID value is determined at the time of form submission (the form is using another plugin called “Forminator” for this process).
However, when I checked this submitted post, the taxonomy was not applied to the post. When I go to edit the submitted post directly from the WP admin panel, the taxonomy checkbox panel is already checked with the same taxonomy as the taxonomy ID value received upon form submission, but it is not applied until I update the post (without any changes). In other words, if I update the post manually on the post editor page without any changes, everything works fine.
I found some forum threads about this and similar issues and tried disabling the Gutenberg editor, but it didn’t fix it.
Why is this happening and is there any way to fix it?
Hi,
I’m creating a generic load more system in a website for one of my client.
The configuration of the system is done by ACF fields in a custom block. The global functioning is as follow:
In the block settings you can:
In a page context, I have no issue. I send the page ID to the back and get_fields() works like a charm to force the desired configuration and return the new posts to load on front.
But where I have an issue, it’s in a FSE template context.
When I create a template for a taxonomy archive in the FSE Editor, ACF seems to save the fields value in the template’s post_content. And in this contexte I cannot fetch the fields values via get_fields() on back. I tried sending the get_the_ID(), get_queried_object_id(), etc. Nothing. ACF cannot recover the fields set in the FSE template.
Is there a way to do this? As I do not want to send the post-type / taxonomy via ajax (and thus stored in the DOM) for security issues.
Thank you.
Hi,
I need some help because I’m trying to setup a page with joboffers and selectable companies where a company might have more than one location.
I’ll try to explain my problem:
I have a custom post type “Jobs”.
I have a custom post type “Companies”.
Some Companies will have multiple locations.
I did setup field group (jobfields) with a relationship field for the post type filter “Companies” so that a company can be assigned to a job.
But now, after assigning a company to a job it should also be possible to select locations out of the locations which are assigned to that company that is selected in the relationship field.
I would like to have a possibility to assign locations to the custom post type “Company”.
Than when adding a job and selecting one company I would like to have the possibility to select only locations which are assigned to the selected company.
In the end there should be a job assigned to company and assigned to selected locations.
I don’t know if I should setup the locations as terms of a taxonomy called “locations” which can be assigned to the companies.
I tried that but couldn’t get it working that only the assigned locations from a company are shown to select. I always had all locations to select from.
Or is it better to have another custom post type e.g. “locations” which can be assigned with another relation field in the company post type. But than I don’t know how to setup the fields for that.
I’m sorry if it sounds a bit confusing but I hope someone gets my point and have an idea how to get this done.
Created a new post_type: instrument;
Created a new taxonomy: instrument-name
I added several different categories A, B, and C in the name, and then set A as the superior category of B.
Afterwards, I opened it to view all categories,/wp-admin/edit-tags.php? taxonomy=instrument-name&post_type=instrument, I can’t see B anymore. If I click sort by name, B will be displayed, but there is no subcategory flag “-” in front of B. From the HTML source code, any subcategory under the category I created with ACF that is class=”level-1″ will not be displayed. These issues are normal in the default article classification directory of WordPress. May I ask if there is any solution? thank you
Hello,
If I want to list some custom-selected posts on a page, I would create a post object field on the option page and allow the user to select the posts they want to display.
What about Taxonomy Terms? For instance, if I want to display custom-selected tags from post_tag and show them on a page, is there a way to select those objects and retrieve them on the frontend? (Something you can see on a blog site a sidebar displaying a list of popular tags for visitors to select. However, I want to have them manually selected.)
Is it possible or is there any workaround?
Thanks
I’ve set up an ACF post type called “encyclopedia” with a taxonomy category called “topics.” I now want to create an Elementor search results page that will only show post types of “encyclopedia” with the category of “topic.” I’ve tried making a PHP filter to restrict results to that criteria, but it’s still showing all entries that contain the entered search term from across the entire site.
Below is the code to show any encyclopedia entries that meet the search criteria, but it’s showing all entries that contain the entered search criteria.
Any suggestions for what I need to do differently?
Thanks in advance for your help.
if (!is_admin()) {
function mv_search_filter($query) {
if ($query->is_search) {
$query->set('post_type', array( 'encyclopedia' ));
}
return $query;
}
add_filter('pre_get_posts','mv_search_filter');
}
I’ve had a site that I’ve used for a clients construction project management that has been running flawlessly with minimal maintenance for years (7-8 years).
They are logging in with custom role using User Role Editor. On the front end they have a form (built into template using acf_form() where they fill out to create a daily log. In the form are several rows of data they can enter including repeater fields. One of the repeater fields is a taxonomy field pulling in a list of subcontractors they can choose from.
Recently they are having an issue with not seeing the taxonomy field or the ability to type in to find a subcontractor. If I am logged in as myself as an admin I see this field working. I’ve also tried the User Role Switcher to switch to the client having the issue and also see the field.
So I’m kind of stumped as to why this would happen and why I can’t recreate it. This all came out of the blue recently. So not sure if some update broke something.
Thanks.
Hello there !
I’m actually working on a site with ACF PRO, and after few hours of unsuccessful research,i’m looking for some help about taxonomy :
In the wordpress back-office as an admin, while creating a CPT, which have a hierarchical taxonomy – is there is any known solution to automatically check the childs when the user check the parent ?
In this case, a few parents have more than 20+ childs , so it can really be time-consuming if user need to add every child manually.
If any of you can give me a tips, i would love take it.
Hi!
I created custom post type and added taxonomy to it. Taxonomy has custom image field in it. I create single post page with Elementor and wanted to insert dynamically the image from taxonomy that current post belongs to but Elementor can’t see the values of post taxonomy fields.
I browsed the internet and this forum, couldn’t find a proper solution. I’d be grateful if anyone has any idea how to achieve this?
Is there a way to make the Taxonomy field look like the Button Group field? I have attempted to add the class “acf-field-button-group” to the Taxonomy field – Presentation- Class section, but that did not work.
Márcio Bento
Jul 22, 2024, 8:13 AM CDT
Hi there,
I created a taxonomy that is global across all custom post types on our website. The taxonomy is ‘Languages’
We had: English, portuguese, French, Spanish, etc.
Now the client wanted to change to the native way of writing those languages: English, Português, Français, Español.
We already changed these names. However, we have a post object field that uses this taxomy. And those are still displaying the old names. How can we quickly update this so the changes take effect? (Without having to go inside one by one and hit update)
Having the option to include multiple taxonomies in the Taxonomy Field would be helpful (instead of creating a separate field for each taxonomy).
Is it possible to populate choices for the Taxonomy field type?
My use case. There are 10 Terms in the taxonomy but I only want to show specific 3 terms.
I have tried something like this
termId : termName
But it does not seem to work. Any suggestions?
Thanks
function my_acf_load_field_options( $field ) {
// Reset choices
$field[‘choices’] = array();
// Define your options
$options = array(
’31’ => ‘Term A’,
’29’ => ‘Term B’,
’44’ => ‘Term C’
);
// Add options to field choices
foreach( $options as $key => $value ) {
$field[‘choices’][$key] = $value;
}
// Return the field
return $field;
}
// Replace ‘company_nature_of_business_2’ with the actual name or key of your ACF field
add_filter(‘acf/load_field/name=taxonmoy_option’, ‘my_acf_load_field_options’);
I’m having issues adding checkbox fields with hard-coded choices (in admin).
Every time I add a checkbox and adding the choices in admin, I’m getting this error:
array_map(): Argument #2 ($array) must be of type array, int given
Checkboxes added using taxonomy field are fine.
In:
/advanced-custom-fields-pro/includes/fields/class-acf-field-checkbox.php:247
This is the code:
$args[‘disabled’] = array_map( ‘esc_attr’, $args[‘disabled’] );
($args[‘disabled’] is 0)
Here’s the field.:
{
“key”: “field_65e14ce0816cf”,
“label”: “Charts Reporting To”,
“name”: “charts_reporting_to”,
“aria-label”: “”,
“type”: “checkbox”,
“instructions”: “”,
“required”: 0,
“conditional_logic”: 0,
“wrapper”: {
“width”: “”,
“class”: “”,
“id”: “”
},
“disabled”: 0,
“relevanssi_exclude”: 0,
“choices”: {
“Country Aircheck”: “Country Aircheck”,
“Music Row”: “Music Row”,
“AMA”: “AMA”,
“Roots Music Report”: “Roots Music Report”,
“Bluegrass Unlimited Survey”: “Bluegrass Unlimited Survey”,
“Bluegrass Today Bluegrass”: “Bluegrass Today Bluegrass”,
“Bluegrass Today Grassicana”: “Bluegrass Today Grassicana”,
“Bluegrass Today Gospel”: “Bluegrass Today Gospel”,
“Singing News”: “Singing News”,
“Singing News Bluegrass”: “Singing News Bluegrass”
},
“default_value”: [],
“return_format”: “value”,
“allow_custom”: 1,
“save_custom”: 0,
“layout”: “vertical”,
“toggle”: 0,
“custom_choice_button_text”: “Add new choice”
},
I noticed all ACF fields have disabled set to zero.
Any help is appreciated.
Hi. I am trying to set a field value on a custom taxonomy term, which may be newly created. Here’s my logic:
$client_term = get_term_by( 'name', $contact['name'], 'mp_client' );
if ( !$client_term ) {
$client_term = wp_insert_term( $contact['name'], 'mp_client' );
}
update_field( 'contact_id', $contact['id'], 'mp_client_' . $client_term->term_id );
For some reason, update_field doesn’t save the value when the term is newly created by wp_insert_term. For existing terms, it works.
Why is that? I’ve tried saving using field_keys, but it makes no difference.
Apologies if what I’m asking about is ACF 101. I’m kind of new when it comes to programmatically updating field values. My problem concerns a site that is using ACF Pro (version 6.3.3). I have a custom post type called “Projects” that is registered through theme code. I’ve created over 100 projects, each with their own featured image (using the built-in WP featured image field). Now, the client wants the ability to have multiple featured images, one for each “discipline” (a custom taxonomy I created for them). There are three disciplines, one of which is called “Architecture”. They want to show a different featured image for each project on the frontend, depending on which discipline term has been selected by the user. To that end, I have created a group called “discipline_imgs” with 3 image sub-fields. Each sub-field’s field name corresponds to a discipline term slug. For example, there’s an image sub-field labelled “Architecture” with the field name “architecture”. Each image sub-field is set to return the image ID.
They want to copy the current featured image in each project to the “architecture” image sub-field, and then they want the other sub-fields updated with different images. So, rather than going through all 115 projects and manually copying the featured image over, I decided to write a script to do it. The script is in the form of a theme page template. Here is the template code:
<?php
/**
* Template Name: Copy Project Featured Image to Architecture Image
*/
defined('ABSPATH') || die(1);
is_super_admin() || die(1);
header('Content-Type: text/plain; charset=' . get_bloginfo('charset'));
query_posts(
[
'post_type' => 'project',
'posts_per_page' => -1,
],
);
$project_count = $project_updated_count = 0;
while (have_posts()) :
the_post();
++$project_count;
[
'architecture' => $architecture_img,
] = (array)get_field('discipline_imgs');
var_dump(compact('architecture_img'));
if (0 < $architecture_img) :
continue;
endif;
$featured_img = get_post_thumbnail_id();
var_dump(compact('featured_img'));
if (!$featured_img) :
continue;
endif;
$result = update_field(
'discipline_imgs',
['architecture' => $featured_img],
);
if ($result) {
++$project_updated_count;
}
endwhile;
echo sprintf(
'Updated %d of %d project(s).',
$project_updated_count,
$project_count,
) . "\n";
I created a page and set the template to this template. When I visit the page, it spits out a bunch of var_dump()
output, so that I know that each project has a value of NULL
for the “architecture” sub-field and a non-zero value for the featured image, as it should be. Then at the end it says “Updated 0 of 115 project(s)”. So something is wrong with the update_field()
lines and the projects aren’t getting updated. Thoughts?
I have a custom post type “Client”, and a custom taxonomy “Region”. I would like to set a different “logo weight” value for each client’s region, and store it in a region_weights array.
I created a region_weights
ACF field of type “Group”, into which i want to dynamically include the sub fields (1 per region attached to the client).
define('REGION_WEIGHTS_FIELD_KEY', 'field_6668114add626');
add_filter('acf/prepare_field/key=' . REGION_WEIGHTS_FIELD_KEY, 'prepare_region_weights_field');
function prepare_region_weights_field($field)
{
global $post;
// Only apply this to the 'region_weights' field group
if ($field['_name'] !== 'region_weights' || $post->post_type !== 'client') {
return $field;
}
// Get the regions associated with this client
$regions = wp_get_post_terms($post->ID, 'region');
if (is_wp_error($regions) || empty($regions)) {
return false; // No regions, no fields to display
}
$field_value = get_post_meta($post->ID, REGION_WEIGHTS_FIELD_KEY, true);
// Generate a field for each region
foreach ($regions as $region) {
$field_name = 'field_region_weights_' . $region->term_id;
$default_value = isset($field_value[$field_name]) ? $field_value[$field_name] : 0;
$region_field = array(
'key' => $field_name,
'label' => $region->name . ' Logo Weight',
'name' => $field_name, // Use the correct field name
'type' => 'select',
'instructions' => 'How often should the ' . $region->name . ' logo appear?',
'required' => 0,
'conditional_logic' => 0,
'wrapper' => array(
'width' => '',
'class' => '',
'id' => '',
),
'choices' => array(
0 => 'Logo should not appear',
1 => 'Logo should appear once in a while',
2 => 'Logo should appear pretty often',
3 => 'Logo should appear most often',
),
'default_value' => $default_value,
'value' => $default_value, // Use the correctly formatted meta key for the value
'_name' => 'region_weights',
'parent' => $field['key'],
'_valid' => 1,
);
$field['sub_fields'][] = $region_field;
}
// Replace the original field with the generated fields
return $field;
}
That part works. What does not work is that i cannot save the fields. The update_field function I attached to the ‘acf/save_post’ action hook returns false and I fail to see why. Can you help ?
add_action('save_post', 'save_client_regionWeights');
function save_client_regionWeights($post_id)
{
// Check if we're saving a 'client' post type
if (get_post_type($post_id) !== 'client') {
return;
}
// Check user permissions
if (!current_user_can('edit_post', $post_id)) {
return;
}
// Check if it's an autosave
if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
return;
}
// Check if ACF data is being saved
if (!isset($_POST['acf'])) {
return;
}
if (!isset($_POST['acf'][REGION_WEIGHTS_FIELD_KEY])) {
return;
}
// Get the regions associated with this client
$regions = wp_get_post_terms($post_id, 'region');
if (is_wp_error($regions) || empty($regions)) {
// No regions, nothing to save
return;
}
// Prepare an array to hold our region weights data
$region_weights_data = array();
// Loop through each region and collect the weight data from $_POST
foreach ($regions as $region) {
$field_name = 'field_region_weights_' . $region->term_id;
if (isset($_POST['acf'][REGION_WEIGHTS_FIELD_KEY][$field_name])) {
// Add this region's weight to our data array
$region_weights_data[$field_name] = $_POST['acf'][REGION_WEIGHTS_FIELD_KEY][$field_name];
} else {
// If no weight was set, default to 0
$region_weights_data[$field_name] = 0;
}
}
// Update the region weights data
update_field(REGION_WEIGHTS_FIELD_KEY, $region_weights_data, $post_id);
}
If I print the content of $_POST[‘acf’] I get sensible data:
Array
(
[field_646f1e398ee52] => Client Something
[field_63c684c9f2e59] => 95926
[field_63c93f5d38405] => 95921
[field_65cde112bc88c] => 2
[field_6668114add626] => Array
(
[field_region_weights_315] => 2
)
)
What am I doing wrong ?
I have been searching for a fix for this and have not found any solutions that have worked for me. It has to be something simple I am missing.
I have created a new Field Group > Field Type > Taxonomy with the multi checkbox appearance. Taxonomy is selected, Save Terms is selected and Load Terms is selected. I am using Term ID for the value.
I am using this snippet below, attached to a query, I got from this site to pull the values of the selected checkboxes on the front-end:
<?php $terms = get_field('app_sort_new'); if( $terms ): ?>
<ul>
<?php foreach( $terms as $term ): ?>
<li>
<h2><?php echo esc_html( $term->name ); ?></h2>
<p><?php echo esc_html( $term->description ); ?></p>
<a>">View all '<?php echo esc_html( $term->name ); ?>' posts</a>
</li>
<?php endforeach; ?>
</ul>
<?php endif; ?>
The only taxonomy property that is being returned is the link with <?php echo esc_url( get_term_link( $term ) ); ?>
I have tried $term->slug;
and that does not work either.
What could I be missing here? No other name, description, slug anything is returned other than the link. Any help is greatly appreciated.
I assume this needs to go into a Front-end issue but I apologize if this is in the wrong spot. My first post here.
Hi everyone, I created a custom post type called “library” and for a taxonomy, called “Bible Portion”. And inside the portion I added a custom field called “week” where I want to mark that this is the portion for this current week.
Now I would like to provide a post view where always the posts of the current week are shown, and all I have to do is to update the category with its custom field.
I already created a page where the category is filtered correctly.
https://www.my-domain.com/author/?bible-portion
Now my question is how can I filter the bible portion that has the custom field “week” filled with “yes”?
Your help is much appreciated
Yonatan
Hi, I have a use case that requires us to attach an organisation to every WP user and it makes most sense (?) to add an Organisation taxonomy to the the User.
I’ve searched the documentation but didn’t see anything like this and the forum has one thread, started back in 2015 with the latest response in 2017.
So the question, is does ACF Pro have this functionality, and if not does anyone know of a way to achieve this?
Any help is greatly appreciated.
C.
Hi,
I am currently working on a woocommerce website and I have an issue on this :
<?php
// Check value exists.
if( have_rows('contenu_flexible', $current_category->taxonomy.'_'.$current_category->term_id) ):
echo "ok";
// Loop through rows.
while ( have_rows('contenu_flexible', $current_category->taxonomy.'_'.$current_category->term_id) ) : the_row();
?>
but I can’t even display the “ok”. And if I do a var dump avec the acf field it shows an array : array(11) {
[0]=>
string(28) “texte_pleine_largeur_de_page”
So I do have data in this field I don’t know how i can manage to display everything I want
Thank you !
HI,
I have a taxonomy called ‘campuses’ that I want to loop through for various items on my site when i got to my field (text, heading, button) i don’t see the option to select the taxonomy to input the field. is there a way to get that taxonomy to populate the text field?