我正在尝试使用重力形式作为前端保存供应商但是我没有获得创建的记录表单确实提交了成功,但我确实启用了用户注册。我正在使用wordpress版本4.5.1和插件verison 5.3.7的重力形式。
我已经为此想到了一切,但仍然无法正常工作。
function wc_create_vendor_on_registration( $entry, $form) {
$username = rgar( $entry, '6' );
$email =rgar( $entry, '5' );
$description =rgar( $entry, '2' );
// Ensure vendor name is unique
if ( term_exists( $username, 'shop_vendor' ) ) {
$append = 1;
$o_username = $username;
while ( term_exists( $username, 'shop_vendor' ) ) {
$username = $o_username . $append;
$append ++;
}
}
// Create the new vendor
$return = wp_insert_term(
$username,
'shop_vendor',
array(
'description' => description ,
'slug' => sanitize_title( $username )
)
);
if ( is_wp_error( $return ) ) {
wc_add_notice( __( '<strong>ERROR</strong>: Unable to create the vendor account for this user. Please contact the administrator to register your account.', 'localization-domain' ), 'error' );
} else {
// 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 );
$caps = array(
"edit_product",
"read_product",
"delete_product",
"edit_products",
"edit_others_products",
"delete_products",
"delete_published_products",
"delete_others_products",
"edit_published_products",
"assign_product_terms",
"upload_files",
"manage_bookings",
);
$skip_review = get_option( 'woocommerce_product_vendors_skip_review' ) == 'yes' ? true : false;
if( $skip_review ) {
$caps[] = 'publish_products';
}
$caps = apply_filters( 'product_vendors_admin_caps', $caps );
$user = new WP_User( $customer_id );
foreach( $caps as $cap ) {
$user->add_cap( $cap );
}
}
}
add_action( 'gform_after_submission_1', 'after_submission', 10, 2 );
add_action( 'woocommerce_created_customer', 'wc_create_vendor_on_registration', 10, 2 );
?>