2016-09-28 14 views
5

Wszystko to dotyczy WooCommerce i rozszerzenia produktu.Sprzedawcy produktów WooCommerce - zaktualizuj niestandardowe pola taksonomii

W mojej funkcji tworzę nowe warunki taksonomii (dostawcy produktu) za każdym razem, gdy moja forma grawitacji jest przesyłana, jednak istnieją dodatkowe pola niestandardowe, które chcę wypełnić.

Następujące prace aktualizują nazwę terminu i ślimak. Próbuję zaktualizować pola, takie jak adres e-mail w systemie PayPal, logo producenta itp.

Do tego testu ręcznie ustawiono zmienne poniżej.

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

Funkcja jest uruchamiana po przesłaniu formularza, po prostu nie dodaje danych do pól taksonomii dostawcy.

enter image description here

enter image description here

pełny kod

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

Odpowiedz

2

najpierw dodać dane do tablicy $ vendor_data a następnie zastosować je przy użyciu następujących:

//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); 
+0

Jak wiedziałeś, że to spec ewentualnie "profil", którego musiał użyć, na przykład mógł odgadnąć "vendor_profile" lub coś podobnego. – JordanC26