Plugin Directory

Changeset 2945562


Ignore:
Timestamp:
07/31/2023 03:54:02 PM (3 years ago)
Author:
putler
Message:

Changes for v2.12.0

Location:
woocommerce-putler-connector/trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • woocommerce-putler-connector/trunk/classes/class-woocommerce-putler-connector.php

    r2847386 r2945562  
    77 */
    88
     9use Automattic\WooCommerce\Utilities\OrderUtil;
     10
    911// Exit if accessed directly.
    1012if ( ! defined( 'ABSPATH' ) ) {
     
    2729
    2830        /**
     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        /**
    2952         *  Constructor.
    3053         */
     
    3659
    3760            $this->name = ( defined( 'PUTLER_GATEWAY' ) ? PUTLER_GATEWAY : 'WooCommerce' );
     61
     62            $this->is_hpos_enabled = self::is_hpos_enabled();
    3863
    3964            add_filter( 'putler_connector_get_order_count', array( &$this, 'get_order_count' ) );
     
    5176                add_action( 'before_delete_post', array( &$this, 'delete_post' ), 9, 1 );
    5277            }
     78
     79            // Action for WooCommerce v7.1 custom order tables related compatibility.
     80            add_action( 'before_woocommerce_init', array( &$this, 'declare_hpos_compatibility' ) );
    5381        }
    5482
     
    158186            global $wpdb;
    159187
    160             $post_type       = get_post_type( $id );
     188            $post_type       = ( $this->is_hpos_enabled ) ? OrderUtil::get_order_type( $id ) : get_post_type( $id );
    161189            $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 ) ) ) {
    164192                return;
    165193            }
     
    177205            );
    178206
     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
    179213            if ( 'shop_order' === $post_type ) {
    180214
    181215                // 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 ) {
    201255
    202256                    $sub_id = ( ! empty( $results['id'] ) ) ? $results['id'] : '';
     
    220274                        $prod = 0;
    221275
    222                         if ( count( $results ) > 0 ) {
     276                        if ( ! empty( $results ) && count( $results ) > 0 ) {
    223277
    224278                            foreach ( $results as $pid ) {
     
    245299                }
    246300            } 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                }
    248306            }
    249307
     
    263321                    'ARRAY_A'
    264322                );  // WPCS: cache ok, db call ok.
    265                 if ( count( $results ) > 0 ) {
     323                if ( ! empty( $results ) && count( $results ) > 0 ) {
    266324
    267325                    $transient_name = ( ! empty( $results['option_name'] ) ) ? substr( $results['option_name'], 11 ) : '';
     
    355413            if ( ( empty( $params['sub_details'] ) ) ) {
    356414                // 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 ) {
    374450                    foreach ( $results as $result ) {
    375451                        $response ['Date']            = $result['formatted_modified_gmt_date'];
     
    434510                ); // WPCS: cache ok, db call ok.
    435511
    436                 if ( count( $results ) > 0 ) {
     512                if ( ! empty( $results ) && count( $results ) > 0 ) {
    437513
    438514                    $name = '';
     
    512588            $post_order_cond = '';
    513589
    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            }
    524613
    525614            if ( ! empty( $order_count_result ) ) {
     
    557646                // For Handling Refund Transactions.
    558647                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                    }
    568669
    569670                    if ( ! empty( $refund_id ) ) {
     
    578679            // Flag for woo2.2+.
    579680            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';
    583683                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'";
    585685                } 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')";
    615687                }
    616688            }
     
    618690            // Code for handling manual refunds.
    619691            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' ";
    621693            } 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' ";
    623695            } 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') ";
    625697            }
    626698
    627699            // Code to get all subscriptions in the specified date range.
    628 
    629700            $modified_sub_ids     = array();
    630701            $modified_sub_details = array();
     
    653724                ); // WPCS: cache ok, db call ok.
    654725
    655                 if ( count( $results ) > 0 ) {
     726                if ( ! empty( $results ) && count( $results ) > 0 ) {
    656727
    657728                    foreach ( $results as $result ) {
     
    683754                        ); // WPCS: cache ok, db call ok.
    684755
    685                         if ( count( $results ) > 0 ) {
     756                        if ( ! empty( $results ) && count( $results ) > 0 ) {
    686757
    687758                            foreach ( $results as $result ) {
     
    751822            }
    752823
    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            }
    774914            $results_order_details_count = $wpdb->num_rows;
    775915
     
    8951035                    ); // WPCS: cache ok, db call ok.
    8961036
    897                     if ( count( $results ) > 0 ) {
     1037                    if ( ! empty( $results ) && count( $results ) > 0 ) {
    8981038                        foreach ( $results as $result ) {
    8991039                            if ( empty( $coupon_data[ $result['slug'] ] ) ) {
     
    9471087                    ); // WPCS: cache ok, db call ok.
    9481088
    949                     if ( count( $sub_taxonomy_ids ) > 0 ) {
     1089                    if ( ! empty( $sub_taxonomy_ids ) && count( $sub_taxonomy_ids ) > 0 ) {
    9501090                        $sub_item_ids = $this->wpdb1->get_col(
    9511091                            "SELECT tr.object_id AS id
     
    10171157
    10181158                                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                                    }
    10221165                                }
    10231166
     
    10461189
    10471190                    // 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                    }
    10731244
    10741245                    $trashed_sub_o_ids = array(); // to store sub_ids whose order has been trashed.
     
    10761247                    // Code to merge all modified subscriptions & Renewal Subscriptions.
    10771248
    1078                     if ( count( $results ) > 0 ) {
     1249                    if ( ! empty( $results ) && count( $results ) > 0 ) {
    10791250                        foreach ( $results as $result ) {
    10801251
     
    11181289                        ); // WPCS: cache ok, db call ok.
    11191290
    1120                         if ( count( $results ) > 0 ) {
     1291                        if ( ! empty( $results ) && count( $results ) > 0 ) {
    11211292                            foreach ( $results as $result ) {
    11221293                                if ( ! isset( $sub_details[ $result['sub_id'] ] ) && empty( $params['order_id'] ) ) {
     
    11811352                        ); // WPCS: cache ok, db call ok.
    11821353
    1183                         if ( count( $results ) > 0 ) {
     1354                        if ( ! empty( $results ) && count( $results ) > 0 ) {
    11841355
    11851356                            foreach ( $item_details as $order_id => &$item_detail ) {
     
    12071378                            if ( ! empty( $sub_o_ids ) ) {
    12081379
    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 ) {
    12221406
    12231407                                    foreach ( $results as $result ) {
     
    12411425
    12421426                                    // 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'] : '';
    12441429
    12451430                                    $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'];
     
    12471432                                    $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'];
    12481433                                    $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( $sub_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;
    12511436
    12521437                                    // Code for creating 'Recurring Payment' 'Created' transaction for subscriptions.
     
    13271512                            ); // WPCS: cache ok, db call ok.
    13281513
    1329                             if ( count( $results ) > 0 ) {
     1514                            if ( ! empty( $results ) && count( $results ) > 0 ) {
    13301515                                foreach ( $results as $result ) {
    13311516                                    $meta_values = explode( ' #wpc# ', $result['meta_value'] );
     
    13571542                                ); // WPCS: cache ok, db call ok.
    13581543
    1359                                 if ( count( $results ) > 0 ) {
     1544                                if ( ! empty( $results ) && count( $results ) > 0 ) {
    13601545                                    foreach ( $results as $result ) {
    13611546
     
    14131598                    ); // WPCS: cache ok, db call ok.
    14141599
    1415                     if ( count( $results ) > 0 ) {
     1600                    if ( ! empty( $results ) && count( $results ) > 0 ) {
    14161601                        foreach ( $results as $result ) {
    14171602                            if ( ! empty( $result['mkey'] ) && ! empty( $sub_meta_keys[ $result['mkey'] ] ) ) {
     
    14311616
    14321617                    // 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 ) {
    14461645                        foreach ( $results as $result ) {
    14471646                            $sub_renewal_id[ $result['order_id'] ] = $result['sub_id'];
     
    14571656                                                        AND id IN ( " . implode( ',', $sub_item_ids ) . ' )
    14581657                                                    GROUP BY sub_id',
    1459                         ARRAY_A
     1658                        'ARRAY_A'
    14601659                    ); // WPCS: cache ok, db call ok.
    14611660
    1462                     if ( count( $results ) > 0 ) {
     1661                    if ( ! empty( $results ) && count( $results ) > 0 ) {
    14631662                        foreach ( $results as $result ) {
    14641663                            $sub_parent_id[ $result['sub_id'] ] = $result['order_id'];
     
    14681667
    14691668                // 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
    14801693                $results_order_item_details_count = $wpdb->num_rows;
    14811694
     
    15021715                        $sub_trans = false; // flag for handling subscription transactions.
    15031716
    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'];
    15081726
    15091727                        if ( defined( 'WPC_IS_WOO22' ) && 'true' === WPC_IS_WOO22 ) {
    15101728                            $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'] ] : '';
    15131729                        }
    15141730
     
    15471763
    15481764                        $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'] : '';
    15501767                        $response ['Type']                         = 'Shopping Cart Payment Received';
    15511768                        $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'] : '';
    15531770                        $response ['Gross']                        = $order_total;
    15541771                        $response ['Fee']                          = ( ! empty( $order_items[ $order_id ]['Stripe Fee'] ) ) ? $order_items[ $order_id ]['Stripe Fee'] : 0.00;
    15551772                        $response ['Fee']                          = ( empty( $response ['Fee'] ) && ! empty( $order_items[ $order_id ]['_stripe_fee'] ) ) ? $order_items[ $order_id ]['_stripe_fee'] : 0.00;
    15561773                        $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'] : '';
    15581775                        $response ['To_Email_Address']             = '';
    15591776                        $response ['Transaction_ID']               = $order_id;
     
    15621779                        $response ['Item_Title']                   = 'Shopping Cart';
    15631780                        $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;
    15651782                        $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;
    15691786                        $response ['Option_1_Name']                = '';
    15701787                        $response ['Option_1_Value']               = '';
     
    15831800                        $response ['Receipt_ID']                   = '';
    15841801                        $response ['Balance']                      = '';
    1585                         $response ['Note']                         = $order_detail['order_note'];
     1802                        $response ['Note']                         = ( ! empty( $order_detail['order_note'] ) ) ? $order_detail['order_note'] : '';
    15861803                        $response ['Address_Line_1']               = ( ! empty( $order_items[ $order_id ]['_billing_address_1'] ) ) ? $order_items[ $order_id ]['_billing_address_1'] : '';
    15871804                        $response ['Address_Line_2']               = ! empty( $order_items[ $order_id ]['_billing_address_2'] ) ? $order_items[ $order_id ]['_billing_address_2'] : '';
    15881805                        $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'] : '';
    15901807                        $response ['Zip_Postal_Code']              = ! empty( $order_items[ $order_id ]['_billing_postcode'] ) ? $order_items[ $order_id ]['_billing_postcode'] : '';
    15911808                        $response ['Country']                      = ! empty( $order_items[ $order_id ]['_billing_country'] ) ? $order_items[ $order_id ]['_billing_country'] : '';
     
    15961813                        if ( ! empty( $item_details[ $order_id ]['coupons'] ) ) {
    15971814                            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;
    15991816                                $value                      = ( ! empty( $coupon_data[ $key ] ) ) ? $coupon_data[ $key ] : $value;
    16001817                            }
     
    17021919                        $sub        = ( ! empty( $item_details[ $order_id ]['subscriptions'] ) ) ? $item_details[ $order_id ]['subscriptions'] : array();
    17031920
     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
    17041961                        if ( ( ! empty( $params['order_id'] ) && ( 'refunded' === $order_status_new || ! empty( $params ['refund_parent_id'] ) ) ) ||
    17051962                                ( empty( $params['order_id'] ) && 'shop_order_refund' === $order_detail['type'] ) ) {
     
    17111968                            }
    17121969
    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;
    17251978                            $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';
    17261979                            $response ['Reference_Txn_ID']  = $order_id;
     
    17562009                            }
    17572010
    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'];
    17592012                            $order_item ['Quantity'] = $cart_item['_qty'];
    17602013
     
    18182071                    ); // WPCS: cache ok, db call ok.
    18192072
    1820                     if ( count( $results ) > 0 ) {
     2073                    if ( ! empty( $results ) && count( $results ) > 0 ) {
    18212074                        foreach ( $results as $result ) {
    18222075
     
    18302083                }
    18312084
    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;
    18332086                $data                  = ( ! empty( $transactions ) ) ? $transactions : array();
    18342087                $data                  = ( ! empty( $sub_transactions ) ) ? array_merge( $data, $sub_transactions ) : $data;
     
    18442097            return $params;
    18452098        }
     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
    18462134    }
    18472135}
  • woocommerce-putler-connector/trunk/languages/woocommerce-putler-connector.pot

    r2847386 r2945562  
    33msgid ""
    44msgstr ""
    5 "Project-Id-Version: Putler Connector for WooCommerce - Accurate Analytics and Reports for your WooCommerce Store 2.11.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"
    77"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
    88"Language-Team: LANGUAGE <[email protected]>\n"
     
    1010"Content-Type: text/plain; charset=UTF-8\n"
    1111"Content-Transfer-Encoding: 8bit\n"
    12 "POT-Creation-Date: 2023-01-12T17:49:28+05:30\n"
     12"POT-Creation-Date: 2023-07-31T20:36:51+05:30\n"
    1313"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"
    1515"X-Domain: woocommerce-putler-connector\n"
    1616
     
    3636
    3737#. translators: Putler URL
    38 #: classes/class-putler-connector.php:162
     38#: classes/class-putler-connector.php:163
    3939msgid "Putler Connector for Putler desktop has deprecated. Please upgrade to <strong><a href=\"%s\" target=\"_blank\">Putler Web</a></strong>."
    4040msgstr ""
    4141
    42 #: classes/class-putler-connector.php:202
    43 #: classes/class-putler-connector.php:293
    44 #: classes/class-putler-connector.php:427
     42#: classes/class-putler-connector.php:203
     43#: classes/class-putler-connector.php:294
     44#: classes/class-putler-connector.php:428
    4545msgid "Putler Connector"
    4646msgstr ""
    4747
    48 #: classes/class-putler-connector.php:216
     48#: classes/class-putler-connector.php:217
    4949msgid "Putler is connected"
    5050msgstr ""
    5151
    52 #: classes/class-putler-connector.php:250
     52#: classes/class-putler-connector.php:251
    5353msgid " & last sync date was "
    5454msgstr ""
    5555
    56 #: classes/class-putler-connector.php:252
     56#: classes/class-putler-connector.php:253
    5757msgid " & No orders have been synced yet."
    5858msgstr ""
    5959
    60 #: classes/class-putler-connector.php:261
     60#: classes/class-putler-connector.php:262
    6161msgid "Trying to Connect to Putler..."
    6262msgstr ""
    6363
    64 #: classes/class-putler-connector.php:282
     64#: classes/class-putler-connector.php:283
    6565msgid "Your transactions are getting synced with Putler. Please check after some time."
    6666msgstr ""
    6767
    68 #: classes/class-putler-connector.php:284
     68#: classes/class-putler-connector.php:285
    6969msgid "Your resync request is under process and your transactions will be resynced soon."
    7070msgstr ""
    7171
    72 #: classes/class-putler-connector.php:287
     72#: classes/class-putler-connector.php:288
    7373msgid "Resync Data"
    7474msgstr ""
    7575
    76 #: classes/class-putler-connector.php:338
     76#: classes/class-putler-connector.php:339
    7777msgid "Successfully Authenticated!!!"
    7878msgstr ""
    7979
    80 #: classes/class-putler-connector.php:400
     80#: classes/class-putler-connector.php:401
    8181msgid "Authenticating..."
    8282msgstr ""
    8383
    84 #: classes/class-putler-connector.php:460
    85 #: classes/class-putler-connector.php:463
    86 #: classes/class-putler-connector.php:469
    87 #: classes/class-putler-connector.php:571
    88 #: classes/class-putler-connector.php:575
    89 #: classes/class-putler-connector.php:583
    90 #: classes/class-putler-connector.php:645
    91 #: classes/class-putler-connector.php:649
    92 #: classes/class-putler-connector.php:657
     84#: 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
    9393msgid "Authentication Failed."
    9494msgstr ""
    9595
    9696#. translators: %s: Name of ecommerce gateway
    97 #: classes/class-putler-connector.php:460
     97#: classes/class-putler-connector.php:461
    9898msgid "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."
    9999msgstr ""
    100100
    101101#. translators: %s: Name of ecommerce gateway
    102 #: classes/class-putler-connector.php:460
     102#: classes/class-putler-connector.php:461
    103103msgid "Try Putler for free!"
    104104msgstr ""
    105105
    106106#. translators: %s: Name of ecommerce gateway
    107 #: classes/class-putler-connector.php:460
     107#: classes/class-putler-connector.php:461
    108108msgid "Once the %s account has been added successfully, please click "
    109109msgstr ""
    110110
    111111#. translators: %s: Name of ecommerce gateway
    112 #: classes/class-putler-connector.php:460
     112#: classes/class-putler-connector.php:461
    113113msgid "here"
    114114msgstr ""
    115115
    116 #: classes/class-putler-connector.php:463
     116#: classes/class-putler-connector.php:464
    117117msgid "You would need to reset the account in "
    118118msgstr ""
    119119
    120 #: classes/class-putler-connector.php:463
     120#: classes/class-putler-connector.php:464
    121121msgid "Putler Web "
    122122msgstr ""
    123123
    124 #: classes/class-putler-connector.php:550
    125 #: classes/class-putler-connector.php:606
     124#: classes/class-putler-connector.php:551
     125#: classes/class-putler-connector.php:607
    126126msgid "Authentication Successful"
    127127msgstr ""
    128128
    129 #: classes/class-putler-connector.php:581
    130 #: classes/class-putler-connector.php:655
    131 #: classes/class-putler-connector.php:800
     129#: classes/class-putler-connector.php:582
     130#: classes/class-putler-connector.php:656
     131#: classes/class-putler-connector.php:801
    132132msgid "Authentication Failure"
    133133msgstr ""
    134134
    135 #: classes/class-putler-connector.php:809
     135#: classes/class-putler-connector.php:810
    136136msgid "Params Missing"
    137137msgstr ""
  • woocommerce-putler-connector/trunk/readme.txt

    r2847395 r2945562  
    66Tags: WooCommerce reports, WooCommerce analytics,  e-Commerce reports, SaaS metrics, Subscription analytics, business reports, store analytics, store reports, sales forecasting, customer segmentation, Google analytics reports
    77Requires at least: 4.8.0
    8 Tested up to: 6.1.1
     8Tested up to: 6.2.2
    99Requires PHP: 5.6
    10 Stable tag: 2.11.2
     10Stable tag: 2.12.0
    1111License: GPL 3.0
    1212
     
    172172== Changelog ==
    173173
     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
    174183= 2.11.2 (12.01.2023) =
    175184* Fix: PHP Error: Call to undefined function in some cases post v2.11.0
     
    308317== Upgrade Notice ==
    309318
     319= 2.12.0 =
     320Declare 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
    310322= 2.11.2 =
    311323PHP 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  
    44 * Plugin URI: https://putler.com/connector/woocommerce/
    55 * Description: Accurate reports, analytics, integrations, growth insights and tools for your WooCommerce store.
    6  * Version: 2.11.2
     6 * Version: 2.12.0
    77 * Author: putler, storeapps
    88 * Author URI: https://putler.com/
     
    1010 * Domain Path: /languages/
    1111 * Requires at least: 4.8.0
    12  * Tested up to: 6.1.1
     12 * Tested up to: 6.2.2
    1313 * Requires PHP: 5.6+
    14  * WC requires at least: 2.0.0
    15  * WC tested up to: 7.0.1
     14 * WC requires at least: 3.0.0
     15 * WC tested up to: 7.9.0
    1616 * Copyright (c) 2006 - 2023 Putler. All rights reserved.
    1717 * License: GNU General Public License v3.0
     
    2626}
    2727
    28 define( 'WPC_VERSION', '2.11.2' );
     28define( 'WPC_VERSION', '2.12.0' );
    2929
    3030// Hooks.
     
    145145    }
    146146}
    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.