Answer the question
In order to leave comments, you need to log in
How to add custom fields to Woocommece product attributes?
Actually the question is "How to add custom fields to Woocommece product attributes?".
Those.
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
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' => '',
));
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question