" . __( 'The Affiliates eShop Integration Light plugin requires an Affiliates plugin to be activated: Visit the Affiliates plugin page', AFF_ESHOP_LIGHT_PLUGIN_DOMAIN ) . ""; } if ( !$eshop_is_active ) { self::$admin_messages[] = "
" . __( 'The Affiliates eShop Integration Light plugin requires the eShop plugin to be activated.', AFF_ESHOP_LIGHT_PLUGIN_DOMAIN ) . "
"; } if ( $affiliates_eshop_is_active ) { self::$admin_messages[] = "
" . __( 'You do not need to use the Affiliates eShop Integration Light plugin because you are already using the advanced Affiliates eShop Integration plugin. Please deactivate the Affiliates eShop Integration Light plugin now.', AFF_ESHOP_LIGHT_PLUGIN_DOMAIN ) . "
"; } if ( !$affiliates_is_active || !$eshop_is_active || $affiliates_eshop_is_active ) { if ( $disable ) { include_once( ABSPATH . 'wp-admin/includes/plugin.php' ); deactivate_plugins( array( __FILE__ ) ); } $verified = false; } if ( $verified ) { add_action ( 'eshop_on_success', array( __CLASS__, 'eshop_on_success' ) ); $options = get_option( self::PLUGIN_OPTIONS , array() ); add_action( 'affiliates_admin_menu', array( __CLASS__, 'affiliates_admin_menu' ) ); add_filter( 'affiliates_footer', array( __CLASS__, 'affiliates_footer' ) ); } } /** * Adds a submenu item to the Affiliates menu for the eShop integration options. */ public static function affiliates_admin_menu() { $page = add_submenu_page( 'affiliates-admin', __( 'Affiliates eShop Integration Light', AFF_ESHOP_LIGHT_PLUGIN_DOMAIN ), __( 'eShop Integration Light', AFF_ESHOP_LIGHT_PLUGIN_DOMAIN ), AFFILIATES_ADMINISTER_OPTIONS, 'affiliates-admin-eshop-light', array( __CLASS__, 'affiliates_admin_eshop_light' ) ); $pages[] = $page; add_action( 'admin_print_styles-' . $page, 'affiliates_admin_print_styles' ); add_action( 'admin_print_scripts-' . $page, 'affiliates_admin_print_scripts' ); } /** * Affiliates eShop Integration Light : admin section. */ public static function affiliates_admin_eshop_light() { $output = ''; if ( !current_user_can( AFFILIATES_ADMINISTER_OPTIONS ) ) { wp_die( __( 'Access denied.', AFF_ESHOP_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; } } update_option( self::PLUGIN_OPTIONS, $options ); } $referral_rate = isset( $options[self::REFERRAL_RATE] ) ? $options[self::REFERRAL_RATE] : self::REFERRAL_RATE_DEFAULT; echo '
' . '

' . __( 'Affiliates eShop Integration Light', AFF_ESHOP_LIGHT_PLUGIN_DOMAIN ) . '

' . '
'; $output .= '

'; $output .= __( 'Get more cool features with Affiliates Pro included in the Affiliates Pro eShop Integration Pack.', AFF_ESHOP_LIGHT_PLUGIN_DOMAIN ); $output .= '
'; $output .= __( 'Download it on itthinx.com.', AFF_ESHOP_LIGHT_PLUGIN_DOMAIN ); $output .= '

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

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

'; $output .= '

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

'; $output .= '

'; $output .= __( 'The referral rate determines the referral amount based on the net sale made.', AFF_ESHOP_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_ESHOP_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 ) { return '
' . '

' . __( "Your site is powered by the LogoAffiliates eShop Integration Light.", AFF_ESHOP_LIGHT_PLUGIN_DOMAIN ) . ' ' . __( 'Get even more awesome features with Affiliates Pro eShop Integration Pack.', AFF_ESHOP_LIGHT_PLUGIN_DOMAIN ) . ' ' . __( 'Download it on itthinx.com.', AFF_ESHOP_LIGHT_PLUGIN_DOMAIN ) . '

' . '
' . $footer; } /** * Record a referral when a new order has been placed. * @param int $order_id the post id of the order */ public static function eshop_on_success( $checkid ) { global $wpdb, $eshopoptions; $eshop_orders_table = $wpdb->prefix . 'eshop_orders'; $eshop_order_items_table = $wpdb->prefix . 'eshop_order_items'; if ( $order = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $eshop_orders_table WHERE checkid = %s;", $checkid ) ) ) { $total = 0.0; $currency = $eshopoptions['currency']; if ( $items = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM $eshop_order_items_table WHERE checkid = %s AND item_id NOT LIKE 'Shipping';", $checkid ) ) ) { foreach( $items as $item ) { $total += floatval( $item->item_qty ) * floatval( $item->item_amt ); } } $order_link = "id ) ) . "'>"; $order_link .= sprintf( __( 'View #%s'), $order->id ); $order_link .= ""; $data = array( 'order_id' => array( 'title' => 'Order #', 'domain' => AFF_ESHOP_PLUGIN_DOMAIN, 'value' => esc_sql( $order->id ) ), 'order_total' => array( 'title' => 'Total', 'domain' => AFF_ESHOP_PLUGIN_DOMAIN, 'value' => esc_sql( $total ) ), 'order_currency' => array( 'title' => 'Currency', 'domain' => AFF_ESHOP_PLUGIN_DOMAIN, 'value' => esc_sql( $currency ) ), 'order_link' => array( 'title' => 'View', 'domain' => AFF_ESHOP_PLUGIN_DOMAIN, 'value' => esc_sql( $order_link ) ) ); $post_id = get_the_ID(); $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( $total ), AFFILIATES_REFERRAL_AMOUNT_DECIMALS ); $description = sprintf( 'Order #%s', $order->id ); affiliates_suggest_referral( $post_id, $description, $data, $amount, $currency ); } } } Affiliates_eShop_Light_Integration::init();