Changeset 2945562
- Timestamp:
- 07/31/2023 03:54:02 PM (3 years ago)
- Location:
- woocommerce-putler-connector/trunk
- Files:
-
- 4 edited
-
classes/class-woocommerce-putler-connector.php (modified) (45 diffs)
-
languages/woocommerce-putler-connector.pot (modified) (3 diffs)
-
readme.txt (modified) (3 diffs)
-
woocommerce-putler-connector.php (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
woocommerce-putler-connector/trunk/classes/class-woocommerce-putler-connector.php
r2847386 r2945562 7 7 */ 8 8 9 use Automattic\WooCommerce\Utilities\OrderUtil; 10 9 11 // Exit if accessed directly. 10 12 if ( ! defined( 'ABSPATH' ) ) { … … 27 29 28 30 /** 31 * Wpdb. 32 * 33 * @var mixed $wpdb1 34 */ 35 private $wpdb1; 36 37 /** 38 * Is HPOS enabled. 39 * 40 * @var bool $is_hpos_enabled 41 */ 42 private $is_hpos_enabled; 43 44 /** 45 * WC table prefix for HPOS. 46 * 47 * @var string $wc_prefix 48 */ 49 private $wc_prefix; 50 51 /** 29 52 * Constructor. 30 53 */ … … 36 59 37 60 $this->name = ( defined( 'PUTLER_GATEWAY' ) ? PUTLER_GATEWAY : 'WooCommerce' ); 61 62 $this->is_hpos_enabled = self::is_hpos_enabled(); 38 63 39 64 add_filter( 'putler_connector_get_order_count', array( &$this, 'get_order_count' ) ); … … 51 76 add_action( 'before_delete_post', array( &$this, 'delete_post' ), 9, 1 ); 52 77 } 78 79 // Action for WooCommerce v7.1 custom order tables related compatibility. 80 add_action( 'before_woocommerce_init', array( &$this, 'declare_hpos_compatibility' ) ); 53 81 } 54 82 … … 158 186 global $wpdb; 159 187 160 $post_type = get_post_type( $id );188 $post_type = ( $this->is_hpos_enabled ) ? OrderUtil::get_order_type( $id ) : get_post_type( $id ); 161 189 $valid_post_type = array( 'shop_order', 'shop_subscription', 'scheduled-action' ); 162 163 if ( empty( $post_type ) || in_array( $post_type, $valid_post_type, true ) === false ) {190 $order = wc_get_order( $id ); 191 if ( empty( $post_type ) || in_array( $post_type, $valid_post_type, true ) === false || ( $this->is_hpos_enabled && ! ( $order instanceof WC_Order ) ) ) { 164 192 return; 165 193 } … … 177 205 ); 178 206 207 if ( $this->is_hpos_enabled ) { 208 $order_modified_date = $order->get_date_modified(); 209 $putler_transaction['Date'] = $this->format_date_time( $order_modified_date, 'm/d/Y' ); 210 $putler_transaction['Time'] = $this->format_date_time( $order_modified_date, 'H:i:s' ); 211 } 212 179 213 if ( 'shop_order' === $post_type ) { 180 214 181 215 // query to find if the order is a subscription renewal order. 182 $results = $wpdb->get_row( 183 $wpdb->prepare( 184 "SELECT ID as id, 185 '' as order_type 186 FROM {$wpdb->prefix}posts 187 WHERE post_parent = %d 188 UNION 189 SELECT meta_value as id, 190 'renewal' as order_type 191 FROM {$wpdb->prefix}postmeta 192 WHERE post_id = %d 193 AND meta_key IN ('_subscription_renewal')", 194 $id, 195 $id 196 ), 197 'ARRAY_A' 198 ); // WPCS: cache ok, db call ok. 199 200 if ( count( $results ) > 0 ) { 216 if ( $this->is_hpos_enabled ) { 217 $results = $wpdb->get_row( 218 $wpdb->prepare( 219 "SELECT id as id, 220 '' as order_type 221 FROM {$wpdb->prefix}wc_orders 222 WHERE parent_order_id = %d 223 UNION 224 SELECT meta_value as id, 225 'renewal' as order_type 226 FROM {$wpdb->prefix}wc_orders_meta 227 WHERE order_id = %d 228 AND meta_key IN ('_subscription_renewal')", 229 $id, 230 $id 231 ), 232 'ARRAY_A' 233 ); // WPCS: cache ok, db call ok. 234 } else { 235 $results = $wpdb->get_row( 236 $wpdb->prepare( 237 "SELECT ID as id, 238 '' as order_type 239 FROM {$wpdb->prefix}posts 240 WHERE post_parent = %d 241 UNION 242 SELECT meta_value as id, 243 'renewal' as order_type 244 FROM {$wpdb->prefix}postmeta 245 WHERE post_id = %d 246 AND meta_key IN ('_subscription_renewal')", 247 $id, 248 $id 249 ), 250 'ARRAY_A' 251 ); // WPCS: cache ok, db call ok. 252 } 253 254 if ( ! empty( $results ) && count( $results ) > 0 ) { 201 255 202 256 $sub_id = ( ! empty( $results['id'] ) ) ? $results['id'] : ''; … … 220 274 $prod = 0; 221 275 222 if ( count( $results ) > 0 ) {276 if ( ! empty( $results ) && count( $results ) > 0 ) { 223 277 224 278 foreach ( $results as $pid ) { … … 245 299 } 246 300 } else { 247 $putler_transaction['Transaction_ID'] = wp_get_post_parent_id( $id ) . '_D_' . get_post_modified_time( 'G', true, $id, false ); 301 if ( $this->is_hpos_enabled ) { 302 $putler_transaction['Transaction_ID'] = $order->get_parent_id() . '_D_' . $this->format_date_time( $order_modified_date, 'G' ); 303 } else { 304 $putler_transaction['Transaction_ID'] = wp_get_post_parent_id( $id ) . '_D_' . get_post_modified_time( 'G', true, $id, false ); 305 } 248 306 } 249 307 … … 263 321 'ARRAY_A' 264 322 ); // WPCS: cache ok, db call ok. 265 if ( count( $results ) > 0 ) {323 if ( ! empty( $results ) && count( $results ) > 0 ) { 266 324 267 325 $transient_name = ( ! empty( $results['option_name'] ) ) ? substr( $results['option_name'], 11 ) : ''; … … 355 413 if ( ( empty( $params['sub_details'] ) ) ) { 356 414 // query to get the sub details. 357 $results = $wpdb->get_results( 358 $wpdb->prepare( 359 "SELECT date_format(post_modified_gmt, %s) AS modified_date, 360 date_format(post_modified_gmt, %s) AS formatted_modified_gmt_date, 361 date_format(post_modified_gmt, %s) AS formatted_modified_gmt_time, 362 post_parent AS order_id 363 FROM {$wpdb->prefix}posts 364 WHERE id = %d", 365 '%Y-%m-%d %T', 366 '%m/%d/%Y', 367 '%T', 368 $params['sub_id'] 369 ), 370 'ARRAY_A' 371 ); // WPCS: cache ok, db call ok. 372 373 if ( count( $results ) > 0 ) { 415 if ( $this->is_hpos_enabled ) { 416 $results = $wpdb->get_results( 417 $wpdb->prepare( 418 "SELECT date_format(date_updated_gmt, %s) AS modified_date, 419 date_format(date_updated_gmt, %s) AS formatted_modified_gmt_date, 420 date_format(date_updated_gmt, %s) AS formatted_modified_gmt_time, 421 parent_order_id AS order_id 422 FROM {$wpdb->prefix}wc_orders 423 WHERE id = %d", 424 '%Y-%m-%d %T', 425 '%m/%d/%Y', 426 '%T', 427 $params['sub_id'] 428 ), 429 'ARRAY_A' 430 ); // WPCS: cache ok, db call ok. 431 } else { 432 $results = $wpdb->get_results( 433 $wpdb->prepare( 434 "SELECT date_format(post_modified_gmt, %s) AS modified_date, 435 date_format(post_modified_gmt, %s) AS formatted_modified_gmt_date, 436 date_format(post_modified_gmt, %s) AS formatted_modified_gmt_time, 437 post_parent AS order_id 438 FROM {$wpdb->prefix}posts 439 WHERE id = %d", 440 '%Y-%m-%d %T', 441 '%m/%d/%Y', 442 '%T', 443 $params['sub_id'] 444 ), 445 'ARRAY_A' 446 ); // WPCS: cache ok, db call ok. 447 } 448 449 if ( ! empty( $results ) && count( $results ) > 0 ) { 374 450 foreach ( $results as $result ) { 375 451 $response ['Date'] = $result['formatted_modified_gmt_date']; … … 434 510 ); // WPCS: cache ok, db call ok. 435 511 436 if ( count( $results ) > 0 ) {512 if ( ! empty( $results ) && count( $results ) > 0 ) { 437 513 438 514 $name = ''; … … 512 588 $post_order_cond = ''; 513 589 514 $order_count_result = $wpdb->get_col( 515 $wpdb->prepare( 516 "SELECT COUNT(posts.ID) as id 517 FROM {$wpdb->prefix}posts AS posts 518 WHERE posts.post_type IN ('shop_order', 'shop_order_refund') 519 AND posts.post_date_gmt != %s 520 AND posts.post_status NOT IN ('trash', 'auto-draft', 'draft')", 521 '0000-00-00 00:00:00' 522 ) 523 ); // WPCS: cache ok, db call ok. 590 if ( $this->is_hpos_enabled ) { 591 $order_count_result = $wpdb->get_col( 592 $wpdb->prepare( 593 "SELECT COUNT(orders.id) as id 594 FROM {$wpdb->prefix}wc_orders AS orders 595 WHERE orders.type IN ('shop_order', 'shop_order_refund') 596 AND orders.date_created_gmt != %s 597 AND orders.status NOT IN ('trash', 'auto-draft', 'draft')", 598 '0000-00-00 00:00:00' 599 ) 600 ); // WPCS: cache ok, db call ok. 601 } else { 602 $order_count_result = $wpdb->get_col( 603 $wpdb->prepare( 604 "SELECT COUNT(posts.ID) as id 605 FROM {$wpdb->prefix}posts AS posts 606 WHERE posts.post_type IN ('shop_order', 'shop_order_refund') 607 AND posts.post_date_gmt != %s 608 AND posts.post_status NOT IN ('trash', 'auto-draft', 'draft')", 609 '0000-00-00 00:00:00' 610 ) 611 ); // WPCS: cache ok, db call ok. 612 } 524 613 525 614 if ( ! empty( $order_count_result ) ) { … … 557 646 // For Handling Refund Transactions. 558 647 if ( 'wc-refunded' === get_post_status( $params['order_id'] ) ) { 559 $refund_id = $wpdb->get_var( 560 $wpdb->prepare( 561 "SELECT MAX(id) AS id 562 FROM {$wpdb->prefix}posts 563 WHERE post_type = 'shop_order_refund' 564 AND post_parent = %d", 565 $params['order_id'] 566 ) 567 ); // WPCS: cache ok, db call ok. 648 if ( $this->is_hpos_enabled ) { 649 $refund_id = $wpdb->get_var( 650 $wpdb->prepare( 651 "SELECT MAX(id) AS id 652 FROM {$wpdb->prefix}wc_orders 653 WHERE type = 'shop_order_refund' 654 AND parent_order_id = %d", 655 $params['order_id'] 656 ) 657 ); // WPCS: cache ok, db call ok. 658 } else { 659 $refund_id = $wpdb->get_var( 660 $wpdb->prepare( 661 "SELECT MAX(id) AS id 662 FROM {$wpdb->prefix}posts 663 WHERE post_type = 'shop_order_refund' 664 AND post_parent = %d", 665 $params['order_id'] 666 ) 667 ); // WPCS: cache ok, db call ok. 668 } 568 669 569 670 if ( ! empty( $refund_id ) ) { … … 578 679 // Flag for woo2.2+. 579 680 if ( defined( 'WPC_IS_WOO22' ) && 'true' === WPC_IS_WOO22 ) { 580 $terms_post_join = ''; 581 $terms_select = 'posts.post_status AS order_status'; 582 681 $terms_post_join = ''; 682 $select_status_col = ( $this->is_hpos_enabled ) ? 'orders.status AS order_status' : 'posts.post_status AS order_status'; 583 683 if ( ! empty( $params['trash'] ) ) { 584 $post_order_cond = " AND posts.post_status = 'trash'";684 $post_order_cond = ( $this->is_hpos_enabled ) ? " AND orders.status = 'trash'" : " AND posts.post_status = 'trash'"; 585 685 } else { 586 $post_order_cond = " AND posts.post_status NOT IN ('auto-draft', 'draft')"; 587 } 588 } else { 589 // Code to get all the term_names along with the term_taxonomy_id in an array. 590 $results_order_status = $wpdb->get_results( 591 $wpdb->prepare( 592 "SELECT terms.name as order_status, 593 term_taxonomy.term_taxonomy_id 594 FROM {$wpdb->prefix}term_taxonomy AS term_taxonomy 595 JOIN {$wpdb->prefix}terms AS terms ON (terms.term_id = term_taxonomy.term_id) 596 WHERE taxonomy = %s", 597 'shop_order_status' 598 ), 599 'ARRAY_A' 600 ); // WPCS: cache ok, db call ok. 601 602 $order_status = array(); 603 604 foreach ( $results_order_status as $results_order_status1 ) { 605 $order_status[ $results_order_status1['term_taxonomy_id'] ] = $results_order_status1['order_status']; 606 } 607 608 $terms_post_join = 'JOIN ' . $wpdb->prefix . "term_relationships AS term_relationships ON (term_relationships.object_id = posts.ID AND posts.post_status IN ('publish','trash'))"; 609 $terms_select = 'term_relationships.term_taxonomy_id AS term_taxonomy_id'; 610 611 if ( ! empty( $params['trash'] ) ) { 612 $post_order_cond = " AND posts.post_status = 'trash'"; 613 } else { 614 $post_order_cond = " AND posts.post_status IN ('publish','trash')"; 686 $post_order_cond = ( $this->is_hpos_enabled ) ? " AND orders.status NOT IN ('auto-draft', 'draft')" : " AND posts.post_status NOT IN ('auto-draft', 'draft')"; 615 687 } 616 688 } … … 618 690 // Code for handling manual refunds. 619 691 if ( ! empty( $params ['refund_parent_id'] ) ) { 620 $cond_type = " AND posts.post_type = 'shop_order_refund' ";692 $cond_type = ( $this->is_hpos_enabled ) ? " AND orders.type = 'shop_order_refund' " : " AND posts.post_type = 'shop_order_refund' "; 621 693 } elseif ( ! empty( $params['order_id'] ) ) { 622 $cond_type = " AND posts.post_type = 'shop_order' ";694 $cond_type = ( $this->is_hpos_enabled ) ? " AND orders.type = 'shop_order' " : " AND posts.post_type = 'shop_order' "; 623 695 } elseif ( empty( $params['order_id'] ) ) { 624 $cond_type = " AND posts.post_type IN ('shop_order', 'shop_order_refund') ";696 $cond_type = ( $this->is_hpos_enabled ) ? " AND orders.type IN ('shop_order', 'shop_order_refund') " : " AND posts.post_type IN ('shop_order', 'shop_order_refund') "; 625 697 } 626 698 627 699 // Code to get all subscriptions in the specified date range. 628 629 700 $modified_sub_ids = array(); 630 701 $modified_sub_details = array(); … … 653 724 ); // WPCS: cache ok, db call ok. 654 725 655 if ( count( $results ) > 0 ) {726 if ( ! empty( $results ) && count( $results ) > 0 ) { 656 727 657 728 foreach ( $results as $result ) { … … 683 754 ); // WPCS: cache ok, db call ok. 684 755 685 if ( count( $results ) > 0 ) {756 if ( ! empty( $results ) && count( $results ) > 0 ) { 686 757 687 758 foreach ( $results as $result ) { … … 751 822 } 752 823 753 $results_order_details = $this->wpdb1->get_results( 754 "SELECT posts.ID as id, 755 posts.post_type as type, 756 posts.post_parent as parent_id, 757 posts.post_excerpt as order_note, 758 date_format(posts.post_date_gmt,'%Y-%m-%d %T') AS date, 759 date_format(posts.post_modified_gmt,'%Y-%m-%d %T') AS modified_date, 760 date_format(posts.post_modified_gmt,'%m/%d/%Y') AS formatted_modified_gmt_date, 761 date_format(posts.post_modified_gmt,'%T') AS formatted_modified_gmt_time, 762 $terms_select 763 FROM {$wpdb->prefix}posts AS posts 764 $terms_post_join 765 WHERE posts.post_date_gmt != '0000-00-00 00:00:00' 766 AND post_modified_gmt BETWEEN '" . $params['start_date'] . "' AND '" . $params['end_date'] . "' 767 $cond_type 768 $cond 769 $post_order_cond 770 GROUP BY posts.ID 771 LIMIT " . $start_limit . ',' . $batch_limit, 772 'ARRAY_A' 773 ); // WPCS: cache ok, db call ok. 824 if ( $this->is_hpos_enabled ) { 825 $order_ids_hpos = array(); 826 $results_order_details = $this->wpdb1->get_results( 827 "SELECT orders.id AS id, orders.type AS type, orders.parent_order_id AS parent_id, orders.customer_note AS order_note, orders.currency AS currency, 828 orders.tax_amount AS tax_amount, orders.total_amount AS total_amount, orders.billing_email AS billing_email, orders.ip_address AS ip_address, 829 orders.payment_method AS payment_method, orders.transaction_id AS transaction_id, 830 date_format(orders.date_created_gmt,'%Y-%m-%d %T') AS date, 831 date_format(orders.date_created_gmt,'%m/%d/%Y') AS formatted_gmt_date, 832 date_format(orders.date_created_gmt,'%T') AS formatted_gmt_time, 833 date_format(orders.date_updated_gmt,'%Y-%m-%d %T') AS modified_date, 834 date_format(orders.date_updated_gmt,'%m/%d/%Y') AS formatted_modified_gmt_date, 835 date_format(orders.date_updated_gmt,'%T') AS formatted_modified_gmt_time, 836 $select_status_col 837 FROM {$wpdb->prefix}wc_orders AS orders 838 WHERE orders.date_created_gmt != '0000-00-00 00:00:00' 839 AND orders.date_updated_gmt BETWEEN '" . $params['start_date'] . "' AND '" . $params['end_date'] . "' 840 $cond_type 841 $cond 842 $post_order_cond 843 GROUP BY orders.id 844 LIMIT " . $start_limit . ',' . $batch_limit, 845 'ARRAY_A' 846 ); // WPCS: cache ok, db call ok. 847 if ( ! empty( $results_order_details ) ) { 848 $order_ids_hpos = array_column( $results_order_details, 'id' ); 849 $discount_data = $this->wpdb1->get_results( 850 "SELECT order_id, SUM(discount_amount) AS total_discount 851 FROM {$wpdb->prefix}wc_order_coupon_lookup 852 WHERE order_id IN ( " . implode( ',', $order_ids_hpos ) . ' ) 853 GROUP BY order_id', 854 'ARRAY_A' 855 ); 856 $discounts = array(); 857 if ( ! empty( $discount_data ) ) { 858 foreach ( $discount_data as $d ) { 859 $discounts[ $d['order_id'] ] = $d; 860 } 861 } 862 863 $billing_address_data = $this->wpdb1->get_results( 864 "SELECT order_id, first_name, last_name, email as billing_email, phone, address_1, 865 address_2, city, state, postcode, country 866 FROM {$wpdb->prefix}wc_order_addresses 867 WHERE order_id IN ( " . implode( ',', $order_ids_hpos ) . " ) AND address_type = 'billing'", 868 'ARRAY_A' 869 ); 870 $billing_address = array(); 871 if ( ! empty( $billing_address_data ) ) { 872 foreach ( $billing_address_data as $b ) { 873 $billing_address[ $b['order_id'] ] = $b; 874 } 875 } 876 877 $order_stats_data = $this->wpdb1->get_results( 878 "SELECT order_id, total_sales, tax_total, shipping_total, net_total 879 FROM {$wpdb->prefix}wc_order_stats 880 WHERE order_id IN ( " . implode( ',', $order_ids_hpos ) . ' )', 881 'ARRAY_A' 882 ); 883 $order_stats = array(); 884 if ( ! empty( $order_stats_data ) ) { 885 foreach ( $order_stats_data as $o ) { 886 $order_stats[ $o['order_id'] ] = $o; 887 } 888 } 889 } 890 } else { 891 $results_order_details = $this->wpdb1->get_results( 892 "SELECT posts.ID as id, 893 posts.post_type as type, 894 posts.post_parent as parent_id, 895 posts.post_excerpt as order_note, 896 date_format(posts.post_date_gmt,'%Y-%m-%d %T') AS date, 897 date_format(posts.post_date_gmt,'%m/%d/%Y') AS formatted_gmt_date, 898 date_format(posts.post_date_gmt,'%T') AS formatted_gmt_time, 899 date_format(posts.post_modified_gmt,'%Y-%m-%d %T') AS modified_date, 900 date_format(posts.post_modified_gmt,'%m/%d/%Y') AS formatted_modified_gmt_date, 901 date_format(posts.post_modified_gmt,'%T') AS formatted_modified_gmt_time, 902 $select_status_col 903 FROM {$wpdb->prefix}posts AS posts 904 $terms_post_join 905 WHERE posts.post_date_gmt != '0000-00-00 00:00:00' 906 AND posts.post_modified_gmt BETWEEN '" . $params['start_date'] . "' AND '" . $params['end_date'] . "' 907 $cond_type 908 $post_order_cond 909 GROUP BY posts.ID 910 LIMIT " . $start_limit . ',' . $batch_limit, 911 'ARRAY_A' 912 ); // WPCS: cache ok, db call ok. 913 } 774 914 $results_order_details_count = $wpdb->num_rows; 775 915 … … 895 1035 ); // WPCS: cache ok, db call ok. 896 1036 897 if ( count( $results ) > 0 ) {1037 if ( ! empty( $results ) && count( $results ) > 0 ) { 898 1038 foreach ( $results as $result ) { 899 1039 if ( empty( $coupon_data[ $result['slug'] ] ) ) { … … 947 1087 ); // WPCS: cache ok, db call ok. 948 1088 949 if ( count( $sub_taxonomy_ids ) > 0 ) {1089 if ( ! empty( $sub_taxonomy_ids ) && count( $sub_taxonomy_ids ) > 0 ) { 950 1090 $sub_item_ids = $this->wpdb1->get_col( 951 1091 "SELECT tr.object_id AS id … … 1017 1157 1018 1158 if ( 2 === $i ) { 1019 $variations[ $variation_att['id'] ][0]['option1_value'] = $variations[ $variation_att['id'] ][0]['option1_name'] . ' : ' . $variations[ $variation_att['id'] ][0]['option1_value'] . ', ' 1020 . $variations[ $variation_att['id'] ][1]['option1_name'] . ' : ' . $variations[ $variation_att['id'] ][1]['option1_value']; 1021 unset( $variations[ $variation_att['id'] ][1] ); 1159 $variations[ $variation_att['id'] ][0]['option1_value'] = $variations[ $variation_att['id'] ][0]['option1_name'] . ' : ' . $variations[ $variation_att['id'] ][0]['option1_value']; 1160 1161 if ( ! empty( $variations[ $variation_att['id'] ][1] ) ) { 1162 $variations[ $variation_att['id'] ][0]['option1_value'] .= ', ' . $variations[ $variation_att['id'] ][1]['option1_name'] . ' : ' . $variations[ $variation_att['id'] ][1]['option1_value']; 1163 unset( $variations[ $variation_att['id'] ][1] ); 1164 } 1022 1165 } 1023 1166 … … 1046 1189 1047 1190 // query to get subscriptions and renewal subscription ids. 1048 $results = $this->wpdb1->get_results( 1049 "SELECT id AS sub_id, 1050 post_parent AS order_id, 1051 '' AS meta_key 1052 FROM {$wpdb->prefix}posts 1053 WHERE post_type = 'shop_subscription' 1054 AND post_parent IN (" . implode( ',', $order_ids ) . ") 1055 AND post_status NOT IN $ps_cond 1056 AND post_date_gmt != '0000-00-00 00:00:00' 1057 GROUP BY id 1058 UNION 1059 SELECT pm.meta_value AS sub_id, 1060 pm.post_id AS order_id, 1061 pm.meta_key AS meta_key 1062 FROM {$wpdb->prefix}postmeta AS pm 1063 JOIN {$wpdb->prefix}posts AS p ON (pm.post_id = p.id 1064 AND p.post_type = 'shop_order' 1065 AND p.post_parent = 0) 1066 WHERE pm.meta_key IN ('_subscription_renewal') 1067 AND pm.post_id IN (" . implode( ',', $order_ids ) . ") 1068 AND p.post_status NOT IN $ps_cond 1069 AND p.post_date_gmt != '0000-00-00 00:00:00' 1070 GROUP BY pm.meta_value, pm.post_id", 1071 'ARRAY_A' 1072 ); // WPCS: cache ok, db call ok. 1191 if ( $this->is_hpos_enabled ) { 1192 $results = $this->wpdb1->get_results( 1193 "SELECT id AS sub_id, 1194 parent_order_id AS order_id, 1195 '' AS meta_key 1196 FROM {$wpdb->prefix}wc_orders 1197 WHERE type = 'shop_subscription' 1198 AND parent_order_id IN (" . implode( ',', $order_ids ) . ") 1199 AND status NOT IN $ps_cond 1200 AND date_created_gmt != '0000-00-00 00:00:00' 1201 GROUP BY id 1202 UNION 1203 SELECT om.meta_value AS sub_id, 1204 om.order_id AS order_id, 1205 om.meta_key AS meta_key 1206 FROM {$wpdb->prefix}wc_orders_meta AS om 1207 JOIN {$wpdb->prefix}wc_orders AS o ON (om.order_id = o.id 1208 AND o.type = 'shop_order' 1209 AND o.parent_order_id = 0 1210 AND om.meta_key = '_subscription_renewal') 1211 WHERE om.order_id IN (" . implode( ',', $order_ids ) . ") 1212 AND o.status NOT IN $ps_cond 1213 AND o.date_created_gmt != '0000-00-00 00:00:00' 1214 GROUP BY om.meta_value, om.order_id", 1215 'ARRAY_A' 1216 ); // WPCS: cache ok, db call ok. 1217 } else { 1218 $results = $this->wpdb1->get_results( 1219 "SELECT id AS sub_id, 1220 post_parent AS order_id, 1221 '' AS meta_key 1222 FROM {$wpdb->prefix}posts 1223 WHERE post_type = 'shop_subscription' 1224 AND post_parent IN (" . implode( ',', $order_ids ) . ") 1225 AND post_status NOT IN $ps_cond 1226 AND post_date_gmt != '0000-00-00 00:00:00' 1227 GROUP BY id 1228 UNION 1229 SELECT pm.meta_value AS sub_id, 1230 pm.post_id AS order_id, 1231 pm.meta_key AS meta_key 1232 FROM {$wpdb->prefix}postmeta AS pm 1233 JOIN {$wpdb->prefix}posts AS p ON (pm.post_id = p.id 1234 AND p.post_type = 'shop_order' 1235 AND p.post_parent = 0 1236 AND pm.meta_key = '_subscription_renewal') 1237 WHERE pm.post_id IN (" . implode( ',', $order_ids ) . ") 1238 AND p.post_status NOT IN $ps_cond 1239 AND p.post_date_gmt != '0000-00-00 00:00:00' 1240 GROUP BY pm.meta_value, pm.post_id", 1241 'ARRAY_A' 1242 ); // WPCS: cache ok, db call ok. 1243 } 1073 1244 1074 1245 $trashed_sub_o_ids = array(); // to store sub_ids whose order has been trashed. … … 1076 1247 // Code to merge all modified subscriptions & Renewal Subscriptions. 1077 1248 1078 if ( count( $results ) > 0 ) {1249 if ( ! empty( $results ) && count( $results ) > 0 ) { 1079 1250 foreach ( $results as $result ) { 1080 1251 … … 1118 1289 ); // WPCS: cache ok, db call ok. 1119 1290 1120 if ( count( $results ) > 0 ) {1291 if ( ! empty( $results ) && count( $results ) > 0 ) { 1121 1292 foreach ( $results as $result ) { 1122 1293 if ( ! isset( $sub_details[ $result['sub_id'] ] ) && empty( $params['order_id'] ) ) { … … 1181 1352 ); // WPCS: cache ok, db call ok. 1182 1353 1183 if ( count( $results ) > 0 ) {1354 if ( ! empty( $results ) && count( $results ) > 0 ) { 1184 1355 1185 1356 foreach ( $item_details as $order_id => &$item_detail ) { … … 1207 1378 if ( ! empty( $sub_o_ids ) ) { 1208 1379 1209 $o_ids = array_keys( $sub_o_ids ); 1210 $results = $this->wpdb1->get_results( 1211 "SELECT post_id as id, 1212 meta_value as mvalue, 1213 meta_key as mkey 1214 FROM {$wpdb->prefix}postmeta 1215 WHERE post_id IN (" . implode( ',', $o_ids ) . ") 1216 AND meta_key IN ('_billing_first_name', '_billing_last_name', '_order_currency', '_billing_email', 'Stripe Fee', '_stripe_fee') 1217 GROUP BY id,meta_key", 1218 'ARRAY_A' 1219 ); // WPCS: cache ok, db call ok. 1220 1221 if ( count( $results ) > 0 ) { 1380 $o_ids = array_keys( $sub_o_ids ); 1381 if ( $this->is_hpos_enabled ) { 1382 $results = $this->wpdb1->get_results( 1383 "SELECT order_id as id, 1384 meta_value as mvalue, 1385 meta_key as mkey 1386 FROM {$wpdb->prefix}wc_orders_meta 1387 WHERE order_id IN (" . implode( ',', $o_ids ) . ") 1388 AND meta_key IN ('Stripe Fee', '_stripe_fee') 1389 GROUP BY id,meta_key", 1390 'ARRAY_A' 1391 ); // WPCS: cache ok, db call ok. 1392 } else { 1393 $results = $this->wpdb1->get_results( 1394 "SELECT post_id as id, 1395 meta_value as mvalue, 1396 meta_key as mkey 1397 FROM {$wpdb->prefix}postmeta 1398 WHERE post_id IN (" . implode( ',', $o_ids ) . ") 1399 AND meta_key IN ('_billing_first_name', '_billing_last_name', '_order_currency', '_billing_email', 'Stripe Fee', '_stripe_fee') 1400 GROUP BY id,meta_key", 1401 'ARRAY_A' 1402 ); // WPCS: cache ok, db call ok. 1403 } 1404 1405 if ( ! empty( $results ) && count( $results ) > 0 ) { 1222 1406 1223 1407 foreach ( $results as $result ) { … … 1241 1425 1242 1426 // Code for checking if the billing info is blank for the subs. 1243 $sub_o_id = array_search( $sub_id, $sub_o_ids, true ); 1427 $sub_o_id = array_search( $sub_id, $sub_o_ids, true ); 1428 $stripe_fee = ( ! empty( $sub_details[ $sub_id ]['Stripe Fee'] ) ) ? $sub_details[ $sub_id ]['Stripe Fee'] : ''; 1244 1429 1245 1430 $sub_details[ $sub_id ]['_billing_first_name'] = ( empty( $sub_details[ $sub_id ]['_billing_first_name'] ) && ! empty( $sub_o_id ) ) ? $sub_order_details[ $sub_o_id ]['_billing_first_name'] : $sub_details[ $sub_id ]['_billing_first_name']; … … 1247 1432 $sub_details[ $sub_id ]['_order_currency'] = ( empty( $sub_details[ $sub_id ]['_order_currency'] ) && ! empty( $sub_o_id ) ) ? $sub_order_details[ $sub_o_id ]['_order_currency'] : $sub_details[ $sub_id ]['_order_currency']; 1248 1433 $sub_details[ $sub_id ]['_billing_email'] = ( empty( $sub_details[ $sub_id ]['_billing_email'] ) && ! empty( $sub_o_id ) ) ? $sub_order_details[ $sub_o_id ]['_billing_email'] : $sub_details[ $sub_id ]['_billing_email']; 1249 $sub_details[ $sub_id ]['Stripe Fee'] = ( empty( $s ub_details[ $sub_id ]['Stripe Fee'] ) && ! empty( $sub_o_id ) ) ? $sub_order_details[ $sub_o_id ]['Stripe Fee'] : $sub_details[ $sub_id ]['Stripe Fee'];1250 $sub_details[ $sub_id ]['Stripe Fee'] = ( empty( $sub_details[ $sub_id ]['_stripe_fee'] ) && ! empty( $sub_o_id ) ) ? $sub_order_details[ $sub_o_id ]['_stripe_fee'] : $sub_details[ $sub_id ]['Stripe Fee'];1434 $sub_details[ $sub_id ]['Stripe Fee'] = ( empty( $stripe_fee ) && ! empty( $sub_o_id ) && ! empty( $sub_order_details[ $sub_o_id ]['Stripe Fee'] ) ) ? $sub_order_details[ $sub_o_id ]['Stripe Fee'] : $stripe_fee; 1435 $sub_details[ $sub_id ]['Stripe Fee'] = ( empty( $sub_details[ $sub_id ]['_stripe_fee'] ) && ! empty( $sub_o_id ) && ! empty( $sub_order_details[ $sub_o_id ]['_stripe_fee'] ) ) ? $sub_order_details[ $sub_o_id ]['_stripe_fee'] : $stripe_fee; 1251 1436 1252 1437 // Code for creating 'Recurring Payment' 'Created' transaction for subscriptions. … … 1327 1512 ); // WPCS: cache ok, db call ok. 1328 1513 1329 if ( count( $results ) > 0 ) {1514 if ( ! empty( $results ) && count( $results ) > 0 ) { 1330 1515 foreach ( $results as $result ) { 1331 1516 $meta_values = explode( ' #wpc# ', $result['meta_value'] ); … … 1357 1542 ); // WPCS: cache ok, db call ok. 1358 1543 1359 if ( count( $results ) > 0 ) {1544 if ( ! empty( $results ) && count( $results ) > 0 ) { 1360 1545 foreach ( $results as $result ) { 1361 1546 … … 1413 1598 ); // WPCS: cache ok, db call ok. 1414 1599 1415 if ( count( $results ) > 0 ) {1600 if ( ! empty( $results ) && count( $results ) > 0 ) { 1416 1601 foreach ( $results as $result ) { 1417 1602 if ( ! empty( $result['mkey'] ) && ! empty( $sub_meta_keys[ $result['mkey'] ] ) ) { … … 1431 1616 1432 1617 // code to get sub meta for switch subscriptions. 1433 $results = $this->wpdb1->get_results( 1434 "SELECT pm.meta_value AS sub_id, 1435 MAX(pm.post_id) AS order_id 1436 FROM {$wpdb->prefix}postmeta AS pm 1437 JOIN {$wpdb->prefix}posts AS p ON (p.id = pm.post_id 1438 AND p.post_type = 'shop_order' 1439 AND pm.meta_key = '_subscription_switch') 1440 WHERE p.id IN ( SELECT post_parent FROM {$wpdb->prefix}posts WHERE post_type = 'shop_subscription' AND id IN ( " . implode( ',', $sub_item_ids ) . ' ) ) 1441 GROUP BY sub_id', 1442 ARRAY_A 1443 ); // WPCS: cache ok, db call ok. 1444 1445 if ( count( $results ) > 0 ) { 1618 if ( $this->is_hpos_enabled ) { 1619 $results = $this->wpdb1->get_results( 1620 "SELECT om.meta_value AS sub_id, 1621 MAX(om.order_id) AS order_id 1622 FROM {$wpdb->prefix}wc_orders_meta AS om 1623 JOIN {$wpdb->prefix}wc_orders AS o ON (o.id = om.order_id 1624 AND o.type = 'shop_order' 1625 AND om.meta_key = '_subscription_switch') 1626 WHERE o.id IN ( SELECT parent_order_id FROM {$wpdb->prefix}wc_orders WHERE type = 'shop_subscription' AND id IN ( " . implode( ',', $sub_item_ids ) . ' ) ) 1627 GROUP BY sub_id', 1628 'ARRAY_A' 1629 ); // WPCS: cache ok, db call ok. 1630 } else { 1631 $results = $this->wpdb1->get_results( 1632 "SELECT pm.meta_value AS sub_id, 1633 MAX(pm.post_id) AS order_id 1634 FROM {$wpdb->prefix}postmeta AS pm 1635 JOIN {$wpdb->prefix}posts AS p ON (p.id = pm.post_id 1636 AND p.post_type = 'shop_order' 1637 AND pm.meta_key = '_subscription_switch') 1638 WHERE p.id IN ( SELECT post_parent FROM {$wpdb->prefix}posts WHERE post_type = 'shop_subscription' AND id IN ( " . implode( ',', $sub_item_ids ) . ' ) ) 1639 GROUP BY sub_id', 1640 'ARRAY_A' 1641 ); // WPCS: cache ok, db call ok. 1642 } 1643 1644 if ( ! empty( $results ) && count( $results ) > 0 ) { 1446 1645 foreach ( $results as $result ) { 1447 1646 $sub_renewal_id[ $result['order_id'] ] = $result['sub_id']; … … 1457 1656 AND id IN ( " . implode( ',', $sub_item_ids ) . ' ) 1458 1657 GROUP BY sub_id', 1459 ARRAY_A1658 'ARRAY_A' 1460 1659 ); // WPCS: cache ok, db call ok. 1461 1660 1462 if ( count( $results ) > 0 ) {1661 if ( ! empty( $results ) && count( $results ) > 0 ) { 1463 1662 foreach ( $results as $result ) { 1464 1663 $sub_parent_id[ $result['sub_id'] ] = $result['order_id']; … … 1468 1667 1469 1668 // Query to get the Order Details. 1470 $results_order_item_details = $this->wpdb1->get_results( 1471 "SELECT post_id as id, 1472 meta_value as mvalue, 1473 meta_key as mkey 1474 FROM {$wpdb->prefix}postmeta 1475 WHERE post_id IN (" . implode( ',', $order_ids ) . ") 1476 AND meta_key NOT IN ('_edit_lock', '_edit_last') 1477 GROUP BY id,meta_key", 1478 'ARRAY_A' 1479 ); // WPCS: cache ok, db call ok. 1669 if ( $this->is_hpos_enabled ) { 1670 $results_order_item_details = $this->wpdb1->get_results( 1671 "SELECT order_id as id, 1672 meta_value as mvalue, 1673 meta_key as mkey 1674 FROM {$wpdb->prefix}wc_orders_meta 1675 WHERE order_id IN (" . implode( ',', $order_ids_hpos ) . ") 1676 AND meta_key NOT IN ('_edit_lock', '_edit_last') 1677 GROUP BY id,meta_key", 1678 'ARRAY_A' 1679 ); // WPCS: cache ok, db call ok. 1680 } else { 1681 $results_order_item_details = $this->wpdb1->get_results( 1682 "SELECT post_id as id, 1683 meta_value as mvalue, 1684 meta_key as mkey 1685 FROM {$wpdb->prefix}postmeta 1686 WHERE post_id IN (" . implode( ',', $order_ids ) . ") 1687 AND meta_key NOT IN ('_edit_lock', '_edit_last') 1688 GROUP BY id,meta_key", 1689 'ARRAY_A' 1690 ); // WPCS: cache ok, db call ok. 1691 } 1692 1480 1693 $results_order_item_details_count = $wpdb->num_rows; 1481 1694 … … 1502 1715 $sub_trans = false; // flag for handling subscription transactions. 1503 1716 1504 $order_id = ( ! empty( $params['refund_parent_id'] ) ) ? $params['refund_parent_id'] : ( ( 'shop_order_refund' === $order_detail['type'] ) ? $man_refund_ids[ $order_detail['id'] ] : $order_detail['id'] ); 1505 $order_total = ( ! empty( $params['refund_parent_id'] ) || 'shop_order_refund' === $order_detail['type'] ) ? round( get_post_meta( $order_detail['id'], '_refund_amount', true ), 2 ) : round( $order_items[ $order_id ]['_order_total'], 2 ); 1506 $date_in_gmt = $order_detail['formatted_modified_gmt_date']; 1507 $time_in_gmt = $order_detail['formatted_modified_gmt_time']; 1717 $order_id = ( ! empty( $params['refund_parent_id'] ) ) ? $params['refund_parent_id'] : ( ( 'shop_order_refund' === $order_detail['type'] ) ? $man_refund_ids[ $order_detail['id'] ] : $order_detail['id'] ); 1718 if ( ( ( ! empty( $params['refund_parent_id'] ) || 'shop_order_refund' === $order_detail['type'] ) ) && ! $this->is_hpos_enabled ) { 1719 $refund_amount = get_post_meta( $order_detail['id'], '_refund_amount', true ); 1720 $order_total = is_numeric( $refund_amount ) ? round( floatval( $refund_amount ), 2 ) : 0.00; 1721 } else { 1722 $order_total = ( ! empty( $order_items[ $order_id ] ) && ! empty( $order_items[ $order_id ]['_order_total'] ) && is_numeric( $order_items[ $order_id ]['_order_total'] ) ) ? round( floatval( $order_items[ $order_id ]['_order_total'] ), 2 ) : 0.00; 1723 } 1724 $date_in_gmt = $order_detail['formatted_gmt_date']; 1725 $time_in_gmt = $order_detail['formatted_gmt_time']; 1508 1726 1509 1727 if ( defined( 'WPC_IS_WOO22' ) && 'true' === WPC_IS_WOO22 ) { 1510 1728 $order_status_new = ( ! empty( $order_detail['order_status'] ) ) ? ( ( 'wc-' === substr( $order_detail['order_status'], 0, 3 ) ) ? substr( $order_detail['order_status'], 3 ) : $order_detail['order_status'] ) : ''; 1511 } else {1512 $order_status_new = ( ! empty( $order_status[ $order_detail['term_taxonomy_id'] ] ) ) ? $order_status[ $order_detail['term_taxonomy_id'] ] : '';1513 1729 } 1514 1730 … … 1547 1763 1548 1764 $response ['Source'] = $this->name; 1549 $response ['Name'] = $order_items[ $order_id ]['_billing_first_name'] . ' ' . $order_items[ $order_id ]['_billing_last_name']; 1765 $response ['Name'] = ( ! empty( $order_items[ $order_id ]['_billing_first_name'] ) ) ? $order_items[ $order_id ]['_billing_first_name'] : ''; 1766 $response ['Name'] .= ( ! empty( $order_items[ $order_id ]['_billing_last_name'] ) ) ? ' ' . $order_items[ $order_id ]['_billing_last_name'] : ''; 1550 1767 $response ['Type'] = 'Shopping Cart Payment Received'; 1551 1768 $response ['Status'] = ucfirst( $order_status_display ); 1552 $response ['Currency'] = $order_items[ $order_id ]['_order_currency'];1769 $response ['Currency'] = ( ! empty( $order_items[ $order_id ]['_order_currency'] ) ) ? $order_items[ $order_id ]['_order_currency'] : ''; 1553 1770 $response ['Gross'] = $order_total; 1554 1771 $response ['Fee'] = ( ! empty( $order_items[ $order_id ]['Stripe Fee'] ) ) ? $order_items[ $order_id ]['Stripe Fee'] : 0.00; 1555 1772 $response ['Fee'] = ( empty( $response ['Fee'] ) && ! empty( $order_items[ $order_id ]['_stripe_fee'] ) ) ? $order_items[ $order_id ]['_stripe_fee'] : 0.00; 1556 1773 $response ['Net'] = $order_total; 1557 $response ['From_Email_Address'] = $order_items[ $order_id ]['_billing_email'];1774 $response ['From_Email_Address'] = ( ! empty( $order_items[ $order_id ]['_billing_email'] ) ) ? $order_items[ $order_id ]['_billing_email'] : ''; 1558 1775 $response ['To_Email_Address'] = ''; 1559 1776 $response ['Transaction_ID'] = $order_id; … … 1562 1779 $response ['Item_Title'] = 'Shopping Cart'; 1563 1780 $response ['Item_ID'] = 0; // Set to 0 for main Order Transaction row. 1564 $response ['Shipping_and_Handling_Amount'] = ( isset( $order_items[ $order_id ]['_order_shipping'] ) && ( empty( $params['refund_parent_id'] ) && 'shop_order_refund' !== $order_detail['type'] ) ) ? round( $order_items[ $order_id ]['_order_shipping'], 2 ) : 0.00;1781 $response ['Shipping_and_Handling_Amount'] = ( isset( $order_items[ $order_id ]['_order_shipping'] ) && ( empty( $params['refund_parent_id'] ) && 'shop_order_refund' !== $order_detail['type'] ) && is_numeric( $order_items[ $order_id ]['_order_shipping'] ) ) ? round( floatval( $order_items[ $order_id ]['_order_shipping'] ), 2 ) : 0.00; 1565 1782 $response ['Insurance_Amount'] = ''; 1566 $response ['Discount'] = ( isset( $order_items[ $order_id ]['_order_discount'] ) && ( empty( $params['refund_parent_id'] ) && $order_detail['type'] ) ) ? round( $order_items[ $order_id ]['_order_discount'], 2 ) : 0.00;1567 $response ['Discount'] += ( isset( $order_items[ $order_id ]['_cart_discount'] ) && ( empty( $params['refund_parent_id'] ) && 'shop_order_refund' !== $order_detail['type'] ) ) ? round( $order_items[ $order_id ]['_cart_discount'], 2 ) : 0.00;1568 $response ['Sales_Tax'] = ( isset( $order_items[ $order_id ]['_order_tax'] ) && ( empty( $params['refund_parent_id'] ) && 'shop_order_refund' !== $order_detail['type'] ) ) ? round( $order_items[ $order_id ]['_order_tax'], 2 ) : 0.00;1783 $response ['Discount'] = ( isset( $order_items[ $order_id ]['_order_discount'] ) && ( empty( $params['refund_parent_id'] ) && $order_detail['type'] ) && is_numeric( $order_items[ $order_id ]['_order_discount'] ) ) ? round( floatval( $order_items[ $order_id ]['_order_discount'] ), 2 ) : 0.00; 1784 $response ['Discount'] += ( isset( $order_items[ $order_id ]['_cart_discount'] ) && ( empty( $params['refund_parent_id'] ) && 'shop_order_refund' !== $order_detail['type'] ) && is_numeric( $order_items[ $order_id ]['_cart_discount'] ) ) ? round( floatval( $order_items[ $order_id ]['_cart_discount'] ), 2 ) : 0.00; 1785 $response ['Sales_Tax'] = ( isset( $order_items[ $order_id ]['_order_tax'] ) && ( empty( $params['refund_parent_id'] ) && 'shop_order_refund' !== $order_detail['type'] ) && is_numeric( $order_items[ $order_id ]['_order_tax'] ) ) ? round( floatval( $order_items[ $order_id ]['_order_tax'] ), 2 ) : 0.00; 1569 1786 $response ['Option_1_Name'] = ''; 1570 1787 $response ['Option_1_Value'] = ''; … … 1583 1800 $response ['Receipt_ID'] = ''; 1584 1801 $response ['Balance'] = ''; 1585 $response ['Note'] = $order_detail['order_note'];1802 $response ['Note'] = ( ! empty( $order_detail['order_note'] ) ) ? $order_detail['order_note'] : ''; 1586 1803 $response ['Address_Line_1'] = ( ! empty( $order_items[ $order_id ]['_billing_address_1'] ) ) ? $order_items[ $order_id ]['_billing_address_1'] : ''; 1587 1804 $response ['Address_Line_2'] = ! empty( $order_items[ $order_id ]['_billing_address_2'] ) ? $order_items[ $order_id ]['_billing_address_2'] : ''; 1588 1805 $response ['Town_City'] = ! empty( $order_items[ $order_id ]['_billing_city'] ) ? $order_items[ $order_id ]['_billing_city'] : ''; 1589 $response ['State_Province'] = $order_items[ $order_id ]['_billing_state'];1806 $response ['State_Province'] = ! empty( $order_items[ $order_id ]['_billing_state'] ) ? $order_items[ $order_id ]['_billing_state'] : ''; 1590 1807 $response ['Zip_Postal_Code'] = ! empty( $order_items[ $order_id ]['_billing_postcode'] ) ? $order_items[ $order_id ]['_billing_postcode'] : ''; 1591 1808 $response ['Country'] = ! empty( $order_items[ $order_id ]['_billing_country'] ) ? $order_items[ $order_id ]['_billing_country'] : ''; … … 1596 1813 if ( ! empty( $item_details[ $order_id ]['coupons'] ) ) { 1597 1814 foreach ( $item_details[ $order_id ]['coupons'] as $key => &$value ) { 1598 $coupon_data[ $key ]['amt'] = ( ! empty( $value['amt'] ) ) ? round( $value['amt'], 2 ) : 0.00;1815 $coupon_data[ $key ]['amt'] = ( ! empty( $value['amt'] ) && is_numeric( $value['amt'] ) ) ? round( floatval( $value['amt'] ), 2 ) : 0.00; 1599 1816 $value = ( ! empty( $coupon_data[ $key ] ) ) ? $coupon_data[ $key ] : $value; 1600 1817 } … … 1702 1919 $sub = ( ! empty( $item_details[ $order_id ]['subscriptions'] ) ) ? $item_details[ $order_id ]['subscriptions'] : array(); 1703 1920 1921 if ( $this->is_hpos_enabled ) { 1922 $temp_order_id = $order_id; 1923 $response ['IP_Address'] = ( ! empty( $order_detail['ip_address'] ) ) ? $order_detail['ip_address'] : ''; 1924 $response ['Shipping_and_Handling_Amount'] = ( ! empty( $order_stats[ $temp_order_id ]['shipping_total'] ) && is_numeric( $order_stats[ $temp_order_id ]['shipping_total'] ) ) ? round( floatval( $order_stats[ $temp_order_id ]['shipping_total'] ), 2 ) : 0.00; 1925 $response ['Discount'] = ( ! empty( $discounts[ $temp_order_id ]['total_discount'] ) && is_numeric( $discounts[ $temp_order_id ]['total_discount'] ) ) ? round( floatval( $discounts[ $temp_order_id ]['total_discount'] ), 2 ) : 0.00; 1926 1927 if ( 'shop_order_refund' === $order_detail['type'] ) { 1928 $temp_order_id = ( isset( $order_detail['parent_id'] ) && $order_detail['parent_id'] ) ? $order_detail['parent_id'] : $order_id; 1929 $order_total = ( ! empty( $order_items[ $order_detail['id'] ]['_refund_amount'] ) && is_numeric( $order_items[ $order_detail['id'] ]['_refund_amount'] ) ) ? round( floatval( $order_items[ $order_detail['id'] ]['_refund_amount'] ), 2 ) : 0.00; 1930 $response ['Shipping_and_Handling_Amount'] = ( ! empty( $order_stats[ $order_detail['id'] ]['shipping_total'] ) && is_numeric( $order_stats[ $order_detail['id'] ]['shipping_total'] ) ) ? round( floatval( $order_stats[ $order_detail['id'] ]['shipping_total'] ), 2 ) : 0.00; 1931 $response ['Discount'] = ( ! empty( $discounts[ $order_detail['id'] ]['total_discount'] ) && is_numeric( $discounts[ $order_detail['id'] ]['total_discount'] ) ) ? round( floatval( $discounts[ $order_detail['id'] ]['total_discount'] ), 2 ) : 0.00; 1932 if ( ! $response ['IP_Address'] ) { 1933 $parent_order = array_filter( 1934 $results_order_details, 1935 function ( $item ) use ( $order_detail ) { 1936 return $item['id'] === $order_detail['parent_id']; 1937 } 1938 ); 1939 $parent_order = reset( $parent_order ); 1940 $response ['IP_Address'] = ( ! empty( $parent_order['ip_address'] ) ) ? $parent_order['ip_address'] : ''; 1941 } 1942 } 1943 $response ['Name'] = ( ! empty( $billing_address[ $temp_order_id ]['first_name'] ) ) ? $billing_address[ $temp_order_id ]['first_name'] : ''; 1944 $response ['Name'] .= ( ! empty( $billing_address[ $temp_order_id ]['last_name'] ) ) ? ' ' . $billing_address[ $temp_order_id ]['last_name'] : ''; 1945 $response ['Currency'] = ( ! empty( $order_detail['currency'] ) ) ? $order_detail['currency'] : ''; 1946 $response ['Gross'] = ( ! empty( $order_stats[ $temp_order_id ]['total_sales'] ) && is_numeric( $order_stats[ $temp_order_id ]['total_sales'] ) ) ? round( floatval( $order_stats[ $temp_order_id ]['total_sales'] ), 2 ) : 0.00; 1947 $response ['Net'] = $response ['Gross']; 1948 $response ['From_Email_Address'] = ( ! empty( $billing_address[ $temp_order_id ]['billing_email'] ) ) ? $billing_address[ $temp_order_id ]['billing_email'] : null; 1949 $response ['Address_Line_1'] = ( ! empty( $billing_address[ $temp_order_id ]['address_1'] ) ) ? $billing_address[ $temp_order_id ]['address_1'] : ''; 1950 $response ['Address_Line_2'] = ( ! empty( $billing_address[ $temp_order_id ]['address_2'] ) ) ? $billing_address[ $temp_order_id ]['address_2'] : ''; 1951 $response ['Town_City'] = ( ! empty( $billing_address[ $temp_order_id ]['city'] ) ) ? $billing_address[ $temp_order_id ]['city'] : ''; 1952 $response ['State_Province'] = ( ! empty( $billing_address[ $temp_order_id ]['state'] ) ) ? $billing_address[ $temp_order_id ]['state'] : ''; 1953 $response ['Zip_Postal_Code'] = ( ! empty( $billing_address[ $temp_order_id ]['postcode'] ) ) ? $billing_address[ $temp_order_id ]['postcode'] : ''; 1954 $response ['Country'] = ( ! empty( $billing_address[ $temp_order_id ]['country'] ) ) ? $billing_address[ $temp_order_id ]['country'] : ''; 1955 $response ['Contact_Phone_Number'] = ( ! empty( $billing_address[ $temp_order_id ]['phone'] ) ) ? $billing_address[ $temp_order_id ]['phone'] : ''; 1956 $response ['Payment_Source'] = ( ! empty( $order_detail['payment_method'] ) ) ? $order_detail['payment_method'] : ''; 1957 $response ['External_Trans_ID'] = ( ! empty( $order_detail['transaction_id'] ) ) ? $order_detail['transaction_id'] : ''; 1958 1959 } 1960 1704 1961 if ( ( ! empty( $params['order_id'] ) && ( 'refunded' === $order_status_new || ! empty( $params ['refund_parent_id'] ) ) ) || 1705 1962 ( empty( $params['order_id'] ) && 'shop_order_refund' === $order_detail['type'] ) ) { … … 1711 1968 } 1712 1969 1713 $response ['Date'] = $order_detail['formatted_modified_gmt_date']; 1714 1715 $response ['Time'] = $order_detail['formatted_modified_gmt_time']; 1716 1717 $response ['Type'] = 'Refund'; 1718 $response ['Status'] = 'Completed'; 1719 $response ['Auction_Site'] = ''; 1720 $response ['Item_Title'] = 'Unknown'; 1721 1722 $response ['Gross'] = - $order_total; // for handling partial & full refunds. 1723 $response ['Net'] = - $order_total; 1724 1970 $response ['Date'] = $order_detail['formatted_modified_gmt_date']; 1971 $response ['Time'] = $order_detail['formatted_modified_gmt_time']; 1972 $response ['Type'] = 'Refund'; 1973 $response ['Status'] = 'Completed'; 1974 $response ['Auction_Site'] = ''; 1975 $response ['Item_Title'] = 'Unknown'; 1976 $response ['Gross'] = - $order_total; // for handling partial & full refunds. 1977 $response ['Net'] = - $order_total; 1725 1978 $response ['Transaction_ID'] = ( ( ! empty( $params ['refund_parent_id'] ) || 'shop_order_refund' === $order_detail['type'] ) && ! empty( $refund_id ) ) ? $order_id . '_R_' . $refund_id : $order_id . '_R'; 1726 1979 $response ['Reference_Txn_ID'] = $order_id; … … 1756 2009 } 1757 2010 1758 $order_item ['Gross'] = ( false === $sub_trans && 'Refund' !== $response ['Type'] ) ? round( $cart_item['_line_total'], 2 ) : $response ['Gross'];2011 $order_item ['Gross'] = ( false === $sub_trans && 'Refund' !== $response ['Type'] && is_numeric( $cart_item['_line_total'] ) ) ? round( floatval( $cart_item['_line_total'] ), 2 ) : $response ['Gross']; 1759 2012 $order_item ['Quantity'] = $cart_item['_qty']; 1760 2013 … … 1818 2071 ); // WPCS: cache ok, db call ok. 1819 2072 1820 if ( count( $results ) > 0 ) {2073 if ( ! empty( $results ) && count( $results ) > 0 ) { 1821 2074 foreach ( $results as $result ) { 1822 2075 … … 1830 2083 } 1831 2084 1832 $order_count = ( is_array( $results_order_details ) ) ? count( $results_order_details ) : 0;2085 $order_count = ( ! empty( $results_order_details ) && is_array( $results_order_details ) ) ? count( $results_order_details ) : 0; 1833 2086 $data = ( ! empty( $transactions ) ) ? $transactions : array(); 1834 2087 $data = ( ! empty( $sub_transactions ) ) ? array_merge( $data, $sub_transactions ) : $data; … … 1844 2097 return $params; 1845 2098 } 2099 2100 /** 2101 * Function to format the date. 2102 * 2103 * @param string $date Date string. 2104 * @param string $format Format string. 2105 * 2106 * @return string The formatted date. 2107 */ 2108 private function format_date_time( $date, $format = 'm/d/Y H:i:s' ) { 2109 $date_time = new DateTime( $date ); 2110 if ( 'U' === $format || 'G' === $format ) { 2111 $time = $date_time->getTimestamp(); 2112 } else { 2113 $time = $date_time->format( $format ); 2114 } 2115 return $time; 2116 } 2117 2118 /** 2119 * Function to check HPOS enabled. 2120 */ 2121 public static function is_hpos_enabled() { 2122 return ( class_exists( 'Automattic\WooCommerce\Utilities\OrderUtil' ) && is_callable( array( '\Automattic\WooCommerce\Utilities\OrderUtil', 'custom_orders_table_usage_is_enabled' ) ) ) ? \Automattic\WooCommerce\Utilities\OrderUtil::custom_orders_table_usage_is_enabled() : false; 2123 } 2124 2125 /** 2126 * Function to declare WooCommerce HPOS compatibility. 2127 */ 2128 public function declare_hpos_compatibility() { 2129 if ( class_exists( \Automattic\WooCommerce\Utilities\FeaturesUtil::class ) ) { 2130 \Automattic\WooCommerce\Utilities\FeaturesUtil::declare_compatibility( 'custom_order_tables', 'woocommerce-putler-connector/woocommerce-putler-connector.php', true ); 2131 } 2132 } 2133 1846 2134 } 1847 2135 } -
woocommerce-putler-connector/trunk/languages/woocommerce-putler-connector.pot
r2847386 r2945562 3 3 msgid "" 4 4 msgstr "" 5 "Project-Id-Version: Putler Connector for WooCommerce - Accurate Analytics and Reports for your WooCommerce Store 2.1 1.2\n"6 "Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/woocommerce-putler-connector -plugin\n"5 "Project-Id-Version: Putler Connector for WooCommerce - Accurate Analytics and Reports for your WooCommerce Store 2.12.0\n" 6 "Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/woocommerce-putler-connector\n" 7 7 "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" 8 8 "Language-Team: LANGUAGE <[email protected]>\n" … … 10 10 "Content-Type: text/plain; charset=UTF-8\n" 11 11 "Content-Transfer-Encoding: 8bit\n" 12 "POT-Creation-Date: 2023-0 1-12T17:49:28+05:30\n"12 "POT-Creation-Date: 2023-07-31T20:36:51+05:30\n" 13 13 "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" 14 "X-Generator: WP-CLI 2. 6.0\n"14 "X-Generator: WP-CLI 2.8.1\n" 15 15 "X-Domain: woocommerce-putler-connector\n" 16 16 … … 36 36 37 37 #. translators: Putler URL 38 #: classes/class-putler-connector.php:16 238 #: classes/class-putler-connector.php:163 39 39 msgid "Putler Connector for Putler desktop has deprecated. Please upgrade to <strong><a href=\"%s\" target=\"_blank\">Putler Web</a></strong>." 40 40 msgstr "" 41 41 42 #: classes/class-putler-connector.php:20 243 #: classes/class-putler-connector.php:29 344 #: classes/class-putler-connector.php:42 742 #: classes/class-putler-connector.php:203 43 #: classes/class-putler-connector.php:294 44 #: classes/class-putler-connector.php:428 45 45 msgid "Putler Connector" 46 46 msgstr "" 47 47 48 #: classes/class-putler-connector.php:21 648 #: classes/class-putler-connector.php:217 49 49 msgid "Putler is connected" 50 50 msgstr "" 51 51 52 #: classes/class-putler-connector.php:25 052 #: classes/class-putler-connector.php:251 53 53 msgid " & last sync date was " 54 54 msgstr "" 55 55 56 #: classes/class-putler-connector.php:25 256 #: classes/class-putler-connector.php:253 57 57 msgid " & No orders have been synced yet." 58 58 msgstr "" 59 59 60 #: classes/class-putler-connector.php:26 160 #: classes/class-putler-connector.php:262 61 61 msgid "Trying to Connect to Putler..." 62 62 msgstr "" 63 63 64 #: classes/class-putler-connector.php:28 264 #: classes/class-putler-connector.php:283 65 65 msgid "Your transactions are getting synced with Putler. Please check after some time." 66 66 msgstr "" 67 67 68 #: classes/class-putler-connector.php:28 468 #: classes/class-putler-connector.php:285 69 69 msgid "Your resync request is under process and your transactions will be resynced soon." 70 70 msgstr "" 71 71 72 #: classes/class-putler-connector.php:28 772 #: classes/class-putler-connector.php:288 73 73 msgid "Resync Data" 74 74 msgstr "" 75 75 76 #: classes/class-putler-connector.php:33 876 #: classes/class-putler-connector.php:339 77 77 msgid "Successfully Authenticated!!!" 78 78 msgstr "" 79 79 80 #: classes/class-putler-connector.php:40 080 #: classes/class-putler-connector.php:401 81 81 msgid "Authenticating..." 82 82 msgstr "" 83 83 84 #: classes/class-putler-connector.php:46 085 #: classes/class-putler-connector.php:46 386 #: classes/class-putler-connector.php:4 6987 #: classes/class-putler-connector.php:57 188 #: classes/class-putler-connector.php:57 589 #: classes/class-putler-connector.php:58 390 #: classes/class-putler-connector.php:64 591 #: classes/class-putler-connector.php:6 4992 #: classes/class-putler-connector.php:65 784 #: classes/class-putler-connector.php:461 85 #: classes/class-putler-connector.php:464 86 #: classes/class-putler-connector.php:470 87 #: classes/class-putler-connector.php:572 88 #: classes/class-putler-connector.php:576 89 #: classes/class-putler-connector.php:584 90 #: classes/class-putler-connector.php:646 91 #: classes/class-putler-connector.php:650 92 #: classes/class-putler-connector.php:658 93 93 msgid "Authentication Failed." 94 94 msgstr "" 95 95 96 96 #. translators: %s: Name of ecommerce gateway 97 #: classes/class-putler-connector.php:46 097 #: classes/class-putler-connector.php:461 98 98 msgid "Please make sure that you have added an %s account in Putler. If you do not have a Putler account, you can create one for free and enjoy trial for 14 days." 99 99 msgstr "" 100 100 101 101 #. translators: %s: Name of ecommerce gateway 102 #: classes/class-putler-connector.php:46 0102 #: classes/class-putler-connector.php:461 103 103 msgid "Try Putler for free!" 104 104 msgstr "" 105 105 106 106 #. translators: %s: Name of ecommerce gateway 107 #: classes/class-putler-connector.php:46 0107 #: classes/class-putler-connector.php:461 108 108 msgid "Once the %s account has been added successfully, please click " 109 109 msgstr "" 110 110 111 111 #. translators: %s: Name of ecommerce gateway 112 #: classes/class-putler-connector.php:46 0112 #: classes/class-putler-connector.php:461 113 113 msgid "here" 114 114 msgstr "" 115 115 116 #: classes/class-putler-connector.php:46 3116 #: classes/class-putler-connector.php:464 117 117 msgid "You would need to reset the account in " 118 118 msgstr "" 119 119 120 #: classes/class-putler-connector.php:46 3120 #: classes/class-putler-connector.php:464 121 121 msgid "Putler Web " 122 122 msgstr "" 123 123 124 #: classes/class-putler-connector.php:55 0125 #: classes/class-putler-connector.php:60 6124 #: classes/class-putler-connector.php:551 125 #: classes/class-putler-connector.php:607 126 126 msgid "Authentication Successful" 127 127 msgstr "" 128 128 129 #: classes/class-putler-connector.php:58 1130 #: classes/class-putler-connector.php:65 5131 #: classes/class-putler-connector.php:80 0129 #: classes/class-putler-connector.php:582 130 #: classes/class-putler-connector.php:656 131 #: classes/class-putler-connector.php:801 132 132 msgid "Authentication Failure" 133 133 msgstr "" 134 134 135 #: classes/class-putler-connector.php:8 09135 #: classes/class-putler-connector.php:810 136 136 msgid "Params Missing" 137 137 msgstr "" -
woocommerce-putler-connector/trunk/readme.txt
r2847395 r2945562 6 6 Tags: WooCommerce reports, WooCommerce analytics, e-Commerce reports, SaaS metrics, Subscription analytics, business reports, store analytics, store reports, sales forecasting, customer segmentation, Google analytics reports 7 7 Requires at least: 4.8.0 8 Tested up to: 6. 1.18 Tested up to: 6.2.2 9 9 Requires PHP: 5.6 10 Stable tag: 2.1 1.210 Stable tag: 2.12.0 11 11 License: GPL 3.0 12 12 … … 172 172 == Changelog == 173 173 174 = 2.12.0 (31.07.2023) = 175 * New: Declare Putler Connector for WooCommerce compatible with High-Performance Order Storage (HPOS) 176 * New: WordPress v6.2.2 compatible 177 * New: WooCommerce v7.9.0 compatible 178 * Fix: PHP Fatal Error: Uncaught TypeError: round(), count() 179 * Fix: Some minor fixes related to formatted date and Stripe fee 180 * Update: Code improvements 181 * Update: POT file 182 174 183 = 2.11.2 (12.01.2023) = 175 184 * Fix: PHP Error: Call to undefined function in some cases post v2.11.0 … … 308 317 == Upgrade Notice == 309 318 319 = 2.12.0 = 320 Declare Putler Connector for WooCommerce compatible with High-Performance Order Storage (HPOS), WordPress v6.2.2 compatible, WooCommerce v7.9.0 compatible, Fixes related to PHP Fatal Error: Uncaught TypeError: round(), count(), Some minor fixes related to formatted date and Stripe fee along with some important updates and fixes, recommended upgrade. 321 310 322 = 2.11.2 = 311 323 PHP Error: Call to undefined function in some cases post v2.11.0 along with some minor fixes, recommended upgrade. -
woocommerce-putler-connector/trunk/woocommerce-putler-connector.php
r2847386 r2945562 4 4 * Plugin URI: https://putler.com/connector/woocommerce/ 5 5 * Description: Accurate reports, analytics, integrations, growth insights and tools for your WooCommerce store. 6 * Version: 2.1 1.26 * Version: 2.12.0 7 7 * Author: putler, storeapps 8 8 * Author URI: https://putler.com/ … … 10 10 * Domain Path: /languages/ 11 11 * Requires at least: 4.8.0 12 * Tested up to: 6. 1.112 * Tested up to: 6.2.2 13 13 * Requires PHP: 5.6+ 14 * WC requires at least: 2.0.015 * WC tested up to: 7. 0.114 * WC requires at least: 3.0.0 15 * WC tested up to: 7.9.0 16 16 * Copyright (c) 2006 - 2023 Putler. All rights reserved. 17 17 * License: GNU General Public License v3.0 … … 26 26 } 27 27 28 define( 'WPC_VERSION', '2.1 1.2' );28 define( 'WPC_VERSION', '2.12.0' ); 29 29 30 30 // Hooks. … … 145 145 } 146 146 } 147 148 /**149 * Action for WooCommerce v7.1 custom order tables related compatibility.150 */151 add_action(152 'before_woocommerce_init',153 function() {154 if ( class_exists( '\Automattic\WooCommerce\Utilities\FeaturesUtil' ) ) {155 \Automattic\WooCommerce\Utilities\FeaturesUtil::declare_compatibility( 'custom_order_tables', __FILE__, false );156 }157 }158 );
Note: See TracChangeset
for help on using the changeset viewer.