Plugin Directory

Changeset 2024649


Ignore:
Timestamp:
02/04/2019 02:16:29 PM (7 years ago)
Author:
jonboss
Message:

version 2.1.1

Location:
simple-woocommerce-favourites
Files:
1 deleted
6 edited
6 copied

Legend:

Unmodified
Added
Removed
  • simple-woocommerce-favourites/tags/2.1.1/includes/class-swf-actions.php

    r2013568 r2024649  
    2424        add_action( "wp_ajax_nopriv_simple_ajax_remove_from_favourites", array( __CLASS__, "remove_favourite" ) );
    2525
     26        if( SWF_Settings::get_auto_add_option() ){
     27            add_action( 'woocommerce_checkout_order_processed', array( __CLASS__, 'add_order_favourites' ) );
     28        }
     29
    2630    }
    2731
     
    3034    */
    3135    public static function add_favourite(){
    32 
    3336        check_ajax_referer('simple_favourites_nonce', 'simple_favourites_nonce');
    34         $favourites = swf_get_favourites();
    35    
    36         $prod_id = sanitize_text_field( $_POST['prod_id'] );
    37         if( !in_array($prod_id, $favourites) ){
    38             $prod_id = (int)$prod_id;
    39             array_push($favourites, $prod_id);
    40             swf_update_favourites($favourites);
     37        $prod_id        = sanitize_text_field( $_POST['prod_id'] );
     38        $favourites     = swf_get_favourites();
     39        if( in_array( $prod_id, $favourites ) ){
     40            echo 'This item is already in your favorites.';
     41        }
     42        else{
     43            swf_add_favourite( $prod_id, $favourites, true );
    4144            echo 'This item has been added to your favorites.';
    42             die();
    4345        }
    44         echo 'This item is already in your favorites.';
    4546        die();
    4647    }
     
    5253        check_ajax_referer('simple_favourites_nonce', 'simple_favourites_nonce');
    5354        $prod_id = (int)sanitize_text_field($_POST['prod_id']);
    54         $user_id = get_current_user_id();
    55         swf_remove_favourite( $user_id, $prod_id );
     55        swf_remove_favourite( $prod_id );
    5656        echo true;
    5757        die();
    5858    }
    5959
     60    /* 
     61        Add Order Products to Favourites
     62    */
     63    public static function add_order_favourites( $order_id ){
     64        $order      = wc_get_order( $order_id );
     65        $items      = $order->get_items();
     66        $favourites = swf_get_favourites();
     67        foreach( $items as $item ){
     68            $product_id = $item->get_product_id();
     69            $favourites = swf_add_favourite( $product_id, $favourites );
     70        }
     71        swf_update_favourites( $favourites );
     72    }
     73
    6074}
    6175SWF_Actions::hooks();
  • simple-woocommerce-favourites/tags/2.1.1/includes/class-swf-settings.php

    r2017783 r2024649  
    1515        'id' => 'product_favourites_display_option',
    1616        'value' => null
     17    ];
     18
     19    private static $auto_add_option = [
     20        'id' => 'purchased_products_auto_favourite'
    1721    ];
    1822
     
    5761            ),
    5862
     63            // Display Options
    5964            array(
    6065                'title'    => 'Display Type',
     
    6873                    'account' => "Automatically add a 'Favourites' tab to the WooCommerce account"
    6974                )
     75            ),
     76
     77            // Automatic add option
     78            array(
     79                'title'    => 'Add purchased products',
     80                'desc'     => "Automatically add purchased products to favourites",
     81                'id'       => self::$auto_add_option['id'],
     82                'default'  => 'no',
     83                'type'     => 'checkbox',
    7084            ),
    7185
     
    95109    }
    96110
     111    /*
     112        Get Auto Add setting
     113    */
     114    public static function get_auto_add_option(){
     115        $auto_add = get_option( self::$auto_add_option['id'] );
     116        if( 'yes' == $auto_add ){
     117            return true;
     118        }
     119        return false;
     120    }
     121
    97122}
    98123SWF_Settings::init();
  • simple-woocommerce-favourites/tags/2.1.1/includes/swf-core-functions.php

    r2013568 r2024649  
    3737    }
    3838
     39    /*
     40        Add Product to Favourites
     41    */
     42    function swf_add_favourite( $product_id, $favourites, $update = false ){
     43        if( ! in_array( $product_id, $favourites ) ){
     44            array_push( $favourites, $product_id );
     45            if( $update ){
     46                swf_update_favourites( $favourites );
     47            }
     48        }
     49        return $favourites;
     50    }
     51
     52    /*
     53        Remove Product from Favourites
     54    */
     55    function swf_remove_favourite( $product_id ){
     56        $user_id    = get_current_user_id();
     57        $favourites = get_user_meta( $user_id, '_simple_favourites_string', true );
     58        if( ($key = array_search( $product_id, $favourites ) ) !== false ){
     59            unset( $favourites[$key] );
     60        }
     61        swf_update_favourites( $favourites, $user_id );
     62    }
     63
    3964    /*
    4065        Update Favourites List
     
    4671        update_user_meta( $user_id, '_simple_favourites_string', $favourites );
    4772    }
    48 
    49     /*
    50         Remove Product from Favourites
    51     */
    52     function swf_remove_favourite( $user_id, $product_id ){
    53         if( !$user_id ){
    54             $user_id = get_current_user_id();
    55         }
    56         $favourites = get_user_meta( $user_id, '_simple_favourites_string', true );
    57         if( ($key = array_search( $product_id, $favourites ) ) !== false ){
    58             unset( $favourites[$key] );
    59         }
    60         swf_update_favourites( $favourites, $user_id );
    61     }
  • simple-woocommerce-favourites/tags/2.1.1/readme.txt

    r2017783 r2024649  
    55Requires at least: 4.4 or higher
    66Tested up to: 5.0.3
    7 Stable tag: 2.1
     7Stable tag: 2.1.1
    88License: GPLv2
    99License URI: https://www.gnu.org/licenses/gpl-2.0.html
     
    3434
    3535== Changelog ==
     36
     37= 2.1.1 =
     38Added feature to allow products to be automatically added to a user's favourites when purchased
    3639
    3740= 2.1 =
  • simple-woocommerce-favourites/trunk/includes/class-swf-actions.php

    r2013568 r2024649  
    2424        add_action( "wp_ajax_nopriv_simple_ajax_remove_from_favourites", array( __CLASS__, "remove_favourite" ) );
    2525
     26        if( SWF_Settings::get_auto_add_option() ){
     27            add_action( 'woocommerce_checkout_order_processed', array( __CLASS__, 'add_order_favourites' ) );
     28        }
     29
    2630    }
    2731
     
    3034    */
    3135    public static function add_favourite(){
    32 
    3336        check_ajax_referer('simple_favourites_nonce', 'simple_favourites_nonce');
    34         $favourites = swf_get_favourites();
    35    
    36         $prod_id = sanitize_text_field( $_POST['prod_id'] );
    37         if( !in_array($prod_id, $favourites) ){
    38             $prod_id = (int)$prod_id;
    39             array_push($favourites, $prod_id);
    40             swf_update_favourites($favourites);
     37        $prod_id        = sanitize_text_field( $_POST['prod_id'] );
     38        $favourites     = swf_get_favourites();
     39        if( in_array( $prod_id, $favourites ) ){
     40            echo 'This item is already in your favorites.';
     41        }
     42        else{
     43            swf_add_favourite( $prod_id, $favourites, true );
    4144            echo 'This item has been added to your favorites.';
    42             die();
    4345        }
    44         echo 'This item is already in your favorites.';
    4546        die();
    4647    }
     
    5253        check_ajax_referer('simple_favourites_nonce', 'simple_favourites_nonce');
    5354        $prod_id = (int)sanitize_text_field($_POST['prod_id']);
    54         $user_id = get_current_user_id();
    55         swf_remove_favourite( $user_id, $prod_id );
     55        swf_remove_favourite( $prod_id );
    5656        echo true;
    5757        die();
    5858    }
    5959
     60    /* 
     61        Add Order Products to Favourites
     62    */
     63    public static function add_order_favourites( $order_id ){
     64        $order      = wc_get_order( $order_id );
     65        $items      = $order->get_items();
     66        $favourites = swf_get_favourites();
     67        foreach( $items as $item ){
     68            $product_id = $item->get_product_id();
     69            $favourites = swf_add_favourite( $product_id, $favourites );
     70        }
     71        swf_update_favourites( $favourites );
     72    }
     73
    6074}
    6175SWF_Actions::hooks();
  • simple-woocommerce-favourites/trunk/includes/class-swf-settings.php

    r2017783 r2024649  
    1515        'id' => 'product_favourites_display_option',
    1616        'value' => null
     17    ];
     18
     19    private static $auto_add_option = [
     20        'id' => 'purchased_products_auto_favourite'
    1721    ];
    1822
     
    5761            ),
    5862
     63            // Display Options
    5964            array(
    6065                'title'    => 'Display Type',
     
    6873                    'account' => "Automatically add a 'Favourites' tab to the WooCommerce account"
    6974                )
     75            ),
     76
     77            // Automatic add option
     78            array(
     79                'title'    => 'Add purchased products',
     80                'desc'     => "Automatically add purchased products to favourites",
     81                'id'       => self::$auto_add_option['id'],
     82                'default'  => 'no',
     83                'type'     => 'checkbox',
    7084            ),
    7185
     
    95109    }
    96110
     111    /*
     112        Get Auto Add setting
     113    */
     114    public static function get_auto_add_option(){
     115        $auto_add = get_option( self::$auto_add_option['id'] );
     116        if( 'yes' == $auto_add ){
     117            return true;
     118        }
     119        return false;
     120    }
     121
    97122}
    98123SWF_Settings::init();
  • simple-woocommerce-favourites/trunk/includes/swf-core-functions.php

    r2013568 r2024649  
    3737    }
    3838
     39    /*
     40        Add Product to Favourites
     41    */
     42    function swf_add_favourite( $product_id, $favourites, $update = false ){
     43        if( ! in_array( $product_id, $favourites ) ){
     44            array_push( $favourites, $product_id );
     45            if( $update ){
     46                swf_update_favourites( $favourites );
     47            }
     48        }
     49        return $favourites;
     50    }
     51
     52    /*
     53        Remove Product from Favourites
     54    */
     55    function swf_remove_favourite( $product_id ){
     56        $user_id    = get_current_user_id();
     57        $favourites = get_user_meta( $user_id, '_simple_favourites_string', true );
     58        if( ($key = array_search( $product_id, $favourites ) ) !== false ){
     59            unset( $favourites[$key] );
     60        }
     61        swf_update_favourites( $favourites, $user_id );
     62    }
     63
    3964    /*
    4065        Update Favourites List
     
    4671        update_user_meta( $user_id, '_simple_favourites_string', $favourites );
    4772    }
    48 
    49     /*
    50         Remove Product from Favourites
    51     */
    52     function swf_remove_favourite( $user_id, $product_id ){
    53         if( !$user_id ){
    54             $user_id = get_current_user_id();
    55         }
    56         $favourites = get_user_meta( $user_id, '_simple_favourites_string', true );
    57         if( ($key = array_search( $product_id, $favourites ) ) !== false ){
    58             unset( $favourites[$key] );
    59         }
    60         swf_update_favourites( $favourites, $user_id );
    61     }
  • simple-woocommerce-favourites/trunk/readme.txt

    r2017783 r2024649  
    55Requires at least: 4.4 or higher
    66Tested up to: 5.0.3
    7 Stable tag: 2.1
     7Stable tag: 2.1.1
    88License: GPLv2
    99License URI: https://www.gnu.org/licenses/gpl-2.0.html
     
    3434
    3535== Changelog ==
     36
     37= 2.1.1 =
     38Added feature to allow products to be automatically added to a user's favourites when purchased
    3639
    3740= 2.1 =
Note: See TracChangeset for help on using the changeset viewer.