So basically we have this field which is shipping number (order_shipping_number)
that is normally updated manually through manual input on the order page.
This field is normally updated before the order status is switched to “Completed”.
On some ocasions, users will select different shipping methods,
based on these shipping methods I am not updating the shipping number (order_shipping_number)
automatically/programatically when it is set to “processing” (meaning the user has paid the order, so sometimes “Processing” is also switched automatically by the payment processors)
(I use “woocommerce_order_status_processing” because this is the stage when customer has officially paid for the order.) so that there doesn’t need to be a manual input anymore but this is only for 40% of the orders. So the value still needs to be updated or changed manually sometimes, before the order is set to “completed”.
So I understand that WP save_post hook fires after “woocommerce_order_status_processing”, overwriting the “update_field” that happened.
But I admit I am not sure what would be the best practice to follow here given this situation
I think that this is an order of operation issue.
The WC woocommerce_order_status_processing fires before the WP save_post hook. ACF updates values on the save_post hook. If you try to update ACF fields on the first hook then ACF runs and updates it again and removes the value you just added.
If the ACF field is available to enter the order_shipping_number when updating the order is there a specific reason that you want to update it with code?
The post is updated to Processing through native woocommerce usage ( inside the Order, it is switched to status “processing” and then pressed the button “Update”.
The field is a standard text field, available in the Order page to be edited, this is correct.
By the way when running the code with some form of debugging like this
add_action( 'woocommerce_order_status_processing', 'update_product_custom_field_', 10, 1 );
function update_product_custom_field_( $order_id ) {
// Log start of function
error_log("Updating custom field for order ID: $order_id");
// Generate the shipping number using the order ID
$shipping_number = 'SHIPPINGNUMBERHERE';
// Check if ACF function exists and update the custom field
if (function_exists('update_field')) {
$result = update_field( 'order_shipping_number', $shipping_number, $order_id );
if ($result) {
error_log("Successfully updated order_shipping_number for order ID: $order_id");
} else {
error_log("Failed to update order_shipping_number for order ID: $order_id");
}
} else {
error_log("ACF update_field function not found.");
}
}
it prints to the logs “Successfully updated order_shipping_number for order ID:”
which makes it seem like the update_field is running correctly, but for some reason is not saving?
It seems there might be an issue in Elementor when querying products by category, specifically in selecting dynamic tags. To address this:
Ensure all plugins, including Elementor and WooCommerce, are updated.
Check Elementor Pro features, as advanced options may require the pro version.
Refer to Elementor documentation and support forums for guidance.
Consider creating a template for product archives using Elementor.
Verify compatibility of dynamic content plugins with Elementor and WooCommerce.
If the issue persists, contact Elementor support for assistance.
Always perform backups before making changes.
Hi,
Sorry for that misunderstanding, I’m working on woocommerce and the plugin “WP Gridbuilder”.
And a php code is exactly what I’m looking for !
So far I’ve done this :
function save_acf_image_as_featured_in_taxonomy($term_id) {
// Assurez-vous de remplacer ‘nom_du_champ_image’ par le slug de votre champ ACF
$image_id = get_field(‘_thumbnail_id_marque’, ‘taxonomy_’ . $term_id);
if ($image_id) {
// Enregistrez l’ID de l’image dans les métadonnées de la taxonomie
update_term_meta($term_id, ‘featured_image_id’, $image_id);
}
}
add_action(‘edited_ma_taxonomie’, ‘save_acf_image_as_featured_in_taxonomy’);
add_action(‘create_ma_taxonomie’, ‘save_acf_image_as_featured_in_taxonomy’);
function set_custom_card_thumbnail_for_taxonomy($object) {
// Obtenez les paramètres du grid courant.
$grid = wpgb_get_grid_settings();
// Si cela ne correspond pas à l’ID du grid 6.
if (6 !== $grid->id) {
return $object;
}
// Si l’objet est une taxonomie (ajustez ‘ma_taxonomie’ pour votre taxonomie).
if (is_a($object, ‘WP_Term’) && ‘marque’ === $object->taxonomy) {
// Obtenez l’ID de l’image ACF pour la taxonomie.
$image_id = get_field(‘_thumbnail_id_marque’, ‘taxonomy_’ . $object->term_id);
// Si un ID d’image est trouvé, affectez-le.
if (!empty($image_id)) {
$object->post_thumbnail = $image_id;
}
}
return $object;
}
add_filter(‘wp_grid_builder/grid/the_object’, ‘set_custom_card_thumbnail_for_taxonomy’);
But it’s not working…
I was poiting out the product category miniatures of woocomerce because, without any dev, it just works fine with what I’m willing to do.
Thanks.
Hello,
Thanks for your answer.
I do build on Woocommerce and it seems to me that the product category, witch is a wp taxonomy, has the featured image.
Anyway I’ve ask the gridbuilder support.
To be continued…
I had the same issue.
I was able to fix it by rolling back to WooCommerce 8.1.1
Actually, there is a solution, but I didn’t have enough time to realize it through acf, maybe this will help someone to realize this task.
And so: on the page of creating/editing taxonomy (attribute), custom form, which has hooks:
woocommerce_after_edit_attribute_fields – for the attribute edit page.
woocommerce_after_add_attribute_fields – for the add attribute page.
I can add a custom input \select \anything through this hook, and then, on the admin_init hook (for example), check $_POST and if my input is there (if my input is there, there will be other inputs from the form), save this value in the database table. You can save it anywhere, but it is more correct to save it in a custom table, and create a link, for example, by the key (slug) of the attribute, for example pa_finish. And as a result, when processing a product or a taxonomy term, we can take the slug of the taxonomy (attribute) and use it in the custom table in the database to get the value that we attached to the form of creating/editing the attribute.
Thus, I can save primitive data, such as select to specify the type of display attribute (image \ color \ text \ select) and based on this, display the necessary html for a particular attribute.
John Huebner – I’ve seen a lot of your posts, and I think you can do it).
hi . I am a beginner in coding and this code is a professional template to display special discounts on the home page. I intend to use this code in my theme. I understand that I have to use $slider_off = get_field('slider_off', 'option');
in the template options page and I have already used it and it works fine for enabling/disabling. But I can’t make a connection between this code $item = $list['slider_off_product'];
and the WooCommerce post. I don’t understand how it communicates with the product and displays product information. Thank you for your help in this matter.
@hube2 , hi trying to do this to apply a class to woocommerce single product gallery thumbnails. i’m using a true/false acf field on media attachment.
this code is not working for me:
<?php
$image = get_field('quick_ship');
$size = 'full'; // (thumbnail, medium, large, full or custom size)
if( $image ) {
echo wp_get_attachment_image( $image, $size, array ('class' => 'quick-ship' ) );
}
Hi there,
You’re right, my first reply is for front-end orders only.
Could you try the code below.
Let me know if it helps (i could re-use it someday).
Cheers,
Rémi
First, we write a small helper function to get and reorder your acf fields
<?php
//Helper function - Reorder acf datas
function maybe_reorder_acf_fields($order_id) {
$name = get_field('{slug/key}', $order_id) ? get_field('{slug/key}', $order_id) : null; //CHANGE with your own acf slug/key
$start_date = get_field('{slug/key}', $order_id) ? get_field('{slug/key}', $order_id) : null; //CHANGE with your own acf slug/key
$adults = get_field('{slug/key}', $order_id) ? get_field('{slug/key}', $order_id) : null; //CHANGE with your own acf slug/key
$children = get_field('{slug/key}', $order_id) ? get_field('{slug/key}', $order_id) : null; //CHANGE with your own acf slug/key
//Don't remember how datas are validated from get_field() - maybe esc/filter_var functions are useless
$custom_acf_metas = array(
'_acf_tour_customer_name' => esc_html($name),
'_acf_tour_start_date' => esc_html($start_date),
'_acf_tour_adults_nbr' => filter_var($adults, FILTER_SANITIZE_NUMBER_INT),
'_acf_tour_child_nbr' => filter_var($children, FILTER_SANITIZE_NUMBER_INT)
);
return $custom_acf_metas;
}
Next we use WP save_post hook to add OR overwrite custom metas each time an order is saved in backend.
https://developer.wordpress.org/reference/hooks/save_post/
Note : my_save_custom_order_metas() will add your acf datas to all products in an order.
You may adapt this code and probably your acf datas depending on your needs.
<?php
//Add new metas to order item(s)
add_action( 'save_post', 'my_save_custom_order_metas', 10, 3 );
function my_save_custom_order_metas( $order_id, $order, $update ) {
//Not sure if post revisions are used for shop orders - it returns false on a valid $order_id
if ( !is_admin() || get_post_type( $order_id ) !== 'shop_order' || wp_is_post_revision( $order_id ) ) return;
//Uncomment those two lines if you want to target specific order status
// $order_status = $order->get_status();
// if( $order_status !== 'wc-processing' ) return null;
$custom_acf_metas = maybe_reorder_acf_fields($order_id);
//Loop over every items added to your order
if( $order->get_items() ) {
foreach ( $order->get_items() as $item_id => $item ) {
//Nested loop over reordered ACF datas
foreach($custom_acf_metas as $new_meta_key => $new_meta_value) {
//Uncomment the two lines below if you don't want to overwrite your values
//$new_meta_exists = wc_get_order_item_meta( $item_id, $new_meta_key, true);
// if( $new_meta_exists !== false ) continue;
if( $new_meta_value !== null ) {
//Probably not really needed too - could be useful
$new_meta_key = sanitize_key($new_meta_key);
$new_meta_value = sanitize_meta( $new_meta_key, $new_meta_value, 'order_itemmeta' );
//Add new meta
$item->add_meta_data(
$new_meta_key,
$new_meta_value,
true
);
}
}
//Don't forget to save modified order here
$order->save();
}
}
}
Finally we keep our last 2 woocommerce filters to modify back-end display key + email and customer account item details (human readable for both).
<?php
//Modify our custom meta key to make it human readable from back-end
add_filter('woocommerce_order_item_display_meta_key', 'filter_wc_order_item_display_meta_key', 20, 3 );
function filter_wc_order_item_display_meta_key( $display_key, $meta, $item ) {
//Don't know if there is a better way to retrieve $order_id (and related acf datas)
$item_datas = $item->get_data();
$order_id = $item_datas['order_id'];
$custom_acf_metas = maybe_reorder_acf_fields($order_id);
// Change displayed label for specific order item meta key
foreach($custom_acf_metas as $new_meta_key => $new_meta_value) {
switch($new_meta_key) {
case '_acf_tour_customer_name' :
$new_display_key = '[your_display_key]'; //CHANGE with your own value
break;
case '_acf_tour_start_date' :
$new_display_key = '[your_display_key]'; //CHANGE with your own value
break;
case '_acf_tour_adults_nbr' :
$new_display_key = '[your_display_key]'; //CHANGE with your own value
break;
case '_acf_tour_child_nbr' :
$new_display_key = '[your_display_key]'; //CHANGE with your own value
break;
}
//Not sure if is_admin is necessary
if( is_admin() && $item->get_type() === 'line_item' && $meta->key === $new_meta_key ) {
$display_key = __($new_display_key, "my-text-domain" );
}
}
return $display_key;
}
// Add custom cart item data to emails AND customer account order details
add_filter( 'woocommerce_order_item_name', 'my_custom_data_in_email', 10, 2 );
function my_custom_data_in_email( $product_name, $item ) {
$item_datas = $item->get_data();
$order_id = $item_datas['order_id'];
$custom_acf_metas = maybe_reorder_acf_fields($order_id);
// Change displayed label for specific order item meta key
foreach($custom_acf_metas as $new_meta_key => $new_meta_value) {
switch($new_meta_key) {
case '_acf_tour_customer_name' :
$new_display_key = '[your_display_key]'; //CHANGE with your own value
break;
case '_acf_tour_start_date' :
$new_display_key = '[your_display_key]'; //CHANGE with your own value
break;
case '_acf_tour_adults_nbr' :
$new_display_key = '[your_display_key]'; //CHANGE with your own value
break;
case '_acf_tour_child_nbr' :
$new_display_key = '[your_display_key]'; //CHANGE with your own value
break;
}
if( isset( $item[$new_meta_key] ) ) {
$product_name .= sprintf(
'<ul><li>%s: %s</li></ul>',
__( $new_display_key, 'RemSEO' ),
esc_html( $item[$new_meta_key] )
);
}
}
return $product_name;
}
Hi there,
I already made something similar but not with ACF datas.
Maybe you could try something like below.
Let me know if it helps.
Rémi
<?php
// Add custom cart item data when a product is added to cart from product page
add_filter( 'woocommerce_add_cart_item_data', 'my_custom_cart_datas', 10, 3 );
function my_custom_cart_datas( $cart_item_data, $product_id, $variation_id ) {
if( !isset( $_POST['new_post_data'] ) ) {
$cart_item_data['new_post_data'] = get_field('name', $order_id);;
}
return $cart_item_data;
}
// Displaying custom cart datas in cart
add_filter( 'woocommerce_get_item_data', 'my_display_custom_cart_datas', 10, 2 );
function my_display_custom_cart_datas( $item_data, $cart_item_data ) {
if( isset( $cart_item_data['new_post_data'] ) ) {
$item_data[] = array(
'name' => __( 'Displayed key', 'my-text-domain' ),
'value' => wc_clean($cart_item_data['new_post_data'])
);
}
return $item_data;
}
// Add custom meta to item (=product) in order (visible in order in back-end)
add_action( 'woocommerce_checkout_create_order_line_item', 'my_custom_order_line', 10, 4 );
function my_custom_order_line( $item, $cart_item_key, $values, $order ) {
if( isset( $values['new_post_data'] ) ) {
$item->add_meta_data(
'_new_item_line_meta',
$values['new_post_data'],
true
);
}
}
//Modify our custom meta key display
add_filter('woocommerce_order_item_display_meta_key', 'filter_wc_order_item_display_meta_key', 20, 3 );
function filter_wc_order_item_display_meta_key( $display_key, $meta, $item ) {
// Change displayed label for specific order item meta key
if( is_admin() && $item->get_type() === 'line_item' && $meta->key === '_new_item_line_meta' ) {
$display_key = __("Displayed key", "my-text-domain" );
}
return $display_key;
}
// Add custom cart item data to emails
add_filter( 'woocommerce_order_item_name', 'my_custom_data_in_email', 10, 2 );
function my_custom_data_in_email( $product_name, $item ) {
if( isset( $item['new_post_data'] ) ) {
$product_name .= sprintf(
'<ul><li>%s: %s</li></ul>',
__( 'Displayed key', 'my-text-domain' ),
esc_html( $item['_new_item_line_meta'] )
);
}
return $product_name;
}
Hi there,
This is an old thread but if my code could be useful, i let it here.
IMPORTANT : Please test it in a dev environment before.
I adapted and didn’t test the multisite adaptations.
It works on a single wordpress installation on ACF 5.1.5+ (tested on acf 6.2)
Note 1 : i hooked on ‘admin_init’ but maybe there is a better hook.
Note 2 : Tested on WP 6.2 only but i guess it would work far below as we only use get_post() and wp_update_post()
Feel free to correct it and share it 🙂
<?php
//Modify ACF group/fields setting and save it globally (DB + local JSON)
add_action('admin_init', 'modify_acf_settings');
function modify_acf_settings() {
//Working on specific fields/posts/groups - REPLACE with your own keys
$acf_posts_to_update = array(1234);
$acf_groups_to_sync = array('group_12345678abcde'); //Used only if you're using local JSON
$acf_fields_to_update = array( 'field_12345678abcde' );
$stored_posts = array();
$stored_acf_groups = array();
//You could modify any field settings from here
//@see https://www.advancedcustomfields.com/resources/acf-update_field/
foreach($acf_fields_to_update as $field) {
$is_field_exists = get_field_object($field);
if($is_field_exists !== false) {
$filter_identifier = strval('acf/update_field/key='.$field);
add_filter($filter_identifier, function($field) {
//$field['required'] = true;
//etc...
}, 10, 1);
}
}
//Then we use WP native functions to modify ACF posts
$updated_post = false;
$i = 0;
foreach($acf_posts_to_update as $post_to_update) {
$post_obj = get_post($post_to_update);
//You could grab and modify any datas returned with get_post()
// Example -> $post_content = $post_obj->post_content;
if($post_obj !== null) {
//Here i want to active a disable group if woocommerce is active
//All we have to do is change the post status (as ACF groups are basically custom post types)
if (&& in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) ) {
$current_status = $post_obj->post_status;
if($current_status == 'acf-disabled') {
$post_obj->post_status = 'publish';
}
//Don't forget to update post and validate/re-serialize modified datas if needed
wp_update_post( $post_obj );
$updated_post = true;
$stored_post[$i] = $post_obj;
} else {
//Disable it if woocommerce is not active and the group is publish
$current_status = $post_obj->post_status;
if($current_status == 'publish') {
$post_obj->post_status = 'acf-disabled';
}
wp_update_post( $post_obj );
$updated_post = true;
$stored_post[$i] = $post_obj;
}
}
$i++;
}
//Last step - Sync modified posts with JSON files
//note : using $updated_post but you could use any check
$update_modified_group = false;
if ( $updated_post === true ) {
$i = 0;
foreach($acf_groups_to_sync as $acf_group) {
$group_to_save = acf_get_field_group($acf_group);
$group_to_save['active'] = 1;
$update_modified_group = acf_write_json_field_group( $group_to_save );
//Add an admin notice is group was not savec correctly
if( boolval($update_modified_group) !== true ) {
add_action( 'admin_notices', 'acf_not_sync_notice' );
} else {
$stored_acf_groups[$i] = $group_to_save;
}
$i++;
}
}
//Finally, we will sync changes in other $blog in a multisite network
$current_blog_id = get_current_blog_id();
$sites = get_sites(
array(
'number' => 50,
'site__not_in' => $current_blog_id, // exclude current site from the loop
)
);
foreach( $sites as $site ) {
switch_to_blog( $site->blog_id );
if( is_array($stored_post) && !empty($stored_post) ) {
foreach($stored_post as $post) {
wp_update_post( $post );
}
}
if( is_array($stored_acf_groups) && !empty($stored_acf_groups) ) {
foreach($stored_acf_groups as $group) {
$update_modified_group = acf_write_json_field_group( $group );
}
}
}
//Don't forget to restore environnement
restore_current_blog();
}
function acf_not_sync_notice() {
?>
<div class="notice error my-acf-notice is-dismissible" >
<p><?php _e( 'Some ACF fields were not synced correctly. Please save the group fields manually.', 'my-text-domain' ); ?></p>
</div>
<?php
}
The issue is being understood. You are showing fields on a WC product page. While you are using ACF to hold those fields the conditions involved and the code required is specific to Woo Commerce (WC), not ACF.
In your function, you need to get the product ID as outlined in the first link I provided: https://stackoverflow.com/questions/27385920/woocommerce-get-current-product-id
Then you need to use that product ID to get the categories that the product is in as outlined in the second link I provided: https://stackoverflow.com/questions/15303031/woocommerce-get-category-for-product-page
Then you need to loop over that list of categories to see if you product is in a given category and display the fields based on that condition.
Thanks to everyone for your input. I don’t think that the issue is being understood, so let me try to clarify. I have two categories: Ammo & Guns.
The first part of the code deals with fields related to Ammo, while the second part of the code is strictly for guns. The code below works well but it shows all the fields for both categories. So What I am looking to accomplish is as follows:
If category equals “Ammo” then
add_action( ‘woocommerce_single_product_summary’, ‘sbnai_display_acf_field_1’, 30 );
function sbnai_display_acf_field_1() {
echo ‘<b>Per Round Cost:</b> ‘ . get_field(‘per_round_cost’) . ‘<br />’;
echo ‘<b>UPC:</b> ‘ . get_field(‘upc’) . ‘<br />’;
echo ‘<b>Caliber:</b> ‘ . get_field(‘caliber’) . ‘<br />’;
echo ‘<b>Bullet Weight:</b> ‘ . get_field(‘bullet_weight’) . ‘<br />’;
echo ‘<b>Bullet Type:</b> ‘ . get_field(‘bullet_type’) . ‘<br />’;
echo ‘<b>Case Type:</b> ‘ . get_field(‘case_type’) . ‘<br />’;
echo ‘<b>Combined Reviews:</b> ‘ . get_field(‘combine_reviews’) . ‘<br />’;
}
Else if category equals “Guns” then
add_action( ‘woocommerce_single_product_summary’, ‘sbnai_display_acf_field_2’, 31 );
function sbnai_display_acf_field_2() {
echo ‘<b>Width:</b> ‘ . get_field(‘width’) . ‘<br />’;
echo ‘<b>Height:</b> ‘ . get_field(‘height’) . ‘<br />’;
echo ‘<b>Depth:</b> ‘ . get_field(‘depth’);
}
Inside of your functions you need to get the product and then get the WC category that the product is in and then only create output when it is the right category.
trying to save the field data of upload file but failed
/ Add ACF file type field to WooCommerce product general settings
function add_acf_file_field_to_woocommerce_product_options() {
global $product_object; // Get the product object
$product_id = $product_object->get_id(); // Get the product ID
// Define the field settings
$field_settings = array(
'key' => 'field_my_file_field',
'label' => 'File Field',
'name' => 'my_file_field',
'type' => 'file',
'instructions' => 'Upload a file',
'return_format' => 'url', // Change this to 'array' if you want more information about the file
<!-- 'location' => array(
array(
array(
'param' => 'post_type',
'operator' => '==',
'value' => 'product',
),
),
), -->
);
// Render the ACF field
acf_render_field_wrap($field_settings);
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['woocommerce_process_product_meta'])) {
$file_field_value = $_POST['acf']['my_file_field'];
// Update the ACF field value
update_field('field_my_file_field', $file_field_value, $product_id);
}
}
// Hook into WooCommerce product general options
add_action('woocommerce_product_options_general_product_data', 'add_acf_file_field_to_woocommerce_product_options');
even this menthod is unable save the upload file data
iam able to insert acf field into product-data -> genreal tab
// Add ACF file type field to WooCommerce product general settings
function add_acf_file_field_to_woocommerce_product_options() {
global $product_object; // Get the product object
// Define the field settings
$field_settings = array(
'key' => 'field_my_file_field',
'label' => 'File Field',
'name' => 'my_file_field',
'type' => 'file',
'instructions' => 'Upload a file',
'return_format' => 'url', // Change this to 'array' if you want more information about the file
'location' => array(
array(
array(
'param' => 'post_type',
'operator' => '==',
'value' => 'product',
),
),
),
);
// Render the ACF field
acf_render_field_wrap($field_settings);
}
// Hook into WooCommerce product general options
add_action('woocommerce_product_options_general_product_data', 'add_acf_file_field_to_woocommerce_product_options');
but upload file is not saved……. when i update the page uploaded file is gone…..
why my upload file is not saved
The only way to do this in WP is to create a “Page” with a “Custom Template” and then generate the content yourself.
If you look at the WP template hierarchy there is no available file to create this list of terms automatically.
Generally, taxonomy terms are listed on the post archive page.
As an example, WooCommerce has a CPT for product and a Custom Taxonomy for product categories. When you view the “Shop” page a list of categories or sub categories is shown with links to those categories followed by a list of products in the current category when a specific category is shown.
To add extra tabs to the WooCommerce product page and populate their content from a CSV or Excel sheet using the Advanced Custom Fields (ACF) plugin, you’ll need to follow these steps:
Install and activate the ACF plugin from the WordPress plugin repository.
Create a new field group in ACF that will contain the text area fields for each tab. Set the location rule to “Post Type” and select “Product” to ensure the field group is associated with the WooCommerce product post type.
Add a text area field for each tab you want to create. You can customize the field settings as needed, such as the field label and field name.
Once you have set up the field group, navigate to a WooCommerce product edit screen in the WordPress backend.
Scroll down to the ACF section, where you should see the fields you created for the tabs. Enter the desired content for each tab in the corresponding text area fields.
To display the content of these tabs on the frontend, you will need to modify your product page template. Locate the file single-product.php in your theme’s directory. If it doesn’t exist, you can create a copy of woocommerce/templates/single-product.php and place it in your theme’s directory.
Edit the single-product.php file and find the section where the product description is displayed. It is typically located within the <div> with the class woocommerce-tabs.
Add the following code inside the <div> with the class woocommerce-tabs:
php
<?php if (have_rows('tab_fields', get_the_ID())) : ?>
<ul class="tabs">
<?php while (have_rows('tab_fields', get_the_ID())) : the_row(); ?>
<li><a>"><?php echo esc_html(get_sub_field('tab_title')); ?></a></li>
<?php endwhile; ?>
</ul>
<?php while (have_rows('tab_fields', get_the_ID())) : the_row(); ?>
<div id="<?php echo sanitize_title(get_sub_field('tab_title')); ?>">
<?php echo wpautop(get_sub_field('tab_content')); ?>
</div>
<?php endwhile; ?>
<?php endif; ?>
This code retrieves the ACF repeater field values for the tabs and generates the HTML structure for the tabs and their content. Each tab is generated based on the field values you entered in the backend.
Save the modified single-product.php file.
Now, when you view a WooCommerce product page on the frontend, you should see the additional tabs with their respective content populated from the ACF fields
Those fields are part of WooCommerce and you cannot use ACF to edit them without adding code.
For example, you can create ACF fields for your front end form that mimic WC fields and then use an acf/save_post action to get the values submitted and update the WC fields.
In this example the WC price field is saved with the meta key of “_regular_price”. Please not that this is only an example, not all WC products will have this field and any updating will depend on how WC stores the data.
// simple example
add_action('acf/save_post', 'my_update_wc_fields');
function my_update_wc_fields($post_id) {
if (get_post_type($post_id) != 'product') {
// not a WC product
return;
}
$price = get_field('my_price_field', $post_id);
if (!empty($price) {
update_post_meta($post_id, '_regular_price', $price);
}
}
In some cases it might be possible to skip the action function and just name your field the same as the WC field. For example you can name an ACF field “_regular_price” as long as the data stored in your ACF field matches the database storage used for WC. In this example an ACF number field would likely work.
It is important in both of the above examples that your field is only used on the front end form and does not appear in the admin when editing because this will cause conflicts with WC.
As I stressed above, this is only a simple example, I don’t know everything about WC or how all of the fields are stored or how they might changed based on other WC product settings.
This is a WooCommerce question and depends on if WC allows the field to be removed.
ehw,
In my case the issue comes from the plugin “Product Table for WooCommerce by codeAstrology (WooproductTable)” if i deactivate it, ACF works fine again 🙁
Thanks for the reply. You are correct, having the information in two places is not smart. I ended up creating a custom shortcode and then using the shortcode to show the shipping time on produt page.
// ACF Brand Shipping time --> product page
add_action( 'woocommerce_before_single_product', 'boazmarketing_shippingtimeshortcode' );
function boazmarketing_shippingtimeshortcode() {
$terms = get_the_terms( $product_id, 'valmistajat' );
foreach ($terms as $term) {
$product_cat = $term->term_id;
}
$brandid = "valmistajat_". $product_cat;
$shippingtime = get_field('toimitusaika', $brandid);
return $shippingtime;
}
add_shortcode('valmistajan_toimitusaika', 'boazmarketing_shippingtimeshortcode');
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.