2016-09-28 64 views
5

这是关于WooCommerce和产品供应商扩展的全部内容。WooCommerce产品供应商 - 更新分类定制字段

在我的函数中,我创建了新的分类术语(产品供应商),每次我的重力形式被提交,但是还有其他的自定义字段,我想填充。

以下工作更新术语名称和slu。。我试图更新字段,如贝宝电子邮件,供应商标志等

对于此测试,我已经手动设置下面的变量。

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

该函数在提交表单时运行,它不会将数据添加到供应商分类标记字段中。

enter image description here

enter image description here

全码

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

回答

2

您首先将数据添加到$ vendor_data数组,然后使用应用了下列文件:

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

如何你知道这是规格吗?如果你需要使用'profile',例如我可能猜到'vendor_profile'或其他东西。 – JordanC26