Appreciate all the guidance I can get on this one.
I am working on a shop using WordPress and Woocommerce. I have a custom order form that I want to display on each product in a specific product category. My idea is to use an ACF field with true/false checkbox to determine whether the products in this category should have an order form or not.
The checkbox is located here:
So I don't want to name a specific product category in my code, instead I want to check if a single product belongs to a category which has a checked checkbox for the order form.
My issue is that I don't understand how to display the order form in a products post when checking the box, without the need to add it in all posts that should display it. Is it possible to access my ACF from a single product when it is added in the taxonomy product_cat? Any ideas?
I found the get_the_terms function but I am not sure how to use it. This is how I've been trying to access my ACF:
function test() {
global $post;
$terms = get_the_terms( $post->ID, 'product_cat' );
$queried_object = get_queried_object();
$taxonomy = $queried_object->taxonomy;
$term_id = $queried_object->term_id;
$checked_form = get_field('orderform', $taxonomy . '_' . $term_id);
if($checked_form) {
echo 'Checked!';
}else{
echo 'Not checked';
var_dump($terms);
var_dump($checked_form);
var_dump($term_id);
}
}
add_action('woocommerce_single_product_summary', 'test');