Added code from feature/20770.
This commit is contained in:
parent
a16933143f
commit
6cddb51786
|
@ -201,6 +201,7 @@ class WC_Admin_Api_Init {
|
|||
// TODO: will this work on multisite?
|
||||
"{$wpdb->prefix}wc_admin_order_stats",
|
||||
"{$wpdb->prefix}wc_admin_order_product_lookup",
|
||||
"{$wpdb->prefix}wc_order_tax_lookup",
|
||||
)
|
||||
);
|
||||
}
|
||||
|
@ -239,6 +240,17 @@ class WC_Admin_Api_Init {
|
|||
KEY product_id (product_id),
|
||||
KEY customer_id (customer_id),
|
||||
KEY date_created (date_created)
|
||||
) $collate;
|
||||
CREATE TABLE {$wpdb->prefix}wc_order_tax_lookup (
|
||||
order_id BIGINT UNSIGNED NOT NULL,
|
||||
tax_rate_id BIGINT UNSIGNED NOT NULL,
|
||||
date_created timestamp DEFAULT '0000-00-00 00:00:00' NOT NULL,
|
||||
shipping_tax double DEFAULT 0 NOT NULL,
|
||||
order_tax double DEFAULT 0 NOT NULL,
|
||||
total_tax double DEFAULT 0 NOT NULL,
|
||||
KEY order_id (order_id),
|
||||
KEY tax_rate_id (tax_rate_id),
|
||||
KEY date_created (date_created)
|
||||
) $collate;";
|
||||
|
||||
return $tables;
|
||||
|
|
|
@ -40,3 +40,40 @@ function wc_admin_order_product_lookup_entry( $order_id ) {
|
|||
}
|
||||
}
|
||||
add_action( 'save_post', 'wc_admin_order_product_lookup_entry', 10, 1 );
|
||||
|
||||
/**
|
||||
* Make an entry in the wc_order_tax_lookup table for an order.
|
||||
*
|
||||
* @since 3.5.0
|
||||
* @param int $order_id Order ID.
|
||||
* @return void
|
||||
*/
|
||||
function wc_order_tax_lookup_entry( $order_id ) {
|
||||
global $wpdb;
|
||||
$order = wc_get_order( $order_id );
|
||||
if ( ! $order ) {
|
||||
return;
|
||||
}
|
||||
foreach ( $order->get_items( 'tax' ) as $tax_item ) {
|
||||
$wpdb->replace(
|
||||
$wpdb->prefix . 'wc_order_tax_lookup',
|
||||
array(
|
||||
'order_id' => $order->get_id(),
|
||||
'date_created' => date( 'Y-m-d H:i:s', $order->get_date_created( 'edit' )->getTimestamp() ),
|
||||
'tax_rate_id' => $tax_item->get_rate_id(),
|
||||
'shipping_tax' => $tax_item->get_shipping_tax_total(),
|
||||
'order_tax' => $tax_item->get_tax_total(),
|
||||
'total_tax' => $tax_item->get_tax_total() + $tax_item->get_shipping_tax_total(),
|
||||
),
|
||||
array(
|
||||
'%d',
|
||||
'%s',
|
||||
'%d',
|
||||
'%f',
|
||||
'%f',
|
||||
'%f',
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
add_action( 'save_post', 'wc_order_tax_lookup_entry', 10, 1 );
|
||||
|
|
Loading…
Reference in New Issue