110 lines
3.2 KiB
PHP
110 lines
3.2 KiB
PHP
<?php
|
|
|
|
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
|
|
|
|
if ( ! class_exists( 'WPDesk_DPD_Tracker' ) ) {
|
|
class WPDesk_DPD_Tracker {
|
|
|
|
public function __construct() {
|
|
}
|
|
|
|
public function hooks() {
|
|
add_filter( 'wpdesk_tracker_data', array( $this, 'wpdesk_tracker_data_dpd' ), 11 );
|
|
}
|
|
|
|
public function wpdesk_tracker_data_dpd( $data ) {
|
|
$shipping_methods = WC()->shipping()->get_shipping_methods();
|
|
if ( isset( $shipping_methods['dpd'] ) ) {
|
|
$dpd = $shipping_methods['dpd'];
|
|
$settings = $dpd->settings;
|
|
|
|
$plugin_data = array();
|
|
if ( isset( $settings['auto_create'] ) ) {
|
|
$plugin_data['auto_create'] = $settings['auto_create'];
|
|
}
|
|
if ( isset( $settings['order_status'] ) ) {
|
|
$plugin_data['order_status'] = $settings['order_status'];
|
|
}
|
|
if ( isset( $settings['complete_order'] ) ) {
|
|
$plugin_data['complete_order'] = $settings['complete_order'];
|
|
}
|
|
if ( isset( $settings['label_format'] ) ) {
|
|
$plugin_data['label_format'] = $settings['label_format'];
|
|
}
|
|
if ( isset( $settings['label_page_format'] ) ) {
|
|
$plugin_data['label_page_format'] = $settings['label_page_format'];
|
|
}
|
|
if ( isset( $settings['label_type'] ) ) {
|
|
$plugin_data['label_type'] = $settings['label_type'];
|
|
}
|
|
if ( isset( $settings['auto_print'] ) ) {
|
|
$plugin_data['auto_print'] = $settings['auto_print'];
|
|
}
|
|
|
|
$plugin_data['parcels'] = array();
|
|
$all_parcels = 0;
|
|
global $wpdb;
|
|
$sql = "
|
|
SELECT count(p.ID) AS count, p.post_status AS post_status, min(p.post_date) AS min, max(p.post_date) AS max
|
|
FROM {$wpdb->posts} p, {$wpdb->postmeta} m
|
|
WHERE p.post_type = 'shipment'
|
|
AND p.ID = m.post_id
|
|
AND m.meta_key = '_integration'
|
|
AND m.meta_value = 'dpd'
|
|
GROUP BY p.post_status
|
|
";
|
|
$query = $wpdb->get_results( $sql );
|
|
if ( $query ) {
|
|
foreach ( $query as $row ) {
|
|
$plugin_data['parcels'][$row->post_status] = $row->count;
|
|
$all_parcels = $all_parcels + $row->count;
|
|
}
|
|
}
|
|
$plugin_data['all_parcels'] = $all_parcels;
|
|
|
|
$plugin_data['dpd_product'] = array();
|
|
$sql = "
|
|
SELECT count(p.ID) AS count, m2.meta_value AS dpd_product
|
|
FROM {$wpdb->posts} p, {$wpdb->postmeta} m1, {$wpdb->postmeta} m2
|
|
WHERE p.post_type = 'shipment'
|
|
AND p.ID = m2.post_id
|
|
AND m1.meta_key = '_integration'
|
|
AND m1.meta_value = 'dpd'
|
|
AND p.ID = m1.post_id
|
|
AND m2.meta_key = '_dpd_product'
|
|
GROUP BY m2.meta_value
|
|
";
|
|
$query = $wpdb->get_results( $sql );
|
|
if ( $query ) {
|
|
foreach ( $query as $row ) {
|
|
$plugin_data['dpd_product'][$row->dpd_product] = $row->count;
|
|
}
|
|
}
|
|
|
|
$sql = "
|
|
SELECT TIMESTAMPDIFF(MONTH, min(p.post_date), max(p.post_date) )+1 AS months
|
|
FROM {$wpdb->posts} p, {$wpdb->postmeta} m
|
|
WHERE p.post_type = 'shipment'
|
|
AND p.ID = m.post_id
|
|
AND m.meta_key = '_integration'
|
|
AND m.meta_value = 'dpd'
|
|
GROUP BY p.post_status
|
|
";
|
|
$query = $wpdb->get_results( $sql );
|
|
if ( $query ) {
|
|
foreach ( $query as $row ) {
|
|
if ( $row->months != 0 ) {
|
|
$plugin_data['avg_parcels_per_month'] = floatval( $all_parcels )/floatval( $row->months );
|
|
}
|
|
}
|
|
}
|
|
$data['dpd'] = $plugin_data;
|
|
|
|
}
|
|
return $data;
|
|
}
|
|
|
|
}
|
|
|
|
}
|