" . __( 'The Affiliates Ready! Ecommerce Integration Light plugin requires an Affiliates plugin to be activated: Visit the Affiliates plugin page', AFF_READY_LIGHT_PLUGIN_DOMAIN ) . ""; } if ( !$ready_is_active ) { self::$admin_messages[] = "
" . __( 'The Affiliates Ready! Ecommerce Integration Light plugin requires the Ready! Ecommerce plugin to be activated.', AFF_READY_LIGHT_PLUGIN_DOMAIN ) . "
"; } if ( $affiliates_ready_is_active ) { self::$admin_messages[] = "
" . __( 'You do not need to use the Affiliates Ready! Ecommerce Integration Light plugin because you are already using the advanced Affiliates Ready! Ecommerce Integration plugin. Please deactivate the Affiliates Ready! Ecommerce Integration Light plugin now.', AFF_READY_LIGHT_PLUGIN_DOMAIN ) . "
"; } if ( !$affiliates_is_active || !$ready_is_active || $affiliates_ready_is_active ) { if ( $disable ) { include_once( ABSPATH . 'wp-admin/includes/plugin.php' ); deactivate_plugins( array( __FILE__ ) ); } $verified = false; } if ( $verified ) { $options = get_option( self::PLUGIN_OPTIONS , array() ); add_action( 'init', array( __CLASS__, 'wp_init' ) ); add_action( 'affiliates_admin_menu', array( __CLASS__, 'affiliates_admin_menu' ) ); add_action( 'affiliates_footer', array( __CLASS__, 'affiliates_footer' ) ); } } /** * Initialize order hook. */ public static function wp_init() { if ( class_exists( 'dispatcher' ) ) { dispatcher::addAction( 'onSuccessOrder', array( __CLASS__, 'onSuccessOrder' ) ); dispatcher::addAction( 'orderPost', array( __CLASS__, 'orderPost' ) ); } } /** * Adds a submenu item to the Affiliates menu for the Ready! Ecommerce integration options. */ public static function affiliates_admin_menu() { $page = add_submenu_page( 'affiliates-admin', __( 'Affiliates Ready! Ecommerce Integration Light', AFF_READY_LIGHT_PLUGIN_DOMAIN ), __( 'Ready! Light', AFF_READY_LIGHT_PLUGIN_DOMAIN ), AFFILIATES_ADMINISTER_OPTIONS, 'affiliates-admin-ready-light', array( __CLASS__, 'affiliates_admin_ready_light' ) ); $pages[] = $page; add_action( 'admin_print_styles-' . $page, 'affiliates_admin_print_styles' ); add_action( 'admin_print_scripts-' . $page, 'affiliates_admin_print_scripts' ); } /** * Affiliates Ready! Ecommerce Integration Light : admin section. */ public static function affiliates_admin_ready_light() { $output = ''; if ( !current_user_can( AFFILIATES_ADMINISTER_OPTIONS ) ) { wp_die( __( 'Access denied.', AFF_READY_LIGHT_PLUGIN_DOMAIN ) ); } $options = get_option( self::PLUGIN_OPTIONS , array() ); if ( isset( $_POST['submit'] ) ) { if ( wp_verify_nonce( $_POST[self::NONCE], self::SET_ADMIN_OPTIONS ) ) { $options[self::REFERRAL_RATE] = floatval( $_POST[self::REFERRAL_RATE] ); if ( $options[self::REFERRAL_RATE] > 1.0 ) { $options[self::REFERRAL_RATE] = 1.0; } else if ( $options[self::REFERRAL_RATE] < 0 ) { $options[self::REFERRAL_RATE] = 0.0; } $options[self::USAGE_STATS] = !empty( $_POST[self::USAGE_STATS] ); } update_option( self::PLUGIN_OPTIONS, $options ); } $referral_rate = isset( $options[self::REFERRAL_RATE] ) ? $options[self::REFERRAL_RATE] : self::REFERRAL_RATE_DEFAULT; $usage_stats = isset( $options[self::USAGE_STATS] ) ? $options[self::USAGE_STATS] : self::USAGE_STATS_DEFAULT; $output .= '
' . '

' . __( 'Affiliates Ready! Ecommerce Integration Light', AFF_READY_LIGHT_PLUGIN_DOMAIN ) . '

' . '
'; $output .= '

'; $output .= __( 'You can support the development of the Affiliates plugin and get additional features with Affiliates Pro available on itthinx.com.', AFF_READY_LIGHT_PLUGIN_DOMAIN ); $output .= '

'; $output .= '
'; $output .= '
'; $output .= '
'; $output .= '

' . __( 'Referral Rate', AFF_READY_LIGHT_PLUGIN_DOMAIN ) . '

'; $output .= '

'; $output .= ''; $output .= ' '; $output .= ''; $output .= '

'; $output .= '

'; $output .= __( 'The referral rate determines the referral amount based on the net sale made.', AFF_READY_LIGHT_PLUGIN_DOMAIN ); $output .= '

'; $output .= '

'; $output .= __( 'Example: Set the referral rate to 0.1 if you want your affiliates to get a 10% commission on each sale.', AFF_READY_LIGHT_PLUGIN_DOMAIN ); $output .= '

'; $output .= '

' . __( 'Usage stats', AFF_READY_LIGHT_PLUGIN_DOMAIN ) . '

'; $output .= '

'; $output .= ''; $output .= ' '; $output .= ''; $output .= '
'; $output .= '' . __( 'This will allow the plugin to help in computing how many installations are actually using it. No personal or site data is transmitted, this simply embeds an icon on the bottom of the Affiliates admin pages, so that the number of visits to these can be counted. This is useful to help prioritize development.', AFF_READY_LIGHT_PLUGIN_DOMAIN ) . ''; $output .= '

'; $output .= '

'; $output .= wp_nonce_field( self::SET_ADMIN_OPTIONS, self::NONCE, true, false ); $output .= ''; $output .= '

'; $output .= '
'; $output .= '
'; $output .= '
'; echo $output; affiliates_footer(); } /** * Add a notice to the footer that the integration is active. * @param string $footer */ public static function affiliates_footer( $footer ) { $options = get_option( self::PLUGIN_OPTIONS , array() ); $usage_stats = isset( $options[self::USAGE_STATS] ) ? $options[self::USAGE_STATS] : self::USAGE_STATS_DEFAULT; return '
' . '

' . ( $usage_stats ? "Logo" : '' ) . __( "Powered by Affiliates Ready! Ecommerce Integration Light.", AFF_READY_LIGHT_PLUGIN_DOMAIN ) . ' ' . __( 'Get additional features with Affiliates Pro.', AFF_READY_LIGHT_PLUGIN_DOMAIN ) . '

' . '
' . $footer; } public static function orderPost( $order_id ) { $order = new orderModel(); if ( $order = $order->get( $order_id ) ) { self::onSuccessOrder( $order ); } } /** * Record a referral on successful order. * * @param array $order */ public static function onSuccessOrder( $order ) { $order_id = isset( $order['id'] ) ? $order['id'] : null; $order_subtotal = isset( $order['sub_total'] ) ? $order['sub_total'] : 0; $currency = isset( $order['currency'] ) && isset( $order['currency']['code'] ) ? $order['currency']['code'] : 'USD'; $data = array( 'order_id' => array( 'title' => 'Order #', 'domain' => AFF_READY_LIGHT_PLUGIN_DOMAIN, 'value' => esc_sql( $order_id ) ), 'order_total' => array( 'title' => 'Total', 'domain' => AFF_READY_LIGHT_PLUGIN_DOMAIN, 'value' => esc_sql( $order_subtotal ) ), 'order_currency' => array( 'title' => 'Currency', 'domain' => AFF_READY_LIGHT_PLUGIN_DOMAIN, 'value' => esc_sql( $currency ) ) ); $options = get_option( self::PLUGIN_OPTIONS , array() ); $referral_rate = isset( $options[self::REFERRAL_RATE] ) ? $options[self::REFERRAL_RATE] : self::REFERRAL_RATE_DEFAULT; $amount = round( floatval( $referral_rate ) * floatval( $order_subtotal ), AFFILIATES_REFERRAL_AMOUNT_DECIMALS ); $description = sprintf( 'Order #%s', $order_id ); $status = null; $order_status = isset( $order['status'] ) ? $order['status'] : null; switch ( $order_status ) { case 'created' : case 'pending' : $status = AFFILIATES_REFERRAL_STATUS_PENDING; break; case 'paid' : case 'confirmed' : case 'delivered' : $status = AFFILIATES_REFERRAL_STATUS_ACCEPTED; break; case 'cancelled' : $status = AFFILIATES_REFERRAL_STATUS_REJECTED; break; } global $post, $post_id; $_post_id = 0;// get_the_ID(); empty at this point affiliates_suggest_referral( $_post_id, $description, $data, $amount, $currency, $status, null, $order_id ); } } Affiliates_Ready_Light_Integration::init();