Plugin Directory

Changeset 2850169


Ignore:
Timestamp:
01/18/2023 02:34:55 AM (3 years ago)
Author:
app360my
Message:

1.3.12

  • bugfix | Fix incorrect method to get user_id in coupon validity check function
Location:
app360/trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • app360/trunk/app360.php

    r2849502 r2850169  
    1111 * Plugin URI: https://www.app360.my/
    1212 * Description: App360 CRM allows the integration between WooCommerce and App360
    13  * Version: 1.3.11
     13 * Version: 1.3.12
    1414 * Author: App360
    1515 * License: GPLv2 or later
  • app360/trunk/readme.txt

    r2849502 r2850169  
    44Requires at least: 5.6
    55Tested up to: 5.8
    6 Stable tag: 1.3.11
     6Stable tag: 1.3.12
    77License: GPLv2 or later
    88
     
    3939== Changelog ==
    4040
     41= 1.3.12 =
     42*Release Date - 17 January 2023*
     43
     44* bugfix  | Fix incorrect method to get user_id in coupon validity check function
     45
    4146= 1.3.11 =
    4247*Release Date - 16 January 2023*
  • app360/trunk/voucher.php

    r2849502 r2850169  
    7575        $code = get_post($coupon->get_id())->post_title;
    7676        if(!in_array($code, $applied_coupons)){
    77             $user_id = get_current_user_id();
    78             $user_id = get_user_meta($user_id, 'app360_userid') ? get_user_meta($user_id, 'app360_userid')[0] : 0;
    79             $reward_id = get_post_meta($coupon->get_id(), 'voucher_id', true) ? get_post_meta($coupon->get_id(), 'voucher_id', true) : 0;
    80             //$tier = get_post_meta($coupon->get_id(), 'app360_tier', true) ? get_post_meta($coupon->get_id(), 'app360_tier', true) : 0;
    81             //$tier_id = get_post_meta($coupon->get_id(), 'app360_tier_id', true) ? get_post_meta($coupon->get_id(), 'app360_tier_id', true) : 0;
    82 
    83             if($reward_id && $reward_id != 0){
    84                 $url = $app360_api_domain.'/client/voucher/apply?';
    85                 $url .= 'user_id='.$user_id;
    86                 $url .= '&reward_id='.$reward_id;
    87                 $headers = array();
    88                 $headers['Content-type'] = 'application/json';
    89                 $headers['apikey'] = $app360_api;
    90                 $response = wp_remote_get($url, ['headers'=> $headers]);
    91 
    92                 $result = is_array($response) && isset($response['body']) ? json_decode($response['body']) : null;
    93                 if( !$result || !$result->available){
    94                     throw new Exception( __( 'You do not have this coupon.', 'woocommerce' ), 107 );
    95                 }
    96                 WC()->session->set( 'voucher_id', $result->voucher_id );
    97             }
     77            $users = array();
     78            $coupon_data = $coupon->get_data();
     79            if($coupon_data) {
     80                $users = $coupon_data['used_by'];
     81            }
     82            if (!$users) {
     83                throw new Exception( __( 'Voucher Apply Error: Unable get any user data from coupon usage!.', 'woocommerce' ), 107 );
     84            }
     85
     86            foreach ($users as $wc_user_id) {
     87                $user_id = get_user_meta($wc_user_id, 'app360_userid') ? get_user_meta($wc_user_id, 'app360_userid')[0] : 0;
     88                $reward_id = get_post_meta($coupon->get_id(), 'voucher_id', true) ? get_post_meta($coupon->get_id(), 'voucher_id', true) : 0;
     89                //$tier = get_post_meta($coupon->get_id(), 'app360_tier', true) ? get_post_meta($coupon->get_id(), 'app360_tier', true) : 0;
     90                //$tier_id = get_post_meta($coupon->get_id(), 'app360_tier_id', true) ? get_post_meta($coupon->get_id(), 'app360_tier_id', true) : 0;
     91
     92                if($reward_id && $reward_id != 0){
     93                    $url = $app360_api_domain.'/client/voucher/apply?';
     94                    $url .= 'user_id='.$user_id;
     95                    $url .= '&reward_id='.$reward_id;
     96                    $headers = array();
     97                    $headers['Content-type'] = 'application/json';
     98                    $headers['apikey'] = $app360_api;
     99                    $response = wp_remote_get($url, ['headers'=> $headers]);
     100
     101                    $result = is_array($response) && isset($response['body']) ? json_decode($response['body']) : null;
     102                    if( !$result || !$result->available){
     103                        throw new Exception( __( 'You do not have this coupon.', 'woocommerce' ), 107 );
     104                    }
     105                    WC()->session->set( 'voucher_id', $result->voucher_id );
     106                }
     107            }
    98108        }
    99109
Note: See TracChangeset for help on using the changeset viewer.