Created
October 7, 2017 15:31
-
-
Save Basilakis/56dab1a70384ac52d47f235c61d802f7 to your computer and use it in GitHub Desktop.
Make customers vendors FES
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
add_action( 'edd_complete_purchase', 'fes_add_buyers_as_vendors', 10, 1 ); | |
function fes_add_buyers_as_vendors( $payment_id ){ | |
$customer_id = edd_get_payment_customer_id( $payment_id ); | |
$db_user = new FES_DB_Vendors(); | |
if ( $db_user->exists( 'id', $customer_id ) { | |
return; | |
} | |
// create user | |
$user = new WP_User( $customer->id ); | |
// note: Insert as pending then set to approved right underneath. | |
$db_user->add( array( | |
'user_id' => $user->ID, | |
'email' => $user->user_email, | |
'username' => $user->user_login, | |
'name' => $user->display_name, | |
'product_count' => 0, | |
'sales_count' => 0, | |
'sales_value' => 0.00, | |
'status' => 'pending', | |
'notes' => '', | |
'date_created' => date( 'Y-m-d H:i:s' ), | |
) ); | |
// set to approved | |
$vendor = new FES_Vendor( $user->ID, true ); | |
$vendor->change_status( 'approved', false ); | |
} | |
// Alternatively | |
add_action( 'edd_complete_purchase', 'fes_add_buyers_as_vendors', 10, 1 ); | |
function fes_add_buyers_as_vendors( $payment_id ){ | |
$user_id = edd_get_payment_customer_id( $payment_id ); | |
$vendor = EDD_FES()->vendors->make_user_vendor( $user_id ); | |
// set to approved | |
$vendor = new FES_Vendor( $user_id, true ); | |
$vendor->change_status( 'approved', false ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment