Merge branch 'master' into fix/issue-20621
This commit is contained in:
commit
9dea1e98db
|
@ -772,15 +772,22 @@ class WC_Admin_List_Table_Orders extends WC_Admin_List_Table {
|
||||||
|
|
||||||
// Filter the orders by the posted customer.
|
// Filter the orders by the posted customer.
|
||||||
if ( ! empty( $_GET['_customer_user'] ) ) { // WPCS: input var ok.
|
if ( ! empty( $_GET['_customer_user'] ) ) { // WPCS: input var ok.
|
||||||
// @codingStandardsIgnoreStart
|
$customer_id = (int) $_GET['_customer_user']; // WPCS: input var ok, sanitization ok.
|
||||||
$query_vars['meta_query'] = array(
|
|
||||||
array(
|
// On WC 3.5.0 the ID of the user that placed the order was moved from the post meta _customer_user to the post_author field in the wp_posts table.
|
||||||
'key' => '_customer_user',
|
if ( version_compare( get_option( 'woocommerce_db_version' ), '3.5.0', '>=' ) ) {
|
||||||
'value' => (int) $_GET['_customer_user'], // WPCS: input var ok, sanitization ok.
|
$query_vars['author'] = $customer_id;
|
||||||
'compare' => '=',
|
} else {
|
||||||
),
|
// @codingStandardsIgnoreStart
|
||||||
);
|
$query_vars['meta_query'] = array(
|
||||||
// @codingStandardsIgnoreEnd
|
array(
|
||||||
|
'key' => '_customer_user',
|
||||||
|
'value' => $customer_id,
|
||||||
|
'compare' => '=',
|
||||||
|
),
|
||||||
|
);
|
||||||
|
// @codingStandardsIgnoreEnd
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Sorting.
|
// Sorting.
|
||||||
|
|
|
@ -69,46 +69,56 @@ class WC_Report_Customers extends WC_Admin_Report {
|
||||||
* Output customers vs guests chart.
|
* Output customers vs guests chart.
|
||||||
*/
|
*/
|
||||||
public function customers_vs_guests() {
|
public function customers_vs_guests() {
|
||||||
|
$customer_args = array(
|
||||||
$customer_order_totals = $this->get_order_report_data(
|
'data' => array(
|
||||||
array(
|
'ID' => array(
|
||||||
'data' => array(
|
'type' => 'post_data',
|
||||||
'ID' => array(
|
'function' => 'COUNT',
|
||||||
'type' => 'post_data',
|
'name' => 'total_orders',
|
||||||
'function' => 'COUNT',
|
|
||||||
'name' => 'total_orders',
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
'where_meta' => array(
|
),
|
||||||
array(
|
'filter_range' => true,
|
||||||
'meta_key' => '_customer_user',
|
|
||||||
'meta_value' => '0',
|
|
||||||
'operator' => '>',
|
|
||||||
),
|
|
||||||
),
|
|
||||||
'filter_range' => true,
|
|
||||||
)
|
|
||||||
);
|
);
|
||||||
|
$guest_args = $customer_args;
|
||||||
|
|
||||||
$guest_order_totals = $this->get_order_report_data(
|
// On WC 3.5.0 the ID of the user that placed the order was moved from the post meta _customer_user to the post_author field in the wp_posts table.
|
||||||
array(
|
if ( version_compare( get_option( 'woocommerce_db_version' ), '3.5.0', '>=' ) ) {
|
||||||
'data' => array(
|
$customer_args['where'] = array(
|
||||||
'ID' => array(
|
array(
|
||||||
'type' => 'post_data',
|
'key' => 'post_author',
|
||||||
'function' => 'COUNT',
|
'value' => '0',
|
||||||
'name' => 'total_orders',
|
'operator' => '>',
|
||||||
),
|
|
||||||
),
|
),
|
||||||
'where_meta' => array(
|
);
|
||||||
array(
|
|
||||||
'meta_key' => '_customer_user',
|
$guest_args['where'] = array(
|
||||||
'meta_value' => '0',
|
array(
|
||||||
'operator' => '=',
|
'key' => 'post_author',
|
||||||
),
|
'value' => '0',
|
||||||
|
'operator' => '=',
|
||||||
),
|
),
|
||||||
'filter_range' => true,
|
);
|
||||||
)
|
} else {
|
||||||
);
|
$customer_args['where_meta'] = array(
|
||||||
|
array(
|
||||||
|
'meta_key' => '_customer_user',
|
||||||
|
'meta_value' => '0',
|
||||||
|
'operator' => '>',
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
$guest_args['where_meta'] = array(
|
||||||
|
array(
|
||||||
|
'meta_key' => '_customer_user',
|
||||||
|
'meta_value' => '0',
|
||||||
|
'operator' => '=',
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
$customer_order_totals = $this->get_order_report_data( $customer_args );
|
||||||
|
$guest_order_totals = $this->get_order_report_data( $guest_args );
|
||||||
|
|
||||||
?>
|
?>
|
||||||
<div class="chart-container">
|
<div class="chart-container">
|
||||||
<div class="chart-placeholder customers_vs_guests pie-chart" style="height:200px"></div>
|
<div class="chart-placeholder customers_vs_guests pie-chart" style="height:200px"></div>
|
||||||
|
@ -246,61 +256,63 @@ class WC_Report_Customers extends WC_Admin_Report {
|
||||||
public function get_main_chart() {
|
public function get_main_chart() {
|
||||||
global $wp_locale;
|
global $wp_locale;
|
||||||
|
|
||||||
$customer_orders = $this->get_order_report_data(
|
$customer_args = array(
|
||||||
array(
|
'data' => array(
|
||||||
'data' => array(
|
'ID' => array(
|
||||||
'ID' => array(
|
'type' => 'post_data',
|
||||||
'type' => 'post_data',
|
'function' => 'COUNT',
|
||||||
'function' => 'COUNT',
|
'name' => 'total_orders',
|
||||||
'name' => 'total_orders',
|
|
||||||
),
|
|
||||||
'post_date' => array(
|
|
||||||
'type' => 'post_data',
|
|
||||||
'function' => '',
|
|
||||||
'name' => 'post_date',
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
'where_meta' => array(
|
'post_date' => array(
|
||||||
array(
|
'type' => 'post_data',
|
||||||
'meta_key' => '_customer_user',
|
'function' => '',
|
||||||
'meta_value' => '0',
|
'name' => 'post_date',
|
||||||
'operator' => '>',
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
'group_by' => $this->group_by_query,
|
),
|
||||||
'order_by' => 'post_date ASC',
|
'group_by' => $this->group_by_query,
|
||||||
'query_type' => 'get_results',
|
'order_by' => 'post_date ASC',
|
||||||
'filter_range' => true,
|
'query_type' => 'get_results',
|
||||||
)
|
'filter_range' => true,
|
||||||
);
|
);
|
||||||
|
$guest_args = $customer_args;
|
||||||
|
|
||||||
$guest_orders = $this->get_order_report_data(
|
// On WC 3.5.0 the ID of the user that placed the order was moved from the post meta _customer_user to the post_author field in the wp_posts table.
|
||||||
array(
|
if ( version_compare( get_option( 'woocommerce_db_version' ), '3.5.0', '>=' ) ) {
|
||||||
'data' => array(
|
$customer_args['where'] = array(
|
||||||
'ID' => array(
|
array(
|
||||||
'type' => 'post_data',
|
'key' => 'post_author',
|
||||||
'function' => 'COUNT',
|
'value' => '0',
|
||||||
'name' => 'total_orders',
|
'operator' => '>',
|
||||||
),
|
|
||||||
'post_date' => array(
|
|
||||||
'type' => 'post_data',
|
|
||||||
'function' => '',
|
|
||||||
'name' => 'post_date',
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
'where_meta' => array(
|
);
|
||||||
array(
|
|
||||||
'meta_key' => '_customer_user',
|
$guest_args['where'] = array(
|
||||||
'meta_value' => '0',
|
array(
|
||||||
'operator' => '=',
|
'key' => 'post_author',
|
||||||
),
|
'value' => '0',
|
||||||
|
'operator' => '=',
|
||||||
),
|
),
|
||||||
'group_by' => $this->group_by_query,
|
);
|
||||||
'order_by' => 'post_date ASC',
|
} else {
|
||||||
'query_type' => 'get_results',
|
$customer_args['where_meta'] = array(
|
||||||
'filter_range' => true,
|
array(
|
||||||
)
|
'meta_key' => '_customer_user',
|
||||||
);
|
'meta_value' => '0',
|
||||||
|
'operator' => '>',
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
$guest_args['where_meta'] = array(
|
||||||
|
array(
|
||||||
|
'meta_key' => '_customer_user',
|
||||||
|
'meta_value' => '0',
|
||||||
|
'operator' => '=',
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
$customer_orders = $this->get_order_report_data( $customer_args );
|
||||||
|
$guest_orders = $this->get_order_report_data( $guest_args );
|
||||||
|
|
||||||
$signups = $this->prepare_chart_data( $this->customers, 'user_registered', '', $this->chart_interval, $this->start_date, $this->chart_groupby );
|
$signups = $this->prepare_chart_data( $this->customers, 'user_registered', '', $this->chart_interval, $this->start_date, $this->chart_groupby );
|
||||||
$customer_orders = $this->prepare_chart_data( $customer_orders, 'post_date', 'total_orders', $this->chart_interval, $this->start_date, $this->chart_groupby );
|
$customer_orders = $this->prepare_chart_data( $customer_orders, 'post_date', 'total_orders', $this->chart_interval, $this->start_date, $this->chart_groupby );
|
||||||
|
|
|
@ -365,15 +365,20 @@ class WC_REST_Orders_Controller extends WC_REST_Legacy_Orders_Controller {
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( isset( $request['customer'] ) ) {
|
if ( isset( $request['customer'] ) ) {
|
||||||
if ( ! empty( $args['meta_query'] ) ) {
|
// On WC 3.5.0 the ID of the user that placed the order was moved from the post meta _customer_user to the post_author field in the wp_posts table.
|
||||||
$args['meta_query'] = array(); // WPCS: slow query ok.
|
if ( version_compare( get_option( 'woocommerce_db_version' ), '3.5.0', '>=' ) ) {
|
||||||
}
|
$args['author'] = $request['customer'];
|
||||||
|
} else {
|
||||||
|
if ( ! empty( $args['meta_query'] ) ) {
|
||||||
|
$args['meta_query'] = array(); // WPCS: slow query ok.
|
||||||
|
}
|
||||||
|
|
||||||
$args['meta_query'][] = array(
|
$args['meta_query'][] = array(
|
||||||
'key' => '_customer_user',
|
'key' => '_customer_user',
|
||||||
'value' => $request['customer'],
|
'value' => $request['customer'],
|
||||||
'type' => 'NUMERIC',
|
'type' => 'NUMERIC',
|
||||||
);
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Search by product.
|
// Search by product.
|
||||||
|
|
|
@ -404,15 +404,20 @@ class WC_REST_Orders_V1_Controller extends WC_REST_Posts_Controller {
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( isset( $request['customer'] ) ) {
|
if ( isset( $request['customer'] ) ) {
|
||||||
if ( ! empty( $args['meta_query'] ) ) {
|
// On WC 3.5.0 the ID of the user that placed the order was moved from the post meta _customer_user to the post_author field in the wp_posts table.
|
||||||
$args['meta_query'] = array();
|
if ( version_compare( get_option( 'woocommerce_db_version' ), '3.5.0', '>=' ) ) {
|
||||||
}
|
$args['author'] = $request['customer'];
|
||||||
|
} else {
|
||||||
|
if ( ! empty( $args['meta_query'] ) ) {
|
||||||
|
$args['meta_query'] = array(); // WPCS: slow query ok.
|
||||||
|
}
|
||||||
|
|
||||||
$args['meta_query'][] = array(
|
$args['meta_query'][] = array(
|
||||||
'key' => '_customer_user',
|
'key' => '_customer_user',
|
||||||
'value' => $request['customer'],
|
'value' => $request['customer'],
|
||||||
'type' => 'NUMERIC',
|
'type' => 'NUMERIC',
|
||||||
);
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Search by product.
|
// Search by product.
|
||||||
|
|
|
@ -132,4 +132,13 @@ class WC_Background_Updater extends WC_Background_Process {
|
||||||
WC_Install::update_db_version();
|
WC_Install::update_db_version();
|
||||||
parent::complete();
|
parent::complete();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* See if the batch limit has been exceeded.
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function is_memory_exceeded() {
|
||||||
|
return $this->memory_exceeded();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -637,7 +637,7 @@ final class WC_Cart_Totals {
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( $this->calculate_tax && $item->product->is_taxable() ) {
|
if ( $this->calculate_tax && $item->product->is_taxable() ) {
|
||||||
$total_taxes = WC_Tax::calc_tax( $item->total, $item->tax_rates, $item->price_includes_tax );
|
$total_taxes = apply_filters( 'woocommerce_calculate_item_totals_taxes', WC_Tax::calc_tax( $item->total, $item->tax_rates, $item->price_includes_tax ), $item, $this );
|
||||||
$item->taxes = $total_taxes;
|
$item->taxes = $total_taxes;
|
||||||
$item->total_tax = array_sum( array_map( array( $this, 'round_line_tax' ), $item->taxes ) );
|
$item->total_tax = array_sum( array_map( array( $this, 'round_line_tax' ), $item->taxes ) );
|
||||||
|
|
||||||
|
|
|
@ -1385,28 +1385,27 @@ class WC_Cart extends WC_Legacy_Cart {
|
||||||
* @return string price or string for the shipping total
|
* @return string price or string for the shipping total
|
||||||
*/
|
*/
|
||||||
public function get_cart_shipping_total() {
|
public function get_cart_shipping_total() {
|
||||||
|
|
||||||
|
// Default total assumes Free shipping.
|
||||||
|
$total = __( 'Free!', 'woocommerce' );
|
||||||
|
|
||||||
if ( 0 < $this->get_shipping_total() ) {
|
if ( 0 < $this->get_shipping_total() ) {
|
||||||
|
|
||||||
if ( $this->display_prices_including_tax() ) {
|
if ( $this->display_prices_including_tax() ) {
|
||||||
$return = wc_price( $this->shipping_total + $this->shipping_tax_total );
|
$total = wc_price( $this->shipping_total + $this->shipping_tax_total );
|
||||||
|
|
||||||
if ( $this->shipping_tax_total > 0 && ! wc_prices_include_tax() ) {
|
if ( $this->shipping_tax_total > 0 && ! wc_prices_include_tax() ) {
|
||||||
$return .= ' <small class="tax_label">' . WC()->countries->inc_tax_or_vat() . '</small>';
|
$total .= ' <small class="tax_label">' . WC()->countries->inc_tax_or_vat() . '</small>';
|
||||||
}
|
}
|
||||||
|
|
||||||
return $return;
|
|
||||||
} else {
|
} else {
|
||||||
$return = wc_price( $this->shipping_total );
|
$total = wc_price( $this->shipping_total );
|
||||||
|
|
||||||
if ( $this->shipping_tax_total > 0 && wc_prices_include_tax() ) {
|
if ( $this->shipping_tax_total > 0 && wc_prices_include_tax() ) {
|
||||||
$return .= ' <small class="tax_label">' . WC()->countries->ex_tax_or_vat() . '</small>';
|
$total .= ' <small class="tax_label">' . WC()->countries->ex_tax_or_vat() . '</small>';
|
||||||
}
|
}
|
||||||
|
|
||||||
return $return;
|
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
return __( 'Free!', 'woocommerce' );
|
|
||||||
}
|
}
|
||||||
|
return apply_filters( 'woocommerce_cart_shipping_total', $total, $this );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -223,11 +223,6 @@ class WC_Emails {
|
||||||
$this->emails['WC_Email_Customer_New_Account'] = include 'emails/class-wc-email-customer-new-account.php';
|
$this->emails['WC_Email_Customer_New_Account'] = include 'emails/class-wc-email-customer-new-account.php';
|
||||||
|
|
||||||
$this->emails = apply_filters( 'woocommerce_email_classes', $this->emails );
|
$this->emails = apply_filters( 'woocommerce_email_classes', $this->emails );
|
||||||
|
|
||||||
// include css inliner.
|
|
||||||
if ( ! class_exists( 'Emogrifier' ) && class_exists( 'DOMDocument' ) ) {
|
|
||||||
include_once dirname( __FILE__ ) . '/libraries/class-emogrifier.php';
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -46,7 +46,7 @@ class WC_Geolite_Integration {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get country 2-letters ISO by IP address.
|
* Get country 2-letters ISO by IP address.
|
||||||
* Retuns empty string when not able to find any ISO code.
|
* Returns empty string when not able to find any ISO code.
|
||||||
*
|
*
|
||||||
* @param string $ip_address User IP address.
|
* @param string $ip_address User IP address.
|
||||||
* @return string
|
* @return string
|
||||||
|
@ -55,9 +55,12 @@ class WC_Geolite_Integration {
|
||||||
$iso_code = '';
|
$iso_code = '';
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$reader = new MaxMind\Db\Reader( $this->database ); // phpcs:ignore PHPCompatibility.PHP.NewLanguageConstructs.t_ns_separatorFound
|
$reader = new MaxMind\Db\Reader( $this->database ); // phpcs:ignore PHPCompatibility.PHP.NewLanguageConstructs.t_ns_separatorFound
|
||||||
$data = $reader->get( $ip_address );
|
$data = $reader->get( $ip_address );
|
||||||
$iso_code = $data['country']['iso_code'];
|
|
||||||
|
if ( isset( $data['country']['iso_code'] ) ) {
|
||||||
|
$iso_code = $data['country']['iso_code'];
|
||||||
|
}
|
||||||
|
|
||||||
$reader->close();
|
$reader->close();
|
||||||
} catch ( Exception $e ) {
|
} catch ( Exception $e ) {
|
||||||
|
|
|
@ -109,6 +109,10 @@ class WC_Install {
|
||||||
'wc_update_343_cleanup_foreign_keys',
|
'wc_update_343_cleanup_foreign_keys',
|
||||||
'wc_update_343_db_version',
|
'wc_update_343_db_version',
|
||||||
),
|
),
|
||||||
|
'3.5.0' => array(
|
||||||
|
'wc_update_350_order_customer_id',
|
||||||
|
'wc_update_350_db_version',
|
||||||
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -36,11 +36,7 @@ class WC_Regenerate_Images {
|
||||||
public static function init() {
|
public static function init() {
|
||||||
add_action( 'image_get_intermediate_size', array( __CLASS__, 'filter_image_get_intermediate_size' ), 10, 3 );
|
add_action( 'image_get_intermediate_size', array( __CLASS__, 'filter_image_get_intermediate_size' ), 10, 3 );
|
||||||
add_filter( 'wp_generate_attachment_metadata', array( __CLASS__, 'add_uncropped_metadata' ) );
|
add_filter( 'wp_generate_attachment_metadata', array( __CLASS__, 'add_uncropped_metadata' ) );
|
||||||
|
add_filter( 'wp_get_attachment_image_src', array( __CLASS__, 'maybe_resize_image' ), 10, 4 );
|
||||||
// Resize WooCommerce images on the fly when browsing site through customizer as to showcase image setting changes in real time.
|
|
||||||
if ( is_customize_preview() ) {
|
|
||||||
add_filter( 'wp_get_attachment_image_src', array( __CLASS__, 'maybe_resize_image' ), 10, 4 );
|
|
||||||
}
|
|
||||||
|
|
||||||
// Not required when Jetpack Photon is in use.
|
// Not required when Jetpack Photon is in use.
|
||||||
if ( method_exists( 'Jetpack', 'is_module_active' ) && Jetpack::is_module_active( 'photon' ) ) {
|
if ( method_exists( 'Jetpack', 'is_module_active' ) && Jetpack::is_module_active( 'photon' ) ) {
|
||||||
|
@ -206,18 +202,32 @@ class WC_Regenerate_Images {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Use a whitelist of sizes we want to resize. Ignore others.
|
// Use a whitelist of sizes we want to resize. Ignore others.
|
||||||
if ( ! in_array( $size, apply_filters( 'woocommerce_image_sizes_to_resize', array( 'woocommerce_thumbnail', 'woocommerce_gallery_thumbnail', 'woocommerce_single', 'shop_thumbnail', 'shop_catalog', 'shop_single' ) ), true ) ) {
|
if ( ! $image || ! in_array( $size, apply_filters( 'woocommerce_image_sizes_to_resize', array( 'woocommerce_thumbnail', 'woocommerce_gallery_thumbnail', 'woocommerce_single', 'shop_thumbnail', 'shop_catalog', 'shop_single' ) ), true ) ) {
|
||||||
return $image;
|
return $image;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get image metadata - we need it to proceed.
|
$image_size = wc_get_image_size( $size );
|
||||||
$imagemeta = wp_get_attachment_metadata( $attachment_id );
|
$ratio_match = false;
|
||||||
|
|
||||||
if ( empty( $imagemeta ) ) {
|
// If '' is passed to either size, we test ratios against the original file. It's uncropped.
|
||||||
return $image;
|
if ( '' === $image_size['width'] || '' === $image_size['height'] ) {
|
||||||
|
$imagedata = wp_get_attachment_metadata( $attachment_id );
|
||||||
|
|
||||||
|
if ( ! $imagedata ) {
|
||||||
|
return $image;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( ! isset( $imagedata['file'] ) && isset( $imagedata['sizes']['full'] ) ) {
|
||||||
|
$imagedata['height'] = $imagedata['sizes']['full']['height'];
|
||||||
|
$imagedata['width'] = $imagedata['sizes']['full']['width'];
|
||||||
|
}
|
||||||
|
|
||||||
|
$ratio_match = wp_image_matches_ratio( $image[1], $image[2], $imagedata['width'], $imagedata['height'] );
|
||||||
|
} else {
|
||||||
|
$ratio_match = wp_image_matches_ratio( $image[1], $image[2], $image_size['width'], $image_size['height'] );
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( ! isset( $imagemeta['sizes'], $imagemeta['sizes'][ $size ] ) || ! self::image_size_matches_settings( $imagemeta['sizes'][ $size ], $size ) ) {
|
if ( ! $ratio_match ) {
|
||||||
return self::resize_and_return_image( $attachment_id, $image, $size, $icon );
|
return self::resize_and_return_image( $attachment_id, $image, $size, $icon );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -316,28 +326,30 @@ class WC_Regenerate_Images {
|
||||||
include ABSPATH . 'wp-admin/includes/image.php';
|
include ABSPATH . 'wp-admin/includes/image.php';
|
||||||
}
|
}
|
||||||
|
|
||||||
$thumbnail = self::get_image( $fullsizepath, $image_size['width'], $image_size['height'], $image_size['crop'] );
|
self::$regenerate_size = is_customize_preview() ? $size . '_preview' : $size;
|
||||||
|
|
||||||
// If the file is already there perhaps just load it.
|
if ( is_customize_preview() ) {
|
||||||
if ( $thumbnail && file_exists( $thumbnail['filename'] ) ) {
|
// Make sure registered image size matches the size we're requesting.
|
||||||
$wp_uploads = wp_upload_dir( null, false );
|
add_image_size( self::$regenerate_size, absint( $image_size['width'] ), absint( $image_size['height'] ), $image_size['crop'] );
|
||||||
$wp_uploads_dir = $wp_uploads['basedir'];
|
|
||||||
$wp_uploads_url = $wp_uploads['baseurl'];
|
|
||||||
|
|
||||||
return array(
|
$thumbnail = self::get_image( $fullsizepath, absint( $image_size['width'] ), absint( $image_size['height'] ), $image_size['crop'] );
|
||||||
0 => str_replace( $wp_uploads_dir, $wp_uploads_url, $thumbnail['filename'] ),
|
|
||||||
1 => $thumbnail['width'],
|
// If the file is already there perhaps just load it if we're using the customizer. No need to store in meta data.
|
||||||
2 => $thumbnail['height'],
|
if ( $thumbnail && file_exists( $thumbnail['filename'] ) ) {
|
||||||
);
|
$wp_uploads = wp_upload_dir( null, false );
|
||||||
|
$wp_uploads_dir = $wp_uploads['basedir'];
|
||||||
|
$wp_uploads_url = $wp_uploads['baseurl'];
|
||||||
|
|
||||||
|
return array(
|
||||||
|
0 => str_replace( $wp_uploads_dir, $wp_uploads_url, $thumbnail['filename'] ),
|
||||||
|
1 => $thumbnail['width'],
|
||||||
|
2 => $thumbnail['height'],
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$metadata = wp_get_attachment_metadata( $attachment_id );
|
$metadata = wp_get_attachment_metadata( $attachment_id );
|
||||||
|
|
||||||
// Make sure registered image size matches the size we're requesting.
|
|
||||||
add_image_size( $size . '_preview', $image_size['width'], $image_size['height'], $image_size['crop'] );
|
|
||||||
|
|
||||||
self::$regenerate_size = $size . '_preview';
|
|
||||||
|
|
||||||
// We only want to regen a specific image size.
|
// We only want to regen a specific image size.
|
||||||
add_filter( 'intermediate_image_sizes', array( __CLASS__, 'adjust_intermediate_image_sizes' ) );
|
add_filter( 'intermediate_image_sizes', array( __CLASS__, 'adjust_intermediate_image_sizes' ) );
|
||||||
|
|
||||||
|
@ -352,14 +364,13 @@ class WC_Regenerate_Images {
|
||||||
return $image;
|
return $image;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Since this is only a preview we should not update the actual size. That will be done later by the background job.
|
if ( isset( $new_metadata['sizes'][ self::$regenerate_size ] ) ) {
|
||||||
if ( isset( $new_metadata['sizes'][ $size . '_preview' ] ) ) {
|
$metadata['sizes'][ self::$regenerate_size ] = $new_metadata['sizes'][ self::$regenerate_size ];
|
||||||
$metadata['sizes'][ $size . '_preview' ] = $new_metadata['sizes'][ $size . '_preview' ];
|
|
||||||
wp_update_attachment_metadata( $attachment_id, $metadata );
|
wp_update_attachment_metadata( $attachment_id, $metadata );
|
||||||
}
|
}
|
||||||
|
|
||||||
// Now we've done our regen, attempt to return the new size.
|
// Now we've done our regen, attempt to return the new size.
|
||||||
$new_image = image_downsize( $attachment_id, $size . '_preview' );
|
$new_image = image_downsize( $attachment_id, self::$regenerate_size );
|
||||||
|
|
||||||
return $new_image ? $new_image : $image;
|
return $new_image ? $new_image : $image;
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,7 +20,7 @@ final class WooCommerce {
|
||||||
*
|
*
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
public $version = '3.4.0';
|
public $version = '3.5.0';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The single instance of the class.
|
* The single instance of the class.
|
||||||
|
|
|
@ -67,7 +67,7 @@ abstract class Abstract_WC_Order_Data_Store_CPT extends WC_Data_Store_WP impleme
|
||||||
'post_type' => $order->get_type( 'edit' ),
|
'post_type' => $order->get_type( 'edit' ),
|
||||||
'post_status' => 'wc-' . ( $order->get_status( 'edit' ) ? $order->get_status( 'edit' ) : apply_filters( 'woocommerce_default_order_status', 'pending' ) ),
|
'post_status' => 'wc-' . ( $order->get_status( 'edit' ) ? $order->get_status( 'edit' ) : apply_filters( 'woocommerce_default_order_status', 'pending' ) ),
|
||||||
'ping_status' => 'closed',
|
'ping_status' => 'closed',
|
||||||
'post_author' => 1,
|
'post_author' => is_callable( array( $order, 'get_customer_id' ) ) ? $order->get_customer_id() : 0,
|
||||||
'post_title' => $this->get_post_title(),
|
'post_title' => $this->get_post_title(),
|
||||||
'post_password' => uniqid( 'order_' ),
|
'post_password' => uniqid( 'order_' ),
|
||||||
'post_parent' => $order->get_parent_id( 'edit' ),
|
'post_parent' => $order->get_parent_id( 'edit' ),
|
||||||
|
@ -139,7 +139,7 @@ abstract class Abstract_WC_Order_Data_Store_CPT extends WC_Data_Store_WP impleme
|
||||||
$changes = $order->get_changes();
|
$changes = $order->get_changes();
|
||||||
|
|
||||||
// Only update the post when the post data changes.
|
// Only update the post when the post data changes.
|
||||||
if ( array_intersect( array( 'date_created', 'date_modified', 'status', 'parent_id', 'post_excerpt' ), array_keys( $changes ) ) ) {
|
if ( array_intersect( array( 'date_created', 'date_modified', 'status', 'parent_id', 'post_excerpt', 'customer_id' ), array_keys( $changes ) ) ) {
|
||||||
$post_data = array(
|
$post_data = array(
|
||||||
'post_date' => gmdate( 'Y-m-d H:i:s', $order->get_date_created( 'edit' )->getOffsetTimestamp() ),
|
'post_date' => gmdate( 'Y-m-d H:i:s', $order->get_date_created( 'edit' )->getOffsetTimestamp() ),
|
||||||
'post_date_gmt' => gmdate( 'Y-m-d H:i:s', $order->get_date_created( 'edit' )->getTimestamp() ),
|
'post_date_gmt' => gmdate( 'Y-m-d H:i:s', $order->get_date_created( 'edit' )->getTimestamp() ),
|
||||||
|
@ -148,6 +148,7 @@ abstract class Abstract_WC_Order_Data_Store_CPT extends WC_Data_Store_WP impleme
|
||||||
'post_excerpt' => $this->get_post_excerpt( $order ),
|
'post_excerpt' => $this->get_post_excerpt( $order ),
|
||||||
'post_modified' => isset( $changes['date_modified'] ) ? gmdate( 'Y-m-d H:i:s', $order->get_date_modified( 'edit' )->getOffsetTimestamp() ) : current_time( 'mysql' ),
|
'post_modified' => isset( $changes['date_modified'] ) ? gmdate( 'Y-m-d H:i:s', $order->get_date_modified( 'edit' )->getOffsetTimestamp() ) : current_time( 'mysql' ),
|
||||||
'post_modified_gmt' => isset( $changes['date_modified'] ) ? gmdate( 'Y-m-d H:i:s', $order->get_date_modified( 'edit' )->getTimestamp() ) : current_time( 'mysql', 1 ),
|
'post_modified_gmt' => isset( $changes['date_modified'] ) ? gmdate( 'Y-m-d H:i:s', $order->get_date_modified( 'edit' )->getTimestamp() ) : current_time( 'mysql', 1 ),
|
||||||
|
'post_author' => is_callable( array( $order, 'get_customer_id' ) ) ? $order->get_customer_id() : 0,
|
||||||
);
|
);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -165,12 +166,27 @@ abstract class Abstract_WC_Order_Data_Store_CPT extends WC_Data_Store_WP impleme
|
||||||
wp_update_post( array_merge( array( 'ID' => $order->get_id() ), $post_data ) );
|
wp_update_post( array_merge( array( 'ID' => $order->get_id() ), $post_data ) );
|
||||||
}
|
}
|
||||||
$order->read_meta_data( true ); // Refresh internal meta data, in case things were hooked into `save_post` or another WP hook.
|
$order->read_meta_data( true ); // Refresh internal meta data, in case things were hooked into `save_post` or another WP hook.
|
||||||
|
|
||||||
|
// If customer changed, update any downloadable permissions.
|
||||||
|
if ( in_array( 'customer_id', $changes ) ) {
|
||||||
|
$this->update_downloadable_permissions( $order );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
$this->update_post_meta( $order );
|
$this->update_post_meta( $order );
|
||||||
$order->apply_changes();
|
$order->apply_changes();
|
||||||
$this->clear_caches( $order );
|
$this->clear_caches( $order );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update downloadable permissions for a given order.
|
||||||
|
*
|
||||||
|
* @param WC_Order $order Order object.
|
||||||
|
*/
|
||||||
|
protected function update_downloadable_permissions( $order ) {
|
||||||
|
$data_store = WC_Data_Store::load( 'customer-download' );
|
||||||
|
$data_store->update_user_by_order_id( $order->get_id(), $order->get_customer_id(), $order->get_billing_email() );
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method to delete an order from the database.
|
* Method to delete an order from the database.
|
||||||
*
|
*
|
||||||
|
|
|
@ -325,18 +325,27 @@ class WC_Customer_Data_Store extends WC_Data_Store_WP implements WC_Customer_Dat
|
||||||
public function get_last_order( &$customer ) {
|
public function get_last_order( &$customer ) {
|
||||||
global $wpdb;
|
global $wpdb;
|
||||||
|
|
||||||
$last_order = $wpdb->get_var(
|
// On WC 3.5.0 the ID of the user that placed the order was moved from the post meta _customer_user to the post_author field in the wp_posts table.
|
||||||
// phpcs:disable WordPress.WP.PreparedSQL.NotPrepared
|
if ( version_compare( get_option( 'woocommerce_db_version' ), '3.5.0', '>=' ) ) {
|
||||||
"SELECT posts.ID
|
$query = "SELECT ID
|
||||||
|
FROM $wpdb->posts
|
||||||
|
WHERE post_author = '" . esc_sql( $customer->get_id() ) . "'
|
||||||
|
AND post_type = 'shop_order'
|
||||||
|
AND post_status IN ( '" . implode( "','", array_map( 'esc_sql', array_keys( wc_get_order_statuses() ) ) ) . "' )
|
||||||
|
ORDER BY ID DESC";
|
||||||
|
} else {
|
||||||
|
$query = "SELECT posts.ID
|
||||||
FROM $wpdb->posts AS posts
|
FROM $wpdb->posts AS posts
|
||||||
LEFT JOIN {$wpdb->postmeta} AS meta on posts.ID = meta.post_id
|
LEFT JOIN {$wpdb->postmeta} AS meta on posts.ID = meta.post_id
|
||||||
WHERE meta.meta_key = '_customer_user'
|
WHERE meta.meta_key = '_customer_user'
|
||||||
AND meta.meta_value = '" . esc_sql( $customer->get_id() ) . "'
|
AND meta.meta_value = '" . esc_sql( $customer->get_id() ) . "'
|
||||||
AND posts.post_type = 'shop_order'
|
AND posts.post_type = 'shop_order'
|
||||||
AND posts.post_status IN ( '" . implode( "','", array_map( 'esc_sql', array_keys( wc_get_order_statuses() ) ) ) . "' )
|
AND posts.post_status IN ( '" . implode( "','", array_map( 'esc_sql', array_keys( wc_get_order_statuses() ) ) ) . "' )
|
||||||
ORDER BY posts.ID DESC"
|
ORDER BY posts.ID DESC";
|
||||||
// phpcs:enable
|
}
|
||||||
);
|
|
||||||
|
// phpcs:ignore WordPress.WP.PreparedSQL.NotPrepared
|
||||||
|
$last_order = $wpdb->get_var( $query );
|
||||||
|
|
||||||
if ( ! $last_order ) {
|
if ( ! $last_order ) {
|
||||||
return false;
|
return false;
|
||||||
|
@ -358,17 +367,25 @@ class WC_Customer_Data_Store extends WC_Data_Store_WP implements WC_Customer_Dat
|
||||||
if ( '' === $count ) {
|
if ( '' === $count ) {
|
||||||
global $wpdb;
|
global $wpdb;
|
||||||
|
|
||||||
$count = $wpdb->get_var(
|
// On WC 3.5.0 the ID of the user that placed the order was moved from the post meta _customer_user to the post_author field in the wp_posts table.
|
||||||
// phpcs:disable WordPress.WP.PreparedSQL.NotPrepared
|
if ( version_compare( get_option( 'woocommerce_db_version' ), '3.5.0', '>=' ) ) {
|
||||||
"SELECT COUNT(*)
|
$query = "SELECT COUNT(*)
|
||||||
|
FROM $wpdb->posts
|
||||||
|
WHERE post_type = 'shop_order'
|
||||||
|
AND post_status IN ( '" . implode( "','", array_map( 'esc_sql', array_keys( wc_get_order_statuses() ) ) ) . "' )
|
||||||
|
AND post_author = " . esc_sql( $customer->get_id() );
|
||||||
|
} else {
|
||||||
|
$query = "SELECT COUNT(*)
|
||||||
FROM $wpdb->posts as posts
|
FROM $wpdb->posts as posts
|
||||||
LEFT JOIN {$wpdb->postmeta} AS meta ON posts.ID = meta.post_id
|
LEFT JOIN {$wpdb->postmeta} AS meta ON posts.ID = meta.post_id
|
||||||
WHERE meta.meta_key = '_customer_user'
|
WHERE meta.meta_key = '_customer_user'
|
||||||
AND posts.post_type = 'shop_order'
|
AND posts.post_type = 'shop_order'
|
||||||
AND posts.post_status IN ( '" . implode( "','", array_map( 'esc_sql', array_keys( wc_get_order_statuses() ) ) ) . "' )
|
AND posts.post_status IN ( '" . implode( "','", array_map( 'esc_sql', array_keys( wc_get_order_statuses() ) ) ) . "' )
|
||||||
AND meta_value = '" . esc_sql( $customer->get_id() ) . "'"
|
AND meta_value = '" . esc_sql( $customer->get_id() ) . "'";
|
||||||
// phpcs:enable
|
}
|
||||||
);
|
|
||||||
|
// phpcs:ignore WordPress.WP.PreparedSQL.NotPrepared
|
||||||
|
$count = $wpdb->get_var( $query );
|
||||||
update_user_meta( $customer->get_id(), '_order_count', $count );
|
update_user_meta( $customer->get_id(), '_order_count', $count );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -393,11 +410,18 @@ class WC_Customer_Data_Store extends WC_Data_Store_WP implements WC_Customer_Dat
|
||||||
global $wpdb;
|
global $wpdb;
|
||||||
|
|
||||||
$statuses = array_map( 'esc_sql', wc_get_is_paid_statuses() );
|
$statuses = array_map( 'esc_sql', wc_get_is_paid_statuses() );
|
||||||
$spent = $wpdb->get_var(
|
|
||||||
// phpcs:disable WordPress.WP.PreparedSQL.NotPrepared
|
// On WC 3.5.0 the ID of the user that placed the order was moved from the post meta _customer_user to the post_author field in the wp_posts table.
|
||||||
apply_filters(
|
if ( version_compare( get_option( 'woocommerce_db_version' ), '3.5.0', '>=' ) ) {
|
||||||
'woocommerce_customer_get_total_spent_query',
|
$query = "SELECT SUM(meta.meta_value)
|
||||||
"SELECT SUM(meta2.meta_value)
|
FROM $wpdb->posts as posts
|
||||||
|
LEFT JOIN {$wpdb->postmeta} AS meta ON posts.ID = meta.post_id
|
||||||
|
WHERE posts.post_author = '" . esc_sql( $customer->get_id() ) . "'
|
||||||
|
AND posts.post_type = 'shop_order'
|
||||||
|
AND posts.post_status IN ( 'wc-" . implode( "','wc-", $statuses ) . "' )
|
||||||
|
AND meta.meta_key = '_order_total'";
|
||||||
|
} else {
|
||||||
|
$query = "SELECT SUM(meta2.meta_value)
|
||||||
FROM $wpdb->posts as posts
|
FROM $wpdb->posts as posts
|
||||||
LEFT JOIN {$wpdb->postmeta} AS meta ON posts.ID = meta.post_id
|
LEFT JOIN {$wpdb->postmeta} AS meta ON posts.ID = meta.post_id
|
||||||
LEFT JOIN {$wpdb->postmeta} AS meta2 ON posts.ID = meta2.post_id
|
LEFT JOIN {$wpdb->postmeta} AS meta2 ON posts.ID = meta2.post_id
|
||||||
|
@ -405,11 +429,11 @@ class WC_Customer_Data_Store extends WC_Data_Store_WP implements WC_Customer_Dat
|
||||||
AND meta.meta_value = '" . esc_sql( $customer->get_id() ) . "'
|
AND meta.meta_value = '" . esc_sql( $customer->get_id() ) . "'
|
||||||
AND posts.post_type = 'shop_order'
|
AND posts.post_type = 'shop_order'
|
||||||
AND posts.post_status IN ( 'wc-" . implode( "','wc-", $statuses ) . "' )
|
AND posts.post_status IN ( 'wc-" . implode( "','wc-", $statuses ) . "' )
|
||||||
AND meta2.meta_key = '_order_total'",
|
AND meta2.meta_key = '_order_total'";
|
||||||
$customer
|
}
|
||||||
)
|
|
||||||
// phpcs:enable
|
// phpcs:ignore WordPress.WP.PreparedSQL.NotPrepared
|
||||||
);
|
$spent = $wpdb->get_var( apply_filters( 'woocommerce_customer_get_total_spent_query', $query, $customer ) );
|
||||||
|
|
||||||
if ( ! $spent ) {
|
if ( ! $spent ) {
|
||||||
$spent = 0;
|
$spent = 0;
|
||||||
|
|
|
@ -107,10 +107,17 @@ class WC_Order_Data_Store_CPT extends Abstract_WC_Order_Data_Store_CPT implement
|
||||||
$date_paid = get_post_meta( $id, '_paid_date', true );
|
$date_paid = get_post_meta( $id, '_paid_date', true );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// On WC 3.5.0 the ID of the user that placed the order was moved from the post meta _customer_user to the post_author field in the wp_posts table.
|
||||||
|
if ( version_compare( get_option( 'woocommerce_db_version' ), '3.5.0', '>=' ) ) {
|
||||||
|
$customer_id = $post_object->post_author;
|
||||||
|
} else {
|
||||||
|
$customer_id = get_post_meta( $id, '_customer_user', true );
|
||||||
|
}
|
||||||
|
|
||||||
$order->set_props(
|
$order->set_props(
|
||||||
array(
|
array(
|
||||||
'order_key' => get_post_meta( $id, '_order_key', true ),
|
'order_key' => get_post_meta( $id, '_order_key', true ),
|
||||||
'customer_id' => get_post_meta( $id, '_customer_user', true ),
|
'customer_id' => $customer_id,
|
||||||
'billing_first_name' => get_post_meta( $id, '_billing_first_name', true ),
|
'billing_first_name' => get_post_meta( $id, '_billing_first_name', true ),
|
||||||
'billing_last_name' => get_post_meta( $id, '_billing_last_name', true ),
|
'billing_last_name' => get_post_meta( $id, '_billing_last_name', true ),
|
||||||
'billing_company' => get_post_meta( $id, '_billing_company', true ),
|
'billing_company' => get_post_meta( $id, '_billing_company', true ),
|
||||||
|
@ -258,10 +265,9 @@ class WC_Order_Data_Store_CPT extends Abstract_WC_Order_Data_Store_CPT implement
|
||||||
update_post_meta( $id, '_shipping_address_index', implode( ' ', $order->get_address( 'shipping' ) ) );
|
update_post_meta( $id, '_shipping_address_index', implode( ' ', $order->get_address( 'shipping' ) ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
// If customer changed, update any downloadable permissions.
|
// If customer email changed, update any downloadable permissions.
|
||||||
if ( in_array( 'customer_id', $updated_props, true ) || in_array( 'billing_email', $updated_props, true ) ) {
|
if ( in_array( 'billing_email', $updated_props ) ) {
|
||||||
$data_store = WC_Data_Store::load( 'customer-download' );
|
$this->update_downloadable_permissions( $order );
|
||||||
$data_store->update_user_by_order_id( $id, $order->get_customer_id(), $order->get_billing_email() );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Mark user account as active.
|
// Mark user account as active.
|
||||||
|
@ -645,6 +651,11 @@ class WC_Order_Data_Store_CPT extends Abstract_WC_Order_Data_Store_CPT implement
|
||||||
'page' => 'paged',
|
'page' => 'paged',
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// On WC 3.5.0 the ID of the user that placed the order was moved from the post meta _customer_user to the post_author field in the wp_posts table.
|
||||||
|
if ( version_compare( get_option( 'woocommerce_db_version' ), '3.5.0', '>=' ) ) {
|
||||||
|
$key_mapping['customer_id'] = 'author';
|
||||||
|
}
|
||||||
|
|
||||||
foreach ( $key_mapping as $query_key => $db_key ) {
|
foreach ( $key_mapping as $query_key => $db_key ) {
|
||||||
if ( isset( $query_vars[ $query_key ] ) ) {
|
if ( isset( $query_vars[ $query_key ] ) ) {
|
||||||
$query_vars[ $db_key ] = $query_vars[ $query_key ];
|
$query_vars[ $db_key ] = $query_vars[ $query_key ];
|
||||||
|
|
|
@ -510,28 +510,45 @@ class WC_Email extends WC_Settings_API {
|
||||||
/**
|
/**
|
||||||
* Apply inline styles to dynamic content.
|
* Apply inline styles to dynamic content.
|
||||||
*
|
*
|
||||||
|
* We only inline CSS for html emails, and to do so we use Emogrifier library (if supported).
|
||||||
|
*
|
||||||
* @param string|null $content Content that will receive inline styles.
|
* @param string|null $content Content that will receive inline styles.
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function style_inline( $content ) {
|
public function style_inline( $content ) {
|
||||||
// make sure we only inline CSS for html emails.
|
if ( in_array( $this->get_content_type(), array( 'text/html', 'multipart/alternative' ), true ) ) {
|
||||||
if ( in_array( $this->get_content_type(), array( 'text/html', 'multipart/alternative' ), true ) && class_exists( 'DOMDocument' ) ) {
|
|
||||||
ob_start();
|
ob_start();
|
||||||
wc_get_template( 'emails/email-styles.php' );
|
wc_get_template( 'emails/email-styles.php' );
|
||||||
$css = apply_filters( 'woocommerce_email_styles', ob_get_clean() );
|
$css = apply_filters( 'woocommerce_email_styles', ob_get_clean() );
|
||||||
|
|
||||||
// apply CSS styles inline for picky email clients.
|
if ( $this->supports_emogrifier() ) {
|
||||||
try {
|
if ( ! class_exists( 'Emogrifier' ) ) {
|
||||||
$emogrifier = new Emogrifier( $content, $css );
|
include_once dirname( dirname( __FILE__ ) ) . '/libraries/class-emogrifier.php';
|
||||||
$content = $emogrifier->emogrify();
|
}
|
||||||
} catch ( Exception $e ) {
|
try {
|
||||||
$logger = wc_get_logger();
|
$emogrifier = new Emogrifier( $content, $css );
|
||||||
$logger->error( $e->getMessage(), array( 'source' => 'emogrifier' ) );
|
$content = $emogrifier->emogrify();
|
||||||
|
} catch ( Exception $e ) {
|
||||||
|
$logger = wc_get_logger();
|
||||||
|
$logger->error( $e->getMessage(), array( 'source' => 'emogrifier' ) );
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$content = '<style type="text/css">' . $css . '</style>' . $content;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return $content;
|
return $content;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return if emogrifier library is supported.
|
||||||
|
*
|
||||||
|
* @since 3.5.0
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
protected function supports_emogrifier() {
|
||||||
|
return class_exists( 'DOMDocument' ) && version_compare( PHP_VERSION, '5.5', '>=' );
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the email content in plain text format.
|
* Get the email content in plain text format.
|
||||||
*
|
*
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -1835,3 +1835,130 @@ function wc_update_343_cleanup_foreign_keys() {
|
||||||
function wc_update_343_db_version() {
|
function wc_update_343_db_version() {
|
||||||
WC_Install::update_db_version( '3.4.3' );
|
WC_Install::update_db_version( '3.4.3' );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Copy order customer_id from post meta to post_author and set post_author to 0 for refunds.
|
||||||
|
*
|
||||||
|
* Two different strategies are used to copy data depending if the update is being executed from
|
||||||
|
* the command line or not. If `wp wc update` is used to update the database, this function
|
||||||
|
* copies data in a single go that is faster but uses more resources. If the databse update was
|
||||||
|
* triggered from the wp-admin, this function copies data in batches which is slower but uses
|
||||||
|
* few resources and thus is less likely to fail on smaller servers.
|
||||||
|
*
|
||||||
|
* @param WC_Background_Updater|false $updater Background updater instance or false if function is called from `wp wc update` WP-CLI command.
|
||||||
|
* @return true|void Return true if near memory limit and needs to restart. Return void if update completed.
|
||||||
|
*/
|
||||||
|
function wc_update_350_order_customer_id( $updater = false ) {
|
||||||
|
global $wpdb;
|
||||||
|
|
||||||
|
$post_types = (array) apply_filters( 'woocommerce_update_350_order_customer_id_post_types', array( 'shop_order' ) );
|
||||||
|
$post_types_placeholders = implode( ', ', array_fill( 0, count( $post_types ), '%s' ) );
|
||||||
|
|
||||||
|
if ( defined( 'WP_CLI' ) && WP_CLI ) {
|
||||||
|
// If running the update from the command-line, copy data in a single go which is faster but uses more resources.
|
||||||
|
$wpdb->query(
|
||||||
|
'CREATE TEMPORARY TABLE customers_map (post_id BIGINT(20), customer_id BIGINT(20), PRIMARY KEY(post_id))'
|
||||||
|
);
|
||||||
|
|
||||||
|
$wpdb->query(
|
||||||
|
"INSERT IGNORE INTO customers_map (SELECT post_id, meta_value FROM wp_postmeta WHERE meta_key = '_customer_user')"
|
||||||
|
);
|
||||||
|
|
||||||
|
$wpdb->query( 'SET sql_safe_updates=1' );
|
||||||
|
|
||||||
|
$wpdb->query(
|
||||||
|
$wpdb->prepare(
|
||||||
|
"UPDATE wp_posts JOIN customers_map ON wp_posts.ID = customers_map.post_id SET wp_posts.post_author = customers_map.customer_id WHERE post_type IN ({$post_types_placeholders})", // phpcs:ignore WordPress.WP.PreparedSQL.NotPrepared
|
||||||
|
$post_types
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
$wpdb->update( $wpdb->posts, array( 'post_author' => 0 ), array( 'post_type' => 'shop_order_refund' ) );
|
||||||
|
} else {
|
||||||
|
// If running the update from the wp-admin, copy data in batches being careful not to use more memory than allowed.
|
||||||
|
$admin_orders_sql = '';
|
||||||
|
$admin_orders = get_transient( 'wc_update_350_admin_orders' );
|
||||||
|
|
||||||
|
if ( false === $admin_orders ) {
|
||||||
|
// Get the list of orders that we don't want to change as they belong to user ID 1.
|
||||||
|
$admin_orders = $wpdb->get_col(
|
||||||
|
$wpdb->prepare(
|
||||||
|
"SELECT ID FROM wp_posts p
|
||||||
|
INNER JOIN wp_postmeta pm ON p.ID = pm.post_id
|
||||||
|
WHERE post_type IN ({$post_types_placeholders}) AND meta_key = '_customer_user' AND meta_value = 1", // phpcs:ignore WordPress.WP.PreparedSQL.NotPrepared
|
||||||
|
$post_types
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
// Cache the list of orders placed by the user ID 1 as to large stores this query can be slow.
|
||||||
|
set_transient( 'wc_update_350_admin_orders', $admin_orders, DAY_IN_SECONDS );
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( ! empty( $admin_orders ) ) {
|
||||||
|
$admin_orders_sql .= ' AND ID NOT IN (' . implode( ', ', $admin_orders ) . ') ';
|
||||||
|
}
|
||||||
|
|
||||||
|
// Query to get a batch of orders IDs to change.
|
||||||
|
$query = $wpdb->prepare(
|
||||||
|
// phpcs:disable WordPress.WP.PreparedSQL.NotPrepared
|
||||||
|
"SELECT ID FROM {$wpdb->posts}
|
||||||
|
WHERE post_author = 1 AND post_type IN ({$post_types_placeholders}) $admin_orders_sql
|
||||||
|
LIMIT 1000",
|
||||||
|
$post_types
|
||||||
|
// phpcs:enable
|
||||||
|
);
|
||||||
|
|
||||||
|
while ( true ) {
|
||||||
|
// phpcs:ignore WordPress.WP.PreparedSQL.NotPrepared
|
||||||
|
$orders_to_update = $wpdb->get_col( $query );
|
||||||
|
|
||||||
|
// Exit loop if no more orders to update.
|
||||||
|
if ( ! $orders_to_update ) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
$orders_meta_data = $wpdb->get_results(
|
||||||
|
// phpcs:ignore WordPress.WP.PreparedSQL.NotPrepared
|
||||||
|
"SELECT post_id, meta_value as customer_id FROM {$wpdb->postmeta} WHERE meta_key = '_customer_user' AND post_id IN (" . implode( ', ', $orders_to_update ) . ')'
|
||||||
|
);
|
||||||
|
|
||||||
|
// Exit loop if no _customer_user metas exist for the list of orders to update.
|
||||||
|
if ( ! $orders_meta_data ) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update post_author for a batch of orders.
|
||||||
|
foreach ( $orders_meta_data as $order_meta ) {
|
||||||
|
// Stop update execution and re-enqueue it if near memory limit.
|
||||||
|
if ( $updater instanceof WC_Background_Updater && $updater->is_memory_exceeded() ) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
$wpdb->update( $wpdb->posts, array( 'post_author' => $order_meta->customer_id ), array( 'ID' => $order_meta->post_id ) );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set post_author to 0 instead of 1 on all shop_order_refunds.
|
||||||
|
while ( true ) {
|
||||||
|
// Stop update execution and re-enqueue it if near memory limit.
|
||||||
|
if ( $updater instanceof WC_Background_Updater && $updater->is_memory_exceeded() ) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
$updated_rows = $wpdb->query( "UPDATE {$wpdb->posts} SET post_author = 0 WHERE post_type = 'shop_order_refund' LIMIT 1000" );
|
||||||
|
|
||||||
|
if ( ! $updated_rows ) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
wp_cache_flush();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update DB Version.
|
||||||
|
*/
|
||||||
|
function wc_update_350_db_version() {
|
||||||
|
WC_Install::update_db_version( '3.5.0' );
|
||||||
|
}
|
||||||
|
|
|
@ -219,11 +219,15 @@ function wc_customer_bought_product( $customer_email, $user_id, $product_id ) {
|
||||||
$result = get_transient( $transient_name );
|
$result = get_transient( $transient_name );
|
||||||
|
|
||||||
if ( false === $result ) {
|
if ( false === $result ) {
|
||||||
$customer_data = array( $user_id );
|
$customer_data = array();
|
||||||
|
|
||||||
if ( $user_id ) {
|
if ( $user_id ) {
|
||||||
$user = get_user_by( 'id', $user_id );
|
$user = get_user_by( 'id', $user_id );
|
||||||
|
|
||||||
|
if ( version_compare( get_option( 'woocommerce_db_version' ), '3.5.0', '<' ) ) {
|
||||||
|
$customer_data[] = $user_id;
|
||||||
|
}
|
||||||
|
|
||||||
if ( isset( $user->user_email ) ) {
|
if ( isset( $user->user_email ) ) {
|
||||||
$customer_data[] = $user->user_email;
|
$customer_data[] = $user->user_email;
|
||||||
}
|
}
|
||||||
|
@ -240,19 +244,31 @@ function wc_customer_bought_product( $customer_email, $user_id, $product_id ) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
$result = $wpdb->get_col(
|
if ( version_compare( get_option( 'woocommerce_db_version' ), '3.5.0', '>=' ) && $user_id ) {
|
||||||
"
|
// Since WC 3.5 wp_posts.post_author is used to store the ID of the customer who placed an order.
|
||||||
SELECT im.meta_value FROM {$wpdb->posts} AS p
|
$query = "SELECT im.meta_value FROM {$wpdb->posts} AS p
|
||||||
INNER JOIN {$wpdb->postmeta} AS pm ON p.ID = pm.post_id
|
INNER JOIN {$wpdb->postmeta} AS pm ON p.ID = pm.post_id
|
||||||
INNER JOIN {$wpdb->prefix}woocommerce_order_items AS i ON p.ID = i.order_id
|
INNER JOIN {$wpdb->prefix}woocommerce_order_items AS i ON p.ID = i.order_id
|
||||||
INNER JOIN {$wpdb->prefix}woocommerce_order_itemmeta AS im ON i.order_item_id = im.order_item_id
|
INNER JOIN {$wpdb->prefix}woocommerce_order_itemmeta AS im ON i.order_item_id = im.order_item_id
|
||||||
WHERE p.post_status IN ( 'wc-" . implode( "','wc-", $statuses ) . "' )
|
WHERE p.post_status IN ( 'wc-" . implode( "','wc-", $statuses ) . "' )
|
||||||
AND pm.meta_key IN ( '_billing_email', '_customer_user' )
|
AND p.post_author = {$user_id}
|
||||||
AND im.meta_key IN ( '_product_id', '_variation_id' )
|
AND pm.meta_key = '_billing_email'
|
||||||
AND im.meta_value != 0
|
AND im.meta_key IN ( '_product_id', '_variation_id' )
|
||||||
AND pm.meta_value IN ( '" . implode( "','", $customer_data ) . "' )
|
AND im.meta_value != 0
|
||||||
"
|
AND pm.meta_value IN ( '" . implode( "','", $customer_data ) . "' )";
|
||||||
); // WPCS: unprepared SQL ok.
|
} else {
|
||||||
|
$query = "SELECT im.meta_value FROM {$wpdb->posts} AS p
|
||||||
|
INNER JOIN {$wpdb->postmeta} AS pm ON p.ID = pm.post_id
|
||||||
|
INNER JOIN {$wpdb->prefix}woocommerce_order_items AS i ON p.ID = i.order_id
|
||||||
|
INNER JOIN {$wpdb->prefix}woocommerce_order_itemmeta AS im ON i.order_item_id = im.order_item_id
|
||||||
|
WHERE p.post_status IN ( 'wc-" . implode( "','wc-", $statuses ) . "' )
|
||||||
|
AND pm.meta_key IN ( '_billing_email', '_customer_user' )
|
||||||
|
AND im.meta_key IN ( '_product_id', '_variation_id' )
|
||||||
|
AND im.meta_value != 0
|
||||||
|
AND pm.meta_value IN ( '" . implode( "','", $customer_data ) . "' )";
|
||||||
|
}
|
||||||
|
|
||||||
|
$result = $wpdb->get_col( $query ); // WPCS: unprepared SQL ok.
|
||||||
$result = array_map( 'absint', $result );
|
$result = array_map( 'absint', $result );
|
||||||
|
|
||||||
set_transient( $transient_name, $result, DAY_IN_SECONDS * 30 );
|
set_transient( $transient_name, $result, DAY_IN_SECONDS * 30 );
|
||||||
|
@ -495,7 +511,7 @@ function wc_get_customer_order_count( $user_id ) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reset _customer_user on orders when a user is deleted.
|
* Reset customer ID on orders when a user is deleted.
|
||||||
*
|
*
|
||||||
* @param int $user_id User ID.
|
* @param int $user_id User ID.
|
||||||
*/
|
*/
|
||||||
|
@ -508,6 +524,22 @@ function wc_reset_order_customer_id_on_deleted_user( $user_id ) {
|
||||||
'meta_value' => $user_id,
|
'meta_value' => $user_id,
|
||||||
)
|
)
|
||||||
); // WPCS: slow query ok.
|
); // WPCS: slow query ok.
|
||||||
|
|
||||||
|
$post_types = (array) apply_filters( 'woocommerce_reset_order_customer_id_post_types', array( 'shop_order' ) );
|
||||||
|
$post_types_placeholders = implode( ', ', array_fill( 0, count( $post_types ), '%s' ) );
|
||||||
|
$query_args = array_merge( $post_types, array( $user_id ) );
|
||||||
|
|
||||||
|
// Since WC 3.5, the customer ID is stored both in the _customer_user postmeta and in the post_author field.
|
||||||
|
// In future versions of WC, the plan is to use only post_author and stop using _customer_user, but for now
|
||||||
|
// we have to update both places.
|
||||||
|
$wpdb->query(
|
||||||
|
// phpcs:disable WordPress.WP.PreparedSQL.NotPrepared, WordPress.DB.PreparedSQLPlaceholders.UnfinishedPrepare
|
||||||
|
$wpdb->prepare(
|
||||||
|
"UPDATE {$wpdb->posts} SET `post_author` = 0 WHERE post_type IN ({$post_types_placeholders}) AND post_author = %d",
|
||||||
|
$query_args
|
||||||
|
)
|
||||||
|
// phpcs:enable
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
add_action( 'deleted_user', 'wc_reset_order_customer_id_on_deleted_user' );
|
add_action( 'deleted_user', 'wc_reset_order_customer_id_on_deleted_user' );
|
||||||
|
|
Loading…
Reference in New Issue