Home › Forums › General Issues › Conditional Display of ACF Single Product Page › Reply To: Conditional Display of ACF Single Product Page
Thanks to everyone for your input. I don’t think that the issue is being understood, so let me try to clarify. I have two categories: Ammo & Guns.
The first part of the code deals with fields related to Ammo, while the second part of the code is strictly for guns. The code below works well but it shows all the fields for both categories. So What I am looking to accomplish is as follows:
If category equals “Ammo” then
add_action( ‘woocommerce_single_product_summary’, ‘sbnai_display_acf_field_1’, 30 );
function sbnai_display_acf_field_1() {
echo ‘<b>Per Round Cost:</b> ‘ . get_field(‘per_round_cost’) . ‘<br />’;
echo ‘<b>UPC:</b> ‘ . get_field(‘upc’) . ‘<br />’;
echo ‘<b>Caliber:</b> ‘ . get_field(‘caliber’) . ‘<br />’;
echo ‘<b>Bullet Weight:</b> ‘ . get_field(‘bullet_weight’) . ‘<br />’;
echo ‘<b>Bullet Type:</b> ‘ . get_field(‘bullet_type’) . ‘<br />’;
echo ‘<b>Case Type:</b> ‘ . get_field(‘case_type’) . ‘<br />’;
echo ‘<b>Combined Reviews:</b> ‘ . get_field(‘combine_reviews’) . ‘<br />’;
}
Else if category equals “Guns” then
add_action( ‘woocommerce_single_product_summary’, ‘sbnai_display_acf_field_2’, 31 );
function sbnai_display_acf_field_2() {
echo ‘<b>Width:</b> ‘ . get_field(‘width’) . ‘<br />’;
echo ‘<b>Height:</b> ‘ . get_field(‘height’) . ‘<br />’;
echo ‘<b>Depth:</b> ‘ . get_field(‘depth’);
}
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.