S
S
Station 722018-11-04 18:12:19
WooCommerce
Station 72, 2018-11-04 18:12:19

How to add custom fields to Woocommece product attributes?

Actually the question is "How to add custom fields to Woocommece product attributes?".
Those.
5bdf0bb92e3b9094193738.png
add a text field here . For example "Full title".
Who knows the hook or plugin what?
ACF tried - not it, since it suggests creating a field for each specific attribute, but I need it for everyone.
Woocommerce field factory doesn't work either.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Station 72, 2018-11-04
@cjstress

All the same it was necessary to use ACF. Used the doc https://www.advancedcustomfields.com/resources/cus...

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

//Add custom operator
add_filter('acf/location/rule_operators', 'acf_location_rules_operators');
function acf_location_rules_operators( $choices ) {
    $choices['start_with'] = 'Starts with';
    return $choices;
}

// Adds custom rule values.
add_filter( 'acf/location/rule_values/wc_prod_attr', function( $choices ){
    $choices['pa_'] = "pa_";
    return $choices;
} );

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

if( function_exists('acf_add_local_field_group') ) {
    acf_add_local_field_group(array(
        'key' => 'group_5bdf16f6a992f',
        'title' => 'Расширенные настройки атрибута',
        'fields' => array(
            array(
                'key' => 'field_5bdf16fc51f9b',
                'label' => 'Заголовок в архиве',
                'name' => 'Расширенный заголовок',
                'type' => 'text',
                'instructions' => '',
                'required' => 0,
                'conditional_logic' => 0,
                'wrapper' => array(
                    'width' => '',
                    'class' => '',
                    'id' => '',
                ),
                'default_value' => '',
                'placeholder' => '',
                'prepend' => '',
                'append' => '',
                'maxlength' => '',
            ),
        ),
        'location' => array(
            array(
                array(
                    'param' => 'wc_prod_attr',
                    'operator' => 'start_with',
                    'value' => 'pa_',
                ),
            ),
        ),
        'menu_order' => 0,
        'position' => 'normal',
        'style' => 'default',
        'label_placement' => 'top',
        'instruction_placement' => 'label',
        'hide_on_screen' => '',
        'active' => 1,
        'description' => '',
    ));
}

5bdf2b7b97bb6174973737.png

4
4isto, 2020-11-10
@4isto

And what should the ACF settings for attributes look like in the admin panel?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question