Created
June 29, 2013 19:31
-
-
Save brandondove/5892349 to your computer and use it in GitHub Desktop.
Automatic AR Affiliates
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 | |
/* | |
Plugin Name: Entrepreneurs Are Affiliates | |
Plugin URI: http://www.vincereed.com/ | |
Description: This plugin enables and disables a user to be an affiliate based on whether or not they have purchased the Entrepreneur product. Affiliate status is double-checked every time a transaction is made. | |
Version: 1.0 | |
Author: Pixel Jar | |
Author URI: http://www.pixeljar.net | |
*/ | |
/** | |
* Copyright (c) 2013 Pixel Jar. All rights reserved. | |
* | |
* Released under the GPL license | |
* http://www.opensource.org/licenses/gpl-license.php | |
* | |
* This is an add-on for WordPress | |
* http://wordpress.org/ | |
* | |
* ********************************************************************** | |
* This program is free software; you can redistribute it and/or modify | |
* it under the terms of the GNU General Public License as published by | |
* the Free Software Foundation; either version 2 of the License, or | |
* (at your option) any later version. | |
* | |
* This program is distributed in the hope that it will be useful, | |
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
* GNU General Public License for more details. | |
* ********************************************************************** | |
*/ | |
add_action( 'mepr-txn-store', 'mp_check_affiliate' ); | |
function mp_check_affiliate( MeprTransaction $txn ) { | |
// $this->id, $this->amount, $this->user_id, $this->product_id, $this->txn_type, $this->status, $this->coupon_id, $this->response, $this->trans_num, $this->subscription_id, $this->gateway, $this->created_at, $this->expires_at | |
$product = get_posts( array( 'post_type' => 'memberpressproduct', 'name' => 'entrepreneur', 'posts_per_page' => 1 ) ); | |
// This transaction is for an Entrepreneur | |
if( $product[0]->ID != $txn->product_id ) | |
return; | |
// The transaction is complete, make this user an affiliate | |
if( $txn->status == 'complete' ) : | |
update_user_meta( $txn->user_id, 'wafp_is_affiliate', '1' ); | |
// The transaction failed, revoke affiliate privileges | |
else : | |
update_user_meta( $txn->user_id, 'wafp_is_affiliate', '0' ); | |
endif; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment