Merge pull request #25428 from woocommerce/update/product-lookuo-table-tax-columns
Add product lookup table tax columns
This commit is contained in:
commit
52e335ae5c
|
@ -140,6 +140,10 @@ class WC_Install {
|
||||||
'wc_update_390_change_geolocation_database_update_cron',
|
'wc_update_390_change_geolocation_database_update_cron',
|
||||||
'wc_update_390_db_version',
|
'wc_update_390_db_version',
|
||||||
),
|
),
|
||||||
|
'4.0.0' => array(
|
||||||
|
'wc_update_product_lookup_tables',
|
||||||
|
'wc_update_400_db_version',
|
||||||
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -903,6 +907,8 @@ CREATE TABLE {$wpdb->prefix}wc_product_meta_lookup (
|
||||||
`rating_count` bigint(20) NULL default 0,
|
`rating_count` bigint(20) NULL default 0,
|
||||||
`average_rating` decimal(3,2) NULL default 0.00,
|
`average_rating` decimal(3,2) NULL default 0.00,
|
||||||
`total_sales` bigint(20) NULL default 0,
|
`total_sales` bigint(20) NULL default 0,
|
||||||
|
`tax_status` varchar(100) NULL default 'taxable',
|
||||||
|
`tax_class` varchar(100) NULL default '',
|
||||||
PRIMARY KEY (`product_id`),
|
PRIMARY KEY (`product_id`),
|
||||||
KEY `virtual` (`virtual`),
|
KEY `virtual` (`virtual`),
|
||||||
KEY `downloadable` (`downloadable`),
|
KEY `downloadable` (`downloadable`),
|
||||||
|
|
|
@ -644,7 +644,7 @@ class WC_Product_Data_Store_CPT extends WC_Data_Store_WP implements WC_Object_Da
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( array_intersect( $this->updated_props, array( 'sku', 'regular_price', 'sale_price', 'date_on_sale_from', 'date_on_sale_to', 'total_sales', 'average_rating', 'stock_quantity', 'stock_status', 'manage_stock', 'downloadable', 'virtual' ) ) ) {
|
if ( array_intersect( $this->updated_props, array( 'sku', 'regular_price', 'sale_price', 'date_on_sale_from', 'date_on_sale_to', 'total_sales', 'average_rating', 'stock_quantity', 'stock_status', 'manage_stock', 'downloadable', 'virtual', 'tax_status', 'tax_class' ) ) ) {
|
||||||
$this->update_lookup_table( $product->get_id(), 'wc_product_meta_lookup' );
|
$this->update_lookup_table( $product->get_id(), 'wc_product_meta_lookup' );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2033,6 +2033,8 @@ class WC_Product_Data_Store_CPT extends WC_Data_Store_WP implements WC_Object_Da
|
||||||
'rating_count' => array_sum( (array) get_post_meta( $id, '_wc_rating_count', true ) ),
|
'rating_count' => array_sum( (array) get_post_meta( $id, '_wc_rating_count', true ) ),
|
||||||
'average_rating' => get_post_meta( $id, '_wc_average_rating', true ),
|
'average_rating' => get_post_meta( $id, '_wc_average_rating', true ),
|
||||||
'total_sales' => get_post_meta( $id, 'total_sales', true ),
|
'total_sales' => get_post_meta( $id, 'total_sales', true ),
|
||||||
|
'tax_status' => get_post_meta( $id, '_tax_status', true ),
|
||||||
|
'tax_class' => get_post_meta( $id, '_tax_class', true ),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
return array();
|
return array();
|
||||||
|
|
|
@ -1365,7 +1365,9 @@ function wc_update_product_lookup_tables() {
|
||||||
'total_sales',
|
'total_sales',
|
||||||
'downloadable',
|
'downloadable',
|
||||||
'virtual',
|
'virtual',
|
||||||
'onsale', // When last column is updated, woocommerce_product_lookup_table_is_generating is updated.
|
'onsale',
|
||||||
|
'tax_class',
|
||||||
|
'tax_status', // When last column is updated, woocommerce_product_lookup_table_is_generating is updated.
|
||||||
);
|
);
|
||||||
|
|
||||||
foreach ( $columns as $index => $column ) {
|
foreach ( $columns as $index => $column ) {
|
||||||
|
@ -1457,6 +1459,8 @@ function wc_update_product_lookup_tables_column( $column ) {
|
||||||
case 'stock_status':
|
case 'stock_status':
|
||||||
case 'average_rating':
|
case 'average_rating':
|
||||||
case 'total_sales':
|
case 'total_sales':
|
||||||
|
case 'tax_class':
|
||||||
|
case 'tax_status':
|
||||||
if ( 'total_sales' === $column ) {
|
if ( 'total_sales' === $column ) {
|
||||||
$meta_key = 'total_sales';
|
$meta_key = 'total_sales';
|
||||||
} elseif ( 'average_rating' === $column ) {
|
} elseif ( 'average_rating' === $column ) {
|
||||||
|
@ -1523,10 +1527,13 @@ function wc_update_product_lookup_tables_column( $column ) {
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
// phpcs:enable WordPress.DB.PreparedSQL.InterpolatedNotPrepared
|
// phpcs:enable WordPress.DB.PreparedSQL.InterpolatedNotPrepared
|
||||||
|
|
||||||
delete_option( 'woocommerce_product_lookup_table_is_generating' ); // Complete.
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Final column - mark complete.
|
||||||
|
if ( 'tax_status' === $column ) {
|
||||||
|
delete_option( 'woocommerce_product_lookup_table_is_generating' );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
add_action( 'wc_update_product_lookup_tables_column', 'wc_update_product_lookup_tables_column' );
|
add_action( 'wc_update_product_lookup_tables_column', 'wc_update_product_lookup_tables_column' );
|
||||||
|
|
||||||
|
|
|
@ -2081,3 +2081,10 @@ function wc_update_390_change_geolocation_database_update_cron() {
|
||||||
function wc_update_390_db_version() {
|
function wc_update_390_db_version() {
|
||||||
WC_Install::update_db_version( '3.9.0' );
|
WC_Install::update_db_version( '3.9.0' );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update DB version.
|
||||||
|
*/
|
||||||
|
function wc_update_400_db_version() {
|
||||||
|
WC_Install::update_db_version( '4.0.0' );
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue