Changeset 2024649
- Timestamp:
- 02/04/2019 02:16:29 PM (7 years ago)
- Location:
- simple-woocommerce-favourites
- Files:
-
- 1 deleted
- 6 edited
- 6 copied
-
tags/2.1.1 (copied) (copied from simple-woocommerce-favourites/trunk)
-
tags/2.1.1/includes/class-simple-woocommerce-favourites.php (copied) (copied from simple-woocommerce-favourites/trunk/includes/class-simple-woocommerce-favourites.php)
-
tags/2.1.1/includes/class-swf-actions.php (modified) (3 diffs)
-
tags/2.1.1/includes/class-swf-display.php (copied) (copied from simple-woocommerce-favourites/trunk/includes/class-swf-display.php)
-
tags/2.1.1/includes/class-swf-settings.php (copied) (copied from simple-woocommerce-favourites/trunk/includes/class-swf-settings.php) (4 diffs)
-
tags/2.1.1/includes/js (deleted)
-
tags/2.1.1/includes/swf-core-functions.php (modified) (2 diffs)
-
tags/2.1.1/readme.txt (copied) (copied from simple-woocommerce-favourites/trunk/readme.txt) (2 diffs)
-
tags/2.1.1/simple-woocommerce-favourites.php (copied) (copied from simple-woocommerce-favourites/trunk/simple-woocommerce-favourites.php)
-
trunk/includes/class-swf-actions.php (modified) (3 diffs)
-
trunk/includes/class-swf-settings.php (modified) (4 diffs)
-
trunk/includes/swf-core-functions.php (modified) (2 diffs)
-
trunk/readme.txt (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
simple-woocommerce-favourites/tags/2.1.1/includes/class-swf-actions.php
r2013568 r2024649 24 24 add_action( "wp_ajax_nopriv_simple_ajax_remove_from_favourites", array( __CLASS__, "remove_favourite" ) ); 25 25 26 if( SWF_Settings::get_auto_add_option() ){ 27 add_action( 'woocommerce_checkout_order_processed', array( __CLASS__, 'add_order_favourites' ) ); 28 } 29 26 30 } 27 31 … … 30 34 */ 31 35 public static function add_favourite(){ 32 33 36 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 ); 41 44 echo 'This item has been added to your favorites.'; 42 die();43 45 } 44 echo 'This item is already in your favorites.';45 46 die(); 46 47 } … … 52 53 check_ajax_referer('simple_favourites_nonce', 'simple_favourites_nonce'); 53 54 $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 ); 56 56 echo true; 57 57 die(); 58 58 } 59 59 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 60 74 } 61 75 SWF_Actions::hooks(); -
simple-woocommerce-favourites/tags/2.1.1/includes/class-swf-settings.php
r2017783 r2024649 15 15 'id' => 'product_favourites_display_option', 16 16 'value' => null 17 ]; 18 19 private static $auto_add_option = [ 20 'id' => 'purchased_products_auto_favourite' 17 21 ]; 18 22 … … 57 61 ), 58 62 63 // Display Options 59 64 array( 60 65 'title' => 'Display Type', … … 68 73 'account' => "Automatically add a 'Favourites' tab to the WooCommerce account" 69 74 ) 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', 70 84 ), 71 85 … … 95 109 } 96 110 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 97 122 } 98 123 SWF_Settings::init(); -
simple-woocommerce-favourites/tags/2.1.1/includes/swf-core-functions.php
r2013568 r2024649 37 37 } 38 38 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 39 64 /* 40 65 Update Favourites List … … 46 71 update_user_meta( $user_id, '_simple_favourites_string', $favourites ); 47 72 } 48 49 /*50 Remove Product from Favourites51 */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 5 5 Requires at least: 4.4 or higher 6 6 Tested up to: 5.0.3 7 Stable tag: 2.1 7 Stable tag: 2.1.1 8 8 License: GPLv2 9 9 License URI: https://www.gnu.org/licenses/gpl-2.0.html … … 34 34 35 35 == Changelog == 36 37 = 2.1.1 = 38 Added feature to allow products to be automatically added to a user's favourites when purchased 36 39 37 40 = 2.1 = -
simple-woocommerce-favourites/trunk/includes/class-swf-actions.php
r2013568 r2024649 24 24 add_action( "wp_ajax_nopriv_simple_ajax_remove_from_favourites", array( __CLASS__, "remove_favourite" ) ); 25 25 26 if( SWF_Settings::get_auto_add_option() ){ 27 add_action( 'woocommerce_checkout_order_processed', array( __CLASS__, 'add_order_favourites' ) ); 28 } 29 26 30 } 27 31 … … 30 34 */ 31 35 public static function add_favourite(){ 32 33 36 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 ); 41 44 echo 'This item has been added to your favorites.'; 42 die();43 45 } 44 echo 'This item is already in your favorites.';45 46 die(); 46 47 } … … 52 53 check_ajax_referer('simple_favourites_nonce', 'simple_favourites_nonce'); 53 54 $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 ); 56 56 echo true; 57 57 die(); 58 58 } 59 59 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 60 74 } 61 75 SWF_Actions::hooks(); -
simple-woocommerce-favourites/trunk/includes/class-swf-settings.php
r2017783 r2024649 15 15 'id' => 'product_favourites_display_option', 16 16 'value' => null 17 ]; 18 19 private static $auto_add_option = [ 20 'id' => 'purchased_products_auto_favourite' 17 21 ]; 18 22 … … 57 61 ), 58 62 63 // Display Options 59 64 array( 60 65 'title' => 'Display Type', … … 68 73 'account' => "Automatically add a 'Favourites' tab to the WooCommerce account" 69 74 ) 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', 70 84 ), 71 85 … … 95 109 } 96 110 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 97 122 } 98 123 SWF_Settings::init(); -
simple-woocommerce-favourites/trunk/includes/swf-core-functions.php
r2013568 r2024649 37 37 } 38 38 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 39 64 /* 40 65 Update Favourites List … … 46 71 update_user_meta( $user_id, '_simple_favourites_string', $favourites ); 47 72 } 48 49 /*50 Remove Product from Favourites51 */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 5 5 Requires at least: 4.4 or higher 6 6 Tested up to: 5.0.3 7 Stable tag: 2.1 7 Stable tag: 2.1.1 8 8 License: GPLv2 9 9 License URI: https://www.gnu.org/licenses/gpl-2.0.html … … 34 34 35 35 == Changelog == 36 37 = 2.1.1 = 38 Added feature to allow products to be automatically added to a user's favourites when purchased 36 39 37 40 = 2.1 =
Note: See TracChangeset
for help on using the changeset viewer.