Ok. I did it the easiest way, by adding customs fields to checkout.
^^
Good explanations there :
http://www.portmanteaudesigns.com/blog/2015/02/04/woocommerce-custom-checkout-fields-email-backend/
Hi @wax
If you want to add the form to the product page, then you need more advanced code and logic. Unfortunately, I can only guide you with the logic. I’m sorry about that.
Like my answer in your other thread, you can use the repeater field and add it to the front-end by using this code:
acf_form(array(
'form' => false,
));
This will strip the ACF’s form tag and let you add it in the add to cart form instead.
When a user clicked the add to cart button, you can get the repeater value by using this code:
$repeater_values = $_POST['acf']['field_1234567890abc'];
Where ‘field_1234567890abc’ is the field key of the repeater. At this time, you need to modify the cart content so it can hold the extra information. Here’s an example how to do it: http://wordpress.stackexchange.com/questions/138595/add-custom-variable-to-cart-content. I’m not sure if it will work or not, though. Please consult to WooCommerce for more information.
I’m not sure if you need to modify the order or not after this process, but I guess you can try it out to find out 🙂
Hope this makes sense.
Hi @wax
You can always create a field group with a repeater field in it. Then, you can add the field group to the order post type and use acf_form()
instead of woocommerce_form_field()
with ‘form’ option set to false in the checkout form. This page should give you more idea about it: https://www.advancedcustomfields.com/resources/acf_form/. After that, just update the repeater values by using the update_field()
function.
You can get the posted repeater value like this:
$repeater_values = $_POST['acf']['field_1234567890abc'];
Where ‘field_1234567890abc’ is the field key.
I hope this makes sense 🙂
Well, with you advices, it seems to work.
If someone is interested :
/**
* Add custom fields to user / checkout
*/
add_action( 'woocommerce_after_order_notes', 'my_custom_checkout_field' );
function my_custom_checkout_field( $checkout ) {
echo '<div id="bv_custom_checkout_field"><h2>Measurements</h2>';
/* Weight */
woocommerce_form_field( 'weight_customer', array(
'type' => 'text',
'class' => array('my-class form-row-wide'),
'label' => __('Your weight'),
'placeholder' => __('Your weight'),
), get_user_meta( get_current_user_id(),'weight_customer' , true ) );
echo '</div>';
}
/**
* Verification
*/
add_action('woocommerce_checkout_process', 'my_custom_checkout_field_process');
function my_custom_checkout_field_process() {
// Check
if ( ! $_POST['weight_customer'] )
wc_add_notice( __( 'Do not forget weight.' ), 'error' );
}
* Update field
*/
add_action( 'woocommerce_checkout_update_order_meta', 'my_custom_checkout_field_update_order_meta' );
function my_custom_checkout_field_update_order_meta( $order_id ) {
if ( ! empty( $_POST['weight_customer'] ) ) {
update_user_meta( get_current_user_id(), 'weight_customer', sanitize_text_field( $_POST['weight_customer'], '' ));
}
}
I just don’t know how to tell him that it is a number (the weight) but it works.
Hi @wax
I believe the article you gave me is used on the my-account page, not the checkout page. If you want to add it on the checkout page, I believe the link I gave you is the proper one. In the order process, you can update the field by using the update_field()
function. Unfortunately, I’m not sure which hook you need to use. In this case, could you please ask the WooCommerce support instead?
Thanks 🙂
Thanks. It looks like it is simpler to do all the thing with woocommerce functions ?
I found this yesterday :
https://support.woothemes.com/hc/en-us/articles/203182373-How-to-add-custom-fields-in-user-registration-on-the-My-Account-page
and I wonder if it is not easier for me to add custom fields like this than with acf (only for registration custom fields).
Because what you say to me is that I need to “marry” acf code & woocommerce code, isn’t it ?
Hi @wax
I’m afraid WooCommerce has a custom registration form on the checkout page. To modify it, please take a look at this page: https://docs.woothemes.com/document/tutorial-customising-checkout-fields-using-actions-and-filters/. To update the custom field value in the database, you can use the update_field()
function. This page should give you more idea about it: https://www.advancedcustomfields.com/resources/update_field/.
I hope this helps. If you have any other questions, feel free to ask me again 🙂
Hi,
I can’t reproduce the problem now, so I think maybe it’s a side effect…
My code is quite simple :
if( function_exists('acf_add_local_field_group') ):
// Woocommerce : Product page fields
acf_add_local_field_group(array (
'key' => 'group_575eadb687a13',
'title' => 'PRODUCT INFORMATIONS',
'fields' => array (
array (
'key' => 'field_575eadcca9ddd',
'label' => '3 Instagram Photos',
'name' => 'three_instagram_photos',
'type' => 'gallery',
'instructions' => '',
'required' => 0,
'conditional_logic' => 0,
'wrapper' => array (
'width' => '',
'class' => '',
'id' => '',
),
'min' => '',
'max' => 3,
'preview_size' => 'medium',
'insert' => 'append',
'library' => 'all',
'min_width' => '',
'min_height' => '',
'min_size' => '',
'max_width' => '',
'max_height' => '',
'max_size' => '',
'mime_types' => '',
),
array (
'key' => 'field_57682747afc89',
'label' => 'External video',
'name' => 'external_video',
'type' => 'oembed',
'instructions' => '',
'required' => 0,
'conditional_logic' => 0,
'wrapper' => array (
'width' => '',
'class' => '',
'id' => '',
),
'width' => '',
'height' => '',
),
array (
'key' => 'field_57714db3280c7',
'label' => 'More description',
'name' => 'more_description',
'type' => 'wysiwyg',
'instructions' => '',
'required' => 0,
'conditional_logic' => 0,
'wrapper' => array (
'width' => '',
'class' => '',
'id' => '',
),
'default_value' => '',
'tabs' => 'all',
'toolbar' => 'full',
'media_upload' => 1,
),
),
'location' => array (
array (
array (
'param' => 'post_type',
'operator' => '==',
'value' => 'product',
),
),
),
'menu_order' => 0,
'position' => 'acf_after_title',
'style' => 'default',
'label_placement' => 'top',
'instruction_placement' => 'label',
'hide_on_screen' => '',
'active' => 1,
'description' => '',
));
...
Hi @jamesryder
I’m not sure but I think your issue _might_ be due to where you’ve placed acf_form_head
.
It should be located before any output and currently you’re placing it smack in the form.
Try this:
<?php
/**
* Output ACF form functionality on the edit account page in woocommerce
*/
function add_acf_head_to_wc(){
if( is_wc_endpoint_url() ){
acf_form_head()
}
}
add_action( 'template_redirect', 'add_acf_head_to_wc', 1000 );
/**
* Output our ACF image field in the WooCommerce edit account form
*/
function woocommerce_edit_account() {
acf_form(array(
'field_groups' => array(931), 'form' => false
));
}
add_action( 'woocommerce_edit_account_form', 'woocommerce_edit_account', 10 );
/**
* Do an ACF save action on the user.
* NOTE: I'm not sure this is even needed..?
*/
function my_woocommerce_save_account_details( $user_id ) {
// $post_id to save against
$post_id = 'user_' . $user_id;
// update the post
do_action('acf/save_post', $post_id);
}
add_action( 'woocommerce_save_account_details', 'my_woocommerce_save_account_details' );
Hi @jzjzjzjzj,
Thanks for the post.
You will only need to call the ACF display function within the woo_new_product_tab_content() function.
The code will look like so:
add_filter( 'woocommerce_product_tabs', 'woo_new_product_tab' );
function woo_new_product_tab( $tabs ) {
// Adds the new tab
$tabs['test_tab'] = array(
'title' => __( 'Shipping', 'woocommerce' ),
'priority' => 50,
'callback' => 'woo_new_product_tab_content'
);
return $tabs;
}
function woo_new_product_tab_content() {
// The new tab content
echo '<h2>New Product Tab</h2>';
echo '<p>Here\'s your new product tab.</p>';
echo get_field('fieldname', $post_id);
}
Yes, I can change the return value and make it work.
However, I’ve used the third party datetime-picker for a lot of functionality during recent years. Its not only for displaying a date and time on a website. Its for schedule import and export of business systems, apis, woocommerce integrations, integrations with booking systems, etc. All these projects will need to be re-tested.
How about disable the new core functionality for datetime-picker if the third party datetime-picker exists?
Ok. And thank you both for answering.
As I am at 80% of the project, and as I am as good developper as english spoker 😉 I gonna try not to go further but to return to a conventional use of woocommerce attribute. Their interface for attributes is a nonsense, but never mind.
I’m not exactly sure of the specifics on how WooCommerce stores product attibutes, but I do know that it stores them in a serialized array in a single postmeta field. You’re going to need to figure out how this array is built and you’re going to need to create an acf/save_post filter (https://www.advancedcustomfields.com/resources/acfsave_post/) to take all the ACF fields and build that array and then store it where WooCommerce expects to find it.
I would start by creating some products with all of the attributes you want to be able to set with ACF and then looking into the database to see where it’s stored and how it is constructed. You’ll be looking for the value with a postmeta key of _product_attributes
Hi @wax
I believe WooCommerce does more than assigning the attributes as taxonomy like what ACF does. They use this attribute to create variations too, so it’s possible that they save the attribute data somewhere else. For further support, could you please ask WooCommerce support instead?
I hope this makes sense 🙂
Following along with the instructions within the link, I’m able to accomplish all the steps except for “Matching the Rule” to the Category Editor page (Sorry for the sloppy code).
add_filter('acf/location/rule_types', 'acf_location_rules_types');
function acf_location_rules_types( $choices ) {
$choices['WooCommerce Category']['woocommerce_category'] = 'WooCommerce Category';
return $choices;
}
add_filter('acf/location/rule_values/woocommerce_category', 'acf_location_rules_values_woocommerce_category');
function acf_location_rules_values_woocommerce_category( $choices ) {
$args = array(
'number' => $number,
'orderby' => $orderby,
'order' => $order,
'hide_empty' => $hide_empty,
'include' => $ids
);
$product_categories = get_terms( 'product_cat', $args );
if( $product_categories ) {
foreach( $product_categories as $cat ) {
$choices[ $cat->name ] = $cat->name;
}
}
return $choices;
}
add_filter('acf/location/rule_match/woocommerce_category', 'acf_location_rules_match_woocommerce_category', 10, 3);
function acf_location_rules_match_woocommerce_category( $match, $rule, $options )
{
$args = array(
'number' => $number,
'orderby' => $orderby,
'order' => $order,
'hide_empty' => $hide_empty,
'include' => $ids
);
$product_categories = get_terms( 'product_cat', $args );
$selected_category = (int) $rule['My Product Category Name'];
if($rule['operator'] == "==")
{
foreach( $product_categories as $cat ) {
$match = ( $cat->name == $selected_category );
}
}
return $match;
}
To show ACF fields on a product page you need to follow the instructions in WooCommerce for customizing templates, copying the template you want to modify into your theme, and then edit the template to add the ACF fields where you want them.
Hi @toad78
I’ve just tested the import file and it was working correctly on my end. It seems that you use the custom fields for WooCommerce product page. Did you add the code in the right template file? I tried it in “single-product.php” template file and the table was showing up. Could you please test it up?
Thanks!
Thanks for your quick response John. The website isn’t using Woocommerce and it’s not do with the theme or any plugins, I know that much as I developed the site myself from scratch.
However, to answer your question, the site is using the following plugins:
I’d refer to @jacobajjarapu and @trainoasis’s comments – it’s working fine in local and staging but not in production. The fields definitely aren’t being used elsewhere. It’s a strange one. For now I’m just going to hardcode the fields as a workaround, but it would be great to know if anybody else is experiencing this issue.
I’m guessing that you’re might be using woocommerce. checkout_url
is a url query parameter used by woocommerce. Using it as a field name can cause unexpected issues. I’m not saying that this is definitely the issue, but it might cause a problem. To be honest, I’ve never seen this happen with a URL field on any site that I’ve worked on.
Somewhere along the line it has something to do with some type of redirect or rewrite that’s happening based on the URL being part of the $_POST values that are being sent to the server.
Can you give me a list of all the plugins that you’re using on the site? I’d really like to try to recreate this just to see if I can. Have you tried deactivating other plugins or changing themes?
Hi @rslaing
Could you please clarify your intention? Did you want to insert the custom field values to the products you have or did you want to show the values on the front end?
If you want to insert the value, I’m afraid there’s no easy way to automate it because ACF doesn’t know what you want to insert for a particular product.
If you want to show the values, please take a look at this page: https://www.advancedcustomfields.com/resources/displaying-custom-field-values-in-your-theme/.
The ID for the_field() function is not the group ID, but your post/product ID. To get it, please take a look at this page: http://stackoverflow.com/questions/27385920/woocommerce-get-current-product-id-or-title-within-sidebar.
I hope this helps!
Thanks James.
I have over 3000 products, and 29 custom fields. Maybe I have misinterpreted your response but are you saying I have to use the_field/get_field functions and do it by hand for each product?
So far, I have managed to automate the product import to Woocommerce, each of them showing on my product pages. I would have thought that there must be an easier way to retrieve the custom fields and display them, by some php coding that I insert into my template rather than insert each field by hand?
Also, having looked at the link you supplied, I don’t have an ID number in the php created by ACF tool, I only have the following, and the only unique reference in the file is ‘key’ => ‘group_5715ebca23858’. Can this be used to pull in the array data to the product pages? If so, how do I do that?
Here is the php output by ACF php tool that I need to be displayed in the product pages:
if( function_exists(‘acf_add_local_field_group’) ):
acf_add_local_field_group(array (
‘key’ => ‘group_5715ebca23858’,
‘title’ => ‘xxx’,
‘fields’ => array (
array (
‘key’ => ‘field_5715ebd45f805’,
‘label’ => ‘Model’,
‘name’ => ‘model’,
‘type’ => ‘text’,
‘instructions’ => ”,
‘required’ => 0,
‘conditional_logic’ => 0,
‘wrapper’ => array (
‘width’ => ”,
‘class’ => ”,
‘id’ => ”,
),
‘default_value’ => ”,
‘placeholder’ => ”,
‘prepend’ => ”,
‘append’ => ”,
‘maxlength’ => ”,
‘readonly’ => 0,
‘disabled’ => 0,
),
array (
‘key’ => ‘field_5715ed8d5f806’,
‘label’ => ‘Product Size’,
‘name’ => ‘product_size’,
‘type’ => ‘text’,
‘instructions’ => ”,
‘required’ => 0,
‘conditional_logic’ => 0,
‘wrapper’ => array (
‘width’ => ”,
‘class’ => ”,
‘id’ => ”,
),
‘default_value’ => ”,
‘placeholder’ => ”,
‘prepend’ => ”,
‘append’ => ”,
‘maxlength’ => ”,
‘readonly’ => 0,
‘disabled’ => 0,
),
array (
‘key’ => ‘field_5715eda85f807’,
‘label’ => ‘Product Power’,
‘name’ => ‘product_power’,
‘type’ => ‘text’,
‘instructions’ => ”,
‘required’ => 0,
‘conditional_logic’ => 0,
‘wrapper’ => array (
‘width’ => ”,
‘class’ => ”,
‘id’ => ”,
),
‘default_value’ => ”,
‘placeholder’ => ”,
‘prepend’ => ”,
‘append’ => ”,
‘maxlength’ => ”,
‘readonly’ => 0,
‘disabled’ => 0,
),
array (
‘key’ => ‘field_5715ede25f80a’,
‘label’ => ‘Liquid Volume’,
‘name’ => ‘liquid_volume’,
‘type’ => ‘text’,
‘instructions’ => ”,
‘required’ => 0,
‘conditional_logic’ => 0,
‘wrapper’ => array (
‘width’ => ”,
‘class’ => ”,
‘id’ => ”,
),
‘default_value’ => ”,
‘placeholder’ => ”,
‘prepend’ => ”,
‘append’ => ”,
‘maxlength’ => ”,
‘readonly’ => 0,
‘disabled’ => 0,
),
array (
‘key’ => ‘field_5715edfe5f80c’,
‘label’ => ‘Fastening’,
‘name’ => ‘fastening’,
‘type’ => ‘text’,
‘instructions’ => ”,
‘required’ => 0,
‘conditional_logic’ => 0,
‘wrapper’ => array (
‘width’ => ”,
‘class’ => ”,
‘id’ => ”,
),
‘default_value’ => ”,
‘placeholder’ => ”,
‘prepend’ => ”,
‘append’ => ”,
‘maxlength’ => ”,
‘readonly’ => 0,
‘disabled’ => 0,
),
array (
‘key’ => ‘field_5715ee115f80d’,
‘label’ => ‘Washable’,
‘name’ => ‘washable’,
‘type’ => ‘text’,
‘instructions’ => ”,
‘required’ => 0,
‘conditional_logic’ => 0,
‘wrapper’ => array (
‘width’ => ”,
‘class’ => ”,
‘id’ => ”,
),
‘default_value’ => ”,
‘placeholder’ => ”,
‘prepend’ => ”,
‘append’ => ”,
‘maxlength’ => ”,
‘readonly’ => 0,
‘disabled’ => 0,
),
array (
‘key’ => ‘field_5715ee225f80f’,
‘label’ => ‘Diameter’,
‘name’ => ‘diameter’,
‘type’ => ‘text’,
‘instructions’ => ”,
‘required’ => 0,
‘conditional_logic’ => 0,
‘wrapper’ => array (
‘width’ => ”,
‘class’ => ”,
‘id’ => ”,
),
‘default_value’ => ”,
‘placeholder’ => ”,
‘prepend’ => ”,
‘append’ => ”,
‘maxlength’ => ”,
‘readonly’ => 0,
‘disabled’ => 0,
),
array (
‘key’ => ‘field_5715ee3a5f811’,
‘label’ => ‘Original Circumference’,
‘name’ => ‘original_circumference’,
‘type’ => ‘text’,
‘instructions’ => ”,
‘required’ => 0,
‘conditional_logic’ => 0,
‘wrapper’ => array (
‘width’ => ”,
‘class’ => ”,
‘id’ => ”,
),
‘default_value’ => ”,
‘placeholder’ => ”,
‘prepend’ => ”,
‘append’ => ”,
‘maxlength’ => ”,
‘readonly’ => 0,
‘disabled’ => 0,
),
array (
‘key’ => ‘field_5715ee4f5f812’,
‘label’ => ‘Original Diameter’,
‘name’ => ‘original_diameter’,
‘type’ => ‘text’,
‘instructions’ => ”,
‘required’ => 0,
‘conditional_logic’ => 0,
‘wrapper’ => array (
‘width’ => ”,
‘class’ => ”,
‘id’ => ”,
),
‘default_value’ => ”,
‘placeholder’ => ”,
‘prepend’ => ”,
‘append’ => ”,
‘maxlength’ => ”,
‘readonly’ => 0,
‘disabled’ => 0,
),
array (
‘key’ => ‘field_5715ee615f813’,
‘label’ => ‘Product Width’,
‘name’ => ‘product_width’,
‘type’ => ‘text’,
‘instructions’ => ”,
‘required’ => 0,
‘conditional_logic’ => 0,
‘wrapper’ => array (
‘width’ => ”,
‘class’ => ”,
‘id’ => ”,
),
‘default_value’ => ”,
‘placeholder’ => ”,
‘prepend’ => ”,
‘append’ => ”,
‘maxlength’ => ”,
‘readonly’ => 0,
‘disabled’ => 0,
),
array (
‘key’ => ‘field_5715ee6c5f814’,
‘label’ => ‘Colour’,
‘name’ => ‘colour’,
‘type’ => ‘text’,
‘instructions’ => ”,
‘required’ => 0,
‘conditional_logic’ => 0,
‘wrapper’ => array (
‘width’ => ”,
‘class’ => ”,
‘id’ => ”,
),
‘default_value’ => ”,
‘placeholder’ => ”,
‘prepend’ => ”,
‘append’ => ”,
‘maxlength’ => ”,
‘readonly’ => 0,
‘disabled’ => 0,
),
array (
‘key’ => ‘field_5715ee7b5f815’,
‘label’ => ‘Flexibility’,
‘name’ => ‘flexibility’,
‘type’ => ‘text’,
‘instructions’ => ”,
‘required’ => 0,
‘conditional_logic’ => 0,
‘wrapper’ => array (
‘width’ => ”,
‘class’ => ”,
‘id’ => ”,
),
‘default_value’ => ”,
‘placeholder’ => ”,
‘prepend’ => ”,
‘append’ => ”,
‘maxlength’ => ”,
‘readonly’ => 0,
‘disabled’ => 0,
),
array (
‘key’ => ‘field_5715ee865f816’,
‘label’ => ‘Controller’,
‘name’ => ‘controller’,
‘type’ => ‘text’,
‘instructions’ => ”,
‘required’ => 0,
‘conditional_logic’ => 0,
‘wrapper’ => array (
‘width’ => ”,
‘class’ => ”,
‘id’ => ”,
),
‘default_value’ => ”,
‘placeholder’ => ”,
‘prepend’ => ”,
‘append’ => ”,
‘maxlength’ => ”,
‘readonly’ => 0,
‘disabled’ => 0,
),
array (
‘key’ => ‘field_5715ee8e5f817’,
‘label’ => ‘Waterproof’,
‘name’ => ‘waterproof’,
‘type’ => ‘text’,
‘instructions’ => ”,
‘required’ => 0,
‘conditional_logic’ => 0,
‘wrapper’ => array (
‘width’ => ”,
‘class’ => ”,
‘id’ => ”,
),
‘default_value’ => ”,
‘placeholder’ => ”,
‘prepend’ => ”,
‘append’ => ”,
‘maxlength’ => ”,
‘readonly’ => 0,
‘disabled’ => 0,
),
array (
‘key’ => ‘field_5715ee985f818’,
‘label’ => ‘Designed For Who’,
‘name’ => ‘designed_for_who’,
‘type’ => ‘text’,
‘instructions’ => ”,
‘required’ => 0,
‘conditional_logic’ => 0,
‘wrapper’ => array (
‘width’ => ”,
‘class’ => ”,
‘id’ => ”,
),
‘default_value’ => ”,
‘placeholder’ => ”,
‘prepend’ => ”,
‘append’ => ”,
‘maxlength’ => ”,
‘readonly’ => 0,
‘disabled’ => 0,
),
array (
‘key’ => ‘field_5715eead5f819’,
‘label’ => ‘What Is It’,
‘name’ => ‘what_is_it’,
‘type’ => ‘text’,
‘instructions’ => ”,
‘required’ => 0,
‘conditional_logic’ => 0,
‘wrapper’ => array (
‘width’ => ”,
‘class’ => ”,
‘id’ => ”,
),
‘default_value’ => ”,
‘placeholder’ => ”,
‘prepend’ => ”,
‘append’ => ”,
‘maxlength’ => ”,
‘readonly’ => 0,
‘disabled’ => 0,
),
array (
‘key’ => ‘field_5715eec65f81a’,
‘label’ => ‘What Is It For’,
‘name’ => ‘what_is_it_for’,
‘type’ => ‘text’,
‘instructions’ => ”,
‘required’ => 0,
‘conditional_logic’ => 0,
‘wrapper’ => array (
‘width’ => ”,
‘class’ => ”,
‘id’ => ”,
),
‘default_value’ => ”,
‘placeholder’ => ”,
‘prepend’ => ”,
‘append’ => ”,
‘maxlength’ => ”,
‘readonly’ => 0,
‘disabled’ => 0,
),
array (
‘key’ => ‘field_5715eef65f81b’,
‘label’ => ‘Product Action’,
‘name’ => ‘product_action’,
‘type’ => ‘text’,
‘instructions’ => ”,
‘required’ => 0,
‘conditional_logic’ => 0,
‘wrapper’ => array (
‘width’ => ”,
‘class’ => ”,
‘id’ => ”,
),
‘default_value’ => ”,
‘placeholder’ => ”,
‘prepend’ => ”,
‘append’ => ”,
‘maxlength’ => ”,
‘readonly’ => 0,
‘disabled’ => 0,
),
array (
‘key’ => ‘field_5715ef045f81c’,
‘label’ => ‘Features’,
‘name’ => ‘features’,
‘type’ => ‘text’,
‘instructions’ => ”,
‘required’ => 0,
‘conditional_logic’ => 0,
‘wrapper’ => array (
‘width’ => ”,
‘class’ => ”,
‘id’ => ”,
),
‘default_value’ => ”,
‘placeholder’ => ”,
‘prepend’ => ”,
‘append’ => ”,
‘maxlength’ => ”,
‘readonly’ => 0,
‘disabled’ => 0,
),
array (
‘key’ => ‘field_5715ef0f5f81d’,
‘label’ => ‘Miscellaneous’,
‘name’ => ‘miscellaneous’,
‘type’ => ‘text’,
‘instructions’ => ”,
‘required’ => 0,
‘conditional_logic’ => 0,
‘wrapper’ => array (
‘width’ => ”,
‘class’ => ”,
‘id’ => ”,
),
‘default_value’ => ”,
‘placeholder’ => ”,
‘prepend’ => ”,
‘append’ => ”,
‘maxlength’ => ”,
‘readonly’ => 0,
‘disabled’ => 0,
),
array (
‘key’ => ‘field_5715ef195f81e’,
‘label’ => ‘Material Name’,
‘name’ => ‘material_name’,
‘type’ => ‘text’,
‘instructions’ => ”,
‘required’ => 0,
‘conditional_logic’ => 0,
‘wrapper’ => array (
‘width’ => ”,
‘class’ => ”,
‘id’ => ”,
),
‘default_value’ => ”,
‘placeholder’ => ”,
‘prepend’ => ”,
‘append’ => ”,
‘maxlength’ => ”,
‘readonly’ => 0,
‘disabled’ => 0,
),
array (
‘key’ => ‘field_5715ef2a5f81f’,
‘label’ => ‘Brand Name’,
‘name’ => ‘brand_name’,
‘type’ => ‘text’,
‘instructions’ => ”,
‘required’ => 0,
‘conditional_logic’ => 0,
‘wrapper’ => array (
‘width’ => ”,
‘class’ => ”,
‘id’ => ”,
),
‘default_value’ => ”,
‘placeholder’ => ”,
‘prepend’ => ”,
‘append’ => ”,
‘maxlength’ => ”,
‘readonly’ => 0,
‘disabled’ => 0,
),
array (
‘key’ => ‘field_5715ef335f820’,
‘label’ => ‘Style Name’,
‘name’ => ‘style_name’,
‘type’ => ‘text’,
‘instructions’ => ”,
‘required’ => 0,
‘conditional_logic’ => 0,
‘wrapper’ => array (
‘width’ => ”,
‘class’ => ”,
‘id’ => ”,
),
‘default_value’ => ”,
‘placeholder’ => ”,
‘prepend’ => ”,
‘append’ => ”,
‘maxlength’ => ”,
‘readonly’ => 0,
‘disabled’ => 0,
),
array (
‘key’ => ‘field_5715ef3d5f821’,
‘label’ => ‘EAN’,
‘name’ => ‘ean’,
‘type’ => ‘text’,
‘instructions’ => ”,
‘required’ => 0,
‘conditional_logic’ => 0,
‘wrapper’ => array (
‘width’ => ”,
‘class’ => ”,
‘id’ => ”,
),
‘default_value’ => ”,
‘placeholder’ => ”,
‘prepend’ => ”,
‘append’ => ”,
‘maxlength’ => ”,
‘readonly’ => 0,
‘disabled’ => 0,
),
),
‘location’ => array (
array (
array (
‘param’ => ‘post_type’,
‘operator’ => ‘==’,
‘value’ => ‘product’,
),
),
),
‘menu_order’ => 1,
‘position’ => ‘normal’,
‘style’ => ‘default’,
‘label_placement’ => ‘top’,
‘instruction_placement’ => ‘label’,
‘hide_on_screen’ => ”,
‘active’ => 1,
‘description’ => ”,
));
endif;
Hi @jpcouss
I’m afraid you need to create a separated filter rather that integrating it in WooCommerce filter. This page should give you more idea about it: https://www.advancedcustomfields.com/resources/creating-wp-archive-custom-field-filter/.
Hope this helps!
Hi @sjk1000
Thanks for the post.
Yes this should be possible, you will only need to create a field group with the set of fields that you want to map to the product post type.
You can then assign the location rule:
show field group if post type == ‘Artist’
To display the value on the product page, you will then need to research the WooCommerce docs for the right filter that relates to the product page.
I hope this info helps.
Hi James,
let me briefly explain my situation where an option to translate choices would be more than welcome. I use ACF select fields mainly for products (woocommerce). I have a select field for product’s materials:
– mat_1 : Aluminum
– mat_2 : Stainless steel
– mat_3 : Glass and aluminium
This is for my default English language, but I also need the same choices for Slovenian language.
But fortunately I’ve found a solution that worked out great:
First I set all fields to Copy (in Edit Field Group) and Copy from translation to original (in WPML Translation Management/Multilingual Content Setup).
Then I wrote if ICL_LANGUAGE_CODE != ‘en’ to output translated string from POT file otherwise normally echo get_field().
Thanks!
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.