Changeset 3386951
- Timestamp:
- 10/30/2025 09:29:51 AM (5 months ago)
- Location:
- gratisfaction-all-in-one-loyalty-contests-referral-program-for-woocommerce/trunk
- Files:
-
- 3 added
- 7 edited
-
grconnect.php (modified) (64 diffs)
-
includes/compat (added)
-
includes/compat/array_column.php (added)
-
includes/compat/hash_equals.php (added)
-
includes/grwoo-api.php (modified) (20 diffs)
-
includes/grwoo-checkout.php (modified) (4 diffs)
-
includes/grwoo-disount.php (modified) (4 diffs)
-
includes/grwoo-http-request-handler.php (modified) (5 diffs)
-
includes/grwoo-product.php (modified) (4 diffs)
-
readme.txt (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
gratisfaction-all-in-one-loyalty-contests-referral-program-for-woocommerce/trunk/grconnect.php
r3274273 r3386951 3 3 /** 4 4 * @package Gratisfaction Connect 5 * @version 4.5. 15 * @version 4.5.2 6 6 */ 7 7 /* … … 9 9 Plugin URI: http://appsmav.com 10 10 Description: Loyalty + Referral + Rewards + Birthdays and Anniversaries + Giveaways + Sweepstakes. 11 Version: 4.5. 111 Version: 4.5.2 12 12 Author: Appsmav 13 13 Author URI: http://appsmav.com … … 32 32 define('GR_PLUGIN_BASE_PATH', dirname(__FILE__)); 33 33 34 // Load PHP compatibility polyfills for older versions 35 if (!function_exists('array_column')) { 36 include_once(GR_PLUGIN_BASE_PATH . '/includes/compat/array_column.php'); 37 } 38 if (!function_exists('hash_equals')) { 39 include_once(GR_PLUGIN_BASE_PATH . '/includes/compat/hash_equals.php'); 40 } 41 34 42 if(!class_exists('GR_Connect')) 35 43 { … … 39 47 const REDEEM_COUPON = 'GRPAYPOINTS'; 40 48 41 public static $_plugin_version = '4.5. 1';49 public static $_plugin_version = '4.5.2'; 42 50 public static $_callback_url = 'https://gratisfaction.appsmav.com/'; 43 51 public static $_api_version = 'newapi/v2/'; … … 119 127 // Validate API response 120 128 if (empty($response) || !empty($response['error'])) { 121 throw new Exception('API request failed: ' . ( $response['message'] ??'Unknown error'));129 throw new Exception('API request failed: ' . (isset($response['message']) ? $response['message'] : 'Unknown error')); 122 130 } 123 131 } … … 167 175 return $message; 168 176 169 $coupon = strtolower($coupon->get_code());170 $redeem_coupon = strtolower(WC()->session->get('gr_paybypoints_coupon', self::REDEEM_COUPON));177 $coupon = appsmav_strtolower($coupon->get_code()); 178 $redeem_coupon = appsmav_strtolower(WC()->session->get('gr_paybypoints_coupon', self::REDEEM_COUPON)); 171 179 if($coupon === $redeem_coupon) 172 180 return __('', 'gratisfaction'); … … 182 190 return $message; 183 191 184 $coupon = strtolower($coupon->get_code());192 $coupon = appsmav_strtolower($coupon->get_code()); 185 193 $redeem_coupon = WC()->session->get('gr_paybypoints_coupon', self::REDEEM_COUPON); 186 if ($coupon === strtolower($redeem_coupon)) {194 if ($coupon === appsmav_strtolower($redeem_coupon)) { 187 195 if (WC_Coupon::WC_COUPON_SUCCESS === $message_code) 188 196 return __(WC()->session->get('gr_redeemed_status_msg'), 'gratisfaction'); … … 207 215 208 216 $redeem_coupon = WC()->session->get('gr_paybypoints_coupon', self::REDEEM_COUPON); 209 if( strstr(strtolower($label),strtolower($redeem_coupon)) && !empty(WC()->session))217 if(appsmav_strstr(appsmav_strtolower($label), appsmav_strtolower($redeem_coupon)) && !empty(WC()->session)) 210 218 { 211 219 $deduct_points_str = ''; 212 $deduct_points = WC()->session->get('gr_user_deduct_points' );220 $deduct_points = WC()->session->get('gr_user_deduct_points', 0); 213 221 214 222 if(!empty($deduct_points)) 215 223 { 216 $point_lable = ($deduct_points > 1) ? WC()->session->get('gr_points_lable' ) : WC()->session->get('gr_point_lable');224 $point_lable = ($deduct_points > 1) ? WC()->session->get('gr_points_lable', '') : WC()->session->get('gr_point_lable', ''); 217 225 $deduct_points_str = ' (' . esc_html($deduct_points) . ' ' . esc_html($point_lable) . ')'; 218 226 } … … 254 262 255 263 $redeem_coupon = WC()->session->get('gr_paybypoints_coupon', self::REDEEM_COUPON); 256 if ( strtolower($coupon_code) !=strtolower($redeem_coupon))264 if (appsmav_strtolower($coupon_code) != appsmav_strtolower($redeem_coupon)) 257 265 return $coupon; 258 266 … … 281 289 282 290 // Set redeem points in descriptions 283 $coupon_discount = WC()->session->get('gr_user_applied_discount' )/$ratio;291 $coupon_discount = WC()->session->get('gr_user_applied_discount', 0)/$ratio; 284 292 $points = WC()->session->get('gr_user_deduct_points', 0); 285 293 … … 595 603 596 604 $param = []; 597 $param['status'] = $param['order_status'] = strtolower($order->get_status());605 $param['status'] = $param['order_status'] = appsmav_strtolower($order->get_status()); 598 606 599 607 $user_email = ''; … … 619 627 if (!empty($gr_applied_points)) 620 628 { 621 $points = explode('_', $gr_applied_points);629 $points = appsmav_explode('_', $gr_applied_points); 622 630 $param['redeem_points'] = empty($points['1']) ? 0 : $points['1']; 623 631 $param['redeem_charges'] = empty($points['2']) ? 0 : $points['2']; … … 626 634 $param['line_items'] = []; 627 635 foreach ($order->get_items('line_item') as $key => $item) { 628 $param['line_items'][] = $item->get_data(); // Only product_id & total are required now636 $param['line_items'][] = self::sanitize_refund_data_for_api($item->get_data()); // Only product_id & total are required now 629 637 } 630 638 … … 645 653 // Set refund data for order change also 646 654 $refundData = array(); 647 foreach ($order->get_refunds() as $key => $refund) { 648 $refundData[$key]['refund'] = $refund->get_data(); 649 foreach ($refund->get_items() as $item_id => $item) { 650 $refundData[$key]['line_items'][$item_id] = $item->get_data(); 655 $refunds = $order->get_refunds(); 656 if (!empty($refunds) && is_array($refunds)) { 657 foreach ($refunds as $key => $refund) { 658 if (empty($refund) || !is_object($refund)) { 659 continue; 660 } 661 $refundData[$key]['refund'] = self::sanitize_refund_data_for_api($refund->get_data()); 662 $refund_items = $refund->get_items(); 663 if (!empty($refund_items) && is_array($refund_items)) { 664 foreach ($refund_items as $item_id => $item) { 665 if (empty($item) || !is_object($item)) { 666 continue; 667 } 668 $refundData[$key]['line_items'][$item_id] = self::sanitize_refund_data_for_api($item->get_data()); 669 } 670 } 651 671 } 652 672 } … … 701 721 { 702 722 703 if( $order->get_parent_id() === 0 && get_post_meta( $order_id, 'has_wcmp_sub_order', true ) == '1'){723 if( appsmav_get_parent_id($order) === 0 && get_post_meta( $order_id, 'has_wcmp_sub_order', true ) == '1'){ 704 724 $param['comment'] = 'Main WCMp Order Id ' . str_replace('wc-', '', sanitize_text_field($_REQUEST['order_status'])) . ' - ' . $order_id . ' From ' . get_option('grconnect_shop_id', 0).' total '.$param['total']; 705 725 $param['total'] = 0; … … 712 732 if(class_exists('WeDevs_Dokan')) 713 733 { 714 if( $order->get_parent_id() === 0 && get_post_meta( $order_id, 'has_sub_order', true ) == '1'){734 if( appsmav_get_parent_id($order) === 0 && get_post_meta( $order_id, 'has_sub_order', true ) == '1'){ 715 735 $param['comment'] = 'Main Dokan Order Id ' . str_replace('wc-', '', sanitize_text_field($_REQUEST['order_status'])) . ' - ' . $order_id . ' From ' . get_option('grconnect_shop_id', 0).' total '.$param['total']; 716 736 $param['total'] = 0; … … 750 770 751 771 $param = []; 752 $param['status'] = $param['order_status'] = strtolower($order->get_status());772 $param['status'] = $param['order_status'] = appsmav_strtolower($order->get_status()); 753 773 754 774 $user_email = ''; … … 778 798 $param['line_items'] = []; 779 799 foreach ($order->get_items('line_item') as $key => $item) { 780 $param['line_items'][] = $item->get_data();800 $param['line_items'][] = self::sanitize_refund_data_for_api($item->get_data()); 781 801 } 782 802 … … 793 813 { 794 814 $redeem_coupon = empty(WC()->session) ? '' : WC()->session->get('gr_paybypoints_coupon', self::REDEEM_COUPON); 795 if(!empty($item_data['name']) && !empty($item_data['discount']) 796 && strtolower($item_data['name']) == strtolower($redeem_coupon)) 797 $points_discount_val = $item_data['discount']; 815 816 // Backward compatibility: Use method calls for WC 3.0+, array access for older versions 817 if(version_compare( WC_VERSION, '3.0', '>=' )) 818 { 819 $coupon_name = $item_data->get_name(); 820 $coupon_discount = $item_data->get_discount(); 821 } 822 else 823 { 824 $coupon_name = isset($item_data['name']) ? $item_data['name'] : ''; 825 $coupon_discount = isset($item_data['discount']) ? $item_data['discount'] : 0; 826 } 827 828 if(!empty($coupon_name) && !empty($coupon_discount) 829 && appsmav_strtolower($coupon_name) == appsmav_strtolower($redeem_coupon)) 830 $points_discount_val = $coupon_discount; 798 831 } 799 832 } … … 817 850 } 818 851 819 if( strtolower($param['order_status']) == 'pending' && empty($param['redeem_points']))852 if(appsmav_strtolower($param['order_status']) == 'pending' && empty($param['redeem_points'])) 820 853 return; 821 854 … … 868 901 { 869 902 870 if( $order->get_parent_id() === 0 && get_post_meta( $order_id, 'has_wcmp_sub_order', true ) == '1'){903 if( appsmav_get_parent_id($order) === 0 && get_post_meta( $order_id, 'has_wcmp_sub_order', true ) == '1'){ 871 904 $param['comment'] = 'Main WCMp Order Id ' . str_replace('wc-', '', sanitize_text_field($_REQUEST['order_status'])) . ' - ' . $order_id . ' From ' . get_option('grconnect_shop_id', 0).' total '.$param['total']; 872 905 $param['total'] = 0; … … 879 912 if(class_exists('WeDevs_Dokan')) 880 913 { 881 if( $order->get_parent_id() === 0 && get_post_meta( $order_id, 'has_sub_order', true ) == '1'){914 if( appsmav_get_parent_id($order) === 0 && get_post_meta( $order_id, 'has_sub_order', true ) == '1'){ 882 915 $param['comment'] = 'Main Dokan Order Id ' . str_replace('wc-', '', sanitize_text_field($_REQUEST['order_status'])) . ' - ' . $order_id . ' From ' . get_option('grconnect_shop_id', 0).' total '.$param['total']; 883 916 $param['total'] = 0; … … 1022 1055 $grCampId = get_option('grconnect_secret'); 1023 1056 $grPayload = get_option('grconnect_payload'); 1024 if (empty($grShopId) || empty($grAppId) || empty($grCampId) || empty($grPayload)) 1025 return; 1057 1058 if (empty($grShopId) || empty($grAppId) || empty($grCampId) || empty($grPayload)) { 1059 return; 1060 } 1026 1061 1027 1062 // Set up the settings for this plugin 1028 if(!empty($_REQUEST['action']) && sanitize_text_field($_REQUEST['action']) == 'woocommerce_delete_refund') 1063 $action = isset($_REQUEST['action']) ? sanitize_text_field($_REQUEST['action']) : ''; 1064 if(!empty($action) && $action == 'woocommerce_delete_refund') 1029 1065 { 1030 1066 $refund = new WC_Order_Refund($refund_id); 1031 $order = new WC_Order($refund->post->post_parent); 1067 if (empty($refund) || !is_object($refund)) { 1068 return; 1069 } 1070 $parent_id = appsmav_get_parent_id($refund); 1071 if (empty($parent_id)) { 1072 return; 1073 } 1074 $order = new WC_Order($parent_id); 1075 if (empty($order) || !is_object($order)) { 1076 return; 1077 } 1032 1078 1033 1079 $param['discount'] = $order->get_total_discount(); … … 1064 1110 $param['customer_id'] = $order->get_user_id(); 1065 1111 $param['order'] = 0; 1066 $param['id_order'] = $refund->post->post_parent;1112 $param['id_order'] = appsmav_get_parent_id($refund); 1067 1113 $param['payload'] = $grPayload; 1068 1114 $param['plugin_version'] = self::$_plugin_version; … … 1088 1134 } 1089 1135 1090 $param['comment'] = 'Order Id Refund Restore - ' . $refund->post->post_parent. ' From ' . get_option('siteurl');1136 $param['comment'] = 'Order Id Refund Restore - ' . appsmav_get_parent_id($refund) . ' From ' . get_option('siteurl'); 1091 1137 $param['status'] = 'Add'; 1092 1138 $param['order_status'] = $order->get_status(); … … 1146 1192 // Set up the settings for this plugin 1147 1193 $order = new WC_Order($order_id); 1194 if (empty($order) || !is_object($order)) { 1195 return; 1196 } 1148 1197 1149 1198 try { … … 1151 1200 if(class_exists('WCMp')) 1152 1201 { 1153 if( $order->get_parent_id() === 0 && get_post_meta( $order_id, 'has_wcmp_sub_order', true ) == '1')1202 if( appsmav_get_parent_id($order) === 0 && get_post_meta( $order_id, 'has_wcmp_sub_order', true ) == '1') 1154 1203 return; 1155 1204 } 1156 1205 if(class_exists('WeDevs_Dokan')) 1157 1206 { 1158 if( $order->get_parent_id() === 0 && get_post_meta( $order_id, 'has_sub_order', true ) == '1')1207 if( appsmav_get_parent_id($order) === 0 && get_post_meta( $order_id, 'has_sub_order', true ) == '1') 1159 1208 return; 1160 1209 } … … 1172 1221 $param['line_items'] = []; 1173 1222 foreach ($order->get_items('line_item') as $key => $item) { 1174 $param['line_items'][] = $item->get_data(); // TODO: Only product_id & total are required now1223 $param['line_items'][] = self::sanitize_refund_data_for_api($item->get_data()); // TODO: Only product_id & total are required now 1175 1224 } 1176 1225 1177 1226 $refundData = array(); 1178 foreach ($order->get_refunds() as $key => $refund) { 1179 $refundData[$key]['refund'] = $refund->get_data(); 1180 foreach ($refund->get_items() as $item_id => $item) { 1181 $refundData[$key]['line_items'][$item_id] = $item->get_data(); 1227 $refunds = $order->get_refunds(); 1228 if (!empty($refunds) && is_array($refunds)) { 1229 foreach ($refunds as $key => $refund) { 1230 if (empty($refund) || !is_object($refund)) { 1231 continue; 1232 } 1233 $refundData[$key]['refund'] = self::sanitize_refund_data_for_api($refund->get_data()); 1234 $refund_items = $refund->get_items(); 1235 if (!empty($refund_items) && is_array($refund_items)) { 1236 foreach ($refund_items as $item_id => $item) { 1237 if (empty($item) || !is_object($item)) { 1238 continue; 1239 } 1240 $refundData[$key]['line_items'][$item_id] = self::sanitize_refund_data_for_api($item->get_data()); 1241 } 1242 } 1182 1243 } 1183 1244 } … … 1235 1296 $param['comment'] = 'Order Id Refunded - ' . $order_id . ' From ' . get_option('siteurl'); 1236 1297 $param['status'] = 'partial_refund'; 1237 $param['order_status'] = strtolower($order->get_status());1298 $param['order_status'] = appsmav_strtolower($order->get_status()); 1238 1299 1239 1300 $param['plugin_version'] = self::$_plugin_version; 1240 1301 $param['payload'] = $grPayload; 1241 1302 $urlApi = self::$_callback_url . self::$_api_version . 'removeEntryNew'; 1242 $this->callGrConnectApi($param, $urlApi); 1303 1304 // Sanitize refund data to handle WC_DateTime objects 1305 $param = self::sanitize_refund_data_for_api($param); 1306 1307 $api_response = $this->callGrConnectApi($param, $urlApi); 1308 1243 1309 } 1244 1310 catch(Exception $ex) … … 1274 1340 //add_action('woocommerce_order_edit_status', [$this, 'send_connect_init']); 1275 1341 add_action('woocommerce_order_status_changed', [$this, 'send_status_init']); 1276 add_action('before_delete_post', [$this, 'send_refund_delete_post_init'] );1342 add_action('before_delete_post', [$this, 'send_refund_delete_post_init'], 20); 1277 1343 //add_action('woocommerce_order_status_refunded', [$this, 'send_refund_init']); 1278 add_action('woocommerce_order_refunded', [$this, 'send_refund_init'] );1344 add_action('woocommerce_order_refunded', [$this, 'send_refund_init'], 20); 1279 1345 add_action('woocommerce_created_customer', [$this, 'send_customer_init']); 1280 1346 add_action('profile_update', [$this, 'customer_profile_update']); … … 1374 1440 { 1375 1441 $redeem_coupon = WC()->session->get('gr_paybypoints_coupon', self::REDEEM_COUPON); 1376 if( strtolower($coupon_code) ===strtolower($redeem_coupon))1442 if(appsmav_strtolower($coupon_code) === appsmav_strtolower($redeem_coupon)) 1377 1443 { 1378 1444 WC()->session->set('gr_applied_points', ''); … … 1389 1455 $cart_count = 0; 1390 1456 if (!empty(WC()->cart)) { 1391 $cart_count = count(WC()->cart->get_cart()); 1457 $cart_items = WC()->cart->get_cart(); 1458 $cart_count = (is_array($cart_items) || $cart_items instanceof Countable) ? count($cart_items) : 0; 1392 1459 1393 1460 //Reset the session values if discount is not there … … 1482 1549 if (strpos($url,$template_name) !== false) { 1483 1550 $start = strpos($url,$template_name); 1484 $first_part = substr($url, $start+ strlen($template_name));1551 $first_part = substr($url, $start+appsmav_strlen($template_name)); 1485 1552 $order_id = substr($first_part, 0, strpos($first_part, '/')); 1486 1553 } … … 1610 1677 $rtype = isset($atts['rtype']) ? sanitize_text_field($atts['rtype']) : ''; 1611 1678 $patternAlphaNum = '/^[a-zA-Z0-9]+$/'; 1612 if (empty($id) || !preg_match($patternAlphaNum, $id) || strlen($id) > 10) {1679 if (empty($id) || !preg_match($patternAlphaNum, $id) || appsmav_strlen($id) > 10) { 1613 1680 return ''; 1614 1681 } 1615 if (!empty($rtype) && (!preg_match($patternAlphaNum, $rtype) || strlen($rtype) > 10)) {1682 if (!empty($rtype) && (!preg_match($patternAlphaNum, $rtype) || appsmav_strlen($rtype) > 10)) { 1616 1683 return ''; 1617 1684 } … … 2101 2168 } 2102 2169 2103 $redeem_point_lable = WC()->session->get('gr_redeem_point_per_dollar_lable' );2170 $redeem_point_lable = WC()->session->get('gr_redeem_point_per_dollar_lable', ''); 2104 2171 2105 2172 $items = WC()->cart->get_cart(); … … 2111 2178 WC()->session->set('gr_discount_applied', 0); 2112 2179 } 2113 else if(WC()->session->get('gr_user_applied_discount' ) <= 0 || empty($items))2180 else if(WC()->session->get('gr_user_applied_discount', 0) <= 0 || empty($items)) 2114 2181 { 2115 2182 WC()->cart->remove_coupon($redeem_coupon); … … 2124 2191 if(WC()->session->get('gr_user_max_discount', 0) > 0 && WC()->session->get('gr_user_deduct_points', 0) >= 1) 2125 2192 { 2126 $discount = WC()->session->get('gr_user_max_discount' );2127 $points = WC()->session->get('gr_user_deduct_points' );2193 $discount = WC()->session->get('gr_user_max_discount', 0); 2194 $points = WC()->session->get('gr_user_deduct_points', 0); 2128 2195 $redeem_point_lable = str_replace('{points}', $points, $redeem_point_lable); 2129 2196 $redeem_point_lable = str_replace('{points_value}', wc_price($discount), $redeem_point_lable); 2130 2197 2131 $point_lable = ($points > 1) ? WC()->session->get('gr_points_lable' ) : WC()->session->get('gr_point_lable');2198 $point_lable = ($points > 1) ? WC()->session->get('gr_points_lable', '') : WC()->session->get('gr_point_lable', ''); 2132 2199 $redeem_point_lable = '<p class="grPointsRedeem" id="gr_checkout_lable_top">' . str_replace('{points_label}', $point_lable, $redeem_point_lable); 2133 2200 … … 2139 2206 $extra_pay_apply = 'display:none;'; 2140 2207 $extra_pay_confirm = ''; 2141 $extra_point_lable = ($extra_pay_points > 1) ? WC()->session->get('gr_points_lable' ) : WC()->session->get('gr_point_lable');2208 $extra_point_lable = ($extra_pay_points > 1) ? WC()->session->get('gr_points_lable', '') : WC()->session->get('gr_point_lable', ''); 2142 2209 2143 2210 $extra_points_info = WC()->session->get('gr_redeem_extra_point_info', ''); … … 2150 2217 2151 2218 // add 'Apply Discount' button 2152 if(WC()->session->get('gr_user_applied_discount' ) == 0)2219 if(WC()->session->get('gr_user_applied_discount', 0) == 0) 2153 2220 { 2154 2221 $btn_agree = WC()->session->get('gr_btn_redeem_confirm', ''); … … 2156 2223 $redeem_point_lable .= '<input type="hidden" name="gr_rewards_apply_discount" class="gr_rewards_apply_discount" value="1" />'; 2157 2224 $redeem_point_lable .= '<input type="submit" class="button gr_rewards_apply_discount_confirm" style="'.$extra_pay_confirm.'" value="'.$btn_agree.'" />'; 2158 $redeem_point_lable .= '<input type="submit" class="button gr_rewards_apply_discount" style="'.$extra_pay_apply.'" value="' . WC()->session->get('gr_redeem_btn_text' ) . '" />';2225 $redeem_point_lable .= '<input type="submit" class="button gr_rewards_apply_discount" style="'.$extra_pay_apply.'" value="' . WC()->session->get('gr_redeem_btn_text', '') . '" />'; 2159 2226 $redeem_point_lable .= '</form>'; 2160 2227 … … 2166 2233 $redeem_point_lable = ''; 2167 2234 2168 if(WC()->session->get('gr_user_applied_discount' ) != $discount)2235 if(WC()->session->get('gr_user_applied_discount', 0) != $discount) 2169 2236 { 2170 2237 WC()->session->set('gr_user_max_discount', $discount); 2171 2238 WC()->session->set('gr_user_deduct_points', $points); 2172 2239 2173 $gr_user_max_discount = WC()->session->get('gr_user_max_discount' );2240 $gr_user_max_discount = WC()->session->get('gr_user_max_discount', 0); 2174 2241 WC()->session->set('gr_user_applied_discount', (!empty($gr_user_max_discount) ? $gr_user_max_discount : 0)); 2175 2242 } … … 2275 2342 if(WC()->session->get('gr_user_max_discount', 0) > 0 && WC()->session->get('gr_user_deduct_points', 0) >= 1) 2276 2343 { 2277 $discount = WC()->session->get('gr_user_max_discount' );2344 $discount = WC()->session->get('gr_user_max_discount', 0); 2278 2345 if(WC()->session->get('gr_user_applied_discount') != $discount) 2279 2346 { … … 2325 2392 } 2326 2393 2327 $redeem_point_lable = WC()->session->get('gr_redeem_point_per_dollar_lable' );2394 $redeem_point_lable = WC()->session->get('gr_redeem_point_per_dollar_lable', ''); 2328 2395 2329 2396 self::gr_calc_point_value(); … … 2333 2400 $redeem_point_lable = str_replace('{points}', $points, $redeem_point_lable); 2334 2401 $redeem_point_lable = str_replace('{points_value}', wc_price($discount), $redeem_point_lable); 2335 $point_lable = ($points > 1) ? WC()->session->get('gr_points_lable' ) : WC()->session->get('gr_point_lable');2402 $point_lable = ($points > 1) ? WC()->session->get('gr_points_lable', '') : WC()->session->get('gr_point_lable', ''); 2336 2403 $redeem_point_lable = str_replace('{points_label}', $point_lable, $redeem_point_lable); 2337 2404 $res['msg'] = $redeem_point_lable; … … 2362 2429 'discounted_amount' => WC()->session->get('gr_user_max_discount', 0), 2363 2430 'points' => WC()->session->get('gr_user_deduct_points', 0), 2364 'cart_count' => count(WC()->cart->get_cart()),2431 'cart_count' => (is_array(WC()->cart->get_cart()) || WC()->cart->get_cart() instanceof Countable) ? count(WC()->cart->get_cart()) : 0, 2365 2432 'is_discount_applied' => 0, 2366 2433 'extra_pbp' => WC()->session->get('gr_user_extra_pay_points', 0) … … 2483 2550 } 2484 2551 2485 if ( is_array($list_products) && count($list_products)>0 )2552 if ( (is_array($list_products) || $list_products instanceof Countable) && count($list_products)>0 ) 2486 2553 { 2487 2554 $product_price_range = array(); … … 2548 2615 $redeem_point_lable = WC()->session->get('gr_redeem_point_product_per_dollar_lable'); 2549 2616 $redeem_point_lable = str_replace('{points}', $discount, $redeem_point_lable); 2550 $point_lable = ($max_points > 1) ? WC()->session->get('gr_points_lable' ) : WC()->session->get('gr_point_lable');2617 $point_lable = ($max_points > 1) ? WC()->session->get('gr_points_lable', '') : WC()->session->get('gr_point_lable', ''); 2551 2618 $redeem_point_lable = str_replace('{points_label}', $point_lable, $redeem_point_lable); 2552 2619 … … 2602 2669 $earn_exclude_products = array(); 2603 2670 if(!empty(WC()->session->get('gr_earn_exclude_products', ''))){ 2604 $earn_exclude_products = explode(',',trim(WC()->session->get('gr_earn_exclude_products', '')));2671 $earn_exclude_products = appsmav_explode(',', appsmav_trim(WC()->session->get('gr_earn_exclude_products', ''))); 2605 2672 $earn_exclude_products = array_map('trim', $earn_exclude_products); 2606 2673 } … … 2648 2715 } 2649 2716 2650 if ( is_array($list_products) && count($list_products)>0 )2717 if ( (is_array($list_products) || $list_products instanceof Countable) && count($list_products)>0 ) 2651 2718 { 2652 2719 $product_price_range = array(); … … 2708 2775 return; 2709 2776 2710 $point_lable = ($point_earn > 1) ? WC()->session->get('gr_points_lable' ) : WC()->session->get('gr_point_lable');2711 2712 $earn_point_lable = WC()->session->get('gr_earn_point_per_dollar_lable' );2777 $point_lable = ($point_earn > 1) ? WC()->session->get('gr_points_lable', '') : WC()->session->get('gr_point_lable', ''); 2778 2779 $earn_point_lable = WC()->session->get('gr_earn_point_per_dollar_lable', ''); 2713 2780 $earn_point_lable = str_replace('{points}', $point_earn, $earn_point_lable); 2714 2781 $earn_point_lable = str_replace('{points_label}', $point_lable, $earn_point_lable); … … 2744 2811 WC()->session->set('gr_user_extra_pay_points', 0); 2745 2812 2746 $redeem_point = WC()->session->get('gr_redeem_point_per_dollar' )/$ratio;2813 $redeem_point = WC()->session->get('gr_redeem_point_per_dollar', 0)/$ratio; 2747 2814 $cart_total = WC()->cart->subtotal; 2748 $discount = floor(WC()->session->get('gr_user_points' ) / $redeem_point);2815 $discount = floor(WC()->session->get('gr_user_points', 0) / $redeem_point); 2749 2816 2750 2817 $applied_coupons = WC()->cart->applied_coupons; … … 2753 2820 foreach($applied_coupons as $cart_coupon) 2754 2821 { 2755 if ( strtolower($cart_coupon) !=strtolower($redeem_coupon))2822 if (appsmav_strtolower($cart_coupon) != appsmav_strtolower($redeem_coupon)) 2756 2823 $cart_total -= WC()->cart->get_coupon_discount_amount($cart_coupon); 2757 2824 } … … 2847 2914 WC()->session->set('gr_user_deduct_points', $points); 2848 2915 2849 if(WC()->cart->has_discount($redeem_coupon) && WC()->session->get('gr_user_applied_discount' ) != $discount)2916 if(WC()->cart->has_discount($redeem_coupon) && WC()->session->get('gr_user_applied_discount', 0) != $discount) 2850 2917 { 2851 2918 WC()->session->set('gr_user_applied_discount', (empty($discount) ? 0 : $discount)); … … 2871 2938 return; 2872 2939 2873 WC()->session->set('gr_api_sess', $app_config['date_updated']);2874 WC()->session->set('gr_loyalty_campaign_enabled', $app_config['points']['loyalty_campaign_enabled']);2875 WC()->session->set('earn_point_enabled', $app_config['points']['earn_point_enabled']);2876 WC()->session->set('gr_purchase_theme_status', $app_config['points']['purchase_theme_status']);2877 WC()->session->set('redeem_point_enabled', $app_config['points']['redeem_purchase_status']);2878 WC()->session->set('gr_roundoff_type', $app_config['points']['gr_roundoff_type']);2879 WC()->session->set('gr_redeem_point_per_dollar', $app_config['points']['redeem_point_per_dollar']);2880 WC()->session->set('gr_redeem_theme_status', $app_config['points']['redeem_theme_status']);2881 WC()->session->set('minimum_order_value', $app_config['points']['minimum_order_value']);2882 WC()->session->set('gr_redeem_point_per_dollar_lable', stripslashes($app_config['lang']['redeem_point_per_dollar_lable']));2883 WC()->session->set('gr_redeem_point_product_per_dollar_lable', stripslashes($app_config['lang']['redeem_point_product_per_dollar_lable']));2884 WC()->session->set('gr_earn_point_per_dollar', stripslashes($app_config['points']['earn_point_per_dollar']));2885 WC()->session->set('gr_earn_point_per_dollar_lable', stripslashes($app_config['lang']['earn_point_per_dollar_lable']));2886 WC()->session->set('gr_point_lable', $app_config['lang']['point_lable']);2887 WC()->session->set('gr_points_lable', $app_config['lang']['points_lable']);2888 WC()->session->set('gr_redeem_btn_text', $app_config['lang']['redeem_btn_text']);2889 WC()->session->set('gr_redeemed_btn_text', $app_config['lang']['redeemed_btn_text']);2890 WC()->session->set('gr_redeemed_status_msg', $app_config['lang']['redeemed_status_msg']);2891 WC()->session->set('label_redeemed_points', $app_config['lang']['label_redeemed_points']);2892 WC()->session->set('label_life_time_points', $app_config['lang']['label_life_time_points']);2893 WC()->session->set('label_available_points', $app_config['lang']['label_available_points']);2894 WC()->session->set('error_more_points_required', $app_config['lang']['error_more_points_required']);2895 WC()->session->set('label_exclusion_points', $app_config['lang']['label_exclusion_points']);2896 WC()->session->set('label_total_points', $app_config['lang']['label_total_points']);2897 WC()->session->set('no_records_found', $app_config['lang']['no_records_found']);2898 WC()->session->set('gr_loyalty_menu_name', stripslashes($app_config['lang']['loyalty_menu_name']));2899 WC()->session->set('gr_loyalty_date_start', $app_config['loyalty']['date_start']);2900 WC()->session->set('gr_loyalty_date_end', $app_config['loyalty']['date_end']);2901 WC()->session->set('gr_loyalty_timezone', $app_config['loyalty']['timezone']);2902 WC()->session->set('gr_loyalty_is_open', $app_config['loyalty']['is_open']);2903 WC()->session->set('gr_global_review_enabled', $app_config['reviews']['global_review_enabled']);2904 WC()->session->set('gr_global_review_points', $app_config['reviews']['global_review_points']);2905 WC()->session->set('gr_global_review_lable_enabled', $app_config['reviews']['global_review_lable_enabled']);2906 WC()->session->set('gr_global_review_lable', $app_config['reviews']['global_review_lable']);2940 WC()->session->set('gr_api_sess', empty($app_config['date_updated']) ? 0 : $app_config['date_updated']); 2941 WC()->session->set('gr_loyalty_campaign_enabled', empty($app_config['points']['loyalty_campaign_enabled']) ? 0 : $app_config['points']['loyalty_campaign_enabled']); 2942 WC()->session->set('earn_point_enabled', empty($app_config['points']['earn_point_enabled']) ? 0 : $app_config['points']['earn_point_enabled']); 2943 WC()->session->set('gr_purchase_theme_status', empty($app_config['points']['purchase_theme_status']) ? 0 : $app_config['points']['purchase_theme_status']); 2944 WC()->session->set('redeem_point_enabled', empty($app_config['points']['redeem_purchase_status']) ? 0 : $app_config['points']['redeem_purchase_status']); 2945 WC()->session->set('gr_roundoff_type', empty($app_config['points']['gr_roundoff_type']) ? 'ROUND' : $app_config['points']['gr_roundoff_type']); 2946 WC()->session->set('gr_redeem_point_per_dollar', empty($app_config['points']['redeem_point_per_dollar']) ? 0 : $app_config['points']['redeem_point_per_dollar']); 2947 WC()->session->set('gr_redeem_theme_status', empty($app_config['points']['redeem_theme_status']) ? 0 : $app_config['points']['redeem_theme_status']); 2948 WC()->session->set('minimum_order_value', empty($app_config['points']['minimum_order_value']) ? 0 : $app_config['points']['minimum_order_value']); 2949 WC()->session->set('gr_redeem_point_per_dollar_lable', empty($app_config['lang']['redeem_point_per_dollar_lable']) ? '' : appsmav_stripslashes($app_config['lang']['redeem_point_per_dollar_lable'])); 2950 WC()->session->set('gr_redeem_point_product_per_dollar_lable', empty($app_config['lang']['redeem_point_product_per_dollar_lable']) ? '' : appsmav_stripslashes($app_config['lang']['redeem_point_product_per_dollar_lable'])); 2951 WC()->session->set('gr_earn_point_per_dollar', empty($app_config['points']['earn_point_per_dollar']) ? 0 : $app_config['points']['earn_point_per_dollar']); 2952 WC()->session->set('gr_earn_point_per_dollar_lable', empty($app_config['lang']['earn_point_per_dollar_lable']) ? '' : appsmav_stripslashes($app_config['lang']['earn_point_per_dollar_lable'])); 2953 WC()->session->set('gr_point_lable', empty($app_config['lang']['point_lable']) ? '' : $app_config['lang']['point_lable']); 2954 WC()->session->set('gr_points_lable', empty($app_config['lang']['points_lable']) ? '' : $app_config['lang']['points_lable']); 2955 WC()->session->set('gr_redeem_btn_text', empty($app_config['lang']['redeem_btn_text']) ? '' : $app_config['lang']['redeem_btn_text']); 2956 WC()->session->set('gr_redeemed_btn_text', empty($app_config['lang']['redeemed_btn_text']) ? '' : $app_config['lang']['redeemed_btn_text']); 2957 WC()->session->set('gr_redeemed_status_msg', empty($app_config['lang']['redeemed_status_msg']) ? '' : $app_config['lang']['redeemed_status_msg']); 2958 WC()->session->set('label_redeemed_points', empty($app_config['lang']['label_redeemed_points']) ? '' : $app_config['lang']['label_redeemed_points']); 2959 WC()->session->set('label_life_time_points', empty($app_config['lang']['label_life_time_points']) ? '' : $app_config['lang']['label_life_time_points']); 2960 WC()->session->set('label_available_points', empty($app_config['lang']['label_available_points']) ? '' : $app_config['lang']['label_available_points']); 2961 WC()->session->set('error_more_points_required', empty($app_config['lang']['error_more_points_required']) ? '' : $app_config['lang']['error_more_points_required']); 2962 WC()->session->set('label_exclusion_points', empty($app_config['lang']['label_exclusion_points']) ? '' : $app_config['lang']['label_exclusion_points']); 2963 WC()->session->set('label_total_points', empty($app_config['lang']['label_total_points']) ? '' : $app_config['lang']['label_total_points']); 2964 WC()->session->set('no_records_found', empty($app_config['lang']['no_records_found']) ? '' : $app_config['lang']['no_records_found']); 2965 WC()->session->set('gr_loyalty_menu_name', appsmav_stripslashes($app_config['lang']['loyalty_menu_name'])); 2966 WC()->session->set('gr_loyalty_date_start', empty($app_config['loyalty']['date_start']) ? 0 : $app_config['loyalty']['date_start']); 2967 WC()->session->set('gr_loyalty_date_end', empty($app_config['loyalty']['date_end']) ? 0 : $app_config['loyalty']['date_end']); 2968 WC()->session->set('gr_loyalty_timezone', empty($app_config['loyalty']['timezone']) ? 'America/Chicago' : $app_config['loyalty']['timezone']); 2969 WC()->session->set('gr_loyalty_is_open', empty($app_config['loyalty']['is_open']) ? 0 : $app_config['loyalty']['is_open']); 2970 WC()->session->set('gr_global_review_enabled', empty($app_config['reviews']['global_review_enabled']) ? 0 : $app_config['reviews']['global_review_enabled']); 2971 WC()->session->set('gr_global_review_points', empty($app_config['reviews']['global_review_points']) ? 0 : $app_config['reviews']['global_review_points']); 2972 WC()->session->set('gr_global_review_lable_enabled', empty($app_config['reviews']['global_review_lable_enabled']) ? 0 : $app_config['reviews']['global_review_lable_enabled']); 2973 WC()->session->set('gr_global_review_lable', empty($app_config['reviews']['global_review_lable']) ? '' : $app_config['reviews']['global_review_lable']); 2907 2974 WC()->session->set('gr_restricted_user_roles', empty($app_config['points']['gr_restricted_user_roles'])?array():$app_config['points']['gr_restricted_user_roles'] ); 2908 2975 WC()->session->set('gr_roles_restrict_type', empty($app_config['points']['gr_roles_restrict_type'])?'restrict':$app_config['points']['gr_roles_restrict_type'] ); … … 2918 2985 WC()->session->set('gr_pay_exclude_categories', empty($app_config['points']['gr_pay_exclude_categories'])?array():$app_config['points']['gr_pay_exclude_categories'] ); 2919 2986 WC()->session->set('gr_pay_redeem_restrict_terms', empty($app_config['points']['gr_pay_redeem_restrict_terms'])?'':$app_config['points']['gr_pay_redeem_restrict_terms'] ); 2920 WC()->session->set('gr_label_redeem_restriction_apply', empty($app_config['lang']['gr_label_redeem_restriction_apply'])?'': stripslashes($app_config['lang']['gr_label_redeem_restriction_apply']) );2921 WC()->session->set('gr_btn_redeem_confirm', empty($app_config['lang']['gr_btn_redeem_confirm'])?'': stripslashes($app_config['lang']['gr_btn_redeem_confirm']) );2922 WC()->session->set('gr_redeem_extra_point_info', empty($app_config['lang']['gr_redeem_extra_point_info'])?'': stripslashes($app_config['lang']['gr_redeem_extra_point_info']) );2987 WC()->session->set('gr_label_redeem_restriction_apply', empty($app_config['lang']['gr_label_redeem_restriction_apply'])?'':appsmav_stripslashes($app_config['lang']['gr_label_redeem_restriction_apply']) ); 2988 WC()->session->set('gr_btn_redeem_confirm', empty($app_config['lang']['gr_btn_redeem_confirm'])?'':appsmav_stripslashes($app_config['lang']['gr_btn_redeem_confirm']) ); 2989 WC()->session->set('gr_redeem_extra_point_info', empty($app_config['lang']['gr_redeem_extra_point_info'])?'':appsmav_stripslashes($app_config['lang']['gr_redeem_extra_point_info']) ); 2923 2990 WC()->session->set('gr_pbp_auto_apply', empty($app_config['points']['gr_pbp_auto_apply'])?0:$app_config['points']['gr_pbp_auto_apply'] ); 2924 2991 WC()->session->set('gr_earn_exclude_products', empty($app_config['points']['gr_earn_exclude_products'])?'':$app_config['points']['gr_earn_exclude_products'] ); … … 3057 3124 'gr_label_redeem_restriction_apply' => $ret['gr_label_redeem_restriction_apply'], 3058 3125 'gr_btn_redeem_confirm' => $ret['gr_btn_redeem_confirm'], 3059 'loyalty_menu_name' => empty($ret['loyalty_menu_name']) ? 'GR Loyalty' : stripslashes($ret['loyalty_menu_name'])3126 'loyalty_menu_name' => empty($ret['loyalty_menu_name']) ? 'GR Loyalty' : appsmav_stripslashes($ret['loyalty_menu_name']) 3060 3127 ), 3061 3128 'reviews' => array( … … 3472 3539 { 3473 3540 $blocked_roles = array_intersect ($roles, $app_config['points']['gr_restricted_user_roles']); 3474 if ($restrict_type == 'restrict' && !empty($blocked_roles) && count($blocked_roles) > 0)3541 if ($restrict_type == 'restrict' && !empty($blocked_roles) && (is_array($blocked_roles) || $blocked_roles instanceof Countable) && count($blocked_roles) > 0) 3475 3542 $is_restricted = true; 3476 else if ($restrict_type == 'allow' && empty($blocked_roles) && count($blocked_roles) == 0)3543 else if ($restrict_type == 'allow' && empty($blocked_roles) && (is_array($blocked_roles) || $blocked_roles instanceof Countable) && count($blocked_roles) == 0) 3477 3544 $is_restricted = true; 3478 3545 } … … 3501 3568 { 3502 3569 $app_config = gr_get_app_config(); 3503 $ex_products = empty($app_config['points']['gr_pay_exclude_products']) ? array() : explode(',', $app_config['points']['gr_pay_exclude_products']);3504 $ex_category = empty($app_config['points']['gr_pay_exclude_categories']) ? array() : explode(',', $app_config['points']['gr_pay_exclude_categories']);3570 $ex_products = empty($app_config['points']['gr_pay_exclude_products']) ? array() : appsmav_explode(',', $app_config['points']['gr_pay_exclude_products']); 3571 $ex_category = empty($app_config['points']['gr_pay_exclude_categories']) ? array() : appsmav_explode(',', $app_config['points']['gr_pay_exclude_categories']); 3505 3572 3506 3573 // Check this product is restricted … … 3808 3875 3809 3876 // Check the user applied their own referral code 3810 if (!empty(WC()->session) && strtolower(WC()->session->get('gr_loyalty_referral_coupon', '')) ==strtolower($coupon_code))3877 if (!empty(WC()->session) && appsmav_strtolower(WC()->session->get('gr_loyalty_referral_coupon', '')) == appsmav_strtolower($coupon_code)) 3811 3878 return false; 3812 3879 … … 3854 3921 3855 3922 // Check the user applied their own referral code 3856 if (!empty(WC()->session) && strtolower(WC()->session->get('gr_loyalty_referral_coupon', '')) ==strtolower($coupon_code)) {3923 if (!empty(WC()->session) && appsmav_strtolower(WC()->session->get('gr_loyalty_referral_coupon', '')) == appsmav_strtolower($coupon_code)) { 3857 3924 wc_add_notice(__("Coupon is not valid."), 'error'); 3858 3925 return false; … … 3869 3936 3870 3937 // Validate the points availabe if "pay by points" applied 3871 if(!empty(WC()->session) && WC()->session->get('gr_user_applied_discount' ) > 0)3938 if(!empty(WC()->session) && WC()->session->get('gr_user_applied_discount', 0) > 0) 3872 3939 { 3873 3940 … … 3911 3978 ) ); 3912 3979 3913 if ( count($customer_orders) > 0) {3980 if ((is_array($customer_orders) || $customer_orders instanceof Countable) && count($customer_orders) > 0) { 3914 3981 return TRUE; 3915 3982 } … … 3926 3993 'numberposts' => -1 3927 3994 )); 3928 if ( count($customer_orders) > 0) {3995 if ((is_array($customer_orders) || $customer_orders instanceof Countable) && count($customer_orders) > 0) { 3929 3996 return TRUE; 3930 3997 } … … 3965 4032 // Possibly do additional admin_init tasks 3966 4033 }// END public static function activate 4034 4035 /** 4036 * Sanitize refund data to handle WC_DateTime objects and other non-serializable data 4037 */ 4038 public static function sanitize_refund_data_for_api($data) { 4039 if (is_array($data)) { 4040 foreach ($data as $key => $value) { 4041 if (is_object($value)) { 4042 // Handle WC_DateTime objects 4043 if (is_a($value, 'WC_DateTime')) { 4044 $data[$key] = $value->format('c'); // ISO 8601 format 4045 } 4046 // Handle other WooCommerce objects 4047 elseif (method_exists($value, 'get_data')) { 4048 $data[$key] = self::sanitize_refund_data_for_api($value->get_data()); 4049 } 4050 // Handle other objects by converting to string 4051 else { 4052 $data[$key] = (string) $value; 4053 } 4054 } 4055 elseif (is_array($value)) { 4056 $data[$key] = self::sanitize_refund_data_for_api($value); 4057 } 4058 } 4059 } 4060 return $data; 4061 } 3967 4062 }// END class GR_Connect 3968 4063 } // END if(!class_exists('GR_Connect')) 4064 4065 /** 4066 * Wrapper functions for PHP 8.1+ compatibility 4067 * Handles null values to prevent deprecation warnings 4068 * Compatible with PHP 5.4 to 8.4 4069 */ 4070 4071 if (!function_exists('appsmav_stripslashes')) { 4072 /** 4073 * Wrapper for stripslashes() that handles null values 4074 * @param mixed $value The value to strip slashes from 4075 * @return string The value with slashes stripped, or empty string if null 4076 */ 4077 function appsmav_stripslashes($value) { 4078 if (is_null($value) || !is_string($value)) { 4079 return ''; 4080 } 4081 return stripslashes($value); 4082 } 4083 } 4084 4085 if (!function_exists('appsmav_strtolower')) { 4086 /** 4087 * Wrapper for strtolower() that handles null values 4088 * @param mixed $value The value to convert to lowercase 4089 * @return string The lowercase string, or empty string if null 4090 */ 4091 function appsmav_strtolower($value) { 4092 if (is_null($value) || !is_string($value)) { 4093 return ''; 4094 } 4095 return strtolower($value); 4096 } 4097 } 4098 4099 if (!function_exists('appsmav_strtoupper')) { 4100 /** 4101 * Wrapper for strtoupper() that handles null values 4102 * @param mixed $value The value to convert to uppercase 4103 * @return string The uppercase string, or empty string if null 4104 */ 4105 function appsmav_strtoupper($value) { 4106 if (is_null($value) || !is_string($value)) { 4107 return ''; 4108 } 4109 return strtoupper($value); 4110 } 4111 } 4112 4113 if (!function_exists('appsmav_strlen')) { 4114 /** 4115 * Wrapper for strlen() that handles null values 4116 * @param mixed $value The value to get length of 4117 * @return int The string length, or 0 if null 4118 */ 4119 function appsmav_strlen($value) { 4120 if (is_null($value) || !is_string($value)) { 4121 return 0; 4122 } 4123 return strlen($value); 4124 } 4125 } 4126 4127 if (!function_exists('appsmav_trim')) { 4128 /** 4129 * Wrapper for trim() that handles null values 4130 * @param mixed $value The value to trim 4131 * @return string The trimmed string, or empty string if null 4132 */ 4133 function appsmav_trim($value) { 4134 if (is_null($value) || !is_string($value)) { 4135 return ''; 4136 } 4137 return trim($value); 4138 } 4139 } 4140 4141 if (!function_exists('appsmav_explode')) { 4142 /** 4143 * Wrapper for explode() that handles null/empty values 4144 * @param string $separator The boundary string 4145 * @param mixed $string The input string 4146 * @param int $limit Maximum number of elements (optional) 4147 * @return array Array of strings, or empty array if input is null/empty 4148 */ 4149 function appsmav_explode($separator, $string, $limit = PHP_INT_MAX) { 4150 if (is_null($string) || !is_string($string) || $string === '') { 4151 return array(); 4152 } 4153 if ($limit === PHP_INT_MAX) { 4154 return explode($separator, $string); 4155 } 4156 return explode($separator, $string, $limit); 4157 } 4158 } 4159 4160 if (!function_exists('appsmav_strstr')) { 4161 /** 4162 * Wrapper for strstr() that handles null values 4163 * @param mixed $haystack The input string 4164 * @param mixed $needle The string to search for 4165 * @param bool $before_needle Return part before needle (optional) 4166 * @return string|false The portion of string, or false if needle is not found 4167 */ 4168 function appsmav_strstr($haystack, $needle, $before_needle = false) { 4169 if (is_null($haystack) || !is_string($haystack)) { 4170 return false; 4171 } 4172 if (is_null($needle)) { 4173 return false; 4174 } 4175 return strstr($haystack, $needle, $before_needle); 4176 } 4177 4178 /** 4179 * Wrapper for substr() that handles null values 4180 * @param mixed $string The input string 4181 * @param int $offset The starting position 4182 * @param int|null $length The maximum length 4183 * @return string The substring or empty string if null 4184 */ 4185 function appsmav_substr($string, $offset, $length = null) { 4186 if (is_null($string) || !is_string($string)) { 4187 return ''; 4188 } 4189 return $length === null ? substr($string, $offset) : substr($string, $offset, $length); 4190 } 4191 4192 /** 4193 * Wrapper for str_replace() that handles null values 4194 * @param mixed $search The value being searched for 4195 * @param mixed $replace The replacement value 4196 * @param mixed $subject The string or array being searched and replaced on 4197 * @return mixed The result string or array 4198 */ 4199 function appsmav_str_replace($search, $replace, $subject) { 4200 if (is_null($subject)) { 4201 return ''; 4202 } 4203 return str_replace($search, $replace, $subject); 4204 } 4205 4206 /** 4207 * Wrapper for preg_match() that handles null values 4208 * @param string $pattern The pattern to search for 4209 * @param mixed $subject The input string 4210 * @param array|null $matches Array to store matches 4211 * @return bool|int Returns 1 if pattern matches, 0 if not, false on error 4212 */ 4213 function appsmav_preg_match($pattern, $subject, &$matches = null) { 4214 if (is_null($subject) || !is_string($subject)) { 4215 return false; 4216 } 4217 return $matches === null ? preg_match($pattern, $subject) : preg_match($pattern, $subject, $matches); 4218 } 4219 } 4220 4221 if (!function_exists('appsmav_get_parent_id')) { 4222 /** 4223 * Backward compatible get_parent_id for WC < 3.0 and WC >= 3.0 4224 */ 4225 function appsmav_get_parent_id($object) { 4226 if (empty($object)) { 4227 return 0; 4228 } 4229 if (method_exists($object, 'get_parent_id')) { 4230 return $object->get_parent_id(); // WC 3.0+ 4231 } 4232 if (isset($object->post->post_parent)) { 4233 return $object->post->post_parent; // WC < 3.0 4234 } 4235 return 0; 4236 } 4237 } 3969 4238 3970 4239 if(class_exists('GR_Connect')) -
gratisfaction-all-in-one-loyalty-contests-referral-program-for-woocommerce/trunk/includes/grwoo-api.php
r3269635 r3386951 319 319 { 320 320 $cat_args = array( 321 'taxonomy' => 'product_cat', 321 322 'orderby' => 'name', 322 323 'order' => 'asc', 323 324 'hide_empty' => false, 324 325 ); 325 $categories = get_terms( 'product_cat',$cat_args );326 $categories = get_terms( $cat_args ); 326 327 327 328 $data = array( … … 357 358 } 358 359 359 if (empty($_POST['first_name']) || strlen($_POST['first_name']) > 50) {360 if (empty($_POST['first_name']) || appsmav_strlen($_POST['first_name']) > 50) { 360 361 throw new Exception("Invalid first name"); 361 362 } 362 363 363 if (!empty($_POST['last_name']) && strlen($_POST['last_name']) > 50) {364 if (!empty($_POST['last_name']) && appsmav_strlen($_POST['last_name']) > 50) { 364 365 throw new Exception("Invalid last name"); 365 366 } … … 452 453 foreach($coupons_data as $item_data) 453 454 { 454 $coupons[] = [ 455 'code' => $item_data['code'], 456 'discount_tax' => $item_data['discount_tax'], 457 'discount' => $item_data['discount'] 458 ]; 455 // Backward compatibility: Use method calls for WC 3.0+, array access for older versions 456 if(version_compare( WC_VERSION, '3.0', '>=' )) 457 { 458 $coupons[] = [ 459 'code' => $item_data->get_code(), 460 'discount_tax' => $item_data->get_discount_tax(), 461 'discount' => $item_data->get_discount() 462 ]; 463 } 464 else 465 { 466 $coupons[] = [ 467 'code' => $item_data['code'], 468 'discount_tax' => $item_data['discount_tax'], 469 'discount' => $item_data['discount'] 470 ]; 471 } 459 472 } 460 473 } … … 510 523 $data = array( 511 524 'error' => 0, 512 'order' => $order->get_data(),525 'order' => GR_Connect::sanitize_refund_data_for_api($order->get_data()), 513 526 'currency' => $curShop, 514 527 'total' => $total, … … 528 541 $param['line_items'] = []; 529 542 foreach ($order->get_items('line_item') as $key => $item) { 530 $param['line_items'][] = $item->get_data();543 $param['line_items'][] = GR_Connect::sanitize_refund_data_for_api($item->get_data()); 531 544 } 532 545 533 546 $refundData = array(); 534 foreach ($order->get_refunds() as $key => $refund) { 535 $refundData[$key]['refund'] = $refund->get_data(); 536 foreach ($refund->get_items() as $item_id => $item) { 537 $refundData[$key]['line_items'][$item_id] = $item->get_data(); 547 $refunds = $order->get_refunds(); 548 if (!empty($refunds) && is_array($refunds)) { 549 foreach ($refunds as $key => $refund) { 550 if (empty($refund) || !is_object($refund)) { 551 continue; 552 } 553 $refundData[$key]['refund'] = GR_Connect::sanitize_refund_data_for_api($refund->get_data()); 554 $refund_items = $refund->get_items(); 555 if (!empty($refund_items) && is_array($refund_items)) { 556 foreach ($refund_items as $item_id => $item) { 557 if (empty($item) || !is_object($item)) { 558 continue; 559 } 560 $refundData[$key]['line_items'][$item_id] = GR_Connect::sanitize_refund_data_for_api($item->get_data()); 561 } 562 } 538 563 } 539 564 } … … 563 588 564 589 $product_ids1 = sanitize_text_field($_POST['product_ids']); 565 $product_ids = explode(',', $product_ids1);590 $product_ids = appsmav_explode(',', $product_ids1); 566 591 567 592 foreach($product_ids as $product_id) { … … 624 649 'name' => $order->get_billing_first_name() . ' ' . $order->get_billing_last_name(), 625 650 'currency' => $order->get_currency(), 626 'coupon' => $order->get_used_coupons(),651 'coupon' => version_compare( WC_VERSION, '3.7', '<' ) ? $order->get_used_coupons() : $order->get_coupon_codes(), 627 652 'status' => $order->get_status() 628 653 ); … … 904 929 ); 905 930 906 $id = wp_insert_post( $new_page, $wp_error = false );931 $id = wp_insert_post( $new_page, true ); 907 932 908 933 if(is_wp_error($id)) { … … 957 982 } 958 983 959 $id = wp_update_post( $params, $wp_error =true );984 $id = wp_update_post( $params, true ); 960 985 961 986 if(is_wp_error($id)) … … 1090 1115 1091 1116 $coupon = new WC_Coupon($coupon_code); 1092 if (!empty($coupon->id)) 1117 $coupon_id = is_callable(array($coupon, 'get_id')) ? $coupon->get_id() : (isset($coupon->id) ? $coupon->id : 0); 1118 if (!empty($coupon_id)) 1093 1119 { 1094 1120 $data['msg'] = 'Yes'; … … 1125 1151 1126 1152 $coupon = new WC_Coupon($new_coupon_code); 1127 if (!empty($coupon->id)) 1153 $new_coupon_id = is_callable(array($coupon, 'get_id')) ? $coupon->get_id() : (isset($coupon->id) ? $coupon->id : 0); 1154 if (!empty($new_coupon_id)) 1128 1155 throw new Exception('Coupon code already exists. Please check and enter a new unique coupon code'); 1129 1156 1130 1157 $coupon = new WC_Coupon($old_coupon_code); 1131 if (empty($coupon->id)) 1158 $old_coupon_id = is_callable(array($coupon, 'get_id')) ? $coupon->get_id() : (isset($coupon->id) ? $coupon->id : 0); 1159 if (empty($old_coupon_id)) 1132 1160 throw new Exception('Coupon code not found. Please check and try again'); 1133 1161 1134 1162 // Update coupon details starts 1135 1163 $my_post = array( 1136 'ID' => $ coupon->id,1164 'ID' => $old_coupon_id, 1137 1165 'post_title' => $new_coupon_code 1138 1166 ); … … 1169 1197 $coupon_code = sanitize_text_field($_POST['coupon_code']); 1170 1198 $coupon = new WC_Coupon($coupon_code); 1171 if (!empty($coupon->id)) 1199 $coupon_id = is_callable(array($coupon, 'get_id')) ? $coupon->get_id() : (isset($coupon->id) ? $coupon->id : 0); 1200 if (!empty($coupon_id)) 1172 1201 { 1173 1202 $validate_usage = empty($_POST['validate_usage']) ? 0 : sanitize_text_field($_POST['validate_usage']); 1174 if(!empty($validate_usage) && (!isset($coupon->usage_count) || $coupon->usage_count != 0)) 1203 $usage_count = is_callable(array($coupon, 'get_usage_count')) ? $coupon->get_usage_count() : (isset($coupon->usage_count) ? $coupon->usage_count : 0); 1204 if(!empty($validate_usage) && $usage_count != 0) 1175 1205 { 1176 $data['id'] = $coupon ->id;1177 $data['usage_count'] = $ coupon->usage_count;1206 $data['id'] = $coupon_id; 1207 $data['usage_count'] = $usage_count; 1178 1208 throw new Exception('Coupon code already used'); 1179 1209 } 1180 1210 1181 $post_id = wp_delete_post($coupon ->id, TRUE);1211 $post_id = wp_delete_post($coupon_id, TRUE); 1182 1212 if ( is_wp_error( $post_id ) ) { 1183 1213 throw new Exception( $post_id->get_error_message()); … … 1230 1260 1231 1261 $order_ids = sanitize_text_field($_POST['order_ids']); 1232 $order_ids = explode(',', $order_ids);1262 $order_ids = appsmav_explode(',', $order_ids); 1233 1263 1234 1264 foreach( $order_ids as $order_id ){ … … 1250 1280 'billing_email' => $order->get_billing_email(), 1251 1281 'currency' => $order->get_currency(), 1252 'coupon' => $order->get_used_coupons(),1282 'coupon' => version_compare( WC_VERSION, '3.7', '<' ) ? $order->get_used_coupons() : $order->get_coupon_codes(), 1253 1283 'date_created' => $order->get_date_created()->format('c'), 1254 1284 'status' => $order->get_status() … … 1289 1319 1290 1320 if (!empty($order_status)) { 1291 $order_status = explode(',', $order_status);1321 $order_status = appsmav_explode(',', $order_status); 1292 1322 } else { 1293 1323 $order_status = array( 'wc-completed','wc-processing' ); … … 1315 1345 'billing_email' => $order->get_billing_email(), 1316 1346 'currency' => $order->get_currency(), 1317 'coupon' => $order->get_used_coupons(),1347 'coupon' => version_compare( WC_VERSION, '3.7', '<' ) ? $order->get_used_coupons() : $order->get_coupon_codes(), 1318 1348 'date_created' => $order->get_date_created()->format('c'), 1319 1349 'status' => $order->get_status() … … 1384 1414 ); 1385 1415 1386 $assoc_args['product_ids'] = !empty($assoc_args['product_ids']) ? json_decode($assoc_args['product_ids'], true) : []; 1387 $assoc_args['exclude_product_ids'] = !empty($assoc_args['exclude_product_ids']) ? json_decode($assoc_args['exclude_product_ids'], true) : []; 1388 $assoc_args['product_category_ids'] = !empty($assoc_args['product_category_ids']) ? json_decode($assoc_args['product_category_ids'], true) : []; 1389 $assoc_args['exclude_product_category_ids'] = !empty($assoc_args['exclude_product_category_ids']) ? json_decode($assoc_args['exclude_product_category_ids'], true) : []; 1390 $assoc_args['customer_emails'] = !empty($assoc_args['customer_emails']) ? json_decode(stripslashes($assoc_args['customer_emails']), true) : []; 1416 // Safe JSON decode with error handling 1417 $assoc_args['product_ids'] = $this->safe_json_decode(isset($assoc_args['product_ids']) ? $assoc_args['product_ids'] : ''); 1418 $assoc_args['exclude_product_ids'] = $this->safe_json_decode(isset($assoc_args['exclude_product_ids']) ? $assoc_args['exclude_product_ids'] : ''); 1419 $assoc_args['product_category_ids'] = $this->safe_json_decode(isset($assoc_args['product_category_ids']) ? $assoc_args['product_category_ids'] : ''); 1420 $assoc_args['exclude_product_category_ids'] = $this->safe_json_decode(isset($assoc_args['exclude_product_category_ids']) ? $assoc_args['exclude_product_category_ids'] : ''); 1421 $assoc_args['customer_emails'] = $this->safe_json_decode(appsmav_stripslashes(isset($assoc_args['customer_emails']) ? $assoc_args['customer_emails'] : '')); 1391 1422 1392 1423 if(!empty($_POST['usage_limit_per_user'])) … … 1472 1503 ); 1473 1504 1474 $id = wp_insert_post($new_coupon, $wp_error = false);1505 $id = wp_insert_post($new_coupon, true); 1475 1506 1476 1507 if(is_wp_error($id)) … … 1502 1533 if (!empty($_POST['custom_attributes'])) 1503 1534 { 1504 $custom_attributes = stripslashes(sanitize_text_field($_POST['custom_attributes']));1535 $custom_attributes = appsmav_stripslashes(sanitize_text_field($_POST['custom_attributes'])); 1505 1536 $custom_attributes = json_decode($custom_attributes, true); 1506 1537 if (!empty($custom_attributes) && is_array($custom_attributes)) … … 1538 1569 return $result; 1539 1570 } 1571 1572 /** 1573 * Safe JSON decode with error handling 1574 * 1575 * @param string $json_string The JSON string to decode 1576 * @return array Returns decoded array or empty array on error 1577 */ 1578 private function safe_json_decode($json_string) { 1579 if (empty($json_string)) { 1580 return array(); 1581 } 1582 1583 $decoded = json_decode($json_string, true); 1584 1585 if (json_last_error() !== JSON_ERROR_NONE) { 1586 return array(); 1587 } 1588 1589 return is_array($decoded) ? $decoded : array(); 1590 } 1540 1591 } -
gratisfaction-all-in-one-loyalty-contests-referral-program-for-woocommerce/trunk/includes/grwoo-checkout.php
r3207752 r3386951 59 59 */ 60 60 public function coupon_label( $label ) { 61 if ( strstr(strtoupper( $label ), 'WC_POINTS_REDEMPTION' ) ) {61 if ( appsmav_strstr( appsmav_strtoupper( $label ), 'WC_POINTS_REDEMPTION' ) ) { 62 62 $label = esc_html( __( 'Points redemption', 'woocommerce-points-and-rewards' ) ); 63 63 } … … 74 74 75 75 foreach ( WC()->cart->get_applied_coupons() as $code ) { 76 if ( strstr( $code, 'wc_points_redemption_' ) ) {76 if ( appsmav_strstr( $code, 'wc_points_redemption_' ) ) { 77 77 $points[] = $code; 78 78 } else { … … 89 89 */ 90 90 public function discount_removed( $coupon_code ) { 91 if ( ! strstr( $coupon_code, 'wc_points_redemption_' ) ) {91 if ( ! appsmav_strstr( $coupon_code, 'wc_points_redemption_' ) ) { 92 92 return; 93 93 } … … 604 604 $existing_discount_amounts = version_compare( WC_VERSION, '3.0.0', '<' ) 605 605 ? WC()->cart->discount_total 606 : WC()->cart->get_cart_discount_total(); 606 : ( version_compare( WC_VERSION, '3.7', '<' ) 607 ? WC()->cart->get_cart_discount_total() 608 : WC()->cart->get_discount_total() ); 607 609 } 608 610 -
gratisfaction-all-in-one-loyalty-contests-referral-program-for-woocommerce/trunk/includes/grwoo-disount.php
r1913442 r3386951 44 44 45 45 public function get_discount_data( $data, $code ) { 46 if ( strtolower( $code ) != $this->get_discount_code() ) {46 if ( appsmav_strtolower( $code ) != $this->get_discount_code() ) { 47 47 return $data; 48 48 } … … 95 95 $discount = 0; 96 96 foreach ( WC()->cart->get_coupons() as $coupon ) { 97 if ( strtolower( $coupon->get_code() ) === $this->get_discount_code() || ! $coupon->is_type( 'fixed_product' ) ) {97 if ( appsmav_strtolower( $coupon->get_code() ) === $this->get_discount_code() || ! $coupon->is_type( 'fixed_product' ) ) { 98 98 continue; 99 99 } … … 115 115 116 116 public function get_discount_amount( $discount, $discounting_amount, $cart_item, $single, $coupon ) { 117 if ( strtolower( $coupon->get_code() ) != $this->get_discount_code() ) {117 if ( appsmav_strtolower( $coupon->get_code() ) != $this->get_discount_code() ) { 118 118 return $discount; 119 119 } … … 176 176 public static function get_discount_code() { 177 177 if ( WC()->session !== null ) { 178 return WC()->session->get( 'gratisfaction_discount_code' );178 return WC()->session->get( 'gratisfaction_discount_code', '' ); 179 179 } 180 180 } -
gratisfaction-all-in-one-loyalty-contests-referral-program-for-woocommerce/trunk/includes/grwoo-http-request-handler.php
r3212496 r3386951 27 27 28 28 private $_error_info = null; 29 30 private $_http_code = null; 29 31 30 32 public function setUrl($url) … … 82 84 $this->_info = ''; 83 85 $this->_error_info = null; 86 $this->_http_code = null; 84 87 $this->_headers = array(); 85 88 … … 106 109 107 110 $this->_resp = $response['body']; 111 $this->_http_code = wp_remote_retrieve_response_code($response); 108 112 } 109 113 else { … … 114 118 115 119 $this->_resp = $response['body']; 120 $this->_http_code = wp_remote_retrieve_response_code($response); 116 121 117 122 } … … 140 145 return $this->_error_info; 141 146 } 147 148 public function getHttpCode() 149 { 150 return $this->_http_code; 151 } 142 152 } -
gratisfaction-all-in-one-loyalty-contests-referral-program-for-woocommerce/trunk/includes/grwoo-product.php
r1913442 r3386951 273 273 $variable_points = array(); 274 274 275 if ( count( $product->get_children() ) > 0 ) { 275 $children = $product->get_children(); 276 if ( (is_array($children) || $children instanceof Countable) && count( $children ) > 0 ) { 276 277 foreach ( $product->get_children() as $child ) { 277 278 $earned = get_post_meta( $child, '_wc_points_earned', true ); … … 282 283 } 283 284 284 if ( count( $variable_points ) > 0 ) {285 if ( (is_array($variable_points) || $variable_points instanceof Countable) && count( $variable_points ) > 0 ) { 285 286 $wc_min_points_earned = min( $variable_points ); 286 287 } … … 448 449 $category_points_array = array(); 449 450 450 if ( $category_points_data && count( $category_points_data ) > 0 ) {451 if ( $category_points_data && (is_array($category_points_data) || $category_points_data instanceof Countable) && count( $category_points_data ) > 0 ) { 451 452 foreach ( $category_points_data as $category ) { 452 453 $category_points_array[ $category->category_id ] = $category->points; … … 604 605 $category_discount_array = array(); 605 606 606 if ( $category_discount_data && count( $category_discount_data ) > 0 ) {607 if ( $category_discount_data && (is_array($category_discount_data) || $category_discount_data instanceof Countable) && count( $category_discount_data ) > 0 ) { 607 608 foreach ( $category_discount_data as $category ) { 608 609 $category_discount_array[ $category->category_id ] = $category->max_discount; -
gratisfaction-all-in-one-loyalty-contests-referral-program-for-woocommerce/trunk/readme.txt
r3362178 r3386951 5 5 Requires at least: 3.0.1 6 6 Tested up to: 6.8 7 Stable tag: 4.5. 17 Stable tag: 4.5.2 8 8 License: GPLv2 or later 9 9 License URI: http://www.gnu.org/licenses/gpl-2.0.html … … 254 254 255 255 == Changelog == 256 = 4.5.2 = 257 PHP version 8.4 release compatibility 258 256 259 = 4.5.1 = 257 260 WordPress version 6.8 release compatibility … … 617 620 618 621 == Upgrade Notice == 619 = 4.5. 1=620 WordPress version 6.8release compatibility622 = 4.5.2 = 623 PHP version 8.4 release compatibility
Note: See TracChangeset
for help on using the changeset viewer.