Home › Forums › Backend Issues (wp-admin) › Trying to add field group to the WooCommerce 'Shop' page (only) › Reply To: Trying to add field group to the WooCommerce 'Shop' page (only)
FWIW, I kept at it and built my own solution. I need to do another re-read of the documentation page to make sure I’m using both hooks correctly, but it at least works for now.
// Add WooCommerce 'Shop' location rule value
// https://www.advancedcustomfields.com/resources/custom-location-rules/
add_filter('acf/location/rule_values/page_type', 'dc_acf_location_rules_values_woo_shop');
function dc_acf_location_rules_values_woo_shop($choices){
$choices[ 'woo-shop-page' ] = 'WooCommerce Shop Page';
return $choices;
}
// Add WooCommerce 'Shop' location rule match
add_filter('acf/location/rule_match/page_type', 'dc_acf_location_rules_match_woo_shop', 10, 3);
function dc_acf_location_rules_match_woo_shop($match, $rule, $options){
if(is_admin() && $rule['value'] == 'woo-shop-page'){
$post_id = $options['post_id'];
$woo_shop_id = get_option( 'woocommerce_shop_page_id' );
if($rule['operator'] == "=="){
$match = $post_id == $woo_shop_id;
}elseif($rule['operator'] == "!="){
$match = $post_id != $woo_shop_id;
}
}
return $match;
}
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.