Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- add_action( 'user_register', 'custom_registration_save', 10, 1 );
- function custom_registration_save( $user_id ) {
- $user = wp_get_current_user( $user_id );
- $username = $user->user_login;
- $email = $user->user_email;
- // 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' => sprintf( __( 'The vendor shop for %s', 'localization-domain' ), $username ),
- '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;
- $vendor_data['commission'] = '50';
- $vendor_data['admins'][] = $user_id;
- 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 );
- foreach( $caps as $cap ) {
- $user->add_cap( $cap );
- }
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement