" . __( 'The Affiliates WooCommerce Integration Light plugin requires an Affiliates plugin to be activated: Visit the Affiliates plugin page', AFF_WOOCOMMERCE_LIGHT_PLUGIN_DOMAIN ) . "";
}
if ( !$woocommerce_is_active ) {
self::$admin_messages[] = "
" . __( 'The
Affiliates WooCommerce Integration Light plugin requires the
WooCommerce plugin to be activated.', AFF_WOOCOMMERCE_LIGHT_PLUGIN_DOMAIN ) . "
";
}
if ( $affiliates_woocommerce_is_active ) {
self::$admin_messages[] = "" . __( 'You do not need to use the Affiliates WooCommerce Integration Light plugin because you are already using the advanced Affiliates WooCommerce Integration plugin. Please deactivate the Affiliates WooCommerce Integration Light plugin now.', AFF_WOOCOMMERCE_LIGHT_PLUGIN_DOMAIN ) . "
";
}
if ( !$affiliates_is_active || !$woocommerce_is_active || $affiliates_woocommerce_is_active ) {
if ( $disable ) {
include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
deactivate_plugins( array( __FILE__ ) );
}
$verified = false;
}
if ( $verified ) {
add_action ( 'woocommerce_checkout_order_processed', array( __CLASS__, 'woocommerce_checkout_order_processed' ) );
$options = get_option( self::PLUGIN_OPTIONS , array() );
add_filter( 'post_type_link', array( __CLASS__, 'post_type_link' ), 10, 4 );
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 WooCommerce integration options.
*/
public static function affiliates_admin_menu() {
$page = add_submenu_page(
'affiliates-admin',
__( 'Affiliates WooCommerce Integration Light', AFF_WOOCOMMERCE_LIGHT_PLUGIN_DOMAIN ),
__( 'WooCommerce Integration Light', AFF_WOOCOMMERCE_LIGHT_PLUGIN_DOMAIN ),
AFFILIATES_ADMINISTER_OPTIONS,
'affiliates-admin-woocommerce-light',
array( __CLASS__, 'affiliates_admin_woocommerce_light' )
);
$pages[] = $page;
add_action( 'admin_print_styles-' . $page, 'affiliates_admin_print_styles' );
add_action( 'admin_print_scripts-' . $page, 'affiliates_admin_print_scripts' );
}
/**
* Affiliates WooCommerce Integration Light : admin section.
*/
public static function affiliates_admin_woocommerce_light() {
$output = '';
if ( !current_user_can( AFFILIATES_ADMINISTER_OPTIONS ) ) {
wp_die( __( 'Access denied.', AFF_WOOCOMMERCE_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 WooCommerce Integration Light', AFF_WOOCOMMERCE_LIGHT_PLUGIN_DOMAIN ) .
'
' .
'';
$output .= '';
$output .= __( 'Get more cool features with Affiliates Pro included in the Affiliates WooCommerce Integration Pack.', AFF_WOOCOMMERCE_LIGHT_PLUGIN_DOMAIN );
// @todo enable link when available on http://www.woothemes.com/extensions/woocommerce-extensions/
//$output .= __( 'Download it on itthinx.com or woocommerce.com.', AFF_WOOCOMMERCE_LIGHT_PLUGIN_DOMAIN );
$output .= __( 'Download it on itthinx.com.', AFF_WOOCOMMERCE_LIGHT_PLUGIN_DOMAIN );
$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
'' .
'
' .
__( "Cool! Your site is powered by the
Affiliates WooCommerce Integration Light.", AFF_WOOCOMMERCE_LIGHT_PLUGIN_DOMAIN ) .
' ' .
__( 'Get even more awesome features with Affiliates Pro included in the Affiliates WooCommerce Integration Pack.', AFF_WOOCOMMERCE_LIGHT_PLUGIN_DOMAIN ) .
' ' .
// @todo enable link when available on http://www.woothemes.com/extensions/woocommerce-extensions/
//__( 'Download it on itthinx.com or woocommerce.com.', AFF_WOOCOMMERCE_LIGHT_PLUGIN_DOMAIN ) .
__( 'Download it on itthinx.com.', AFF_WOOCOMMERCE_LIGHT_PLUGIN_DOMAIN ) .
'
' .
'
' .
$footer;
}
/**
* Returns an edit link for shop_order post types.
*
* @param string $post_link
* @param array $post
* @param boolean $leavename
* @param boolean $sample
*/
public static function post_type_link( $post_link, $post, $leavename, $sample ) {
$link = $post_link;
if (
// right post type
isset( $post->post_type) && ( $post->post_type == self::SHOP_ORDER_POST_TYPE ) &&
// admin page
is_admin() &&
// right admin page
isset( $_REQUEST['page'] ) && in_array( $_REQUEST['page'], self::$shop_order_link_modify_pages ) &&
// check link
( preg_match( "/" . self::SHOP_ORDER_POST_TYPE . "=([^&]*)/", $post_link, $matches ) === 1 ) &&
isset( $matches[1] ) && ( $matches[1] === $post->post_name )
) {
$link = admin_url( 'post.php?post=' . $post->ID . '&action=edit' );
}
return $link;
}
/**
* Record a referral when a new order has been processed.
*
* Note that we can't hook into the order process before(*), because
* the meta data would not have been added.
*
* (*) We could hook into woocommerce_checkout_update_order_meta but the
* 'coupons' meta data would not be there, so if we want to use it here at
* some point, woocommerce_checkout_order_processed is a better choice.
* @param int $order_id the post id of the order
*/
public static function woocommerce_checkout_order_processed( $order_id ) {
$order_subtotal = get_post_meta( $order_id, '_order_subtotal', true );
$currency = get_option( 'woocommerce_currency' );
$order_link = '';
$order_link .= sprintf( __( 'Order #%s', AFF_WOOCOMMERCE_LIGHT_PLUGIN_DOMAIN ), $order_id );
$order_link .= "";
$data = array(
'order_id' => array(
'title' => 'Order #',
'domain' => AFF_WOOCOMMERCE_LIGHT_PLUGIN_DOMAIN,
'value' => esc_sql( $order_id )
),
'order_total' => array(
'title' => 'Total',
'domain' => AFF_WOOCOMMERCE_LIGHT_PLUGIN_DOMAIN,
'value' => esc_sql( $order_subtotal )
),
'order_currency' => array(
'title' => 'Currency',
'domain' => AFF_WOOCOMMERCE_LIGHT_PLUGIN_DOMAIN,
'value' => esc_sql( $currency )
),
'order_link' => array(
'title' => 'Order',
'domain' => AFF_WOOCOMMERCE_LIGHT_PLUGIN_DOMAIN,
'value' => esc_sql( $order_link )
)
);
$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 );
affiliates_suggest_referral( $order_id, $description, $data, $amount, $currency );
}
}
Affiliates_WooCommerce_Light_Integration::init();