Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Bower components Debian packages RPM packages NuGet packages

jsarnowski / jsarnowski/flexible-shipping-pro   php

Repository URL to install this package:

Version: 1.11.1 

/ wpdesk / wp-wpdesk-tracker / src / data_provider / class-wpdesk-tracker-data-provider-orders-country.php

<?php

namespace FSProVendor;

/**
 * WP Desk Tracker
 *
 * @class        WPDESK_Tracker
 * @version        1.3.2
 * @package        WPDESK/Helper
 * @category    Class
 * @author        WP Desk
 */
if (!\defined('ABSPATH')) {
    exit;
}
if (!\class_exists('FSProVendor\\WPDesk_Tracker_Data_Provider_Orders_Country')) {
    /**
     * Class WPDesk_Tracker_Data_Provider_Orders_Country
     */
    class WPDesk_Tracker_Data_Provider_Orders_Country implements \WPDesk_Tracker_Data_Provider
    {
        /**
         * Info about shipping coutry per order.
         *
         * @return array Data provided to tracker.
         */
        public function get_data()
        {
            global $wpdb;
            $query = $wpdb->get_results("\n            \tSELECT m.meta_value AS shipping_country, p.post_status AS post_status , COUNT(p.ID) AS orders\n            \tFROM {$wpdb->postmeta} m, {$wpdb->posts} p\n            \tWHERE p.ID = m.post_id\n            \tAND m.meta_key = '_shipping_country'\n            \tGROUP BY shipping_country, post_status ORDER BY orders DESC");
            $data['shipping_country_per_order'] = array();
            if ($query) {
                foreach ($query as $row) {
                    if (!isset($data['shipping_country_per_order'][$row->shipping_country])) {
                        $data['shipping_country_per_order'][$row->shipping_country] = array();
                    }
                    $data['shipping_country_per_order'][$row->shipping_country][$row->post_status] = $row->orders;
                }
            }
            return $data;
        }
    }
}