WooCommerce Product Providers - Update Custom Taxonomy Fields

All of this applies to the WooCommerce extension and the product extension.

In my function, I create new taxonomic terms (Product Providers) every time my severity form is submitted, however there are additional custom fields that I want to fill out.

The following works to update the name and slug. I am trying to update fields such as PayPal email, Vendor logo, etc.

For this test, I manually set the variables below.

$user = 'formname'; $email = ' example@gmail.com '; $description = 'this is a test'; $return = wp_insert_term( $user, // the term 'wcpv_product_vendors', // the taxonomy array( 'description'=> $description, 'slug' => $user, ) ); // Update vendor data $vendor_data['paypal_email'] = $email; // The email used for the account will be used for the payments $vendor_data['commission'] = '50'; // The commission is 50% for each order update_option( 'shop_vendor_' . $return['term_id'], $vendor_data ); // Update vendor data $vendor_data['paypal_email'] = $email; // The email used for the account will be used for the payments $vendor_data['commission'] = '50'; // The commission is 50% for each order $vendor_data['admins'][] = $customer_id; // The registered account is also the admin of the vendor update_option( 'shop_vendor_' . $return['term_id'], $vendor_data ); 

The function starts when the form is submitted; it simply does not add data to the provider taxonomy fields.

enter image description here

enter image description here

Full code

 //Woocommerce - ETSY - Import function create_vendor_form( $entry, $form ) { //////////////////////////////////////////////////////////////////////////// GET DATA FROM API $user = rgar( $entry, '1' ); $email = rgar( $entry, '2' ); $description = rgar( $entry, '3' ); $return = wp_insert_term( $user, // the term 'wcpv_product_vendors', // the taxonomy array( 'description'=> $description, 'slug' => $user, ) ); // Update vendor data $vendor_data['paypal_email'] = $email; // The email used for the account will be used for the payments $vendor_data['commission'] = '50'; // The commission is 50% for each order $vendor_data['admins'][] = $customer_id; // The registered account is also the admin of the vendor update_option( 'shop_vendor_' . $return['term_id'], $vendor_data ); ////////////////////////////////////////////////////////// end GET DATA FROM API } add_action( 'gform_after_submission_2', 'create_vendor_form', 10, 2 ); 
+5
source share
1 answer

First you add data to the $ vendor_data array and then apply it using the following:

 //Add the data to the array $vendor_data['paypal'] = $email; $vendor_data['profile'] = $description; //Update the term meta with the above values. update_term_meta($return['term_id'], 'vendor_data', $vendor_data); 
+2
source

Source: https://habr.com/ru/post/1257390/


All Articles