On the Woocommerce Product Attributes page, I have the following working for one Woocommerce attribute (called myattribute). The following adds the custom field to the add / edit page of the terms for myattribute:
add_action( 'myattribute_add_form_fields', array( $this, 'add_new_field' ), 10, 2 );
add_action( 'created_myattribute', array( $this, 'save_new_field' ), 10, 2 );
add_action( 'myattribute_edit_form_fields', array( $this, 'update_new_field' ), 10, 2 );
add_action( 'edited_myattribute', array( $this, 'updated_new_field' ), 10, 2 );
Is there a way to do the same but for all attributes, without needing to name them in the add_action?
The reason is that I have numerous attributes and would like to add custom fields to all the terms related to those attributes.
Thanks in advance.
2
Answers
This might not be the best solution but it works for me:
I was looking for the same solution and so far this quick code helped me achieve the custom field on any product attribute edit/add views.
There is a clear difference between adding fields in edit taxonomy screen and in edit taxonomy term screen. Looking into your codes, I think you want to achieve the second one.
This is how I have done it –
Note: This is just adds the field. You will have to save the field values by using the hooks you wrote in your question. Hope everyone gets the idea.