属性选项的 Woocommerce ACF get_field

时间:2021-03-12 04:09:52

标签: php wordpress woocommerce advanced-custom-fields

我已经找到了如何使用以下代码将 ACF 添加到属性选项(不是属性集本身)。


// Adds a custom rule type.
add_filter( 'acf/location/rule_types', function( $choices ){
    $choices[ __("Other",'acf') ]['wc_prod_attr'] = 'WC Product Attribute';
    return $choices;
} );

// Adds custom rule values.
add_filter( 'acf/location/rule_values/wc_prod_attr', function( $choices ){
    foreach ( wc_get_attribute_taxonomies() as $attr ) {
        $pa_name = wc_attribute_taxonomy_name( $attr->attribute_name );
        $choices[ $pa_name ] = $attr->attribute_label;
    }
    return $choices;
} );

// Matching the custom rule.
add_filter( 'acf/location/rule_match/wc_prod_attr', function( $match, $rule, $options ){
    if ( isset( $options['taxonomy'] ) ) {
        if ( '==' === $rule['operator'] ) {
            $match = $rule['value'] === $options['taxonomy'];
        } elseif ( '!=' === $rule['operator'] ) {
            $match = $rule['value'] !== $options['taxonomy'];
        }
    }
    return $match;
}, 10, 3 );

我来自 Jordan Smith 的文章,该文章可以在网上找到。但是,它没有涉及如何取回字段值。提供选项的 id 并不是一件简单的事情,即 get_field( "modified_price", 521 )

有谁知道如何获取选项的自定义字段值?

0 个答案:

没有答案
相关问题