简体   繁体   中英

WooCommerce Product Vendors - update taxonomy custom fields

This is all in regards to WooCommerce and the Product Vendor extension.

In my function I'm creating new taxonomy terms (Product Vendors) each time my gravity form is submitted, however there are additional custom fields which I want to populate.

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

For this test I've 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 runs when the form is submitted, it's just not adding data into the vendor taxonomy fields.

在此输入图像描述

在此输入图像描述

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 );

You first add the 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);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM