O
O
oxlee2020-07-20 19:53:52
WordPress
oxlee, 2020-07-20 19:53:52

How to display the ACF field under the category heading?

Good afternoon. How to insert text under the title of a category, or rather a subcategory?

The text is set by the ACF plugin and should be output by the ml-atr-cat tag.
It was possible to display only under the title, but the prescribed meta is not displayed in any way.


function my_woocommerce_after_shop_loop() {
$cate = get_queried_object();
$cateID = $cate->term_id;
$mycat = 'product_cat_' . $cateID;
$my_gallery = get_field('ml-acf-pc-atr', $mycat);
echo '' . ( $my_gallery ) . '';
}

add_action('woocommerce_subcategory_count_html', 'my_woocommerce_after_shop_loop', 10, 2);


ml-prodcat-atr is a meta key by which the content specified in the field in the category description should be displayed.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton Litvinenko, 2020-07-21
@oxlee

Here is the working code

function add_custom_field_subcat( $category ) {

  $value = get_field('category_description', 'product_cat_'. $category->term_id);

  echo $value; 

}
add_action( 'woocommerce_before_subcategory_title', 'add_custom_field_subcat', 15 );

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question