Plugin Directory

Changeset 2700997


Ignore:
Timestamp:
03/29/2022 06:26:11 AM (4 years ago)
Author:
codup
Message:

updated files

Location:
codup-woocommerce-referral-system/trunk
Files:
11 edited

Legend:

Unmodified
Added
Removed
  • codup-woocommerce-referral-system/trunk/codup-woocommerce-referral-system.php

    r2394438 r2700997  
    33Plugin Name: Codup WooCommerce Referral System
    44Description: Build up your own referral system
    5 Version:     1.1.1.11
     5Version:     1.1.1.12
    66Author:      codup.io
    77Author URI:  http://codup.io/
     
    1010Text Domain: codup_woocommerce_referral_system
    1111Domain Path: /languages
    12 
     12Tested up to: 5.9.2
    1313*/
    1414
     
    2323 */
    2424if (in_array('woocommerce/woocommerce.php', apply_filters('active_plugins', get_option('active_plugins')))){
    25   
     25 
    2626    define('CWRF_SLUG', 'cwrf');
    2727    define('CWRF_PLUGIN_NAME','codup-woocommerce-referral-system');
    28     define('CWRF_PLUGIN_VER','1.1.1.4');
     28    define('CWRF_PLUGIN_VER','1.1.1.12');
    2929    define('CWRF_PLUGIN_BASENAME', plugin_basename(__FILE__));
    3030    define('CWRF_PLUGIN_DIR', __DIR__);
     
    5050else{
    5151    global $pagenow;
    52    
     52    
    5353    // Throw an error in the wordpress admin console
    5454    add_action('admin_notices', 'cwrf_plugin_notice');       
  • codup-woocommerce-referral-system/trunk/includes/class.codup-wcrf-email.php

    r1874660 r2700997  
    11<?php
    22
    3 if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
     3if ( ! defined( 'ABSPATH' ) ) {
     4    exit; // Exit if accessed directly
     5}
    46
    57if ( ! class_exists( 'CodupWC_ReferralSystem_Email' ) ) :
    68
    7 /**
    8  * A custom WooCommerce Email class
    9  *
    10  * @since 0.1
    11  * @extends \WC_Email
    12  */
    13 class CodupWC_ReferralSystem_Email extends WC_Email{   
     9    /**
     10    * A custom WooCommerce Email class
     11    *
     12    * @since 0.1
     13    * @extends \WC_Email
     14    */
     15    class CodupWC_ReferralSystem_Email extends WC_Email {
    1416
    15     /**
    16     * Constructor
    17     */
    18     function __construct() {
     17        /**
     18        * Constructor
     19        */
     20        function __construct() {
    1921
    20         $this->id                   = 'wcrf_referral_email';
    21         $this->title                = __( 'Codup Referral Emails', 'codup_woocommerce_referral_system' );
    22         $this->description          = __( 'Referral emails are sent when a customer is rewarded by referral system', 'codup_woocommerce_referral_system' );
     22            $this->id          = 'wcrf_referral_email';
     23            $this->title       = __( 'Codup Referral Emails', 'codup_woocommerce_referral_system' );
     24            $this->description = __( 'Referral emails are sent when a customer is rewarded by referral system', 'codup_woocommerce_referral_system' );
    2325
    24         $this->template_html        = 'emails/wcrf-email.php';
    25         $this->template_plain       = 'emails/plain/wcrf-email-plain.php';
     26            $this->template_html  = 'emails/wcrf-email.php';
     27            $this->template_plain = 'emails/plain/wcrf-email-plain.php';
    2628
    27         $this->subject              = __( 'Referrer Reward!', 'codup_woocommerce_referral_system');
    28         $this->heading              = __( 'Congratulations! You have been awarded for being a referrer', 'codup_woocommerce_referral_system');     
     29            $this->subject = __( 'Referrer Reward!', 'codup_woocommerce_referral_system' );
     30            $this->heading = __( 'Congratulations! You have been awarded for being a referrer', 'codup_woocommerce_referral_system' );
    2931
    30         add_action('codup_wcrf_send_email', array($this, 'trigger'), 10, 4 );
    31         // Call parent constructor
    32         parent::__construct(); 
     32            add_action( 'codup_wcrf_send_email', array( $this, 'trigger' ), 10, 4 );
     33            // Call parent constructor
     34            parent::__construct();
     35        }
     36
     37        /**
     38         * trigger function.
     39         *
     40         * @access public
     41         * @return void
     42         */
     43        function trigger( $order, $referrer, $new, $old ) {
     44            if ( $order ) {
     45                $this->object        = $order;
     46                $this->recipient     = $referrer->user_email;
     47                $this->referrer_name = $referrer->display_name;
     48                $this->statusnew     = $new;
     49                $this->statusold     = $old;
     50
     51            }
     52
     53            if ( ! $this->get_recipient() ) {
     54                return;
     55            }
     56
     57            $this->send( $this->get_recipient(), $this->get_subject(), $this->get_content(), $this->get_headers(), $this->get_attachments() );
     58        }
     59
     60        /**
     61         * get_content_html function.
     62         *
     63         * @access public
     64         * @return string
     65         */
     66        function get_content_html() {
     67            ob_start();
     68            wc_get_template(
     69                $this->template_html,
     70                array(
     71                    'order'         => $this->object,
     72                    'new'           => $this->statusnew,
     73                    'old'           => $this->statusold,
     74                    'email_heading' => $this->get_heading(),
     75                    'referrer_name' => $this->referrer_name,
     76                    'coupon'        => get_option( CWRF_SLUG . '_coupon_list', true ),
     77                    'sent_to_admin' => false,
     78                    'plain_text'    => false,
     79                ),
     80                '',
     81                trailingslashit( dirname( __FILE__ ) . DS . 'templates' )
     82            );
     83            return ob_get_clean();
     84        }
     85
     86        /**
     87         * get_content_plain function.
     88         *
     89         * @access public
     90         * @return string
     91         */
     92        function get_content_plain() {
     93            ob_start();
     94            wc_get_template(
     95                $this->template_plain,
     96                array(
     97                    'order'         => $this->object,
     98                    'email_heading' => $this->get_heading(),
     99                    'referrer_name' => $this->referrer_name,
     100                    'coupon'        => get_option( CWRF_SLUG . '_coupon_list', true ),
     101                    'sent_to_admin' => false,
     102                    'plain_text'    => true,
     103                ),
     104                '',
     105                trailingslashit( dirname( __FILE__ ) . DS . 'templates' )
     106            );
     107            return ob_get_clean();
     108        }
     109
     110        /**
     111         * Initialise Settings Form Fields
     112         *
     113         * @access public
     114         * @return void
     115         */
     116        function init_form_fields() {
     117            $this->form_fields = array(
     118                'enabled'    => array(
     119                    'title'   => 'Enable/Disable',
     120                    'type'    => 'checkbox',
     121                    'label'   => 'Enable this email notification',
     122                    'default' => 'yes',
     123                ),
     124                'subject'    => array(
     125                    'title'       => __( 'Email subject', 'woocommerce' ),
     126                    'type'        => 'text',
     127                    'description' => sprintf( __( 'Subject of the email defaults to <code>%s</code>', 'woocommerce' ), $this->subject ),
     128                    'placeholder' => $this->subject,
     129                    'default'     => '',
     130                ),
     131                'heading'    => array(
     132                    'title'       => __( 'Email heading', 'woocommerce' ),
     133                    'type'        => 'text',
     134                    'description' => sprintf( __( 'Heading of the email defaults to <code>%s</code>', 'woocommerce' ), $this->heading ),
     135                    'placeholder' => $this->heading,
     136                    'default'     => '',
     137                ),
     138                'email_type' => array(
     139                    'title'       => __( 'Email type', 'woocommerce' ),
     140                    'type'        => 'select',
     141                    'description' => __( 'Choose which format of email to send.', 'woocommerce' ),
     142                    'default'     => 'html',
     143                    'class'       => 'email_type',
     144                    'options'     => array(
     145                        'plain' => __( 'Plain text', 'woocommerce' ),
     146                        'html'  => __( 'HTML', 'woocommerce' ),
     147                    ),
     148                ),
     149            );
     150        }
    33151    }
    34152
    35     /**
    36      * trigger function.
    37      *
    38      * @access public
    39      * @return void
    40      */
    41     function trigger( $order, $referrer, $new, $old ){     
    42         if ( $order ) {
    43             $this->object           = $order;
    44             $this->recipient        = $referrer->user_email;
    45             $this->referrer_name    = $referrer->display_name;
    46             $this->statusnew        = $new;
    47             $this->statusold        = $old;
    48 
    49         }       
    50        
    51         if ( ! $this->get_recipient() )
    52             return;
    53 
    54         $this->send( $this->get_recipient(), $this->get_subject(), $this->get_content(), $this->get_headers(), $this->get_attachments() );
    55     }
    56 
    57     /**
    58      * get_content_html function.
    59      *
    60      * @access public
    61      * @return string
    62      */
    63     function get_content_html(){
    64         ob_start();
    65         wc_get_template( $this->template_html, array(
    66             'order'         => $this->object,
    67             'new'               => $this->statusnew,
    68             'old'               => $this->statusold,
    69             'email_heading' => $this->get_heading(),
    70             'referrer_name' => $this->referrer_name,           
    71             'coupon'        => get_option(CWRF_SLUG.'_coupon_list', true),
    72             'sent_to_admin' => false,
    73             'plain_text'    => false
    74         ),'', trailingslashit(dirname(__FILE__).DS. 'templates'));
    75         return ob_get_clean();
    76     }
    77 
    78     /**
    79      * get_content_plain function.
    80      *
    81      * @access public
    82      * @return string
    83      */
    84     function get_content_plain(){
    85         ob_start();
    86         wc_get_template( $this->template_plain, array(
    87             'order'         => $this->object,
    88             'email_heading' => $this->get_heading(),
    89             'referrer_name' => $this->referrer_name,           
    90             'coupon'        => get_option(CWRF_SLUG.'_coupon_list', true),
    91             'sent_to_admin' => false,
    92             'plain_text'    => true
    93         ),'', trailingslashit(dirname(__FILE__).DS. 'templates'));
    94         return ob_get_clean();
    95     }
    96 
    97     /**
    98      * Initialise Settings Form Fields
    99      *
    100      * @access public
    101      * @return void
    102      */
    103     function init_form_fields(){
    104         $this->form_fields = array(
    105             'enabled' => array(
    106                 'title' => 'Enable/Disable',
    107                 'type' => 'checkbox',
    108                 'label' => 'Enable this email notification',
    109                 'default' => 'yes'
    110             ),
    111             'subject' => array(
    112                 'title'         => __( 'Email subject', 'woocommerce' ),
    113                 'type'          => 'text',
    114                 'description'   => sprintf( __( 'Subject of the email defaults to <code>%s</code>', 'woocommerce' ), $this->subject ),
    115                 'placeholder'   => $this->subject ,
    116                 'default'       => ''
    117             ),
    118             'heading' => array(
    119                 'title'         => __( 'Email heading', 'woocommerce' ),
    120                 'type'          => 'text',
    121                 'description'   => sprintf( __( 'Heading of the email defaults to <code>%s</code>', 'woocommerce' ), $this->heading ),
    122                 'placeholder'   => $this->heading ,
    123                 'default'       => ''
    124             ),
    125             'email_type' => array(
    126                 'title'         => __( 'Email type', 'woocommerce' ),
    127                 'type'          => 'select',
    128                 'description'   => __( 'Choose which format of email to send.', 'woocommerce' ),
    129                 'default'       => 'html',
    130                 'class'         => 'email_type',
    131                 'options'       => array(
    132                     'plain'         => __( 'Plain text', 'woocommerce' ),
    133                     'html'          => __( 'HTML', 'woocommerce' ),
    134                 )
    135             )
    136         );
    137     }
    138 }
    139 
    140153endif;
  • codup-woocommerce-referral-system/trunk/includes/class.codup-wcrf.php

    r2394438 r2700997  
    11<?php
    22
    3 class CodupWCReferralSystem{
    4 
    5     const OPT_REDIRECT_LINK = CWRF_SLUG.'_redirect_link';
    6     const OPT_REFERRAL_SLUG = CWRF_SLUG.'_referral_slug';
    7     const OPT_REFERRAL_EXPIRY = CWRF_SLUG.'_referral_expiry';
    8     const OPT_REFEREE_AWARD = CWRF_SLUG.'_referee_award';
    9     const OPT_COUPON_LIST = CWRF_SLUG.'_coupon_list';
    10 
    11     private static $optDefaults = array(
    12         CodupWCReferralSystem::OPT_REDIRECT_LINK => '',
    13         CodupWCReferralSystem::OPT_REFERRAL_SLUG => 'cwrf_ref',
    14         CodupWCReferralSystem::OPT_REFERRAL_EXPIRY => 1,
    15         CodupWCReferralSystem::OPT_REFEREE_AWARD => 1
    16        
    17     );   
    18 
    19     function __construct(){     
    20        
    21         add_filter('plugin_action_links_'.CWRF_PLUGIN_BASENAME, array($this, 'addActionLinks'));       
    22        
    23         /** Add settings tabs to woocommerce setting tabs **/
    24         add_filter('woocommerce_settings_tabs_array', array($this, 'addSettingsTab'), 50);
    25         add_action('woocommerce_settings_tabs_'.CWRF_SLUG, array($this, 'addSettingsTabContents'));
    26         add_action('woocommerce_update_options_'.CWRF_SLUG, array($this, 'saveSettings'));
    27         add_action('init', array($this, 'addSettingDefaults'));
    28 
    29         /** Add custom link and page to woocommerce account menu for referral system **/
    30         add_filter ( 'woocommerce_account_menu_items',  array($this, 'add_referral_link') );
    31         add_filter( 'woocommerce_get_endpoint_url', array($this, 'hook_referral_endpoint'), 10, 4 );
    32         add_shortcode('cwrf-referral-system', array($this, 'add_referral_system_page'));
    33         add_action('template_redirect', array($this, 'save_referral_parameter'));
    34 
    35         /** Award referrer and referee **/
    36         add_filter( 'woocommerce_order_status_changed', array($this, 'reward_referrer'), 10, 3 );
    37         add_action('woocommerce_applied_coupon', array($this, 'apply_coupon_validation'));
    38         add_action('woocommerce_before_cart', array($this, 'apply_coupon_for_referral'));
    39         add_action('woocommerce_removed_coupon', array($this, 'remove_reward_coupon'));
    40 
    41         /** Add custom email to woocommerce emails */
    42         add_filter( 'woocommerce_email_classes', array($this, 'add_custom_wcrf_email') );
    43         add_filter('woocommerce_locate_core_template', array($this, 'locate_core_template'), 10, 3);
    44        
    45     }     
    46 
    47     /**
    48     * Inserts default values into WordPress options.
    49     */
    50     function addSettingDefaults(){
    51         foreach(CodupWCReferralSystem::$optDefaults as $key => $defaultValue){
    52             if(!get_option($key)){
    53                 add_option($key, $defaultValue);   
    54             }
    55         }
    56     }
    57    
    58     /**
    59     * Adds the CWL tab to WooCommerce settings page.
    60      * @param string[] $tabs
    61      * @return string[]
    62      */
    63     function addSettingsTab( $tabs ){
    64         $tabs[CWRF_SLUG] = __('Referral Sytem', CWRF_SLUG);
    65         return $tabs;
    66     }
    67    
    68     /**
    69      * Adds the content of the CWL settings tab in WC settings page.
    70      */
    71     function addSettingsTabContents(){
    72         do_shortcode('[codup_ads_top]');
    73         woocommerce_admin_fields( $this->generateSettingsFields() );
    74     }
    75 
    76 
    77     /**
    78      * Saves the settings entered into the form.
    79      */
    80     function saveSettings(){
    81         woocommerce_update_options( $this->generateSettingsFields() );
    82     }
    83 
    84     /**
    85      * Generates the WC settings fields configuration for this plugin tab.
    86      * @return mixed[]
    87      */
    88     private function generateSettingsFields(){
    89        
    90         $settings = array(           
    91             'general_title' => array(
    92                 'title' => __('Referral System Settings', CWRF_SLUG),
    93                 'type' => 'title',
    94                 'id' => CWRF_SLUG.'_general_title'
    95             ),
    96             'table_content' => array(
    97                 'type' => 'title',
    98                 'desc' => __('<hr><h4>Copy this short code <span style="font-weight:800;">[cwrf-refferal-system]</span> and paste it into your page to generate referral link.<h4/>', CWRF_SLUG),
    99                 'id' => 'short_code_label'
    100             ),
    101             'redirect_link' => array(
    102                 'title' => __('Redirect Page', CWRF_SLUG),
    103                 'type' => 'select',
    104                 'options' => $this->get_pages(),             
    105                 'desc_tip' => __('Select the page where you want the user with referral link to redirect.', CWRF_SLUG),
    106                 'id' => CodupWCReferralSystem::OPT_REDIRECT_LINK,
    107                 'class' => 'cwrf-redirect-link'
    108             ),
    109             'referral_slug' => array(
    110                 'title' => __('Referral URL Variable', CWRF_SLUG),
    111                 'type' => 'text',
    112                 'desc' => '',
    113                 'desc_tip' => __('Create your custom slug, a part of referral url identifying the referrer by ID', CWRF_SLUG),
    114                 'id' => CodupWCReferralSystem::OPT_REFERRAL_SLUG,
    115                 'class' => 'cwrf-referral-slug'
    116             ),           
    117             'referral_expiry' => array(
    118                 'title' => __('Referral Expiry', CWRF_SLUG),
    119                 'type' => 'number',
    120                 'desc' => __('days', CWRF_SLUG),
    121                 'desc_tip' => __('Set referral link expiry in days.', CWRF_SLUG),
    122                 'id' => CodupWCReferralSystem::OPT_REFERRAL_EXPIRY,
    123                 'class' => 'cwrf-referral-expiry'
    124             ),
    125             'referee_award' => array(
    126                 'title' => __('Award Referee?', CWRF_SLUG),
    127                 'type' => 'checkbox',
    128                 'desc' => __('<span class="description">Select whether to reward the referee along with referrer</span>', CWRF_SLUG),
    129                 'id' => CodupWCReferralSystem::OPT_REFEREE_AWARD,
    130                 'class' => 'cwrf-referee-award'
    131             ),
    132             'coupons_list' => array(
    133                 'title' => __('Select Coupon to Reward', CWRF_SLUG),
    134                 'type' => 'select',
    135                 'options' => $this->get_coupons(),
    136                 'desc' => '',
    137                 'id' => CodupWCReferralSystem::OPT_COUPON_LIST,
    138                 'class' => 'cwrf-coupun-list'
    139             ),
    140             'general_section_end' => array(
    141                 'type' => 'sectionend',
    142                 'id' => CWRF_SLUG.'_general_title'
    143             )
    144         );     
    145        
    146         return apply_filters(CWRF_SLUG.'_settings', $settings);
    147     }
    148 
    149     function get_pages(){
    150         $pages = array();
    151         $args = array(
    152             'post_status' => 'publish'
    153         );
    154         $result = get_pages($args, ARRAY_A, 'page');
    155         foreach($result as $page){
    156             $pages[$page->post_title] = $page->post_title;
    157         }
    158 
    159         return $pages;
    160     }
    161 
    162     function get_coupons(){
    163         $args = array(
    164             'posts_per_page'   => -1,
    165             'orderby'          => 'title',
    166             'order'            => 'asc',
    167             'post_type'        => 'shop_coupon',
    168             'post_status'      => 'publish',
    169         );
    170            
    171         $posts = get_posts( $args );
    172         $coupons = array();
    173         foreach ($posts as $key => $post) {
    174             $coupons[$post->post_title] =  $post->post_title;
    175         }
    176 
    177         return $coupons;
    178     }
    179 
    180     function add_referral_link( $menu_links ){       
    181        
    182         $new = array( 'referrallink' => 'Referral System' );     
    183         $menu_links = array_slice( $menu_links, 0, 1, true )
    184         + $new
    185         + array_slice( $menu_links, 1, NULL, true );
    186         return $menu_links;   
    187     }     
    188 
    189     function hook_referral_endpoint( $url, $endpoint, $value, $permalink ){     
    190        
    191         if( $endpoint === 'referrallink' ) {
    192             $pages = get_pages( ['sort_column' => 'ID'] );
    193 
    194             foreach($pages as $page){
    195                 if( preg_match( '[cwrf-referral-system]', $page->post_content  ) ){
    196 
    197                     $url = site_url().'/'. $page->post_name .'/';
    198                     break;
    199                 }
    200             }
    201         }
    202         return $url;     
    203     }
    204 
    205     function add_referral_system_page(){
    206 
    207         if( !is_admin() ){
    208             $referral_slug = get_option(CWRF_SLUG.'_referral_slug');
    209             ob_start();
    210             include(dirname(__FILE__). '/templates'.'/referral_system.php');
    211             $referral_system_page_content = ob_get_contents();
    212             ob_get_clean();
    213             return $referral_system_page_content;
    214         }
    215     }
    216 
    217     function save_referral_parameter(){       
    218         global $wp;
    219        
    220         $referral_slug = get_option(CWRF_SLUG.'_referral_slug');
    221 
    222         if( isset( $_GET[$referral_slug] ) ){
    223             $referrer = $_GET[$referral_slug];           
    224             $redirect_page = get_option(CWRF_SLUG.'_redirect_link', true);
    225 
    226             if($referrer != get_current_user_id() && get_userdata($referrer) && !$_COOKIE["STYXKEY_cwrref"]){                       
    227                 $referral_expiry = get_option(CWRF_SLUG.'_referral_expiry', true);
    228                 setcookie("STYXKEY_cwrref", $referrer, time() + (24 * 3600 * $referral_expiry), "/");
    229                        
    230             }   
    231 
    232             $page = get_page_by_title( $redirect_page, ARRAY_A, 'page' );
    233             wp_redirect($page['guid']);     
    234             exit;       
    235            
    236         }
    237     }
    238 
    239     function reward_referrer( $order, $old_status, $new_status ){       
    240         global $wpdb;
    241 
    242         if (is_numeric($order)) {
    243             $order = wc_get_order($order);
    244         }
    245        
    246         $table = $wpdb->prefix . CWRF_SLUG . "_coupon_rewards";
    247        
    248        
    249         if($_COOKIE["STYXKEY_cwrref"] && $new_status == 'processing'){
    250 
    251             $referrer_id = $_COOKIE["STYXKEY_cwrref"];           
    252             $coupon_code = get_option(CWRF_SLUG.'_coupon_list', true);
    253             $query = "SELECT * FROM  " . $table . " WHERE user_id = '".$referrer_id."' AND coupon_code = '".$coupon_code . "'";
    254             $result = $wpdb->get_results($query, ARRAY_A);
    255 
    256             if(sizeof($result) == 0){
    257                 $data = array(                   
    258                     'user_id' => $referrer_id,
    259                     'coupon_code' => $coupon_code,
    260                     'coupon_count' => 1
    261 
    262                 );
    263                
    264                 $wpdb->insert( $table, $data);
    265             }
    266             else{
    267                
    268                 $data = array(                   
    269                     'user_id' => $referrer_id,
    270                     'coupon_code' => $coupon_code,
    271                     'coupon_count' => $result[0]['coupon_count'] + 1
    272 
    273                 );
    274                 $where = array(
    275                     'id' => $result[0]['id']
    276                 );
    277 
    278                 $wpdb->update( $table, $data, $where);
    279 
    280             }
    281             $user = get_userdata($referrer_id);
    282 
    283             setcookie("STYXKEY_cwrref", "", time() - 3600, "/");
    284             setcookie("STYXKEY_remove_coupon", "", time() - 3600, "/");
    285             do_action('codup_wcrf_send_email', $order, $user, $new_status, $old_status);   
    286            
    287         }
    288        
    289         $current_user_id = get_current_user_id();
    290         $coupons = $order->get_used_coupons();
    291         $query = "SELECT id, coupon_code, coupon_count FROM  " . $table . " WHERE user_id = '".$current_user_id."'";
    292         $users_coupons = $wpdb->get_results($query, ARRAY_A);
    293 
    294         foreach($users_coupons as $coupon){
    295             if(in_array($coupon['coupon_code'], $coupons)){
    296                 $data = array(                   
    297                     'user_id' => $current_user_id,
    298                     'coupon_code' => $coupon['coupon_code'],
    299                     'coupon_count' => $coupon['coupon_count'] - 1
    300 
    301                 );
    302                 $where = array(
    303                     'id' => $coupon['id']
    304                 );
    305 
    306                 $wpdb->update( $table, $data, $where);
    307             }
    308         }
    309     }
    310 
    311     function apply_coupon_validation(){
    312         global $woocommerce;
    313 
    314         $awardReferee = get_option(CWRF_SLUG.'_referee_award', true);
    315         $coupon_code = get_option(CWRF_SLUG.'_coupon_list', true);
    316         $applied_coupons = $woocommerce->cart->get_applied_coupons();
    317         $coupons = $this->get_reward_coupons();   
    318 
    319         foreach($coupons as $coupon){
    320 
    321             if($coupon['coupon_code'] == $coupon_code && $_COOKIE["STYXKEY_cwrref"] && $awardReferee == "yes"){             
    322                 break;
    323             }
    324 
    325             if(in_array($coupon['coupon_code'], $applied_coupons) ){
    326                 $coupon_data = new WC_Coupon($coupon['coupon_code']);
    327                 if($coupon_data->is_valid()){
    328                     if($coupon['coupon_count'] <= 0){
    329                         $woocommerce->cart->remove_coupon( sanitize_text_field( $coupon['coupon_code']  ));
    330                         $woocommerce->cart->calculate_totals();
    331                        
    332                         wc_clear_notices();
    333                         wc_print_notice( 'You have reached the limit to use this discount!', 'error' );
    334                        
    335                        
    336                     }
    337                 }
    338             }
    339         }               
    340     }
    341 
    342     function apply_coupon_for_referral(){
    343         global $woocommerce;
    344 
    345         $awardReferee = get_option(CWRF_SLUG.'_referee_award', true);
    346         $coupon_code = get_option(CWRF_SLUG.'_coupon_list', true);
    347    
    348         if($_COOKIE["STYXKEY_cwrref"] && $awardReferee == "yes" ){
    349            
    350             wc_clear_notices();
    351             $isCouponAlreadyApplied = in_array($coupon_code, $woocommerce->cart->get_applied_coupons());
    352            
    353             global $woocommerce;
    354             $coupon_data = new WC_Coupon($coupon_code);
    355             $checkUsageLimit = $coupon_data->usage_limit - $coupon_data->usage_count; //check if Usage Limit Exceeeds
    356 
    357             if(!$isCouponAlreadyApplied && $_COOKIE["STYXKEY_remove_coupon"] != 'yes' && $checkUsageLimit != 0){
    358                 $woocommerce->cart->add_discount( sanitize_text_field( $coupon_code ));
    359                 wc_clear_notices();
    360                 wc_print_notice( 'A discount coupon has been applied for being a referee!', 'success' );
    361             }
    362 
    363             if(!$isCouponAlreadyApplied && $_COOKIE["STYXKEY_remove_coupon"] == 'yes'){                     
    364                 wc_print_notice( 'Get your referee discount by using coupon <strong>'.$coupon_code . '</strong>', 'notice' );       
    365             }
    366         }
    367     }
    368 
    369     function remove_reward_coupon( $coupon_code ){
    370        
    371         $reward_coupon_code = get_option(CWRF_SLUG.'_coupon_list', true);
    372        
    373         if($reward_coupon_code == $coupon_code && !$_COOKIE["STYXKEY_remove_coupon"]){
    374            
    375             $referral_expiry = get_option(CWRF_SLUG.'_referral_expiry', true);           
    376            
    377             setcookie("STYXKEY_remove_coupon", 'yes', time() + (24 * 3600 * $referral_expiry), "/");
    378         }
    379     }
    380 
    381     function get_reward_coupons( $user_id='' ){       
    382         if(!is_user_logged_in()){
    383             return array();
    384         }
    385 
    386         global $wpdb;
    387 
    388         if($user_id == ''){
    389             $user_id = get_current_user_id();
    390         }
    391 
    392         $table = $wpdb->prefix . CWRF_SLUG . "_coupon_rewards";       
    393         $query = "SELECT * FROM  " . $table . " WHERE user_id = '".$user_id. "'";
    394         $coupons = $wpdb->get_results($query, ARRAY_A);
    395 
    396         return $coupons;
    397     }
    398 
    399     /**
    400      *  Add a custom email to the list of emails WooCommerce should load on settings page
    401      *
    402      * @since 0.1
    403      * @param array $email_classes available email classes
    404      * @return array filtered available email classes
    405      */
    406     function add_custom_wcrf_email( $email_classes ) {
    407         // include our custom email class
    408         require_once( dirname(__FILE__).DS. 'class.codup-wcrf-email.php' );
    409 
    410         // add the email class to the list of email classes that WooCommerce loads
    411         $email_classes['CodupWC_ReferralSystem_Email'] = new CodupWC_ReferralSystem_Email();
    412 
    413         return $email_classes;
    414     }
    415 
    416     /**
    417      * Locate the plugin email templates
    418      *
    419      * @param $core_file
    420      * @param $template
    421      * @param $template_base
    422      *
    423      * @return string
    424      */
    425     function locate_core_template( $core_file, $template, $template_base ) {
    426         $custom_template = array(
    427             'emails/wcrf-email.php',
    428             'emails/plain/wcrf-email-plain.php',
    429         );
    430 
    431         if (in_array($template, $custom_template)) {
    432             $core_file = trailingslashit( dirname(__FILE__).DS. 'templates') . $template;
    433         }     
    434 
    435         return $core_file;
    436     }
    437 
    438      /**
    439      * Add links to the bottom of the plugin name in the WP plugins list
    440      * @param array $links
    441      */
    442     function addActionLinks( $links ){
    443         $cwlLinks = array(
    444             '<a href="'.admin_url('admin.php?page=wc-settings&tab=cwrf').'">Settings</a>'
    445         );
    446        
    447         return array_merge($cwlLinks, $links);
    448     }   
     3class CodupWCReferralSystem {
     4
     5    const OPT_REDIRECT_LINK   = CWRF_SLUG . '_redirect_link';
     6    const OPT_REFERRAL_SLUG   = CWRF_SLUG . '_referral_slug';
     7    const OPT_REFERRAL_EXPIRY = CWRF_SLUG . '_referral_expiry';
     8    const OPT_REFEREE_AWARD   = CWRF_SLUG . '_referee_award';
     9    const OPT_COUPON_LIST     = CWRF_SLUG . '_coupon_list';
     10
     11    private static $optDefaults = array(
     12        self::OPT_REDIRECT_LINK  => '',
     13        self::OPT_REFERRAL_SLUG  => 'cwrf_ref',
     14        self::OPT_REFERRAL_EXPIRY => 1,
     15        self::OPT_REFEREE_AWARD   => 1,
     16
     17    );
     18
     19    function __construct() {
     20
     21        add_filter( 'plugin_action_links_' . CWRF_PLUGIN_BASENAME, array( $this, 'addActionLinks' ) );
     22
     23        /** Add settings tabs to woocommerce setting tabs */
     24        add_filter( 'woocommerce_settings_tabs_array', array( $this, 'addSettingsTab' ), 50 );
     25        add_action( 'woocommerce_settings_tabs_' . CWRF_SLUG, array( $this, 'addSettingsTabContents' ) );
     26        add_action( 'woocommerce_update_options_' . CWRF_SLUG, array( $this, 'saveSettings' ) );
     27        add_action( 'init', array( $this, 'addSettingDefaults' ) );
     28
     29        /** Add custom link and page to woocommerce account menu for referral system */
     30        add_filter( 'woocommerce_account_menu_items', array( $this, 'add_referral_link' ) );
     31        add_filter( 'woocommerce_get_endpoint_url', array( $this, 'hook_referral_endpoint' ), 10, 4 );
     32        add_shortcode( 'cwrf-referral-system', array( $this, 'add_referral_system_page' ) );
     33        add_action( 'template_redirect', array( $this, 'save_referral_parameter' ) );
     34
     35        /** Award referrer and referee */
     36        add_filter( 'woocommerce_order_status_changed', array( $this, 'reward_referrer' ), 10, 3 );
     37        add_action( 'woocommerce_applied_coupon', array( $this, 'apply_coupon_validation' ) );
     38        add_action( 'woocommerce_before_cart', array( $this, 'apply_coupon_for_referral' ) );
     39        add_action( 'woocommerce_removed_coupon', array( $this, 'remove_reward_coupon' ) );
     40
     41        /** Add custom email to woocommerce emails */
     42        add_filter( 'woocommerce_email_classes', array( $this, 'add_custom_wcrf_email' ) );
     43        add_filter( 'woocommerce_locate_core_template', array( $this, 'locate_core_template' ), 10, 3 );
     44
     45    }
     46
     47    /**
     48    * Inserts default values into WordPress options.
     49    */
     50    function addSettingDefaults() {
     51        foreach ( self::$optDefaults as $key => $defaultValue ) {
     52            if ( ! get_option( $key ) ) {
     53                add_option( $key, $defaultValue );
     54            }
     55        }
     56    }
     57
     58    /**
     59    * Adds the CWL tab to WooCommerce settings page.
     60     *
     61     * @param string[] $tabs
     62     * @return string[]
     63     */
     64    function addSettingsTab( $tabs ) {
     65        $tabs[ CWRF_SLUG ] = __( 'Referral Sytem', CWRF_SLUG );
     66        return $tabs;
     67    }
     68
     69    /**
     70     * Adds the content of the CWL settings tab in WC settings page.
     71     */
     72    function addSettingsTabContents() {
     73        do_shortcode( '[codup_ads_top]' );
     74        woocommerce_admin_fields( $this->generateSettingsFields() );
     75    }
     76
     77
     78    /**
     79     * Saves the settings entered into the form.
     80     */
     81    function saveSettings() {
     82        woocommerce_update_options( $this->generateSettingsFields() );
     83    }
     84
     85    /**
     86     * Generates the WC settings fields configuration for this plugin tab.
     87     *
     88     * @return mixed[]
     89     */
     90    private function generateSettingsFields() {
     91
     92        $settings = array(
     93            'general_title'       => array(
     94                'title' => __( 'Referral System Settings', CWRF_SLUG ),
     95                'type'  => 'title',
     96                'id'    => CWRF_SLUG . '_general_title',
     97            ),
     98            'table_content'       => array(
     99                'type' => 'title',
     100                'desc' => __( '<hr><h4>Copy this short code <span style="font-weight:800;">[cwrf-refferal-system]</span> and paste it into your page to generate referral link.<h4/>', CWRF_SLUG ),
     101                'id'   => 'short_code_label',
     102            ),
     103            'redirect_link'       => array(
     104                'title'    => __( 'Redirect Page', CWRF_SLUG ),
     105                'type'     => 'select',
     106                'options'  => $this->get_pages(),
     107                'desc_tip' => __( 'Select the page where you want the user with referral link to redirect.', CWRF_SLUG ),
     108                'id'       => self::OPT_REDIRECT_LINK,
     109                'class'    => 'cwrf-redirect-link',
     110            ),
     111            'referral_slug'       => array(
     112                'title'    => __( 'Referral URL Variable', CWRF_SLUG ),
     113                'type'     => 'text',
     114                'desc'     => '',
     115                'desc_tip' => __( 'Create your custom slug, a part of referral url identifying the referrer by ID', CWRF_SLUG ),
     116                'id'       => self::OPT_REFERRAL_SLUG,
     117                'class'    => 'cwrf-referral-slug',
     118            ),
     119            'referral_expiry'     => array(
     120                'title'    => __( 'Referral Expiry', CWRF_SLUG ),
     121                'type'     => 'number',
     122                'desc'     => __( 'days', CWRF_SLUG ),
     123                'desc_tip' => __( 'Set referral link expiry in days.', CWRF_SLUG ),
     124                'id'       => self::OPT_REFERRAL_EXPIRY,
     125                'class'    => 'cwrf-referral-expiry',
     126            ),
     127            'referee_award'       => array(
     128                'title' => __( 'Award Referee?', CWRF_SLUG ),
     129                'type'  => 'checkbox',
     130                'desc'  => __( '<span class="description">Select whether to reward the referee along with referrer</span>', CWRF_SLUG ),
     131                'id'    => self::OPT_REFEREE_AWARD,
     132                'class' => 'cwrf-referee-award',
     133            ),
     134            'coupons_list'        => array(
     135                'title'   => __( 'Select Coupon to Reward', CWRF_SLUG ),
     136                'type'    => 'select',
     137                'options' => $this->get_coupons(),
     138                'desc'    => '',
     139                'id'      => self::OPT_COUPON_LIST,
     140                'class'   => 'cwrf-coupun-list',
     141            ),
     142            'general_section_end' => array(
     143                'type' => 'sectionend',
     144                'id'   => CWRF_SLUG . '_general_title',
     145            ),
     146        );
     147
     148        return apply_filters( CWRF_SLUG . '_settings', $settings );
     149    }
     150
     151    function get_pages() {
     152        $pages  = array();
     153        $args   = array(
     154            'post_status' => 'publish',
     155        );
     156        $result = get_pages( $args, ARRAY_A, 'page' );
     157        foreach ( $result as $page ) {
     158            $pages[ $page->post_title ] = $page->post_title;
     159        }
     160
     161        return $pages;
     162    }
     163
     164    function get_coupons() {
     165        $args = array(
     166            'posts_per_page' => -1,
     167            'orderby'        => 'title',
     168            'order'          => 'asc',
     169            'post_type'      => 'shop_coupon',
     170            'post_status'    => 'publish',
     171        );
     172
     173        $posts   = get_posts( $args );
     174        $coupons = array();
     175        foreach ( $posts as $key => $post ) {
     176            $coupons[ $post->post_title ] = $post->post_title;
     177        }
     178
     179        return $coupons;
     180    }
     181
     182    function add_referral_link( $menu_links ) {
     183
     184        $new        = array( 'referrallink' => 'Referral System' );
     185        $menu_links = array_slice( $menu_links, 0, 1, true )
     186        + $new
     187        + array_slice( $menu_links, 1, null, true );
     188        return $menu_links;
     189    }
     190
     191    function hook_referral_endpoint( $url, $endpoint, $value, $permalink ) {
     192
     193        if ( $endpoint === 'referrallink' ) {
     194            $pages = get_pages( array( 'sort_column' => 'ID' ) );
     195
     196            foreach ( $pages as $page ) {
     197                if ( preg_match( '[cwrf-referral-system]', $page->post_content ) ) {
     198
     199                    $url = site_url() . '/' . $page->post_name . '/';
     200                    break;
     201                }
     202            }
     203        }
     204        return $url;
     205    }
     206
     207    function add_referral_system_page() {
     208
     209        if ( ! is_admin() ) {
     210            $referral_slug = get_option( CWRF_SLUG . '_referral_slug' );
     211            ob_start();
     212            include dirname( __FILE__ ) . '/templates' . '/referral_system.php';
     213            $referral_system_page_content = ob_get_contents();
     214            ob_get_clean();
     215            return $referral_system_page_content;
     216        }
     217    }
     218
     219    function save_referral_parameter() {
     220        global $wp;
     221
     222        $referral_slug = get_option( CWRF_SLUG . '_referral_slug' );
     223
     224        if ( isset( $_GET[ $referral_slug ] ) ) {
     225            $referrer      = $_GET[ $referral_slug ];
     226            $redirect_page = get_option( CWRF_SLUG . '_redirect_link', true );
     227
     228            if ( $referrer != get_current_user_id() && get_userdata( $referrer ) && ! $_COOKIE['STYXKEY_cwrref'] ) {
     229                $referral_expiry = get_option( CWRF_SLUG . '_referral_expiry', true );
     230                setcookie( 'STYXKEY_cwrref', $referrer, time() + ( 24 * 3600 * $referral_expiry ), '/' );
     231
     232            }
     233
     234            $page = get_page_by_title( $redirect_page, ARRAY_A, 'page' );
     235            wp_redirect( $page['guid'] );
     236            exit;
     237
     238        }
     239    }
     240
     241    function reward_referrer( $order, $old_status, $new_status ) {
     242        global $wpdb;
     243
     244        if ( is_numeric( $order ) ) {
     245            $order = wc_get_order( $order );
     246        }
     247
     248        $table = $wpdb->prefix . CWRF_SLUG . '_coupon_rewards';
     249
     250        if ( $_COOKIE['STYXKEY_cwrref'] && $new_status == 'processing' ) {
     251
     252            $referrer_id = $_COOKIE['STYXKEY_cwrref'];
     253            $coupon_code = get_option( CWRF_SLUG . '_coupon_list', true );
     254            $query       = 'SELECT * FROM  ' . $table . " WHERE user_id = '" . $referrer_id . "' AND coupon_code = '" . $coupon_code . "'";
     255            $result      = $wpdb->get_results( $query, ARRAY_A );
     256
     257            if ( sizeof( $result ) == 0 ) {
     258                $data = array(
     259                    'user_id'      => $referrer_id,
     260                    'coupon_code'  => $coupon_code,
     261                    'coupon_count' => 1,
     262
     263                );
     264
     265                $wpdb->insert( $table, $data );
     266            } else {
     267
     268                $data = array(
     269                    'user_id'      => $referrer_id,
     270                    'coupon_code' => $coupon_code,
     271                    'coupon_count' => $result[0]['coupon_count'] + 1,
     272
     273                );
     274                $where = array(
     275                    'id' => $result[0]['id'],
     276                );
     277
     278                $wpdb->update( $table, $data, $where );
     279
     280            }
     281            $user = get_userdata( $referrer_id );
     282
     283            setcookie( 'STYXKEY_cwrref', '', time() - 3600, '/' );
     284            setcookie( 'STYXKEY_remove_coupon', '', time() - 3600, '/' );
     285            do_action( 'codup_wcrf_send_email', $order, $user, $new_status, $old_status );
     286
     287        }
     288
     289        $current_user_id = get_current_user_id();
     290        $coupons        = $order->get_used_coupons();
     291        $query           = 'SELECT id, coupon_code, coupon_count FROM  ' . $table . " WHERE user_id = '" . $current_user_id . "'";
     292        $users_coupons   = $wpdb->get_results( $query, ARRAY_A );
     293
     294        foreach ( $users_coupons as $coupon ) {
     295            if ( in_array( $coupon['coupon_code'], $coupons ) ) {
     296                $data = array(
     297                    'user_id'      => $current_user_id,
     298                    'coupon_code' => $coupon['coupon_code'],
     299                    'coupon_count' => $coupon['coupon_count'] - 1,
     300
     301                );
     302                $where = array(
     303                    'id' => $coupon['id'],
     304                );
     305
     306                $wpdb->update( $table, $data, $where );
     307            }
     308        }
     309    }
     310
     311    function apply_coupon_validation() {
     312        global $woocommerce;
     313
     314        $awardReferee    = get_option( CWRF_SLUG . '_referee_award', true );
     315        $coupon_code     = get_option( CWRF_SLUG . '_coupon_list', true );
     316        $applied_coupons = $woocommerce->cart->get_applied_coupons();
     317        $coupons         = $this->get_reward_coupons();
     318
     319        foreach ( $coupons as $coupon ) {
     320
     321            if ( $coupon['coupon_code'] == $coupon_code && $_COOKIE['STYXKEY_cwrref'] && $awardReferee == 'yes' ) {
     322                break;
     323            }
     324
     325            if ( in_array( $coupon['coupon_code'], $applied_coupons ) ) {
     326                $coupon_data = new WC_Coupon( $coupon['coupon_code'] );
     327                if ( $coupon_data->is_valid() ) {
     328                    if ( $coupon['coupon_count'] <= 0 ) {
     329                        $woocommerce->cart->remove_coupon( sanitize_text_field( $coupon['coupon_code'] ) );
     330                        $woocommerce->cart->calculate_totals();
     331
     332                        wc_clear_notices();
     333                        wc_print_notice( 'You have reached the limit to use this discount!', 'error' );
     334
     335                    }
     336                }
     337            }
     338        }
     339    }
     340
     341    function apply_coupon_for_referral() {
     342        global $woocommerce;
     343
     344        $awardReferee = get_option( CWRF_SLUG . '_referee_award', true );
     345        $coupon_code  = get_option( CWRF_SLUG . '_coupon_list', true );
     346
     347        if ( $_COOKIE['STYXKEY_cwrref'] && $awardReferee == 'yes' ) {
     348
     349            wc_clear_notices();
     350            $isCouponAlreadyApplied = in_array( $coupon_code, $woocommerce->cart->get_applied_coupons() );
     351
     352            global $woocommerce;
     353            $coupon_data     = new WC_Coupon( $coupon_code );
     354            $checkUsageLimit = $coupon_data->usage_limit - $coupon_data->usage_count; // check if Usage Limit Exceeeds
     355
     356            if ( ! $isCouponAlreadyApplied && $_COOKIE['STYXKEY_remove_coupon'] != 'yes' && $checkUsageLimit != 0 ) {
     357                $woocommerce->cart->add_discount( sanitize_text_field( $coupon_code ) );
     358                wc_clear_notices();
     359                wc_print_notice( 'A discount coupon has been applied for being a referee!', 'success' );
     360            }
     361
     362            if ( ! $isCouponAlreadyApplied && $_COOKIE['STYXKEY_remove_coupon'] == 'yes' ) {
     363                wc_print_notice( 'Get your referee discount by using coupon <strong>' . $coupon_code . '</strong>', 'notice' );
     364            }
     365        }
     366    }
     367
     368    function remove_reward_coupon( $coupon_code ) {
     369
     370        $reward_coupon_code = get_option( CWRF_SLUG . '_coupon_list', true );
     371
     372        if ( $reward_coupon_code == $coupon_code && ! $_COOKIE['STYXKEY_remove_coupon'] ) {
     373
     374            $referral_expiry = get_option( CWRF_SLUG . '_referral_expiry', true );
     375
     376            setcookie( 'STYXKEY_remove_coupon', 'yes', time() + ( 24 * 3600 * $referral_expiry ), '/' );
     377        }
     378    }
     379
     380    function get_reward_coupons( $user_id = '' ) {
     381        if ( ! is_user_logged_in() ) {
     382            return array();
     383        }
     384
     385        global $wpdb;
     386
     387        if ( $user_id == '' ) {
     388            $user_id = get_current_user_id();
     389        }
     390
     391        $table   = $wpdb->prefix . CWRF_SLUG . '_coupon_rewards';
     392        $query   = 'SELECT * FROM  ' . $table . " WHERE user_id = '" . $user_id . "'";
     393        $coupons = $wpdb->get_results( $query, ARRAY_A );
     394
     395        return $coupons;
     396    }
     397
     398    /**
     399     *  Add a custom email to the list of emails WooCommerce should load on settings page
     400     *
     401     * @since 0.1
     402     * @param array $email_classes available email classes
     403     * @return array filtered available email classes
     404     */
     405    function add_custom_wcrf_email( $email_classes ) {
     406        // include our custom email class
     407        require_once dirname( __FILE__ ) . DS . 'class.codup-wcrf-email.php';
     408
     409        // add the email class to the list of email classes that WooCommerce loads
     410        $email_classes['CodupWC_ReferralSystem_Email'] = new CodupWC_ReferralSystem_Email();
     411
     412        return $email_classes;
     413    }
     414
     415    /**
     416     * Locate the plugin email templates
     417     *
     418     * @param $core_file
     419     * @param $template
     420     * @param $template_base
     421     *
     422     * @return string
     423     */
     424    function locate_core_template( $core_file, $template, $template_base ) {
     425        $custom_template = array(
     426            'emails/wcrf-email.php',
     427            'emails/plain/wcrf-email-plain.php',
     428        );
     429
     430        if ( in_array( $template, $custom_template ) ) {
     431            $core_file = trailingslashit( dirname( __FILE__ ) . DS . 'templates' ) . $template;
     432        }
     433
     434        return $core_file;
     435    }
     436
     437     /**
     438      * Add links to the bottom of the plugin name in the WP plugins list
     439      *
     440      * @param array $links
     441      */
     442    function addActionLinks( $links ) {
     443        $cwlLinks = array(
     444            '<a href="' . admin_url( 'admin.php?page=wc-settings&tab=cwrf' ) . '">Settings</a>',
     445        );
     446
     447        return array_merge( $cwlLinks, $links );
     448    }
    449449}
  • codup-woocommerce-referral-system/trunk/includes/lib/codupads/codupads.php

    r1874660 r2700997  
    11<?php
    22
    3 class CodupAds{     
     3class CodupAds {
    44
    5     public function __construct(){
    6         add_shortcode('codup_ads_top', array($this, 'codup_render_top_ads'));
    7         add_shortcode('codup_ads_right', array($this, 'codup_render_right_ads'));
    8         add_action('admin_init', array($this, 'add_style_scripts'));
    9         add_action('init', array($this, 'add_style_scripts'));
    10        
     5    public function __construct() {
     6        add_shortcode( 'codup_ads_top', array( $this, 'codup_render_top_ads' ) );
     7        add_shortcode( 'codup_ads_right', array( $this, 'codup_render_right_ads' ) );
     8        add_action( 'admin_init', array( $this, 'add_style_scripts' ) );
     9        add_action( 'init', array( $this, 'add_style_scripts' ) );
    1110
    1211    }
    1312
    14     function cwrf_get_woo_version_number(){
    15         if ( ! function_exists( 'get_plugins' ) )
    16             require_once( ABSPATH . 'wp-admin/includes/plugin.php' );
    17        
     13    function cwrf_get_woo_version_number() {
     14        if ( ! function_exists( 'get_plugins' ) ) {
     15            require_once ABSPATH . 'wp-admin/includes/plugin.php';
     16        }
     17
    1818        $plugin_folder = get_plugins( '/' . 'woocommerce' );
    19         $plugin_file = 'woocommerce.php';
    20        
    21         if(isset( $plugin_folder[$plugin_file]['Version'])) {
    22             return $plugin_folder[$plugin_file]['Version'];
     19        $plugin_file   = 'woocommerce.php';
    2320
    24         }
    25         else{
     21        if ( isset( $plugin_folder[ $plugin_file ]['Version'] ) ) {
     22            return $plugin_folder[ $plugin_file ]['Version'];
    2623
    27             return NULL;
     24        } else {
     25
     26            return null;
    2827        }
    2928    }
    3029
    31     function add_style_scripts(){
     30    function add_style_scripts() {
    3231        $pluginConfig = array(
    33        
    34             "pluginName" => CWRF_PLUGIN_NAME,
    35             "pluginVersion" => CWRF_PLUGIN_VER,
    36             "pageSlug" => CWRF_PAGE_SLUG,
    37             "wpVersion" => get_bloginfo('version'),
    38             "wcVersion" => $this->cwrf_get_woo_version_number()
     32
     33            'pluginName'    => CWRF_PLUGIN_NAME,
     34            'pluginVersion' => CWRF_PLUGIN_VER,
     35            'pageSlug'      => CWRF_PAGE_SLUG,
     36            'wpVersion'     => get_bloginfo( 'version' ),
     37            'wcVersion'     => $this->cwrf_get_woo_version_number(),
    3938        );
    40         wp_enqueue_script(CWRF_PLUGIN_NAME, plugin_dir_url( __FILE__ ) . 'scripts/adscript.js', array( 'jquery' ), CWRF_PLUGIN_VER, false );
    41         wp_enqueue_style(CWRF_PLUGIN_NAME.'- codupads-styles', plugin_dir_url( __FILE__ ) . 'styles/style.css', array(), CWRF_PLUGIN_VER, 'all' );
    42         wp_localize_script(CWRF_PLUGIN_NAME,'PluginConfig',$pluginConfig);
    43     }   
    44 
    45     function codup_render_top_ads(){
    46         echo '<div id="codup-topad" class="wrap"></div>';
     39        wp_enqueue_script( CWRF_PLUGIN_NAME, plugin_dir_url( __FILE__ ) . 'scripts/adscript.js', array( 'jquery' ), CWRF_PLUGIN_VER, false );
     40        wp_enqueue_style( CWRF_PLUGIN_NAME . '- codupads-styles', plugin_dir_url( __FILE__ ) . 'styles/style.css', array(), CWRF_PLUGIN_VER, 'all' );
     41        wp_localize_script( CWRF_PLUGIN_NAME, 'PluginConfig', $pluginConfig );
    4742    }
    4843
    49     function codup_render_right_ads(){     
    50         echo '<div id="codup-rightad" class="stick-to-right"></div>';
    51     }
     44    function codup_render_top_ads() {
     45        echo '<div id="codup-topad" class="wrap"></div>';
     46    }
     47
     48    function codup_render_right_ads() {
     49        echo '<div id="codup-rightad" class="stick-to-right"></div>';
     50    }
    5251
    5352
    5453}
    55        
    56            
    5754
    5855
     56
     57
  • codup-woocommerce-referral-system/trunk/includes/lib/codupads/scripts/adscript.js

    r2119191 r2700997  
    11(function($) {
    2    
    3    
    4     $.ajax({
    5         url: "http://wpads.coduplabs.com/",
    6        
    7         data: {
    8             pluginConfig: PluginConfig
    9         },
    10         type: 'GET',
    11         headers: {
    12             'X-Codup-Ads' : 'ae237uiew4222ghq'
    13         },
    14         success: appendAds
    15     });
    16    
    17     function appendAds(data) {
    182
    19         data = JSON.parse(data);
    20         $('#codup-topad').html(data.topad);
    21         $('#codup-rightad').html(data.rightad);
     3    $.ajax(
     4        {
     5            url: "http://wpads.coduplabs.com/",
    226
    23     }
    24    
    25 })(jQuery);
     7            data: {
     8                pluginConfig: PluginConfig
     9            },
     10            type: 'GET',
     11            headers: {
     12                'X-Codup-Ads' : 'ae237uiew4222ghq'
     13            },
     14            success: appendAds
     15        }
     16    );
     17
     18    function appendAds(data) {
     19
     20        data = JSON.parse( data );
     21        $( '#codup-topad' ).html( data.topad );
     22        $( '#codup-rightad' ).html( data.rightad );
     23
     24    }
     25
     26})( jQuery );
  • codup-woocommerce-referral-system/trunk/includes/lib/codupads/styles/style.css

    r1874660 r2700997  
    11.codup-settings-page {
    2     width : 68%;
    3     display: inline-block;
    4     float: left;
     2    width : 68%;
     3    display: inline-block;
     4    float: left;
    55}
    66
    77.stick-to-right {
    8     margin-top: 60px;
    9     display: inline-block;
     8    margin-top: 60px;
     9    display: inline-block;
    1010}
    1111
    1212#codup-topad{
    1313    box-shadow: 0 1px 1px 0 rgba(0,0,0,.1);
    14     background-color: white;
    15     margin-right: 0;
     14    background-color: white;
     15    margin-right: 0;
    1616}
    1717
    1818#codup-topad img{
    1919    vertical-align: middle;
    20     padding: 10px;
    21     height: 16px;
     20    padding: 10px;
     21    height: 16px;
    2222}
    2323#codup-topad a{
  • codup-woocommerce-referral-system/trunk/includes/lib/tables.php

    r1874660 r2700997  
    44global $wpdb;
    55
    6 $wpdb->query("
    7     CREATE TABLE IF NOT EXISTS `" . $wpdb->prefix . CWRF_SLUG . "_coupon_rewards` (
     6$wpdb->query(
     7    '
     8    CREATE TABLE IF NOT EXISTS `' . $wpdb->prefix . CWRF_SLUG . '_coupon_rewards` (
    89      `id` int(11) NOT NULL AUTO_INCREMENT,
    910      `user_id` int(11) NOT NULL, 
     
    1415      PRIMARY KEY (`id`)
    1516    ) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=0
    16 ");
     17'
     18);
  • codup-woocommerce-referral-system/trunk/includes/templates/emails/plain/wcrf-email-plain.php

    r1874660 r2700997  
    22/**
    33 * Codup woocommerce referral system email template
    4  * 
     4 *
    55 * This template can be overridden by copying it to yourtheme/woocommerce/emails/wcrf-email.php .
    6  * 
     6 *
    77 * @param  array  $coupon           The coupon which is rewarded
    88 *
    9  * @param  string $referrer_name    First name and last name of referrer who is being rewarded. 
     9 * @param  string $referrer_name    First name and last name of referrer who is being rewarded.
    1010 */
    11 if (!defined('ABSPATH')) {
    12     exit;
     11if ( ! defined( 'ABSPATH' ) ) {
     12    exit;
    1313}
    1414
     
    1717 */
    1818
    19 echo sprintf(__('Hi %s,', 'codup_woocommerce_referral_system'), $referrer_name);
     19echo sprintf( __( 'Hi %s,', 'codup_woocommerce_referral_system' ), $referrer_name );
    2020
    2121echo "\n\n";
    2222
    23 echo sprintf(__('Thank you for referring a new customer. Here\'s a little treat from us. Enjoy the discount by using coupon %s on your next order.' ), $coupon);
     23echo sprintf( __( 'Thank you for referring a new customer. Here\'s a little treat from us. Enjoy the discount by using coupon %s on your next order.' ), $coupon );
    2424
    2525echo "\n";
    2626
    27 echo sprintf(__('Shop now at %s', 'codup_woocommerce_referral_system'), site_url().'/shop');
     27echo sprintf( __( 'Shop now at %s', 'codup_woocommerce_referral_system' ), site_url() . '/shop' );
    2828
    2929echo "\n\n";
  • codup-woocommerce-referral-system/trunk/includes/templates/emails/wcrf-email.php

    r1874660 r2700997  
    22/**
    33 * Codup woocommerce referral system email template
    4  * 
     4 *
    55 * This template can be overridden by copying it to yourtheme/woocommerce/emails/wcrf-email.php .
    6  *
    7  * @param  array  $coupon           The coupon which is rewarded
    86 *
    9  * @param  string $referrer_name    First name and last name of referrer who is being rewarded.   
     7 * @param  array  $coupon           The coupon which is rewarded
     8 *
     9 * @param  string $referrer_name    First name and last name of referrer who is being rewarded.
    1010 */
    11 if (!defined('ABSPATH')) {
    12     exit;
     11if ( ! defined( 'ABSPATH' ) ) {
     12    exit;
    1313}
    1414
     
    1616 * @hooked WC_Emails::email_header() Output the email header
    1717 */
    18 do_action('woocommerce_email_header', $email_heading, $email);
     18do_action( 'woocommerce_email_header', $email_heading, $email );
    1919?>
    2020
    2121<div>       
    22     <?php printf(__('Hi <strong>%s</strong>,', 'codup_woocommerce_referral_system'), $referrer_name); ?> 
     22    <?php printf( __( 'Hi <strong>%s</strong>,', 'codup_woocommerce_referral_system' ), $referrer_name ); ?> 
    2323</div>
    2424
    2525<div>   
    26     <?php printf(__('Thank you for referring a new customer. Here\'s a little treat from us. Enjoy the discount by using coupon <strong>%s</strong> on your next order.' ), $coupon);?>
     26    <?php printf( __( 'Thank you for referring a new customer. Here\'s a little treat from us. Enjoy the discount by using coupon <strong>%s</strong> on your next order.' ), $coupon ); ?>
    2727</div>
    2828<div>
    29     <?php printf(__('<a href="%s">Shop now! </a>', 'codup_woocommerce_referral_system'), site_url().'/shop');?>
     29    <?php printf( __( '<a href="%s">Shop now! </a>', 'codup_woocommerce_referral_system' ), site_url() . '/shop' ); ?>
    3030</div>
    3131
     
    3434 * @hooked WC_Emails::email_footer() Output the email footer
    3535 */
    36 do_action('woocommerce_email_footer', $email);
     36do_action( 'woocommerce_email_footer', $email );
  • codup-woocommerce-referral-system/trunk/includes/templates/referral_system.php

    r2022715 r2700997  
    1 <?php echo do_shortcode("[codup_ads_top]"); ?>
     1<?php echo do_shortcode( '[codup_ads_top]' ); ?>
    22<div class="cwrf_referral_system">
    33    <div class="cwrf_referral_link">
    4         <p>Your referral url: <span><strong><?php echo site_url(). '/?' . $referral_slug . '=' . get_current_user_id(); ?></strong></span></p>
     4        <p>Your referral url: <span><strong><?php echo site_url() . '/?' . $referral_slug . '=' . get_current_user_id(); ?></strong></span></p>
    55       
    66    </div>
  • codup-woocommerce-referral-system/trunk/readme.txt

    r2394438 r2700997  
    22Contributors: Codup
    33Tags: WooCommerce, Referral System, Affiliate, Referral
    4 Tested up to: 5.5.1
     4Tested up to: 5.9.2
    55License: GPLv2 or later
    66
Note: See TracChangeset for help on using the changeset viewer.