Last active
April 22, 2024 13:52
-
-
Save marcosnakamine/4917a570da70afbd56c62e949ab40b69 to your computer and use it in GitHub Desktop.
WooCommerce - Add new rule to ACF
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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