Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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    = '[email protected]';
$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.

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 );
like image 880
wharfdale Avatar asked Sep 28 '16 12:09

wharfdale


1 Answers

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);
like image 193
DesignLocker Avatar answered Oct 23 '22 12:10

DesignLocker