Support

Account

Home Forums Backend Issues (wp-admin) Show ACF field and title only on specific product category Reply To: Show ACF field and title only on specific product category

  • @bulldogsnare As I can understand, you have created a date field for the product category taxonomy and you want to display it in your product category archives. Here is one approach to do that –

    function tax_date_field(){
    
    	// get the current taxonomy term
    	$term = get_queried_object();
    
    	//ACF field
    	$date = get_field('class_dates', $term);
    	$class_date = '';
    
    	if( is_tax('product_cat') && $date ) {
    		$class_date = sprintf(
    			'<div class="class-date"><label>%s</label>%s</div>',
    			esc_html__('Post Dates:', 'your-themes-text-domain'),
    			esc_html( $date )
    		);
    	}
    
    	return $class_date;
    
    }

    Now you can echo the function to your product category archives. To do that, WooCommerce have some hooks for the taxonomy archive page which you can find inside archive-product.php template file inside WooCommerce plugin folder.

    Here I am hooking it to woocommerce_before_shop_loop. In your functions.php –

    add_action('woocommerce_before_shop_loop', 'show_post_dates', 11);
    function show_post_dates(){
    	echo tax_date_field();
    }

    Now the field will be shown at product taxonomy archives. Let me know if you have any questions.