How to add custom field in Woocommerce Category Or Post Category with ACF Plugin?

How to add custom field in Woocommerce Category Or Post Category with ACF Plugin?

Let's start working on How to add a custom field in Woocommerce Category Or Post Category in WordPress and display on your theme. It's pretty different from normal custom field display shortcode. So let's get started.

1: First install ACF plugin and active on your website.

2: After that click on Custom Fields menu from WordPress admin left sidebar.

3: Click on add new button and you will see ACF form with the setting.

4: Give Group name and click on Add Field button and create your custom field by giving value in and

5: Now scroll down and you will see Rules. Just select "Show this field group if" drop-down and select Taxonomy Term from the dropdown. see snapshot below.

 

How to add custom field in Woocommerce Category Or Post Category with ACF Plugin?

Just do it like snapshot and you will see the custom field in your category when you edit from the backend. See another snapshot below that how it looks like.

Display custom field will look like this on category page.

After that, You just need to display on category page like in woocommerce.php file.

$term = get_term_by( 'slug', $wp_query->query_vars['term'], $wp_query->query_vars['taxonomy']);
$field = get_field('YOUR_CUSTOM_FIELD_NAME', $term->taxonomy.'_'.$term->term_id);
echo print_r( $field, true);

That's it. This will display your custom field value on the frontend.