Skip to content

Instantly share code, notes, and snippets.

@marcosnakamine
Last active April 22, 2024 13:52
Show Gist options
  • Save marcosnakamine/4917a570da70afbd56c62e949ab40b69 to your computer and use it in GitHub Desktop.
Save marcosnakamine/4917a570da70afbd56c62e949ab40b69 to your computer and use it in GitHub Desktop.
WooCommerce - Add new rule to ACF
<?php
add_filter('acf/location/rule_types', 'acf_location_rules_types');
function acf_location_rules_types( $choices ) {
$choices['Woocommerce']['woocommerce_attribute'] = 'Atributo';
return $choices;
}
add_filter('acf/location/rule_values/woocommerce_attribute', 'acf_location_rules_values_woocommerce_attribute');
function acf_location_rules_values_woocommerce_attribute( $choices ) {
$atributes = wc_get_attribute_taxonomies();
foreach ($atributes as $key => $value) {
$choices['pa_'.$value->attribute_name] = $value->attribute_label;
}
return $choices;
}
add_filter('acf/location/rule_match/woocommerce_attribute', 'acf_location_rules_match_woocommerce_attribute', 10, 3);
function acf_location_rules_match_woocommerce_attribute( $match, $rule, $options ) {
$match = $_GET['taxonomy'] == $rule['value'];
return $match;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment