Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WooCommerce Category and ACF

I'm using the Advanced Custom Fields (ACF) Plugin. On the WooCommerce product category, I want to have a content area for seo. ACF would help me but doesn't work, as nothing is shown on the front end of the site.

content-product.php has the the extra field:

<li <?php post_class(); ?> style="max-width:<?php echo $column_width; ?>px">
    <div class="mk-product-holder">
    <?php do_action( 'woocommerce_before_shop_loop_item' ); ?>

        <div class="mk-love-holder">
        <?php if( function_exists('mk_love_this') ) mk_love_this();      ?>
        </div>

        <h3><a href="<?php echo get_permalink();?>"><?php the_title(); ?></a>

        // Here is the extrafield SEO-text, the field is registered in fields with name "extratext"
        <?php echo get_field('extratext'); ?>       

        </h3>
    </div>
</li>

WooCommerce Category Screenshot: http://www.directupload.net/file/d/3952/kzb8dcjk_png.htm

like image 758
Kieselerd Avatar asked Dec 25 '22 20:12

Kieselerd


1 Answers

You haven't set the $postId parameter for the get_field() function, so it's defaulting to the current post object (which will probably be the first post in the category).

See the Get a value from other places section in the documentation for instructions on how to get a field from other places.

So you'll want to write something like this:

<?php
$queriedObject=get_queried_object();
echo get_field('extratext','product_cat_'.$queriedObject->term_id);
?>
like image 61
Jared Avatar answered Jan 14 '23 15:01

Jared