Custom Product Templates Per Category #1093
Unanswered
antforager
asked this question in
Q&A
Replies: 1 comment
|
You can override the For example: add_action( 'woocommerce_before_add_to_cart_quantity', 'add_acf_before_quantity' );
function add_acf_before_quantity() {
global $product;
// Get the ACF field value (assuming it's attached to the product post)
$custom_field = get_field( 'my_custom_field', $product->get_id() );
if ( $custom_field ) {
echo '<div class="my-custom-field">' . esc_html( $custom_field ) . '</div>';
}
} |
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
I haven't gotten this to work yet but I want to use the ACF (Advanced Custom Fields) plugin to have different fields per category. When I edit a product, it would have a text box for that custom field.
Category Ant Farm has extra fields for Hydration Instructions, and FAQ. Category Harvester Ants would have an extra field for Preferred Seeds, and Common Challenges. Category Supplies doesn't have any custom fields. When I edit the Black Harvester Ant product, I expect to see a text box for Preferred seeds and Common Challenges.
I need to get the single product page to display the custom fields for the category. It is my understanding that we can't have customizations for product pages based on the category because woocommerce.php is used. Could I override the single product page in my child and have conditional logic that displays the section if it exists? Is there a better way to do this?
All reactions