2016-05-11 11:44:12 +00:00
< ? php
/**
* WooCommerce Updates
*
* Functions for updating data , used by the background updater .
*
2018-01-31 17:09:21 +00:00
* @ package WooCommerce / Functions
* @ version 3.3 . 0
2016-05-11 11:44:12 +00:00
*/
2018-03-08 21:31:01 +00:00
defined ( 'ABSPATH' ) || exit ;
2016-05-11 11:44:12 +00:00
2017-10-05 11:48:26 +00:00
/**
* Update file paths for 2.0
*
* @ return void
*/
2016-05-11 11:44:12 +00:00
function wc_update_200_file_paths () {
global $wpdb ;
2017-10-05 11:48:26 +00:00
// Upgrade old style files paths to support multiple file paths.
2017-02-13 12:58:42 +00:00
$existing_file_paths = $wpdb -> get_results ( " SELECT meta_value, meta_id, post_id FROM { $wpdb -> postmeta } WHERE meta_key = '_file_path' AND meta_value != ''; " );
2016-05-11 11:44:12 +00:00
if ( $existing_file_paths ) {
2016-08-27 04:23:02 +00:00
foreach ( $existing_file_paths as $existing_file_path ) {
2016-05-11 11:44:12 +00:00
$old_file_path = trim ( $existing_file_path -> meta_value );
if ( ! empty ( $old_file_path ) ) {
$file_paths = serialize ( array ( md5 ( $old_file_path ) => $old_file_path ) );
$wpdb -> query ( $wpdb -> prepare ( " UPDATE { $wpdb -> postmeta } SET meta_key = '_file_paths', meta_value = %s WHERE meta_id = %d " , $file_paths , $existing_file_path -> meta_id ) );
$wpdb -> query ( $wpdb -> prepare ( " UPDATE { $wpdb -> prefix } woocommerce_downloadable_product_permissions SET download_id = %s WHERE product_id = %d " , md5 ( $old_file_path ), $existing_file_path -> post_id ) );
}
}
}
}
2017-10-05 11:48:26 +00:00
/**
* Update permalinks for 2.0
*
* @ return void
*/
2016-05-11 11:44:12 +00:00
function wc_update_200_permalinks () {
2017-10-05 11:48:26 +00:00
// Setup default permalinks if shop page is defined.
2017-11-23 12:41:31 +00:00
$permalinks = get_option ( 'woocommerce_permalinks' );
$shop_page_id = wc_get_page_id ( 'shop' );
2016-05-11 11:44:12 +00:00
if ( empty ( $permalinks ) && $shop_page_id > 0 ) {
2017-11-23 12:41:31 +00:00
$base_slug = $shop_page_id > 0 && get_post ( $shop_page_id ) ? get_page_uri ( $shop_page_id ) : 'shop' ;
2016-05-11 11:44:12 +00:00
2017-11-23 12:41:31 +00:00
$category_base = get_option ( 'woocommerce_prepend_shop_page_to_urls' ) == 'yes' ? trailingslashit ( $base_slug ) : '' ;
$category_slug = get_option ( 'woocommerce_product_category_slug' ) ? get_option ( 'woocommerce_product_category_slug' ) : _x ( 'product-category' , 'slug' , 'woocommerce' );
$tag_slug = get_option ( 'woocommerce_product_tag_slug' ) ? get_option ( 'woocommerce_product_tag_slug' ) : _x ( 'product-tag' , 'slug' , 'woocommerce' );
2016-05-11 11:44:12 +00:00
2016-09-02 01:51:31 +00:00
if ( 'yes' == get_option ( 'woocommerce_prepend_shop_page_to_products' ) ) {
2016-05-11 11:44:12 +00:00
$product_base = trailingslashit ( $base_slug );
} else {
2017-11-23 14:17:21 +00:00
$product_slug = get_option ( 'woocommerce_product_slug' );
if ( false !== $product_slug && ! empty ( $product_slug ) ) {
2016-05-11 11:44:12 +00:00
$product_base = trailingslashit ( $product_slug );
} else {
2016-09-02 01:51:31 +00:00
$product_base = trailingslashit ( _x ( 'product' , 'slug' , 'woocommerce' ) );
2016-05-11 11:44:12 +00:00
}
}
2017-03-07 20:24:24 +00:00
if ( get_option ( 'woocommerce_prepend_category_to_products' ) == 'yes' ) {
2016-09-02 01:51:31 +00:00
$product_base .= trailingslashit ( '%product_cat%' );
2017-03-07 20:24:24 +00:00
}
2016-05-11 11:44:12 +00:00
$permalinks = array (
2017-11-23 12:41:31 +00:00
'product_base' => untrailingslashit ( $product_base ),
'category_base' => untrailingslashit ( $category_base . $category_slug ),
'attribute_base' => untrailingslashit ( $category_base ),
'tag_base' => untrailingslashit ( $category_base . $tag_slug ),
2016-05-11 11:44:12 +00:00
);
update_option ( 'woocommerce_permalinks' , $permalinks );
}
}
2017-10-05 11:48:26 +00:00
/**
* Update sub - category display options for 2.0
*
* @ return void
*/
2016-05-11 11:44:12 +00:00
function wc_update_200_subcat_display () {
2017-10-05 11:48:26 +00:00
// Update subcat display settings.
2016-05-11 11:44:12 +00:00
if ( get_option ( 'woocommerce_shop_show_subcategories' ) == 'yes' ) {
if ( get_option ( 'woocommerce_hide_products_when_showing_subcategories' ) == 'yes' ) {
update_option ( 'woocommerce_shop_page_display' , 'subcategories' );
} else {
update_option ( 'woocommerce_shop_page_display' , 'both' );
}
}
if ( get_option ( 'woocommerce_show_subcategories' ) == 'yes' ) {
if ( get_option ( 'woocommerce_hide_products_when_showing_subcategories' ) == 'yes' ) {
update_option ( 'woocommerce_category_archive_display' , 'subcategories' );
} else {
update_option ( 'woocommerce_category_archive_display' , 'both' );
}
}
}
2017-10-05 11:48:26 +00:00
/**
* Update tax rates for 2.0
*
* @ return void
*/
2016-05-11 11:44:12 +00:00
function wc_update_200_taxrates () {
global $wpdb ;
2017-10-05 11:48:26 +00:00
// Update tax rates.
2017-11-23 12:41:31 +00:00
$loop = 0 ;
2016-05-11 11:44:12 +00:00
$tax_rates = get_option ( 'woocommerce_tax_rates' );
2017-03-07 20:24:24 +00:00
if ( $tax_rates ) {
2016-05-11 11:44:12 +00:00
foreach ( $tax_rates as $tax_rate ) {
foreach ( $tax_rate [ 'countries' ] as $country => $states ) {
$states = array_reverse ( $states );
foreach ( $states as $state ) {
2016-09-07 22:32:24 +00:00
if ( '*' == $state ) {
2016-05-11 11:44:12 +00:00
$state = '' ;
2016-09-07 22:32:24 +00:00
}
2016-05-11 11:44:12 +00:00
$wpdb -> insert (
2017-10-05 11:48:26 +00:00
$wpdb -> prefix . 'woocommerce_tax_rates' ,
2016-05-11 11:44:12 +00:00
array (
'tax_rate_country' => $country ,
'tax_rate_state' => $state ,
'tax_rate' => $tax_rate [ 'rate' ],
'tax_rate_name' => $tax_rate [ 'label' ],
'tax_rate_priority' => 1 ,
2016-09-07 22:32:24 +00:00
'tax_rate_compound' => ( 'yes' === $tax_rate [ 'compound' ] ) ? 1 : 0 ,
'tax_rate_shipping' => ( 'yes' === $tax_rate [ 'shipping' ] ) ? 1 : 0 ,
2016-05-11 11:44:12 +00:00
'tax_rate_order' => $loop ,
2016-08-27 01:46:45 +00:00
'tax_rate_class' => $tax_rate [ 'class' ],
2016-05-11 11:44:12 +00:00
)
);
$loop ++ ;
}
}
}
2017-03-07 20:24:24 +00:00
}
2016-05-11 11:44:12 +00:00
$local_tax_rates = get_option ( 'woocommerce_local_tax_rates' );
2017-03-07 20:24:24 +00:00
if ( $local_tax_rates ) {
2016-05-11 11:44:12 +00:00
foreach ( $local_tax_rates as $tax_rate ) {
2016-09-07 22:32:24 +00:00
$location_type = ( 'postcode' === $tax_rate [ 'location_type' ] ) ? 'postcode' : 'city' ;
2016-05-11 11:44:12 +00:00
2016-09-07 22:32:24 +00:00
if ( '*' == $tax_rate [ 'state' ] ) {
2016-05-11 11:44:12 +00:00
$tax_rate [ 'state' ] = '' ;
2016-09-07 22:32:24 +00:00
}
2016-05-11 11:44:12 +00:00
$wpdb -> insert (
2017-10-05 11:48:26 +00:00
$wpdb -> prefix . 'woocommerce_tax_rates' ,
2016-05-11 11:44:12 +00:00
array (
'tax_rate_country' => $tax_rate [ 'country' ],
'tax_rate_state' => $tax_rate [ 'state' ],
'tax_rate' => $tax_rate [ 'rate' ],
'tax_rate_name' => $tax_rate [ 'label' ],
'tax_rate_priority' => 2 ,
2016-09-07 22:32:24 +00:00
'tax_rate_compound' => ( 'yes' === $tax_rate [ 'compound' ] ) ? 1 : 0 ,
'tax_rate_shipping' => ( 'yes' === $tax_rate [ 'shipping' ] ) ? 1 : 0 ,
2016-05-11 11:44:12 +00:00
'tax_rate_order' => $loop ,
2016-08-27 01:46:45 +00:00
'tax_rate_class' => $tax_rate [ 'class' ],
2016-05-11 11:44:12 +00:00
)
);
$tax_rate_id = $wpdb -> insert_id ;
if ( $tax_rate [ 'locations' ] ) {
foreach ( $tax_rate [ 'locations' ] as $location ) {
$wpdb -> insert (
2017-10-05 11:48:26 +00:00
$wpdb -> prefix . 'woocommerce_tax_rate_locations' ,
2016-05-11 11:44:12 +00:00
array (
'location_code' => $location ,
'tax_rate_id' => $tax_rate_id ,
'location_type' => $location_type ,
)
);
}
}
$loop ++ ;
}
2017-03-07 20:24:24 +00:00
}
2016-05-11 11:44:12 +00:00
update_option ( 'woocommerce_tax_rates_backup' , $tax_rates );
update_option ( 'woocommerce_local_tax_rates_backup' , $local_tax_rates );
delete_option ( 'woocommerce_tax_rates' );
delete_option ( 'woocommerce_local_tax_rates' );
}
2017-10-05 11:48:26 +00:00
/**
2017-11-23 14:17:54 +00:00
* Update order item line items for 2.0
2017-10-05 11:48:26 +00:00
*
* @ return void
*/
2016-05-11 11:44:12 +00:00
function wc_update_200_line_items () {
global $wpdb ;
2017-10-05 11:48:26 +00:00
// Now its time for the massive update to line items - move them to the new DB tables.
// Reverse with UPDATE `wpwc_postmeta` SET meta_key = '_order_items' WHERE meta_key = '_order_items_old'.
2017-11-23 12:41:31 +00:00
$order_item_rows = $wpdb -> get_results (
" SELECT meta_value, post_id FROM { $wpdb -> postmeta } WHERE meta_key = '_order_items' "
);
2016-05-11 11:44:12 +00:00
foreach ( $order_item_rows as $order_item_row ) {
$order_items = ( array ) maybe_unserialize ( $order_item_row -> meta_value );
foreach ( $order_items as $order_item ) {
if ( ! isset ( $order_item [ 'line_total' ] ) && isset ( $order_item [ 'taxrate' ] ) && isset ( $order_item [ 'cost' ] ) ) {
2017-11-23 12:41:31 +00:00
$order_item [ 'line_tax' ] = number_format ( ( $order_item [ 'cost' ] * $order_item [ 'qty' ] ) * ( $order_item [ 'taxrate' ] / 100 ), 2 , '.' , '' );
$order_item [ 'line_total' ] = $order_item [ 'cost' ] * $order_item [ 'qty' ];
$order_item [ 'line_subtotal_tax' ] = $order_item [ 'line_tax' ];
$order_item [ 'line_subtotal' ] = $order_item [ 'line_total' ];
2016-05-11 11:44:12 +00:00
}
2017-11-23 12:41:31 +00:00
$order_item [ 'line_tax' ] = isset ( $order_item [ 'line_tax' ] ) ? $order_item [ 'line_tax' ] : 0 ;
$order_item [ 'line_total' ] = isset ( $order_item [ 'line_total' ] ) ? $order_item [ 'line_total' ] : 0 ;
$order_item [ 'line_subtotal_tax' ] = isset ( $order_item [ 'line_subtotal_tax' ] ) ? $order_item [ 'line_subtotal_tax' ] : 0 ;
$order_item [ 'line_subtotal' ] = isset ( $order_item [ 'line_subtotal' ] ) ? $order_item [ 'line_subtotal' ] : 0 ;
2016-05-11 11:44:12 +00:00
2017-11-23 12:41:31 +00:00
$item_id = wc_add_order_item (
$order_item_row -> post_id ,
array (
'order_item_name' => $order_item [ 'name' ],
'order_item_type' => 'line_item' ,
)
);
2017-10-05 11:48:26 +00:00
// Add line item meta.
if ( $item_id ) {
wc_add_order_item_meta ( $item_id , '_qty' , absint ( $order_item [ 'qty' ] ) );
wc_add_order_item_meta ( $item_id , '_tax_class' , $order_item [ 'tax_class' ] );
wc_add_order_item_meta ( $item_id , '_product_id' , $order_item [ 'id' ] );
wc_add_order_item_meta ( $item_id , '_variation_id' , $order_item [ 'variation_id' ] );
wc_add_order_item_meta ( $item_id , '_line_subtotal' , wc_format_decimal ( $order_item [ 'line_subtotal' ] ) );
wc_add_order_item_meta ( $item_id , '_line_subtotal_tax' , wc_format_decimal ( $order_item [ 'line_subtotal_tax' ] ) );
wc_add_order_item_meta ( $item_id , '_line_total' , wc_format_decimal ( $order_item [ 'line_total' ] ) );
wc_add_order_item_meta ( $item_id , '_line_tax' , wc_format_decimal ( $order_item [ 'line_tax' ] ) );
$meta_rows = array ();
// Insert meta.
2016-05-11 11:44:12 +00:00
if ( ! empty ( $order_item [ 'item_meta' ] ) ) {
foreach ( $order_item [ 'item_meta' ] as $key => $meta ) {
2017-10-05 11:48:26 +00:00
// Backwards compatibility.
2016-05-11 11:44:12 +00:00
if ( is_array ( $meta ) && isset ( $meta [ 'meta_name' ] ) ) {
$meta_rows [] = '(' . $item_id . ',"' . esc_sql ( $meta [ 'meta_name' ] ) . '","' . esc_sql ( $meta [ 'meta_value' ] ) . '")' ;
} else {
$meta_rows [] = '(' . $item_id . ',"' . esc_sql ( $key ) . '","' . esc_sql ( $meta ) . '")' ;
}
}
}
2017-10-05 11:48:26 +00:00
// Insert meta rows at once.
if ( count ( $meta_rows ) > 0 ) {
2017-11-23 12:41:31 +00:00
$wpdb -> query (
$wpdb -> prepare (
" INSERT INTO { $wpdb -> prefix } woocommerce_order_itemmeta ( order_item_id, meta_key, meta_value )
2017-11-23 14:17:21 +00:00
VALUES " . implode( ',', $meta_rows ) . ';', // @codingStandardsIgnoreLine
2017-11-23 12:41:31 +00:00
$order_item_row -> post_id
)
);
2016-05-11 11:44:12 +00:00
}
2017-10-05 11:48:26 +00:00
// Delete from DB (rename).
2017-11-23 12:41:31 +00:00
$wpdb -> query (
$wpdb -> prepare (
" UPDATE { $wpdb -> postmeta }
SET meta_key = '_order_items_old'
WHERE meta_key = '_order_items'
AND post_id = % d " ,
$order_item_row -> post_id
)
);
2017-10-05 11:48:26 +00:00
}
2016-05-11 11:44:12 +00:00
unset ( $meta_rows , $item_id , $order_item );
}
}
2017-10-05 11:48:26 +00:00
// Do the same kind of update for order_taxes - move to lines.
// Reverse with UPDATE `wpwc_postmeta` SET meta_key = '_order_taxes' WHERE meta_key = '_order_taxes_old'.
2017-11-23 12:41:31 +00:00
$order_tax_rows = $wpdb -> get_results (
" SELECT meta_value, post_id FROM { $wpdb -> postmeta }
WHERE meta_key = '_order_taxes' "
);
2016-05-11 11:44:12 +00:00
foreach ( $order_tax_rows as $order_tax_row ) {
$order_taxes = ( array ) maybe_unserialize ( $order_tax_row -> meta_value );
2016-06-06 18:39:23 +00:00
if ( ! empty ( $order_taxes ) ) {
2016-08-27 04:23:02 +00:00
foreach ( $order_taxes as $order_tax ) {
2016-05-11 11:44:12 +00:00
2017-03-07 20:24:24 +00:00
if ( ! isset ( $order_tax [ 'label' ] ) || ! isset ( $order_tax [ 'cart_tax' ] ) || ! isset ( $order_tax [ 'shipping_tax' ] ) ) {
2016-05-11 11:44:12 +00:00
continue ;
2017-03-07 20:24:24 +00:00
}
2016-05-11 11:44:12 +00:00
2017-11-23 12:41:31 +00:00
$item_id = wc_add_order_item (
$order_tax_row -> post_id , array (
'order_item_name' => $order_tax [ 'label' ],
'order_item_type' => 'tax' ,
)
);
2017-10-05 11:48:26 +00:00
// Add line item meta.
if ( $item_id ) {
wc_add_order_item_meta ( $item_id , 'compound' , absint ( isset ( $order_tax [ 'compound' ] ) ? $order_tax [ 'compound' ] : 0 ) );
wc_add_order_item_meta ( $item_id , 'tax_amount' , wc_clean ( $order_tax [ 'cart_tax' ] ) );
wc_add_order_item_meta ( $item_id , 'shipping_tax_amount' , wc_clean ( $order_tax [ 'shipping_tax' ] ) );
2016-05-11 11:44:12 +00:00
}
2017-10-05 11:48:26 +00:00
// Delete from DB (rename).
2017-11-23 12:41:31 +00:00
$wpdb -> query (
$wpdb -> prepare (
" UPDATE { $wpdb -> postmeta }
SET meta_key = '_order_taxes_old'
WHERE meta_key = '_order_taxes'
AND post_id = % d " ,
$order_tax_row -> post_id
)
);
2016-05-11 11:44:12 +00:00
unset ( $tax_amount );
}
}
}
}
2017-10-05 11:48:26 +00:00
/**
* Update image settings for 2.0
*
* @ return void
*/
2016-05-11 11:44:12 +00:00
function wc_update_200_images () {
// Grab the pre 2.0 Image options and use to populate the new image options settings,
2017-10-05 11:48:26 +00:00
// cleaning up afterwards like nice people do.
2016-05-11 11:44:12 +00:00
foreach ( array ( 'catalog' , 'single' , 'thumbnail' ) as $value ) {
2017-11-23 12:41:31 +00:00
$old_settings = array_filter (
array (
'width' => get_option ( 'woocommerce_' . $value . '_image_width' ),
'height' => get_option ( 'woocommerce_' . $value . '_image_height' ),
'crop' => get_option ( 'woocommerce_' . $value . '_image_crop' ),
)
);
2016-05-11 11:44:12 +00:00
2016-09-02 01:51:31 +00:00
if ( ! empty ( $old_settings ) && update_option ( 'shop_' . $value . '_image_size' , $old_settings ) ) {
2016-05-11 11:44:12 +00:00
delete_option ( 'woocommerce_' . $value . '_image_width' );
delete_option ( 'woocommerce_' . $value . '_image_height' );
delete_option ( 'woocommerce_' . $value . '_image_crop' );
}
}
}
2017-10-05 11:48:26 +00:00
/**
* Update DB version for 2.0
*
* @ return void
*/
2016-05-11 11:44:12 +00:00
function wc_update_200_db_version () {
WC_Install :: update_db_version ( '2.0.0' );
}
2017-10-05 11:48:26 +00:00
/**
* Update Brazilian States for 2.0 . 9
*
* @ return void
*/
2016-05-11 11:44:12 +00:00
function wc_update_209_brazillian_state () {
global $wpdb ;
2017-10-05 11:48:26 +00:00
// Update brazillian state codes.
2016-05-11 11:44:12 +00:00
$wpdb -> update (
$wpdb -> postmeta ,
array (
2016-08-27 01:46:45 +00:00
'meta_value' => 'BA' ,
2016-05-11 11:44:12 +00:00
),
array (
'meta_key' => '_billing_state' ,
2016-08-27 01:46:45 +00:00
'meta_value' => 'BH' ,
2016-05-11 11:44:12 +00:00
)
);
$wpdb -> update (
$wpdb -> postmeta ,
array (
2016-08-27 01:46:45 +00:00
'meta_value' => 'BA' ,
2016-05-11 11:44:12 +00:00
),
array (
'meta_key' => '_shipping_state' ,
2016-08-27 01:46:45 +00:00
'meta_value' => 'BH' ,
2016-05-11 11:44:12 +00:00
)
);
$wpdb -> update (
$wpdb -> usermeta ,
array (
2016-08-27 01:46:45 +00:00
'meta_value' => 'BA' ,
2016-05-11 11:44:12 +00:00
),
array (
'meta_key' => 'billing_state' ,
2016-08-27 01:46:45 +00:00
'meta_value' => 'BH' ,
2016-05-11 11:44:12 +00:00
)
);
$wpdb -> update (
$wpdb -> usermeta ,
array (
2016-08-27 01:46:45 +00:00
'meta_value' => 'BA' ,
2016-05-11 11:44:12 +00:00
),
array (
'meta_key' => 'shipping_state' ,
2016-08-27 01:46:45 +00:00
'meta_value' => 'BH' ,
2016-05-11 11:44:12 +00:00
)
);
}
2017-10-05 11:48:26 +00:00
/**
* Update DB version for 2.0 . 9
*
* @ return void
*/
2016-05-11 11:44:12 +00:00
function wc_update_209_db_version () {
WC_Install :: update_db_version ( '2.0.9' );
}
2017-10-05 11:48:26 +00:00
/**
* Remove pages for 2.1
*
* @ return void
*/
2016-05-11 11:44:12 +00:00
function wc_update_210_remove_pages () {
2017-10-05 11:48:26 +00:00
// Pages no longer used.
2016-09-02 01:51:31 +00:00
wp_trash_post ( get_option ( 'woocommerce_pay_page_id' ) );
wp_trash_post ( get_option ( 'woocommerce_thanks_page_id' ) );
wp_trash_post ( get_option ( 'woocommerce_view_order_page_id' ) );
wp_trash_post ( get_option ( 'woocommerce_change_password_page_id' ) );
wp_trash_post ( get_option ( 'woocommerce_edit_address_page_id' ) );
wp_trash_post ( get_option ( 'woocommerce_lost_password_page_id' ) );
2016-05-11 11:44:12 +00:00
}
2017-10-05 11:48:26 +00:00
/**
* Update file paths to support multiple files for 2.1
*
* @ return void
*/
2016-05-11 11:44:12 +00:00
function wc_update_210_file_paths () {
global $wpdb ;
2017-10-05 11:48:26 +00:00
// Upgrade file paths to support multiple file paths + names etc.
2017-02-13 12:58:42 +00:00
$existing_file_paths = $wpdb -> get_results ( " SELECT meta_value, meta_id FROM { $wpdb -> postmeta } WHERE meta_key = '_file_paths' AND meta_value != ''; " );
2016-05-11 11:44:12 +00:00
if ( $existing_file_paths ) {
2016-08-27 04:23:02 +00:00
foreach ( $existing_file_paths as $existing_file_path ) {
2016-05-11 11:44:12 +00:00
$needs_update = false ;
$new_value = array ();
$value = maybe_unserialize ( trim ( $existing_file_path -> meta_value ) );
if ( $value ) {
foreach ( $value as $key => $file ) {
if ( ! is_array ( $file ) ) {
$needs_update = true ;
$new_value [ $key ] = array (
'file' => $file ,
2016-08-27 01:46:45 +00:00
'name' => wc_get_filename_from_url ( $file ),
2016-05-11 11:44:12 +00:00
);
} else {
$new_value [ $key ] = $file ;
}
}
if ( $needs_update ) {
$new_value = serialize ( $new_value );
$wpdb -> query ( $wpdb -> prepare ( " UPDATE { $wpdb -> postmeta } SET meta_key = %s, meta_value = %s WHERE meta_id = %d " , '_downloadable_files' , $new_value , $existing_file_path -> meta_id ) );
}
}
}
}
}
2017-10-05 11:48:26 +00:00
/**
* Update DB version for 2.1
*
* @ return void
*/
2016-05-11 11:44:12 +00:00
function wc_update_210_db_version () {
WC_Install :: update_db_version ( '2.1.0' );
}
2017-10-05 11:48:26 +00:00
/**
* Update shipping options for 2.2
*
* @ return void
*/
2016-05-11 11:44:12 +00:00
function wc_update_220_shipping () {
$woocommerce_ship_to_destination = 'shipping' ;
if ( get_option ( 'woocommerce_ship_to_billing_address_only' ) === 'yes' ) {
$woocommerce_ship_to_destination = 'billing_only' ;
} elseif ( get_option ( 'woocommerce_ship_to_billing' ) === 'yes' ) {
$woocommerce_ship_to_destination = 'billing' ;
}
add_option ( 'woocommerce_ship_to_destination' , $woocommerce_ship_to_destination , '' , 'no' );
}
2017-10-05 11:48:26 +00:00
/**
* Update order statuses for 2.2
*
* @ return void
*/
2016-05-11 11:44:12 +00:00
function wc_update_220_order_status () {
global $wpdb ;
2017-11-23 12:41:31 +00:00
$wpdb -> query (
" UPDATE { $wpdb -> posts } as posts
2016-06-15 18:20:48 +00:00
LEFT JOIN { $wpdb -> term_relationships } AS rel ON posts . ID = rel . object_id
2016-05-11 11:44:12 +00:00
LEFT JOIN { $wpdb -> term_taxonomy } AS tax USING ( term_taxonomy_id )
LEFT JOIN { $wpdb -> terms } AS term USING ( term_id )
SET posts . post_status = 'wc-pending'
WHERE posts . post_type = 'shop_order'
AND posts . post_status = 'publish'
AND tax . taxonomy = 'shop_order_status'
2017-11-23 12:41:31 +00:00
AND term . slug LIKE 'pending%' ; "
2016-05-11 11:44:12 +00:00
);
2017-11-23 12:41:31 +00:00
$wpdb -> query (
" UPDATE { $wpdb -> posts } as posts
2016-06-15 18:20:48 +00:00
LEFT JOIN { $wpdb -> term_relationships } AS rel ON posts . ID = rel . object_id
2016-05-11 11:44:12 +00:00
LEFT JOIN { $wpdb -> term_taxonomy } AS tax USING ( term_taxonomy_id )
LEFT JOIN { $wpdb -> terms } AS term USING ( term_id )
SET posts . post_status = 'wc-processing'
WHERE posts . post_type = 'shop_order'
AND posts . post_status = 'publish'
AND tax . taxonomy = 'shop_order_status'
2017-11-23 12:41:31 +00:00
AND term . slug LIKE 'processing%' ; "
2016-05-11 11:44:12 +00:00
);
2017-11-23 12:41:31 +00:00
$wpdb -> query (
" UPDATE { $wpdb -> posts } as posts
2016-06-15 18:20:48 +00:00
LEFT JOIN { $wpdb -> term_relationships } AS rel ON posts . ID = rel . object_id
2016-05-11 11:44:12 +00:00
LEFT JOIN { $wpdb -> term_taxonomy } AS tax USING ( term_taxonomy_id )
LEFT JOIN { $wpdb -> terms } AS term USING ( term_id )
SET posts . post_status = 'wc-on-hold'
WHERE posts . post_type = 'shop_order'
AND posts . post_status = 'publish'
AND tax . taxonomy = 'shop_order_status'
2017-11-23 12:41:31 +00:00
AND term . slug LIKE 'on-hold%' ; "
2016-05-11 11:44:12 +00:00
);
2017-11-23 12:41:31 +00:00
$wpdb -> query (
" UPDATE { $wpdb -> posts } as posts
2016-06-15 18:20:48 +00:00
LEFT JOIN { $wpdb -> term_relationships } AS rel ON posts . ID = rel . object_id
2016-05-11 11:44:12 +00:00
LEFT JOIN { $wpdb -> term_taxonomy } AS tax USING ( term_taxonomy_id )
LEFT JOIN { $wpdb -> terms } AS term USING ( term_id )
SET posts . post_status = 'wc-completed'
WHERE posts . post_type = 'shop_order'
AND posts . post_status = 'publish'
AND tax . taxonomy = 'shop_order_status'
2017-11-23 12:41:31 +00:00
AND term . slug LIKE 'completed%' ; "
2016-05-11 11:44:12 +00:00
);
2017-11-23 12:41:31 +00:00
$wpdb -> query (
" UPDATE { $wpdb -> posts } as posts
2016-06-15 18:20:48 +00:00
LEFT JOIN { $wpdb -> term_relationships } AS rel ON posts . ID = rel . object_id
2016-05-11 11:44:12 +00:00
LEFT JOIN { $wpdb -> term_taxonomy } AS tax USING ( term_taxonomy_id )
LEFT JOIN { $wpdb -> terms } AS term USING ( term_id )
SET posts . post_status = 'wc-cancelled'
WHERE posts . post_type = 'shop_order'
AND posts . post_status = 'publish'
AND tax . taxonomy = 'shop_order_status'
2017-11-23 12:41:31 +00:00
AND term . slug LIKE 'cancelled%' ; "
2016-05-11 11:44:12 +00:00
);
2017-11-23 12:41:31 +00:00
$wpdb -> query (
" UPDATE { $wpdb -> posts } as posts
2016-06-15 18:20:48 +00:00
LEFT JOIN { $wpdb -> term_relationships } AS rel ON posts . ID = rel . object_id
2016-05-11 11:44:12 +00:00
LEFT JOIN { $wpdb -> term_taxonomy } AS tax USING ( term_taxonomy_id )
LEFT JOIN { $wpdb -> terms } AS term USING ( term_id )
SET posts . post_status = 'wc-refunded'
WHERE posts . post_type = 'shop_order'
AND posts . post_status = 'publish'
AND tax . taxonomy = 'shop_order_status'
2017-11-23 12:41:31 +00:00
AND term . slug LIKE 'refunded%' ; "
2016-05-11 11:44:12 +00:00
);
2017-11-23 12:41:31 +00:00
$wpdb -> query (
" UPDATE { $wpdb -> posts } as posts
2016-06-15 18:20:48 +00:00
LEFT JOIN { $wpdb -> term_relationships } AS rel ON posts . ID = rel . object_id
2016-05-11 11:44:12 +00:00
LEFT JOIN { $wpdb -> term_taxonomy } AS tax USING ( term_taxonomy_id )
LEFT JOIN { $wpdb -> terms } AS term USING ( term_id )
SET posts . post_status = 'wc-failed'
WHERE posts . post_type = 'shop_order'
AND posts . post_status = 'publish'
AND tax . taxonomy = 'shop_order_status'
2017-11-23 12:41:31 +00:00
AND term . slug LIKE 'failed%' ; "
2016-05-11 11:44:12 +00:00
);
}
2017-10-05 11:48:26 +00:00
/**
* Update variations for 2.2
*
* @ return void
*/
2016-05-11 11:44:12 +00:00
function wc_update_220_variations () {
global $wpdb ;
2017-10-05 11:48:26 +00:00
// Update variations which manage stock.
2017-11-23 12:41:31 +00:00
$update_variations = $wpdb -> get_results (
" SELECT DISTINCT posts.ID AS variation_id, posts.post_parent AS variation_parent FROM { $wpdb -> posts } as posts
2016-05-11 11:44:12 +00:00
LEFT OUTER JOIN { $wpdb -> postmeta } AS postmeta ON posts . ID = postmeta . post_id AND postmeta . meta_key = '_stock'
LEFT OUTER JOIN { $wpdb -> postmeta } as postmeta2 ON posts . ID = postmeta2 . post_id AND postmeta2 . meta_key = '_manage_stock'
WHERE posts . post_type = 'product_variation'
AND postmeta . meta_value IS NOT NULL
AND postmeta . meta_value != ''
2017-11-23 12:41:31 +00:00
AND postmeta2 . meta_value IS NULL "
);
2016-05-11 11:44:12 +00:00
foreach ( $update_variations as $variation ) {
$parent_backorders = get_post_meta ( $variation -> variation_parent , '_backorders' , true );
add_post_meta ( $variation -> variation_id , '_manage_stock' , 'yes' , true );
add_post_meta ( $variation -> variation_id , '_backorders' , $parent_backorders ? $parent_backorders : 'no' , true );
}
}
2017-10-05 11:48:26 +00:00
/**
* Update attributes for 2.2
*
* @ return void
*/
2016-05-11 11:44:12 +00:00
function wc_update_220_attributes () {
global $wpdb ;
2017-10-05 11:48:26 +00:00
// Update taxonomy names with correct sanitized names.
$attribute_taxonomies = $wpdb -> get_results ( 'SELECT attribute_name, attribute_id FROM ' . $wpdb -> prefix . 'woocommerce_attribute_taxonomies' );
2016-05-11 11:44:12 +00:00
foreach ( $attribute_taxonomies as $attribute_taxonomy ) {
$sanitized_attribute_name = wc_sanitize_taxonomy_name ( $attribute_taxonomy -> attribute_name );
if ( $sanitized_attribute_name !== $attribute_taxonomy -> attribute_name ) {
if ( ! $wpdb -> get_var ( $wpdb -> prepare ( " SELECT 1=1 FROM { $wpdb -> prefix } woocommerce_attribute_taxonomies WHERE attribute_name = %s; " , $sanitized_attribute_name ) ) ) {
2017-10-05 11:48:26 +00:00
// Update attribute.
2016-05-11 11:44:12 +00:00
$wpdb -> update (
" { $wpdb -> prefix } woocommerce_attribute_taxonomies " ,
array (
2016-08-27 01:46:45 +00:00
'attribute_name' => $sanitized_attribute_name ,
2016-05-11 11:44:12 +00:00
),
array (
2016-08-27 01:46:45 +00:00
'attribute_id' => $attribute_taxonomy -> attribute_id ,
2016-05-11 11:44:12 +00:00
)
);
2017-10-05 11:48:26 +00:00
// Update terms.
2016-05-11 11:44:12 +00:00
$wpdb -> update (
$wpdb -> term_taxonomy ,
array ( 'taxonomy' => wc_attribute_taxonomy_name ( $sanitized_attribute_name ) ),
array ( 'taxonomy' => 'pa_' . $attribute_taxonomy -> attribute_name )
);
}
}
}
}
2017-10-05 11:48:26 +00:00
/**
* Update DB version for 2.2
*
* @ return void
*/
2016-05-11 11:44:12 +00:00
function wc_update_220_db_version () {
WC_Install :: update_db_version ( '2.2.0' );
}
2017-10-05 11:48:26 +00:00
/**
* Update options for 2.3
*
* @ return void
*/
2016-05-11 11:44:12 +00:00
function wc_update_230_options () {
// _money_spent and _order_count may be out of sync - clear them
delete_metadata ( 'user' , 0 , '_money_spent' , '' , true );
delete_metadata ( 'user' , 0 , '_order_count' , '' , true );
2017-10-05 11:48:26 +00:00
// To prevent taxes being hidden when using a default 'no address' in a store with tax inc prices, set the woocommerce_default_customer_address to use the store base address by default.
2016-05-11 11:44:12 +00:00
if ( '' === get_option ( 'woocommerce_default_customer_address' , false ) && wc_prices_include_tax () ) {
update_option ( 'woocommerce_default_customer_address' , 'base' );
}
}
2017-10-05 11:48:26 +00:00
/**
* Update DB version for 2.3
*
* @ return void
*/
2016-05-11 11:44:12 +00:00
function wc_update_230_db_version () {
WC_Install :: update_db_version ( '2.3.0' );
}
2017-10-05 11:48:26 +00:00
/**
* Update calc discount options for 2.4
*
* @ return void
*/
2016-05-11 11:44:12 +00:00
function wc_update_240_options () {
/**
* Coupon discount calculations .
* Maintain the old coupon logic for upgrades .
*/
update_option ( 'woocommerce_calc_discounts_sequentially' , 'yes' );
}
2017-10-05 11:48:26 +00:00
/**
* Update shipping methods for 2.4
*
* @ return void
*/
2016-05-11 11:44:12 +00:00
function wc_update_240_shipping_methods () {
/**
* Flat Rate Shipping .
* Update legacy options to new math based options .
*/
$shipping_methods = array (
'woocommerce_flat_rates' => new WC_Shipping_Legacy_Flat_Rate (),
2016-08-27 01:46:45 +00:00
'woocommerce_international_delivery_flat_rates' => new WC_Shipping_Legacy_International_Delivery (),
2016-05-11 11:44:12 +00:00
);
foreach ( $shipping_methods as $flat_rate_option_key => $shipping_method ) {
2017-10-05 11:48:26 +00:00
// Stop this running more than once if routine is repeated.
2016-05-11 11:44:12 +00:00
if ( version_compare ( $shipping_method -> get_option ( 'version' , 0 ), '2.4.0' , '<' ) ) {
2017-10-05 11:48:26 +00:00
$has_classes = count ( WC () -> shipping -> get_shipping_classes () ) > 0 ;
2016-05-11 11:44:12 +00:00
$cost_key = $has_classes ? 'no_class_cost' : 'cost' ;
$min_fee = $shipping_method -> get_option ( 'minimum_fee' );
2017-11-23 12:41:31 +00:00
$math_cost_strings = array (
'cost' => array (),
'no_class_cost' => array (),
);
2017-11-23 14:17:21 +00:00
2016-05-11 11:44:12 +00:00
$math_cost_strings [ $cost_key ][] = $shipping_method -> get_option ( 'cost' );
2017-11-23 14:17:21 +00:00
$fee = $shipping_method -> get_option ( 'fee' );
2016-05-11 11:44:12 +00:00
2017-11-23 14:17:21 +00:00
if ( $fee ) {
2016-05-11 11:44:12 +00:00
$math_cost_strings [ $cost_key ][] = strstr ( $fee , '%' ) ? '[fee percent="' . str_replace ( '%' , '' , $fee ) . '" min="' . esc_attr ( $min_fee ) . '"]' : $fee ;
}
foreach ( WC () -> shipping -> get_shipping_classes () as $shipping_class ) {
$rate_key = 'class_cost_' . $shipping_class -> slug ;
2016-08-27 03:23:21 +00:00
$math_cost_strings [ $rate_key ] = $math_cost_strings [ 'no_class_cost' ];
2016-05-11 11:44:12 +00:00
}
2017-11-23 14:17:21 +00:00
$flat_rates = array_filter ( ( array ) get_option ( $flat_rate_option_key , array () ) );
if ( $flat_rates ) {
2016-05-11 11:44:12 +00:00
foreach ( $flat_rates as $shipping_class => $rate ) {
$rate_key = 'class_cost_' . $shipping_class ;
if ( $rate [ 'cost' ] || $rate [ 'fee' ] ) {
$math_cost_strings [ $rate_key ][] = $rate [ 'cost' ];
$math_cost_strings [ $rate_key ][] = strstr ( $rate [ 'fee' ], '%' ) ? '[fee percent="' . str_replace ( '%' , '' , $rate [ 'fee' ] ) . '" min="' . esc_attr ( $min_fee ) . '"]' : $rate [ 'fee' ];
}
}
}
if ( 'item' === $shipping_method -> type ) {
foreach ( $math_cost_strings as $key => $math_cost_string ) {
$math_cost_strings [ $key ] = array_filter ( array_map ( 'trim' , $math_cost_strings [ $key ] ) );
if ( ! empty ( $math_cost_strings [ $key ] ) ) {
2017-10-05 11:48:26 +00:00
$last_key = max ( 0 , count ( $math_cost_strings [ $key ] ) - 1 );
2016-05-11 11:44:12 +00:00
$math_cost_strings [ $key ][ 0 ] = '( ' . $math_cost_strings [ $key ][ 0 ];
$math_cost_strings [ $key ][ $last_key ] .= ' ) * [qty]' ;
}
}
}
2016-08-27 03:23:21 +00:00
$math_cost_strings [ 'cost' ][] = $shipping_method -> get_option ( 'cost_per_order' );
2016-05-11 11:44:12 +00:00
2017-10-05 11:48:26 +00:00
// Save settings.
2016-05-11 11:44:12 +00:00
foreach ( $math_cost_strings as $option_id => $math_cost_string ) {
$shipping_method -> settings [ $option_id ] = implode ( ' + ' , array_filter ( $math_cost_string ) );
}
$shipping_method -> settings [ 'version' ] = '2.4.0' ;
$shipping_method -> settings [ 'type' ] = 'item' === $shipping_method -> settings [ 'type' ] ? 'class' : $shipping_method -> settings [ 'type' ];
update_option ( $shipping_method -> plugin_id . $shipping_method -> id . '_settings' , $shipping_method -> settings );
}
}
}
2017-10-05 11:48:26 +00:00
/**
* Update API keys for 2.4
*
* @ return void
*/
2016-05-11 11:44:12 +00:00
function wc_update_240_api_keys () {
global $wpdb ;
/**
* Update the old user API keys to the new Apps keys .
*/
$api_users = $wpdb -> get_results ( " SELECT user_id FROM $wpdb->usermeta WHERE meta_key = 'woocommerce_api_consumer_key' " );
$apps_keys = array ();
2017-10-05 11:48:26 +00:00
// Get user data.
2016-05-11 11:44:12 +00:00
foreach ( $api_users as $_user ) {
2017-11-23 12:41:31 +00:00
$user = get_userdata ( $_user -> user_id );
2016-05-11 11:44:12 +00:00
$apps_keys [] = array (
'user_id' => $user -> ID ,
'permissions' => $user -> woocommerce_api_key_permissions ,
'consumer_key' => wc_api_hash ( $user -> woocommerce_api_consumer_key ),
'consumer_secret' => $user -> woocommerce_api_consumer_secret ,
2016-08-27 01:46:45 +00:00
'truncated_key' => substr ( $user -> woocommerce_api_consumer_secret , - 7 ),
2016-05-11 11:44:12 +00:00
);
}
if ( ! empty ( $apps_keys ) ) {
2017-10-05 11:48:26 +00:00
// Create new apps.
2016-05-11 11:44:12 +00:00
foreach ( $apps_keys as $app ) {
$wpdb -> insert (
$wpdb -> prefix . 'woocommerce_api_keys' ,
$app ,
array (
'%d' ,
'%s' ,
'%s' ,
'%s' ,
2016-08-27 02:08:49 +00:00
'%s' ,
2016-05-11 11:44:12 +00:00
)
);
}
2017-10-05 11:48:26 +00:00
// Delete old user keys from usermeta.
2016-05-11 11:44:12 +00:00
foreach ( $api_users as $_user ) {
$user_id = intval ( $_user -> user_id );
delete_user_meta ( $user_id , 'woocommerce_api_consumer_key' );
delete_user_meta ( $user_id , 'woocommerce_api_consumer_secret' );
delete_user_meta ( $user_id , 'woocommerce_api_key_permissions' );
}
}
}
2017-10-05 11:48:26 +00:00
/**
* Update webhooks for 2.4
*
* @ return void
*/
2016-05-11 11:44:12 +00:00
function wc_update_240_webhooks () {
/**
* Webhooks .
* Make sure order . update webhooks get the woocommerce_order_edit_status hook .
*/
2017-11-23 12:41:31 +00:00
$order_update_webhooks = get_posts (
array (
'posts_per_page' => - 1 ,
'post_type' => 'shop_webhook' ,
'meta_key' => '_topic' ,
'meta_value' => 'order.updated' ,
)
);
2016-05-11 11:44:12 +00:00
foreach ( $order_update_webhooks as $order_update_webhook ) {
$webhook = new WC_Webhook ( $order_update_webhook -> ID );
$webhook -> set_topic ( 'order.updated' );
}
}
2017-10-05 11:48:26 +00:00
/**
* Update refunds for 2.4
*
* @ return void
*/
2016-05-11 11:44:12 +00:00
function wc_update_240_refunds () {
global $wpdb ;
/**
* Refunds for full refunded orders .
* Update fully refunded orders to ensure they have a refund line item so reports add up .
*/
2017-11-23 12:41:31 +00:00
$refunded_orders = get_posts (
array (
'posts_per_page' => - 1 ,
'post_type' => 'shop_order' ,
'post_status' => array ( 'wc-refunded' ),
)
);
2016-05-11 11:44:12 +00:00
2017-10-05 11:48:26 +00:00
// Ensure emails are disabled during this update routine.
2016-05-11 11:44:12 +00:00
remove_all_actions ( 'woocommerce_order_status_refunded_notification' );
remove_all_actions ( 'woocommerce_order_partially_refunded_notification' );
remove_action ( 'woocommerce_order_status_refunded' , array ( 'WC_Emails' , 'send_transactional_email' ) );
remove_action ( 'woocommerce_order_partially_refunded' , array ( 'WC_Emails' , 'send_transactional_email' ) );
foreach ( $refunded_orders as $refunded_order ) {
$order_total = get_post_meta ( $refunded_order -> ID , '_order_total' , true );
2017-11-23 12:41:31 +00:00
$refunded_total = $wpdb -> get_var (
$wpdb -> prepare (
" SELECT SUM( postmeta.meta_value )
FROM $wpdb -> postmeta AS postmeta
INNER JOIN $wpdb -> posts AS posts ON ( posts . post_type = 'shop_order_refund' AND posts . post_parent = % d )
WHERE postmeta . meta_key = '_refund_amount'
AND postmeta . post_id = posts . ID " ,
$refunded_order -> ID
)
);
2016-05-11 11:44:12 +00:00
if ( $order_total > $refunded_total ) {
2017-11-23 12:41:31 +00:00
wc_create_refund (
array (
'amount' => $order_total - $refunded_total ,
'reason' => __ ( 'Order fully refunded' , 'woocommerce' ),
'order_id' => $refunded_order -> ID ,
'line_items' => array (),
'date' => $refunded_order -> post_modified ,
)
);
2016-05-11 11:44:12 +00:00
}
}
wc_delete_shop_order_transients ();
}
2017-10-05 11:48:26 +00:00
/**
* Update DB version for 2.4
*
* @ return void
*/
2016-05-11 11:44:12 +00:00
function wc_update_240_db_version () {
WC_Install :: update_db_version ( '2.4.0' );
}
2017-10-05 11:48:26 +00:00
/**
* Update variations for 2.4 . 1
*
* @ return void
*/
2016-05-11 11:44:12 +00:00
function wc_update_241_variations () {
global $wpdb ;
2017-10-05 11:48:26 +00:00
// Select variations that don't have any _stock_status implemented on WooCommerce 2.2.
2017-11-23 12:41:31 +00:00
$update_variations = $wpdb -> get_results (
" SELECT DISTINCT posts.ID AS variation_id, posts.post_parent AS variation_parent
2016-05-11 11:44:12 +00:00
FROM { $wpdb -> posts } as posts
LEFT OUTER JOIN { $wpdb -> postmeta } AS postmeta ON posts . ID = postmeta . post_id AND postmeta . meta_key = '_stock_status'
WHERE posts . post_type = 'product_variation'
2017-11-23 12:41:31 +00:00
AND postmeta . meta_value IS NULL "
);
2016-05-11 11:44:12 +00:00
foreach ( $update_variations as $variation ) {
2017-10-05 11:48:26 +00:00
// Get the parent _stock_status.
2016-05-11 11:44:12 +00:00
$parent_stock_status = get_post_meta ( $variation -> variation_parent , '_stock_status' , true );
2017-10-05 11:48:26 +00:00
// Set the _stock_status.
2016-05-11 11:44:12 +00:00
add_post_meta ( $variation -> variation_id , '_stock_status' , $parent_stock_status ? $parent_stock_status : 'instock' , true );
2017-10-05 11:48:26 +00:00
// Delete old product children array.
2016-05-11 11:44:12 +00:00
delete_transient ( 'wc_product_children_' . $variation -> variation_parent );
}
2017-10-05 11:48:26 +00:00
// Invalidate old transients such as wc_var_price.
2016-05-11 11:44:12 +00:00
WC_Cache_Helper :: get_transient_version ( 'product' , true );
}
2017-10-05 11:48:26 +00:00
/**
* Update DB version for 2.4 . 1
*
* @ return void
*/
2016-05-11 11:44:12 +00:00
function wc_update_241_db_version () {
WC_Install :: update_db_version ( '2.4.1' );
}
2017-10-05 11:48:26 +00:00
/**
* Update currency settings for 2.5
*
* @ return void
*/
2016-05-11 11:44:12 +00:00
function wc_update_250_currency () {
global $wpdb ;
// Fix currency settings for LAK currency.
$current_currency = get_option ( 'woocommerce_currency' );
if ( 'KIP' === $current_currency ) {
update_option ( 'woocommerce_currency' , 'LAK' );
}
// Update LAK currency code.
$wpdb -> update (
$wpdb -> postmeta ,
array (
2016-08-27 01:46:45 +00:00
'meta_value' => 'LAK' ,
2016-05-11 11:44:12 +00:00
),
array (
'meta_key' => '_order_currency' ,
2016-08-27 01:46:45 +00:00
'meta_value' => 'KIP' ,
2016-05-11 11:44:12 +00:00
)
);
}
2017-10-05 11:48:26 +00:00
/**
* Update DB version for 2.5
*
* @ return void
*/
2016-05-11 11:44:12 +00:00
function wc_update_250_db_version () {
WC_Install :: update_db_version ( '2.5.0' );
}
2017-10-05 11:48:26 +00:00
/**
* Update ship to countries options for 2.6
*
* @ return void
*/
2016-05-11 11:44:12 +00:00
function wc_update_260_options () {
2017-10-05 11:48:26 +00:00
// woocommerce_calc_shipping option has been removed in 2.6.
2016-05-11 11:44:12 +00:00
if ( 'no' === get_option ( 'woocommerce_calc_shipping' ) ) {
update_option ( 'woocommerce_ship_to_countries' , 'disabled' );
}
WC_Admin_Notices :: add_notice ( 'legacy_shipping' );
}
2017-10-05 11:48:26 +00:00
/**
* Update term meta for 2.6
*
* @ return void
*/
2016-05-11 11:44:12 +00:00
function wc_update_260_termmeta () {
global $wpdb ;
/**
2017-10-05 11:48:26 +00:00
* Migrate term meta to WordPress tables .
2016-05-11 11:44:12 +00:00
*/
if ( get_option ( 'db_version' ) >= 34370 && $wpdb -> get_var ( " SHOW TABLES LIKE ' { $wpdb -> prefix } woocommerce_termmeta'; " ) ) {
if ( $wpdb -> query ( " INSERT INTO { $wpdb -> termmeta } ( term_id, meta_key, meta_value ) SELECT woocommerce_term_id, meta_key, meta_value FROM { $wpdb -> prefix } woocommerce_termmeta; " ) ) {
$wpdb -> query ( " DROP TABLE IF EXISTS { $wpdb -> prefix } woocommerce_termmeta " );
2016-06-16 22:31:19 +00:00
wp_cache_flush ();
2016-05-11 11:44:12 +00:00
}
}
}
2017-10-05 11:48:26 +00:00
/**
* Update zones for 2.6
*
* @ return void
*/
2016-05-11 11:44:12 +00:00
function wc_update_260_zones () {
global $wpdb ;
/**
* Old ( table rate ) shipping zones to new core shipping zones migration .
* zone_enabled and zone_type are no longer used , but it ' s safe to leave them be .
*/
if ( $wpdb -> get_var ( " SHOW COLUMNS FROM ` { $wpdb -> prefix } woocommerce_shipping_zones` LIKE 'zone_enabled'; " ) ) {
$wpdb -> query ( " ALTER TABLE { $wpdb -> prefix } woocommerce_shipping_zones CHANGE `zone_type` `zone_type` VARCHAR(40) NOT NULL DEFAULT ''; " );
$wpdb -> query ( " ALTER TABLE { $wpdb -> prefix } woocommerce_shipping_zones CHANGE `zone_enabled` `zone_enabled` INT(1) NOT NULL DEFAULT 1; " );
}
}
2017-10-05 11:48:26 +00:00
/**
* Update zone methods for 2.6
*
* @ return void
*/
2016-05-11 11:44:12 +00:00
function wc_update_260_zone_methods () {
global $wpdb ;
/**
* Shipping zones in WC 2.6 . 0 use a table named woocommerce_shipping_zone_methods .
* Migrate the old data out of woocommerce_shipping_zone_shipping_methods into the new table and port over any known options ( used by table rates and flat rate boxes ) .
*/
if ( $wpdb -> get_var ( " SHOW TABLES LIKE ' { $wpdb -> prefix } woocommerce_shipping_zone_shipping_methods'; " ) ) {
2017-02-13 12:58:42 +00:00
$old_methods = $wpdb -> get_results ( " SELECT zone_id, shipping_method_type, shipping_method_order, shipping_method_id FROM { $wpdb -> prefix } woocommerce_shipping_zone_shipping_methods; " );
2016-07-19 15:16:26 +00:00
2016-05-11 11:44:12 +00:00
if ( $old_methods ) {
$max_new_id = $wpdb -> get_var ( " SELECT MAX(instance_id) FROM { $wpdb -> prefix } woocommerce_shipping_zone_methods " );
$max_old_id = $wpdb -> get_var ( " SELECT MAX(shipping_method_id) FROM { $wpdb -> prefix } woocommerce_shipping_zone_shipping_methods " );
2017-10-05 11:48:26 +00:00
// Avoid ID conflicts.
2016-05-11 11:44:12 +00:00
$wpdb -> query ( $wpdb -> prepare ( " ALTER TABLE { $wpdb -> prefix } woocommerce_shipping_zone_methods AUTO_INCREMENT = %d; " , max ( $max_new_id , $max_old_id ) + 1 ) );
2017-10-05 11:48:26 +00:00
// Store changes.
2016-05-11 11:44:12 +00:00
$changes = array ();
2017-10-05 11:48:26 +00:00
// Move data.
2016-05-11 11:44:12 +00:00
foreach ( $old_methods as $old_method ) {
2017-11-23 12:41:31 +00:00
$wpdb -> insert (
$wpdb -> prefix . 'woocommerce_shipping_zone_methods' , array (
'zone_id' => $old_method -> zone_id ,
'method_id' => $old_method -> shipping_method_type ,
'method_order' => $old_method -> shipping_method_order ,
)
);
2016-05-11 11:44:12 +00:00
$new_instance_id = $wpdb -> insert_id ;
2017-10-05 11:48:26 +00:00
// Move main settings.
2016-05-11 11:44:12 +00:00
$older_settings_key = 'woocommerce_' . $old_method -> shipping_method_type . '-' . $old_method -> shipping_method_id . '_settings' ;
$old_settings_key = 'woocommerce_' . $old_method -> shipping_method_type . '_' . $old_method -> shipping_method_id . '_settings' ;
add_option ( 'woocommerce_' . $old_method -> shipping_method_type . '_' . $new_instance_id . '_settings' , get_option ( $old_settings_key , get_option ( $older_settings_key ) ) );
// Handling for table rate and flat rate box shipping.
if ( 'table_rate' === $old_method -> shipping_method_type ) {
2017-10-05 11:48:26 +00:00
// Move priority settings.
2016-05-11 11:44:12 +00:00
add_option ( 'woocommerce_table_rate_default_priority_' . $new_instance_id , get_option ( 'woocommerce_table_rate_default_priority_' . $old_method -> shipping_method_id ) );
add_option ( 'woocommerce_table_rate_priorities_' . $new_instance_id , get_option ( 'woocommerce_table_rate_priorities_' . $old_method -> shipping_method_id ) );
2017-10-05 11:48:26 +00:00
// Move rates.
2016-05-11 11:44:12 +00:00
$wpdb -> update (
$wpdb -> prefix . 'woocommerce_shipping_table_rates' ,
array (
2016-08-27 01:46:45 +00:00
'shipping_method_id' => $new_instance_id ,
2016-05-11 11:44:12 +00:00
),
array (
2016-08-27 01:46:45 +00:00
'shipping_method_id' => $old_method -> shipping_method_id ,
2016-05-11 11:44:12 +00:00
)
);
} elseif ( 'flat_rate_boxes' === $old_method -> shipping_method_type ) {
$wpdb -> update (
$wpdb -> prefix . 'woocommerce_shipping_flat_rate_boxes' ,
array (
2016-08-27 01:46:45 +00:00
'shipping_method_id' => $new_instance_id ,
2016-05-11 11:44:12 +00:00
),
array (
2016-08-27 01:46:45 +00:00
'shipping_method_id' => $old_method -> shipping_method_id ,
2016-05-11 11:44:12 +00:00
)
);
}
$changes [ $old_method -> shipping_method_id ] = $new_instance_id ;
}
// $changes contains keys (old method ids) and values (new instance ids) if extra processing is needed in plugins.
// Store this to an option so extensions can pick it up later, then fire an action.
update_option ( 'woocommerce_updated_instance_ids' , $changes );
do_action ( 'woocommerce_updated_instance_ids' , $changes );
}
}
2016-07-19 15:16:26 +00:00
// Change ranges used to ...
$wpdb -> query ( " UPDATE { $wpdb -> prefix } woocommerce_shipping_zone_locations SET location_code = REPLACE( location_code, '-', '...' ); " );
2016-05-11 11:44:12 +00:00
}
2017-10-05 11:48:26 +00:00
/**
* Update refunds for 2.6
*
* @ return void
*/
2016-05-11 11:44:12 +00:00
function wc_update_260_refunds () {
global $wpdb ;
/**
2017-10-05 11:48:26 +00:00
* Refund item qty should be negative .
2016-05-11 11:44:12 +00:00
*/
2017-11-23 12:41:31 +00:00
$wpdb -> query (
" UPDATE { $wpdb -> prefix } woocommerce_order_itemmeta as item_meta
LEFT JOIN { $wpdb -> prefix } woocommerce_order_items as items ON item_meta . order_item_id = items . order_item_id
LEFT JOIN { $wpdb -> posts } as posts ON items . order_id = posts . ID
SET item_meta . meta_value = item_meta . meta_value * - 1
WHERE item_meta . meta_value > 0 AND item_meta . meta_key = '_qty' AND posts . post_type = 'shop_order_refund' "
);
2016-05-11 11:44:12 +00:00
}
2017-10-05 11:48:26 +00:00
/**
* Update DB version for 2.6
*
* @ return void
*/
2016-05-11 11:44:12 +00:00
function wc_update_260_db_version () {
WC_Install :: update_db_version ( '2.6.0' );
}
2016-08-03 20:32:02 +00:00
2017-10-05 11:48:26 +00:00
/**
* Update webhooks for 3.0
*
* @ return void
*/
2017-03-15 16:55:07 +00:00
function wc_update_300_webhooks () {
2016-08-03 20:32:02 +00:00
/**
* Make sure product . update webhooks get the woocommerce_product_quick_edit_save
* and woocommerce_product_bulk_edit_save hooks .
*/
2017-11-23 12:41:31 +00:00
$product_update_webhooks = get_posts (
array (
'posts_per_page' => - 1 ,
'post_type' => 'shop_webhook' ,
'meta_key' => '_topic' ,
'meta_value' => 'product.updated' ,
)
);
2016-08-03 20:32:02 +00:00
foreach ( $product_update_webhooks as $product_update_webhook ) {
$webhook = new WC_Webhook ( $product_update_webhook -> ID );
$webhook -> set_topic ( 'product.updated' );
}
}
2016-08-09 08:00:51 +00:00
/**
* Add an index to the field comment_type to improve the response time of the query
* used by WC_Comments :: wp_count_comments () to get the number of comments by type .
*/
2017-03-15 16:55:07 +00:00
function wc_update_300_comment_type_index () {
2016-08-09 08:00:51 +00:00
global $wpdb ;
2017-02-16 16:45:50 +00:00
$index_exists = $wpdb -> get_row ( " SHOW INDEX FROM { $wpdb -> comments } WHERE column_name = 'comment_type' and key_name = 'woo_idx_comment_type' " );
if ( is_null ( $index_exists ) ) {
// Add an index to the field comment_type to improve the response time of the query
// used by WC_Comments::wp_count_comments() to get the number of comments by type.
$wpdb -> query ( " ALTER TABLE { $wpdb -> comments } ADD INDEX woo_idx_comment_type (comment_type) " );
}
2016-08-09 08:00:51 +00:00
}
WIP - Product CRUD (#12065)
* Created function to get the catalog visibility options
* First methods for WP_Product crud
* Product set methods
* Fixed several erros while setting data
* First methods for WP_Product crud
* Product set methods
* Fixed several erros while setting data
* Hardcode the get_type per product class
* Initial look through getters and setters and abstract data
* Missing var
* Add related product functions and deprecate those in class.
* No need to exclude ID
* Fixed coding standards and improved the docblocks
* Get cached terms from wc_get_related_terms()
* Fixed wrong variable in wc_get_related_terms
* Use count() instead of sizeof()
* Sanitize ids later
* Remove unneeded comments
* wc_get_product_term_ids instead of related wording and use in other places.
get_the_terms is used here and also handles caching, something
wp_get_post_terms does not.
* Clean up the abstract product class a bit, deprecate two functions we have renamed, make update & create work properly, and add some tests for it.
* Bump template version
* Handle PR feedback: Remove duplicate regular_price update, allow changing of post status for products, remove deprecation for get_title since we might still offer it as a function
* Made abstract function useful
* External Product CRUD
* _virtual meta should be 'no', not taxable, in product unit test helper
* Grouped product class
* Tests
* Move children to meta and update test
* Use get_upsell_ids
* Spacing in query
* Moving and refactoring methods
* Availability html
* Tidy/add todos
* Rename method
* Put back review functions (still todo)
* missing $this
* get_price_including_tax/excluding_tax functions
* wc_get_price_to_display
* Price handling
* [Product CRUD] Variable (#12146)
* [Product CRUD] Variable Products
* Handle PR feedback.
* [Product CRUD] Grouped Handling (#12151)
* Handle grouped product saving
* Update routine
* [Product CRUD] Product crud terms (#12149)
* Category and tag id handling
* Replace template functions
* Remove todo
* Handle default name in save function
* Product crud admin save routine (#12174)
* Initial props
* Work on admin saving
* Set/get attributes
* Atom was moaning about this before but no longer.
* Update get_shipping_class
* WC_Product_Attribute
* Use getter in admin panel
* Fix attribute saving
* Spacing
* Fix comment
* wc_implode_text_attributes helper function
* [Product CRUD] Product crud admin use getters (#12196)
* Initial props
* Work on admin saving
* Set/get attributes
* Atom was moaning about this before but no longer.
* Update get_shipping_class
* WC_Product_Attribute
* Use getter in admin panel
* Fix attribute saving
* Move settings into new files
* Refactor panels and use getters
* Use getters for variation panel
* Revert save variation changes for now
* Add todos
* Fix downloads
* REST API CRUD Updates
* Additional API updates/fixes. Added some todos
* Fix final failing tests and implementing setters/getters and attributes functionality.
* Fix comparison for is_on_sale and remove download_type from WC_Product.
* Add a wc_get_products wrapper.
* Remove the download type input from the product data metabox for downloadable products. (#12221)
* [Product CRUD] Variations - setters, getters and admin. (#12228)
* Started on variation changes
* Stock functions
* Variation class
* Bulk change ->id to get_id() to fix variation form display
* Missing status
* Fix add to cart
* Start on stored data save
* save variation
* Save_variations
* Variation edit panel
* Save variations code works.
* Remove stored data code and fix save
* Improve legacy class
* wc_bool_to_string
* prepare_set_attributes
* Use wc_get_products
* More feedback fixes
* Feedback fixes
* Implement CRUD in the legacy REST API
* Handle PR feedback
* [Product CRUD] Getter setter proxy methods (#12236)
* Started on variation changes
* Stock functions
* Variation class
* Bulk change ->id to get_id() to fix variation form display
* Missing status
* Fix add to cart
* Start on stored data save
* save variation
* Save_variations
* Variation edit panel
* Save variations code works.
* Remove stored data code and fix save
* Improve legacy class
* wc_bool_to_string
* prepare_set_attributes
* Use wc_get_products
* More feedback fixes
* get_prop implementation in abstract and data classes
* Implement set_prop
* Change handling
* Array key exists
* set_object_read
* Use get_the_terms() instead of wp_get_post_terms()
wp_get_post_terms() is a wrapper around wp_get_object_terms() which does not
use the object cache, and generates a database query every time it is used.
get_the_terms() however can use data from the object cache if present.
* Allow WP_Query to preload post data, and meta in wc_get_products()
Allow WP_Query to bulk query for post data and meta if more than
just IDs are requested from wc_get_products(). Reduces query count
significantly.
* [Product CRUD] Variable, variation, notices, and stock handling (#12277)
* No longer needed
* Remove old todos
* Use getters in admin list
* Related and upsells update for CRUD
* Fix notice in gallery
* Variable fixes and todos
* Context
* Price sync
* Revert variation attributes change
* Return parent data in view context
* Defer term counting
* wc_find_matching_product_variation
* Stock manage tweaks
* Stock fixes
* Correct id
* correct id
* Better sync
* Data logic setter fix
* feedback
* First methods for WP_Product crud
* Product set methods
* Fixed several erros while setting data
* Hardcode the get_type per product class
* Initial look through getters and setters and abstract data
* Missing var
* Fixed coding standards and improved the docblocks
* Get cached terms from wc_get_related_terms()
* Fixed wrong variable in wc_get_related_terms
* Use count() instead of sizeof()
* Add related product functions and deprecate those in class.
* No need to exclude ID
* Sanitize ids later
* Clean up the abstract product class a bit, deprecate two functions we have renamed, make update & create work properly, and add some tests for it.
* Remove unneeded comments
* wc_get_product_term_ids instead of related wording and use in other places.
get_the_terms is used here and also handles caching, something
wp_get_post_terms does not.
* Handle PR feedback: Remove duplicate regular_price update, allow changing of post status for products, remove deprecation for get_title since we might still offer it as a function
* External Product CRUD
* _virtual meta should be 'no', not taxable, in product unit test helper
* Bump template version
* Made abstract function useful
* Grouped product class
* Tests
* Move children to meta and update test
* Use get_upsell_ids
* Spacing in query
* Moving and refactoring methods
* Availability html
* Tidy/add todos
* Rename method
* Put back review functions (still todo)
* missing $this
* get_price_including_tax/excluding_tax functions
* wc_get_price_to_display
* Price handling
* [Product CRUD] Variable (#12146)
* [Product CRUD] Variable Products
* Handle PR feedback.
* [Product CRUD] Grouped Handling (#12151)
* Handle grouped product saving
* Update routine
* [Product CRUD] Product crud terms (#12149)
* Category and tag id handling
* Replace template functions
* Remove todo
* Handle default name in save function
* Product crud admin save routine (#12174)
* Initial props
* Work on admin saving
* Set/get attributes
* Atom was moaning about this before but no longer.
* Update get_shipping_class
* WC_Product_Attribute
* Use getter in admin panel
* Fix attribute saving
* Spacing
* Fix comment
* wc_implode_text_attributes helper function
* [Product CRUD] Product crud admin use getters (#12196)
* Initial props
* Work on admin saving
* Set/get attributes
* Atom was moaning about this before but no longer.
* Update get_shipping_class
* WC_Product_Attribute
* Use getter in admin panel
* Fix attribute saving
* Move settings into new files
* Refactor panels and use getters
* Use getters for variation panel
* Revert save variation changes for now
* Add todos
* Fix downloads
* REST API CRUD Updates
* Additional API updates/fixes. Added some todos
* Fix final failing tests and implementing setters/getters and attributes functionality.
* Fix comparison for is_on_sale and remove download_type from WC_Product.
* Add a wc_get_products wrapper.
* Remove the download type input from the product data metabox for downloadable products. (#12221)
* [Product CRUD] Variations - setters, getters and admin. (#12228)
* Started on variation changes
* Stock functions
* Variation class
* Bulk change ->id to get_id() to fix variation form display
* Missing status
* Fix add to cart
* Start on stored data save
* save variation
* Save_variations
* Variation edit panel
* Save variations code works.
* Remove stored data code and fix save
* Improve legacy class
* wc_bool_to_string
* prepare_set_attributes
* Use wc_get_products
* More feedback fixes
* Feedback fixes
* Implement CRUD in the legacy REST API
* Handle PR feedback
* [Product CRUD] Getter setter proxy methods (#12236)
* Started on variation changes
* Stock functions
* Variation class
* Bulk change ->id to get_id() to fix variation form display
* Missing status
* Fix add to cart
* Start on stored data save
* save variation
* Save_variations
* Variation edit panel
* Save variations code works.
* Remove stored data code and fix save
* Improve legacy class
* wc_bool_to_string
* prepare_set_attributes
* Use wc_get_products
* More feedback fixes
* get_prop implementation in abstract and data classes
* Implement set_prop
* Change handling
* Array key exists
* set_object_read
* Use get_the_terms() instead of wp_get_post_terms()
wp_get_post_terms() is a wrapper around wp_get_object_terms() which does not
use the object cache, and generates a database query every time it is used.
get_the_terms() however can use data from the object cache if present.
* [Product CRUD] Variable, variation, notices, and stock handling (#12277)
* No longer needed
* Remove old todos
* Use getters in admin list
* Related and upsells update for CRUD
* Fix notice in gallery
* Variable fixes and todos
* Context
* Price sync
* Revert variation attributes change
* Return parent data in view context
* Defer term counting
* wc_find_matching_product_variation
* Stock manage tweaks
* Stock fixes
* Correct id
* correct id
* Better sync
* Data logic setter fix
* feedback
* Prevent notices
* Handle image_id from parent
* Fix error
* Remove _wc_save_product_price
* Remove todo
* Fixed wrong variation URLs
* Fixed undefined $image_id in WC_Product_Variation::get_image_id()
* Allow wc_rest_prepare_date_response() handle timestamps
* Updated get methods on REST API for variations
* Use variations CRUD to save variations metadata
* [Product CRUD] Abstract todos (#12305)
* Get dimensions and weights, with soft deprecation
* Product attributes
* Ratings
* Fix read method
* Downloads
* Feedback
* Revert "[Product CRUD] Abstract todos (#12305)"
This reverts commit 9a6136fcf88fec16f97457b7c8a4388f7587bfa2.
* Remove deprecated get_variation_id()
* New default attributes method
* [Product CRUD] Product Datastore (#12317)
* Fix up tests in the product/* folder.
* Handle data store updates for grouped, variable, external, simple, and general data store updates for products.
* Variations & variable changes.
* Update -functions.php calls to use data store.
* Add an interface for the public product data store methods.
* Finished product factory tests
* Correctly delete in the api, fix up some comments, and implement an interface for the public variable methods.
* Fix up delete in all versions of the api
* Handle feedback
* Match protected decloration to parent
* Product crud abstract todos (#12316)
* Get dimensions and weights, with soft deprecation
* Product attributes
* Ratings
* Fix read method
* Downloads
* Feedback
* Fix up store
* Fixed method returning in write context
* Fix error in variation admin
* Check for parent value - fixes tax class
* Remove old/complete todos
* Allow set tax class as "parent"
* Removed duplicated sync
* Fixed wrong variation URLs
* Fixed undefined $image_id in WC_Product_Variation::get_image_id()
* Allow wc_rest_prepare_date_response() handle timestamps
* Updated get methods on REST API for variations
* Use variations CRUD to save variations metadata
* Remove deprecated get_variation_id()
* New default attributes method
* Fixed method returning in write context
* Allow set tax class as "parent"
* Removed duplicated sync
* Fixed coding standards
* TODO is not accurate.
* Should pass WC_Product instancies to WC_Comments methods (#12327)
* Use new method in abstract order class to prevent headers sent issue in tests
* Fixed variable description in REST API
* Updated how create initial product variation
* Fixed a few fatal errors and warnings in Products CRUD (#12329)
* Fixed a few fatal errors and warnings in Products CRUD
* Fixed sync functions
* Add variations CRUD to legacy API (#12331)
* Apply crud to variable products in legacy API v1
* New REST API do not need fallback for default attributes
* Apply variations CRUD to legacy API v2
* Legacy v2 - save default attributes
* Variations in legacy API v2 do not have descriptions
* Fixed legacy API v2 variations params
* Applied variations CRUD to legacy API v3
* Sync before save in legacy apis
* Punc
* Removed API todos
* Removed test
* Products endpoint tweaks (#12354)
* Var type already normalized on CRUD
* Let Product CRUD handle with validation, sanitization and conditional checks
* Set downloads using WC_Product_Download
* Stop try catch exceptions more than one time
* Handle WC_Data_Exception in legacy API
* Complete remove products when fails on creating
* On creating I mean!
* Already have a method to complete delete products
* Fixed standards using WP CodeSniffer
* get_the_terms() returns false when empty
* get_manage_stock returns boolean
@claudiosanches
* Merge conflict
* Variations API endpoint fixes
* Product CRUD improvements (#12359)
* args is not used any more - remove todo
* Added test for attributes
* wc_get_price_excluding_tax usage
* parent usage
* Fix rating counts
* Test fixes
* Cleanup after tests
* Make sure status transition code runs even during API calls, not just in admin.
* Default visibility
* Fix attribute setting in API
* Use get name instead of get title
* variation id usage
* Improved cross sell templates
* variation_data
* Grouped product sync
* Notices
* Sync is not needed in API
* Delete
* Rename interfaces
* Update counts in data store
2016-11-16 12:38:24 +00:00
2017-10-05 11:48:26 +00:00
/**
* Update grouped products for 3.0
*
* @ return void
*/
2017-03-15 16:55:07 +00:00
function wc_update_300_grouped_products () {
WIP - Product CRUD (#12065)
* Created function to get the catalog visibility options
* First methods for WP_Product crud
* Product set methods
* Fixed several erros while setting data
* First methods for WP_Product crud
* Product set methods
* Fixed several erros while setting data
* Hardcode the get_type per product class
* Initial look through getters and setters and abstract data
* Missing var
* Add related product functions and deprecate those in class.
* No need to exclude ID
* Fixed coding standards and improved the docblocks
* Get cached terms from wc_get_related_terms()
* Fixed wrong variable in wc_get_related_terms
* Use count() instead of sizeof()
* Sanitize ids later
* Remove unneeded comments
* wc_get_product_term_ids instead of related wording and use in other places.
get_the_terms is used here and also handles caching, something
wp_get_post_terms does not.
* Clean up the abstract product class a bit, deprecate two functions we have renamed, make update & create work properly, and add some tests for it.
* Bump template version
* Handle PR feedback: Remove duplicate regular_price update, allow changing of post status for products, remove deprecation for get_title since we might still offer it as a function
* Made abstract function useful
* External Product CRUD
* _virtual meta should be 'no', not taxable, in product unit test helper
* Grouped product class
* Tests
* Move children to meta and update test
* Use get_upsell_ids
* Spacing in query
* Moving and refactoring methods
* Availability html
* Tidy/add todos
* Rename method
* Put back review functions (still todo)
* missing $this
* get_price_including_tax/excluding_tax functions
* wc_get_price_to_display
* Price handling
* [Product CRUD] Variable (#12146)
* [Product CRUD] Variable Products
* Handle PR feedback.
* [Product CRUD] Grouped Handling (#12151)
* Handle grouped product saving
* Update routine
* [Product CRUD] Product crud terms (#12149)
* Category and tag id handling
* Replace template functions
* Remove todo
* Handle default name in save function
* Product crud admin save routine (#12174)
* Initial props
* Work on admin saving
* Set/get attributes
* Atom was moaning about this before but no longer.
* Update get_shipping_class
* WC_Product_Attribute
* Use getter in admin panel
* Fix attribute saving
* Spacing
* Fix comment
* wc_implode_text_attributes helper function
* [Product CRUD] Product crud admin use getters (#12196)
* Initial props
* Work on admin saving
* Set/get attributes
* Atom was moaning about this before but no longer.
* Update get_shipping_class
* WC_Product_Attribute
* Use getter in admin panel
* Fix attribute saving
* Move settings into new files
* Refactor panels and use getters
* Use getters for variation panel
* Revert save variation changes for now
* Add todos
* Fix downloads
* REST API CRUD Updates
* Additional API updates/fixes. Added some todos
* Fix final failing tests and implementing setters/getters and attributes functionality.
* Fix comparison for is_on_sale and remove download_type from WC_Product.
* Add a wc_get_products wrapper.
* Remove the download type input from the product data metabox for downloadable products. (#12221)
* [Product CRUD] Variations - setters, getters and admin. (#12228)
* Started on variation changes
* Stock functions
* Variation class
* Bulk change ->id to get_id() to fix variation form display
* Missing status
* Fix add to cart
* Start on stored data save
* save variation
* Save_variations
* Variation edit panel
* Save variations code works.
* Remove stored data code and fix save
* Improve legacy class
* wc_bool_to_string
* prepare_set_attributes
* Use wc_get_products
* More feedback fixes
* Feedback fixes
* Implement CRUD in the legacy REST API
* Handle PR feedback
* [Product CRUD] Getter setter proxy methods (#12236)
* Started on variation changes
* Stock functions
* Variation class
* Bulk change ->id to get_id() to fix variation form display
* Missing status
* Fix add to cart
* Start on stored data save
* save variation
* Save_variations
* Variation edit panel
* Save variations code works.
* Remove stored data code and fix save
* Improve legacy class
* wc_bool_to_string
* prepare_set_attributes
* Use wc_get_products
* More feedback fixes
* get_prop implementation in abstract and data classes
* Implement set_prop
* Change handling
* Array key exists
* set_object_read
* Use get_the_terms() instead of wp_get_post_terms()
wp_get_post_terms() is a wrapper around wp_get_object_terms() which does not
use the object cache, and generates a database query every time it is used.
get_the_terms() however can use data from the object cache if present.
* Allow WP_Query to preload post data, and meta in wc_get_products()
Allow WP_Query to bulk query for post data and meta if more than
just IDs are requested from wc_get_products(). Reduces query count
significantly.
* [Product CRUD] Variable, variation, notices, and stock handling (#12277)
* No longer needed
* Remove old todos
* Use getters in admin list
* Related and upsells update for CRUD
* Fix notice in gallery
* Variable fixes and todos
* Context
* Price sync
* Revert variation attributes change
* Return parent data in view context
* Defer term counting
* wc_find_matching_product_variation
* Stock manage tweaks
* Stock fixes
* Correct id
* correct id
* Better sync
* Data logic setter fix
* feedback
* First methods for WP_Product crud
* Product set methods
* Fixed several erros while setting data
* Hardcode the get_type per product class
* Initial look through getters and setters and abstract data
* Missing var
* Fixed coding standards and improved the docblocks
* Get cached terms from wc_get_related_terms()
* Fixed wrong variable in wc_get_related_terms
* Use count() instead of sizeof()
* Add related product functions and deprecate those in class.
* No need to exclude ID
* Sanitize ids later
* Clean up the abstract product class a bit, deprecate two functions we have renamed, make update & create work properly, and add some tests for it.
* Remove unneeded comments
* wc_get_product_term_ids instead of related wording and use in other places.
get_the_terms is used here and also handles caching, something
wp_get_post_terms does not.
* Handle PR feedback: Remove duplicate regular_price update, allow changing of post status for products, remove deprecation for get_title since we might still offer it as a function
* External Product CRUD
* _virtual meta should be 'no', not taxable, in product unit test helper
* Bump template version
* Made abstract function useful
* Grouped product class
* Tests
* Move children to meta and update test
* Use get_upsell_ids
* Spacing in query
* Moving and refactoring methods
* Availability html
* Tidy/add todos
* Rename method
* Put back review functions (still todo)
* missing $this
* get_price_including_tax/excluding_tax functions
* wc_get_price_to_display
* Price handling
* [Product CRUD] Variable (#12146)
* [Product CRUD] Variable Products
* Handle PR feedback.
* [Product CRUD] Grouped Handling (#12151)
* Handle grouped product saving
* Update routine
* [Product CRUD] Product crud terms (#12149)
* Category and tag id handling
* Replace template functions
* Remove todo
* Handle default name in save function
* Product crud admin save routine (#12174)
* Initial props
* Work on admin saving
* Set/get attributes
* Atom was moaning about this before but no longer.
* Update get_shipping_class
* WC_Product_Attribute
* Use getter in admin panel
* Fix attribute saving
* Spacing
* Fix comment
* wc_implode_text_attributes helper function
* [Product CRUD] Product crud admin use getters (#12196)
* Initial props
* Work on admin saving
* Set/get attributes
* Atom was moaning about this before but no longer.
* Update get_shipping_class
* WC_Product_Attribute
* Use getter in admin panel
* Fix attribute saving
* Move settings into new files
* Refactor panels and use getters
* Use getters for variation panel
* Revert save variation changes for now
* Add todos
* Fix downloads
* REST API CRUD Updates
* Additional API updates/fixes. Added some todos
* Fix final failing tests and implementing setters/getters and attributes functionality.
* Fix comparison for is_on_sale and remove download_type from WC_Product.
* Add a wc_get_products wrapper.
* Remove the download type input from the product data metabox for downloadable products. (#12221)
* [Product CRUD] Variations - setters, getters and admin. (#12228)
* Started on variation changes
* Stock functions
* Variation class
* Bulk change ->id to get_id() to fix variation form display
* Missing status
* Fix add to cart
* Start on stored data save
* save variation
* Save_variations
* Variation edit panel
* Save variations code works.
* Remove stored data code and fix save
* Improve legacy class
* wc_bool_to_string
* prepare_set_attributes
* Use wc_get_products
* More feedback fixes
* Feedback fixes
* Implement CRUD in the legacy REST API
* Handle PR feedback
* [Product CRUD] Getter setter proxy methods (#12236)
* Started on variation changes
* Stock functions
* Variation class
* Bulk change ->id to get_id() to fix variation form display
* Missing status
* Fix add to cart
* Start on stored data save
* save variation
* Save_variations
* Variation edit panel
* Save variations code works.
* Remove stored data code and fix save
* Improve legacy class
* wc_bool_to_string
* prepare_set_attributes
* Use wc_get_products
* More feedback fixes
* get_prop implementation in abstract and data classes
* Implement set_prop
* Change handling
* Array key exists
* set_object_read
* Use get_the_terms() instead of wp_get_post_terms()
wp_get_post_terms() is a wrapper around wp_get_object_terms() which does not
use the object cache, and generates a database query every time it is used.
get_the_terms() however can use data from the object cache if present.
* [Product CRUD] Variable, variation, notices, and stock handling (#12277)
* No longer needed
* Remove old todos
* Use getters in admin list
* Related and upsells update for CRUD
* Fix notice in gallery
* Variable fixes and todos
* Context
* Price sync
* Revert variation attributes change
* Return parent data in view context
* Defer term counting
* wc_find_matching_product_variation
* Stock manage tweaks
* Stock fixes
* Correct id
* correct id
* Better sync
* Data logic setter fix
* feedback
* Prevent notices
* Handle image_id from parent
* Fix error
* Remove _wc_save_product_price
* Remove todo
* Fixed wrong variation URLs
* Fixed undefined $image_id in WC_Product_Variation::get_image_id()
* Allow wc_rest_prepare_date_response() handle timestamps
* Updated get methods on REST API for variations
* Use variations CRUD to save variations metadata
* [Product CRUD] Abstract todos (#12305)
* Get dimensions and weights, with soft deprecation
* Product attributes
* Ratings
* Fix read method
* Downloads
* Feedback
* Revert "[Product CRUD] Abstract todos (#12305)"
This reverts commit 9a6136fcf88fec16f97457b7c8a4388f7587bfa2.
* Remove deprecated get_variation_id()
* New default attributes method
* [Product CRUD] Product Datastore (#12317)
* Fix up tests in the product/* folder.
* Handle data store updates for grouped, variable, external, simple, and general data store updates for products.
* Variations & variable changes.
* Update -functions.php calls to use data store.
* Add an interface for the public product data store methods.
* Finished product factory tests
* Correctly delete in the api, fix up some comments, and implement an interface for the public variable methods.
* Fix up delete in all versions of the api
* Handle feedback
* Match protected decloration to parent
* Product crud abstract todos (#12316)
* Get dimensions and weights, with soft deprecation
* Product attributes
* Ratings
* Fix read method
* Downloads
* Feedback
* Fix up store
* Fixed method returning in write context
* Fix error in variation admin
* Check for parent value - fixes tax class
* Remove old/complete todos
* Allow set tax class as "parent"
* Removed duplicated sync
* Fixed wrong variation URLs
* Fixed undefined $image_id in WC_Product_Variation::get_image_id()
* Allow wc_rest_prepare_date_response() handle timestamps
* Updated get methods on REST API for variations
* Use variations CRUD to save variations metadata
* Remove deprecated get_variation_id()
* New default attributes method
* Fixed method returning in write context
* Allow set tax class as "parent"
* Removed duplicated sync
* Fixed coding standards
* TODO is not accurate.
* Should pass WC_Product instancies to WC_Comments methods (#12327)
* Use new method in abstract order class to prevent headers sent issue in tests
* Fixed variable description in REST API
* Updated how create initial product variation
* Fixed a few fatal errors and warnings in Products CRUD (#12329)
* Fixed a few fatal errors and warnings in Products CRUD
* Fixed sync functions
* Add variations CRUD to legacy API (#12331)
* Apply crud to variable products in legacy API v1
* New REST API do not need fallback for default attributes
* Apply variations CRUD to legacy API v2
* Legacy v2 - save default attributes
* Variations in legacy API v2 do not have descriptions
* Fixed legacy API v2 variations params
* Applied variations CRUD to legacy API v3
* Sync before save in legacy apis
* Punc
* Removed API todos
* Removed test
* Products endpoint tweaks (#12354)
* Var type already normalized on CRUD
* Let Product CRUD handle with validation, sanitization and conditional checks
* Set downloads using WC_Product_Download
* Stop try catch exceptions more than one time
* Handle WC_Data_Exception in legacy API
* Complete remove products when fails on creating
* On creating I mean!
* Already have a method to complete delete products
* Fixed standards using WP CodeSniffer
* get_the_terms() returns false when empty
* get_manage_stock returns boolean
@claudiosanches
* Merge conflict
* Variations API endpoint fixes
* Product CRUD improvements (#12359)
* args is not used any more - remove todo
* Added test for attributes
* wc_get_price_excluding_tax usage
* parent usage
* Fix rating counts
* Test fixes
* Cleanup after tests
* Make sure status transition code runs even during API calls, not just in admin.
* Default visibility
* Fix attribute setting in API
* Use get name instead of get title
* variation id usage
* Improved cross sell templates
* variation_data
* Grouped product sync
* Notices
* Sync is not needed in API
* Delete
* Rename interfaces
* Update counts in data store
2016-11-16 12:38:24 +00:00
global $wpdb ;
$parents = $wpdb -> get_col ( " SELECT DISTINCT( post_parent ) FROM { $wpdb -> posts } WHERE post_parent > 0 AND post_type = 'product'; " );
foreach ( $parents as $parent_id ) {
$parent = wc_get_product ( $parent_id );
if ( $parent && $parent -> is_type ( 'grouped' ) ) {
2017-11-23 12:41:31 +00:00
$children_ids = get_posts (
array (
'post_parent' => $parent_id ,
'posts_per_page' => - 1 ,
'post_type' => 'product' ,
'fields' => 'ids' ,
)
);
2017-04-19 09:35:39 +00:00
update_post_meta ( $parent_id , '_children' , $children_ids );
// Update children to remove the parent.
$wpdb -> update (
$wpdb -> posts ,
array (
'post_parent' => 0 ,
),
array (
'post_parent' => $parent_id ,
)
);
WIP - Product CRUD (#12065)
* Created function to get the catalog visibility options
* First methods for WP_Product crud
* Product set methods
* Fixed several erros while setting data
* First methods for WP_Product crud
* Product set methods
* Fixed several erros while setting data
* Hardcode the get_type per product class
* Initial look through getters and setters and abstract data
* Missing var
* Add related product functions and deprecate those in class.
* No need to exclude ID
* Fixed coding standards and improved the docblocks
* Get cached terms from wc_get_related_terms()
* Fixed wrong variable in wc_get_related_terms
* Use count() instead of sizeof()
* Sanitize ids later
* Remove unneeded comments
* wc_get_product_term_ids instead of related wording and use in other places.
get_the_terms is used here and also handles caching, something
wp_get_post_terms does not.
* Clean up the abstract product class a bit, deprecate two functions we have renamed, make update & create work properly, and add some tests for it.
* Bump template version
* Handle PR feedback: Remove duplicate regular_price update, allow changing of post status for products, remove deprecation for get_title since we might still offer it as a function
* Made abstract function useful
* External Product CRUD
* _virtual meta should be 'no', not taxable, in product unit test helper
* Grouped product class
* Tests
* Move children to meta and update test
* Use get_upsell_ids
* Spacing in query
* Moving and refactoring methods
* Availability html
* Tidy/add todos
* Rename method
* Put back review functions (still todo)
* missing $this
* get_price_including_tax/excluding_tax functions
* wc_get_price_to_display
* Price handling
* [Product CRUD] Variable (#12146)
* [Product CRUD] Variable Products
* Handle PR feedback.
* [Product CRUD] Grouped Handling (#12151)
* Handle grouped product saving
* Update routine
* [Product CRUD] Product crud terms (#12149)
* Category and tag id handling
* Replace template functions
* Remove todo
* Handle default name in save function
* Product crud admin save routine (#12174)
* Initial props
* Work on admin saving
* Set/get attributes
* Atom was moaning about this before but no longer.
* Update get_shipping_class
* WC_Product_Attribute
* Use getter in admin panel
* Fix attribute saving
* Spacing
* Fix comment
* wc_implode_text_attributes helper function
* [Product CRUD] Product crud admin use getters (#12196)
* Initial props
* Work on admin saving
* Set/get attributes
* Atom was moaning about this before but no longer.
* Update get_shipping_class
* WC_Product_Attribute
* Use getter in admin panel
* Fix attribute saving
* Move settings into new files
* Refactor panels and use getters
* Use getters for variation panel
* Revert save variation changes for now
* Add todos
* Fix downloads
* REST API CRUD Updates
* Additional API updates/fixes. Added some todos
* Fix final failing tests and implementing setters/getters and attributes functionality.
* Fix comparison for is_on_sale and remove download_type from WC_Product.
* Add a wc_get_products wrapper.
* Remove the download type input from the product data metabox for downloadable products. (#12221)
* [Product CRUD] Variations - setters, getters and admin. (#12228)
* Started on variation changes
* Stock functions
* Variation class
* Bulk change ->id to get_id() to fix variation form display
* Missing status
* Fix add to cart
* Start on stored data save
* save variation
* Save_variations
* Variation edit panel
* Save variations code works.
* Remove stored data code and fix save
* Improve legacy class
* wc_bool_to_string
* prepare_set_attributes
* Use wc_get_products
* More feedback fixes
* Feedback fixes
* Implement CRUD in the legacy REST API
* Handle PR feedback
* [Product CRUD] Getter setter proxy methods (#12236)
* Started on variation changes
* Stock functions
* Variation class
* Bulk change ->id to get_id() to fix variation form display
* Missing status
* Fix add to cart
* Start on stored data save
* save variation
* Save_variations
* Variation edit panel
* Save variations code works.
* Remove stored data code and fix save
* Improve legacy class
* wc_bool_to_string
* prepare_set_attributes
* Use wc_get_products
* More feedback fixes
* get_prop implementation in abstract and data classes
* Implement set_prop
* Change handling
* Array key exists
* set_object_read
* Use get_the_terms() instead of wp_get_post_terms()
wp_get_post_terms() is a wrapper around wp_get_object_terms() which does not
use the object cache, and generates a database query every time it is used.
get_the_terms() however can use data from the object cache if present.
* Allow WP_Query to preload post data, and meta in wc_get_products()
Allow WP_Query to bulk query for post data and meta if more than
just IDs are requested from wc_get_products(). Reduces query count
significantly.
* [Product CRUD] Variable, variation, notices, and stock handling (#12277)
* No longer needed
* Remove old todos
* Use getters in admin list
* Related and upsells update for CRUD
* Fix notice in gallery
* Variable fixes and todos
* Context
* Price sync
* Revert variation attributes change
* Return parent data in view context
* Defer term counting
* wc_find_matching_product_variation
* Stock manage tweaks
* Stock fixes
* Correct id
* correct id
* Better sync
* Data logic setter fix
* feedback
* First methods for WP_Product crud
* Product set methods
* Fixed several erros while setting data
* Hardcode the get_type per product class
* Initial look through getters and setters and abstract data
* Missing var
* Fixed coding standards and improved the docblocks
* Get cached terms from wc_get_related_terms()
* Fixed wrong variable in wc_get_related_terms
* Use count() instead of sizeof()
* Add related product functions and deprecate those in class.
* No need to exclude ID
* Sanitize ids later
* Clean up the abstract product class a bit, deprecate two functions we have renamed, make update & create work properly, and add some tests for it.
* Remove unneeded comments
* wc_get_product_term_ids instead of related wording and use in other places.
get_the_terms is used here and also handles caching, something
wp_get_post_terms does not.
* Handle PR feedback: Remove duplicate regular_price update, allow changing of post status for products, remove deprecation for get_title since we might still offer it as a function
* External Product CRUD
* _virtual meta should be 'no', not taxable, in product unit test helper
* Bump template version
* Made abstract function useful
* Grouped product class
* Tests
* Move children to meta and update test
* Use get_upsell_ids
* Spacing in query
* Moving and refactoring methods
* Availability html
* Tidy/add todos
* Rename method
* Put back review functions (still todo)
* missing $this
* get_price_including_tax/excluding_tax functions
* wc_get_price_to_display
* Price handling
* [Product CRUD] Variable (#12146)
* [Product CRUD] Variable Products
* Handle PR feedback.
* [Product CRUD] Grouped Handling (#12151)
* Handle grouped product saving
* Update routine
* [Product CRUD] Product crud terms (#12149)
* Category and tag id handling
* Replace template functions
* Remove todo
* Handle default name in save function
* Product crud admin save routine (#12174)
* Initial props
* Work on admin saving
* Set/get attributes
* Atom was moaning about this before but no longer.
* Update get_shipping_class
* WC_Product_Attribute
* Use getter in admin panel
* Fix attribute saving
* Spacing
* Fix comment
* wc_implode_text_attributes helper function
* [Product CRUD] Product crud admin use getters (#12196)
* Initial props
* Work on admin saving
* Set/get attributes
* Atom was moaning about this before but no longer.
* Update get_shipping_class
* WC_Product_Attribute
* Use getter in admin panel
* Fix attribute saving
* Move settings into new files
* Refactor panels and use getters
* Use getters for variation panel
* Revert save variation changes for now
* Add todos
* Fix downloads
* REST API CRUD Updates
* Additional API updates/fixes. Added some todos
* Fix final failing tests and implementing setters/getters and attributes functionality.
* Fix comparison for is_on_sale and remove download_type from WC_Product.
* Add a wc_get_products wrapper.
* Remove the download type input from the product data metabox for downloadable products. (#12221)
* [Product CRUD] Variations - setters, getters and admin. (#12228)
* Started on variation changes
* Stock functions
* Variation class
* Bulk change ->id to get_id() to fix variation form display
* Missing status
* Fix add to cart
* Start on stored data save
* save variation
* Save_variations
* Variation edit panel
* Save variations code works.
* Remove stored data code and fix save
* Improve legacy class
* wc_bool_to_string
* prepare_set_attributes
* Use wc_get_products
* More feedback fixes
* Feedback fixes
* Implement CRUD in the legacy REST API
* Handle PR feedback
* [Product CRUD] Getter setter proxy methods (#12236)
* Started on variation changes
* Stock functions
* Variation class
* Bulk change ->id to get_id() to fix variation form display
* Missing status
* Fix add to cart
* Start on stored data save
* save variation
* Save_variations
* Variation edit panel
* Save variations code works.
* Remove stored data code and fix save
* Improve legacy class
* wc_bool_to_string
* prepare_set_attributes
* Use wc_get_products
* More feedback fixes
* get_prop implementation in abstract and data classes
* Implement set_prop
* Change handling
* Array key exists
* set_object_read
* Use get_the_terms() instead of wp_get_post_terms()
wp_get_post_terms() is a wrapper around wp_get_object_terms() which does not
use the object cache, and generates a database query every time it is used.
get_the_terms() however can use data from the object cache if present.
* [Product CRUD] Variable, variation, notices, and stock handling (#12277)
* No longer needed
* Remove old todos
* Use getters in admin list
* Related and upsells update for CRUD
* Fix notice in gallery
* Variable fixes and todos
* Context
* Price sync
* Revert variation attributes change
* Return parent data in view context
* Defer term counting
* wc_find_matching_product_variation
* Stock manage tweaks
* Stock fixes
* Correct id
* correct id
* Better sync
* Data logic setter fix
* feedback
* Prevent notices
* Handle image_id from parent
* Fix error
* Remove _wc_save_product_price
* Remove todo
* Fixed wrong variation URLs
* Fixed undefined $image_id in WC_Product_Variation::get_image_id()
* Allow wc_rest_prepare_date_response() handle timestamps
* Updated get methods on REST API for variations
* Use variations CRUD to save variations metadata
* [Product CRUD] Abstract todos (#12305)
* Get dimensions and weights, with soft deprecation
* Product attributes
* Ratings
* Fix read method
* Downloads
* Feedback
* Revert "[Product CRUD] Abstract todos (#12305)"
This reverts commit 9a6136fcf88fec16f97457b7c8a4388f7587bfa2.
* Remove deprecated get_variation_id()
* New default attributes method
* [Product CRUD] Product Datastore (#12317)
* Fix up tests in the product/* folder.
* Handle data store updates for grouped, variable, external, simple, and general data store updates for products.
* Variations & variable changes.
* Update -functions.php calls to use data store.
* Add an interface for the public product data store methods.
* Finished product factory tests
* Correctly delete in the api, fix up some comments, and implement an interface for the public variable methods.
* Fix up delete in all versions of the api
* Handle feedback
* Match protected decloration to parent
* Product crud abstract todos (#12316)
* Get dimensions and weights, with soft deprecation
* Product attributes
* Ratings
* Fix read method
* Downloads
* Feedback
* Fix up store
* Fixed method returning in write context
* Fix error in variation admin
* Check for parent value - fixes tax class
* Remove old/complete todos
* Allow set tax class as "parent"
* Removed duplicated sync
* Fixed wrong variation URLs
* Fixed undefined $image_id in WC_Product_Variation::get_image_id()
* Allow wc_rest_prepare_date_response() handle timestamps
* Updated get methods on REST API for variations
* Use variations CRUD to save variations metadata
* Remove deprecated get_variation_id()
* New default attributes method
* Fixed method returning in write context
* Allow set tax class as "parent"
* Removed duplicated sync
* Fixed coding standards
* TODO is not accurate.
* Should pass WC_Product instancies to WC_Comments methods (#12327)
* Use new method in abstract order class to prevent headers sent issue in tests
* Fixed variable description in REST API
* Updated how create initial product variation
* Fixed a few fatal errors and warnings in Products CRUD (#12329)
* Fixed a few fatal errors and warnings in Products CRUD
* Fixed sync functions
* Add variations CRUD to legacy API (#12331)
* Apply crud to variable products in legacy API v1
* New REST API do not need fallback for default attributes
* Apply variations CRUD to legacy API v2
* Legacy v2 - save default attributes
* Variations in legacy API v2 do not have descriptions
* Fixed legacy API v2 variations params
* Applied variations CRUD to legacy API v3
* Sync before save in legacy apis
* Punc
* Removed API todos
* Removed test
* Products endpoint tweaks (#12354)
* Var type already normalized on CRUD
* Let Product CRUD handle with validation, sanitization and conditional checks
* Set downloads using WC_Product_Download
* Stop try catch exceptions more than one time
* Handle WC_Data_Exception in legacy API
* Complete remove products when fails on creating
* On creating I mean!
* Already have a method to complete delete products
* Fixed standards using WP CodeSniffer
* get_the_terms() returns false when empty
* get_manage_stock returns boolean
@claudiosanches
* Merge conflict
* Variations API endpoint fixes
* Product CRUD improvements (#12359)
* args is not used any more - remove todo
* Added test for attributes
* wc_get_price_excluding_tax usage
* parent usage
* Fix rating counts
* Test fixes
* Cleanup after tests
* Make sure status transition code runs even during API calls, not just in admin.
* Default visibility
* Fix attribute setting in API
* Use get name instead of get title
* variation id usage
* Improved cross sell templates
* variation_data
* Grouped product sync
* Notices
* Sync is not needed in API
* Delete
* Rename interfaces
* Update counts in data store
2016-11-16 12:38:24 +00:00
}
}
}
2017-10-05 11:48:26 +00:00
/**
* Update shipping tax classes for 3.0
*
* @ return void
*/
2017-03-15 16:55:07 +00:00
function wc_update_300_settings () {
WIP - Product CRUD (#12065)
* Created function to get the catalog visibility options
* First methods for WP_Product crud
* Product set methods
* Fixed several erros while setting data
* First methods for WP_Product crud
* Product set methods
* Fixed several erros while setting data
* Hardcode the get_type per product class
* Initial look through getters and setters and abstract data
* Missing var
* Add related product functions and deprecate those in class.
* No need to exclude ID
* Fixed coding standards and improved the docblocks
* Get cached terms from wc_get_related_terms()
* Fixed wrong variable in wc_get_related_terms
* Use count() instead of sizeof()
* Sanitize ids later
* Remove unneeded comments
* wc_get_product_term_ids instead of related wording and use in other places.
get_the_terms is used here and also handles caching, something
wp_get_post_terms does not.
* Clean up the abstract product class a bit, deprecate two functions we have renamed, make update & create work properly, and add some tests for it.
* Bump template version
* Handle PR feedback: Remove duplicate regular_price update, allow changing of post status for products, remove deprecation for get_title since we might still offer it as a function
* Made abstract function useful
* External Product CRUD
* _virtual meta should be 'no', not taxable, in product unit test helper
* Grouped product class
* Tests
* Move children to meta and update test
* Use get_upsell_ids
* Spacing in query
* Moving and refactoring methods
* Availability html
* Tidy/add todos
* Rename method
* Put back review functions (still todo)
* missing $this
* get_price_including_tax/excluding_tax functions
* wc_get_price_to_display
* Price handling
* [Product CRUD] Variable (#12146)
* [Product CRUD] Variable Products
* Handle PR feedback.
* [Product CRUD] Grouped Handling (#12151)
* Handle grouped product saving
* Update routine
* [Product CRUD] Product crud terms (#12149)
* Category and tag id handling
* Replace template functions
* Remove todo
* Handle default name in save function
* Product crud admin save routine (#12174)
* Initial props
* Work on admin saving
* Set/get attributes
* Atom was moaning about this before but no longer.
* Update get_shipping_class
* WC_Product_Attribute
* Use getter in admin panel
* Fix attribute saving
* Spacing
* Fix comment
* wc_implode_text_attributes helper function
* [Product CRUD] Product crud admin use getters (#12196)
* Initial props
* Work on admin saving
* Set/get attributes
* Atom was moaning about this before but no longer.
* Update get_shipping_class
* WC_Product_Attribute
* Use getter in admin panel
* Fix attribute saving
* Move settings into new files
* Refactor panels and use getters
* Use getters for variation panel
* Revert save variation changes for now
* Add todos
* Fix downloads
* REST API CRUD Updates
* Additional API updates/fixes. Added some todos
* Fix final failing tests and implementing setters/getters and attributes functionality.
* Fix comparison for is_on_sale and remove download_type from WC_Product.
* Add a wc_get_products wrapper.
* Remove the download type input from the product data metabox for downloadable products. (#12221)
* [Product CRUD] Variations - setters, getters and admin. (#12228)
* Started on variation changes
* Stock functions
* Variation class
* Bulk change ->id to get_id() to fix variation form display
* Missing status
* Fix add to cart
* Start on stored data save
* save variation
* Save_variations
* Variation edit panel
* Save variations code works.
* Remove stored data code and fix save
* Improve legacy class
* wc_bool_to_string
* prepare_set_attributes
* Use wc_get_products
* More feedback fixes
* Feedback fixes
* Implement CRUD in the legacy REST API
* Handle PR feedback
* [Product CRUD] Getter setter proxy methods (#12236)
* Started on variation changes
* Stock functions
* Variation class
* Bulk change ->id to get_id() to fix variation form display
* Missing status
* Fix add to cart
* Start on stored data save
* save variation
* Save_variations
* Variation edit panel
* Save variations code works.
* Remove stored data code and fix save
* Improve legacy class
* wc_bool_to_string
* prepare_set_attributes
* Use wc_get_products
* More feedback fixes
* get_prop implementation in abstract and data classes
* Implement set_prop
* Change handling
* Array key exists
* set_object_read
* Use get_the_terms() instead of wp_get_post_terms()
wp_get_post_terms() is a wrapper around wp_get_object_terms() which does not
use the object cache, and generates a database query every time it is used.
get_the_terms() however can use data from the object cache if present.
* Allow WP_Query to preload post data, and meta in wc_get_products()
Allow WP_Query to bulk query for post data and meta if more than
just IDs are requested from wc_get_products(). Reduces query count
significantly.
* [Product CRUD] Variable, variation, notices, and stock handling (#12277)
* No longer needed
* Remove old todos
* Use getters in admin list
* Related and upsells update for CRUD
* Fix notice in gallery
* Variable fixes and todos
* Context
* Price sync
* Revert variation attributes change
* Return parent data in view context
* Defer term counting
* wc_find_matching_product_variation
* Stock manage tweaks
* Stock fixes
* Correct id
* correct id
* Better sync
* Data logic setter fix
* feedback
* First methods for WP_Product crud
* Product set methods
* Fixed several erros while setting data
* Hardcode the get_type per product class
* Initial look through getters and setters and abstract data
* Missing var
* Fixed coding standards and improved the docblocks
* Get cached terms from wc_get_related_terms()
* Fixed wrong variable in wc_get_related_terms
* Use count() instead of sizeof()
* Add related product functions and deprecate those in class.
* No need to exclude ID
* Sanitize ids later
* Clean up the abstract product class a bit, deprecate two functions we have renamed, make update & create work properly, and add some tests for it.
* Remove unneeded comments
* wc_get_product_term_ids instead of related wording and use in other places.
get_the_terms is used here and also handles caching, something
wp_get_post_terms does not.
* Handle PR feedback: Remove duplicate regular_price update, allow changing of post status for products, remove deprecation for get_title since we might still offer it as a function
* External Product CRUD
* _virtual meta should be 'no', not taxable, in product unit test helper
* Bump template version
* Made abstract function useful
* Grouped product class
* Tests
* Move children to meta and update test
* Use get_upsell_ids
* Spacing in query
* Moving and refactoring methods
* Availability html
* Tidy/add todos
* Rename method
* Put back review functions (still todo)
* missing $this
* get_price_including_tax/excluding_tax functions
* wc_get_price_to_display
* Price handling
* [Product CRUD] Variable (#12146)
* [Product CRUD] Variable Products
* Handle PR feedback.
* [Product CRUD] Grouped Handling (#12151)
* Handle grouped product saving
* Update routine
* [Product CRUD] Product crud terms (#12149)
* Category and tag id handling
* Replace template functions
* Remove todo
* Handle default name in save function
* Product crud admin save routine (#12174)
* Initial props
* Work on admin saving
* Set/get attributes
* Atom was moaning about this before but no longer.
* Update get_shipping_class
* WC_Product_Attribute
* Use getter in admin panel
* Fix attribute saving
* Spacing
* Fix comment
* wc_implode_text_attributes helper function
* [Product CRUD] Product crud admin use getters (#12196)
* Initial props
* Work on admin saving
* Set/get attributes
* Atom was moaning about this before but no longer.
* Update get_shipping_class
* WC_Product_Attribute
* Use getter in admin panel
* Fix attribute saving
* Move settings into new files
* Refactor panels and use getters
* Use getters for variation panel
* Revert save variation changes for now
* Add todos
* Fix downloads
* REST API CRUD Updates
* Additional API updates/fixes. Added some todos
* Fix final failing tests and implementing setters/getters and attributes functionality.
* Fix comparison for is_on_sale and remove download_type from WC_Product.
* Add a wc_get_products wrapper.
* Remove the download type input from the product data metabox for downloadable products. (#12221)
* [Product CRUD] Variations - setters, getters and admin. (#12228)
* Started on variation changes
* Stock functions
* Variation class
* Bulk change ->id to get_id() to fix variation form display
* Missing status
* Fix add to cart
* Start on stored data save
* save variation
* Save_variations
* Variation edit panel
* Save variations code works.
* Remove stored data code and fix save
* Improve legacy class
* wc_bool_to_string
* prepare_set_attributes
* Use wc_get_products
* More feedback fixes
* Feedback fixes
* Implement CRUD in the legacy REST API
* Handle PR feedback
* [Product CRUD] Getter setter proxy methods (#12236)
* Started on variation changes
* Stock functions
* Variation class
* Bulk change ->id to get_id() to fix variation form display
* Missing status
* Fix add to cart
* Start on stored data save
* save variation
* Save_variations
* Variation edit panel
* Save variations code works.
* Remove stored data code and fix save
* Improve legacy class
* wc_bool_to_string
* prepare_set_attributes
* Use wc_get_products
* More feedback fixes
* get_prop implementation in abstract and data classes
* Implement set_prop
* Change handling
* Array key exists
* set_object_read
* Use get_the_terms() instead of wp_get_post_terms()
wp_get_post_terms() is a wrapper around wp_get_object_terms() which does not
use the object cache, and generates a database query every time it is used.
get_the_terms() however can use data from the object cache if present.
* [Product CRUD] Variable, variation, notices, and stock handling (#12277)
* No longer needed
* Remove old todos
* Use getters in admin list
* Related and upsells update for CRUD
* Fix notice in gallery
* Variable fixes and todos
* Context
* Price sync
* Revert variation attributes change
* Return parent data in view context
* Defer term counting
* wc_find_matching_product_variation
* Stock manage tweaks
* Stock fixes
* Correct id
* correct id
* Better sync
* Data logic setter fix
* feedback
* Prevent notices
* Handle image_id from parent
* Fix error
* Remove _wc_save_product_price
* Remove todo
* Fixed wrong variation URLs
* Fixed undefined $image_id in WC_Product_Variation::get_image_id()
* Allow wc_rest_prepare_date_response() handle timestamps
* Updated get methods on REST API for variations
* Use variations CRUD to save variations metadata
* [Product CRUD] Abstract todos (#12305)
* Get dimensions and weights, with soft deprecation
* Product attributes
* Ratings
* Fix read method
* Downloads
* Feedback
* Revert "[Product CRUD] Abstract todos (#12305)"
This reverts commit 9a6136fcf88fec16f97457b7c8a4388f7587bfa2.
* Remove deprecated get_variation_id()
* New default attributes method
* [Product CRUD] Product Datastore (#12317)
* Fix up tests in the product/* folder.
* Handle data store updates for grouped, variable, external, simple, and general data store updates for products.
* Variations & variable changes.
* Update -functions.php calls to use data store.
* Add an interface for the public product data store methods.
* Finished product factory tests
* Correctly delete in the api, fix up some comments, and implement an interface for the public variable methods.
* Fix up delete in all versions of the api
* Handle feedback
* Match protected decloration to parent
* Product crud abstract todos (#12316)
* Get dimensions and weights, with soft deprecation
* Product attributes
* Ratings
* Fix read method
* Downloads
* Feedback
* Fix up store
* Fixed method returning in write context
* Fix error in variation admin
* Check for parent value - fixes tax class
* Remove old/complete todos
* Allow set tax class as "parent"
* Removed duplicated sync
* Fixed wrong variation URLs
* Fixed undefined $image_id in WC_Product_Variation::get_image_id()
* Allow wc_rest_prepare_date_response() handle timestamps
* Updated get methods on REST API for variations
* Use variations CRUD to save variations metadata
* Remove deprecated get_variation_id()
* New default attributes method
* Fixed method returning in write context
* Allow set tax class as "parent"
* Removed duplicated sync
* Fixed coding standards
* TODO is not accurate.
* Should pass WC_Product instancies to WC_Comments methods (#12327)
* Use new method in abstract order class to prevent headers sent issue in tests
* Fixed variable description in REST API
* Updated how create initial product variation
* Fixed a few fatal errors and warnings in Products CRUD (#12329)
* Fixed a few fatal errors and warnings in Products CRUD
* Fixed sync functions
* Add variations CRUD to legacy API (#12331)
* Apply crud to variable products in legacy API v1
* New REST API do not need fallback for default attributes
* Apply variations CRUD to legacy API v2
* Legacy v2 - save default attributes
* Variations in legacy API v2 do not have descriptions
* Fixed legacy API v2 variations params
* Applied variations CRUD to legacy API v3
* Sync before save in legacy apis
* Punc
* Removed API todos
* Removed test
* Products endpoint tweaks (#12354)
* Var type already normalized on CRUD
* Let Product CRUD handle with validation, sanitization and conditional checks
* Set downloads using WC_Product_Download
* Stop try catch exceptions more than one time
* Handle WC_Data_Exception in legacy API
* Complete remove products when fails on creating
* On creating I mean!
* Already have a method to complete delete products
* Fixed standards using WP CodeSniffer
* get_the_terms() returns false when empty
* get_manage_stock returns boolean
@claudiosanches
* Merge conflict
* Variations API endpoint fixes
* Product CRUD improvements (#12359)
* args is not used any more - remove todo
* Added test for attributes
* wc_get_price_excluding_tax usage
* parent usage
* Fix rating counts
* Test fixes
* Cleanup after tests
* Make sure status transition code runs even during API calls, not just in admin.
* Default visibility
* Fix attribute setting in API
* Use get name instead of get title
* variation id usage
* Improved cross sell templates
* variation_data
* Grouped product sync
* Notices
* Sync is not needed in API
* Delete
* Rename interfaces
* Update counts in data store
2016-11-16 12:38:24 +00:00
$woocommerce_shipping_tax_class = get_option ( 'woocommerce_shipping_tax_class' );
if ( '' === $woocommerce_shipping_tax_class ) {
update_option ( 'woocommerce_shipping_tax_class' , 'inherit' );
} elseif ( 'standard' === $woocommerce_shipping_tax_class ) {
update_option ( 'woocommerce_shipping_tax_class' , '' );
}
}
2016-12-08 10:56:45 +00:00
/**
* Convert meta values into term for product visibility .
*/
2017-03-15 16:55:07 +00:00
function wc_update_300_product_visibility () {
2016-12-08 10:56:45 +00:00
global $wpdb ;
2017-03-27 10:55:36 +00:00
WC_Install :: create_terms ();
2017-11-23 14:17:21 +00:00
$featured_term = get_term_by ( 'name' , 'featured' , 'product_visibility' );
if ( $featured_term ) {
2017-03-31 11:42:07 +00:00
$wpdb -> query ( $wpdb -> prepare ( " INSERT IGNORE INTO { $wpdb -> term_relationships } SELECT post_id, %d, 0 FROM { $wpdb -> postmeta } WHERE meta_key = '_featured' AND meta_value = 'yes'; " , $featured_term -> term_taxonomy_id ) );
2016-12-08 10:56:45 +00:00
}
2017-11-23 14:17:21 +00:00
$exclude_search_term = get_term_by ( 'name' , 'exclude-from-search' , 'product_visibility' );
if ( $exclude_search_term ) {
2017-03-31 11:42:07 +00:00
$wpdb -> query ( $wpdb -> prepare ( " INSERT IGNORE INTO { $wpdb -> term_relationships } SELECT post_id, %d, 0 FROM { $wpdb -> postmeta } WHERE meta_key = '_visibility' AND meta_value IN ('hidden', 'catalog'); " , $exclude_search_term -> term_taxonomy_id ) );
2016-12-08 10:56:45 +00:00
}
2017-11-23 14:17:21 +00:00
$exclude_catalog_term = get_term_by ( 'name' , 'exclude-from-catalog' , 'product_visibility' );
if ( $exclude_catalog_term ) {
2017-03-31 11:42:07 +00:00
$wpdb -> query ( $wpdb -> prepare ( " INSERT IGNORE INTO { $wpdb -> term_relationships } SELECT post_id, %d, 0 FROM { $wpdb -> postmeta } WHERE meta_key = '_visibility' AND meta_value IN ('hidden', 'search'); " , $exclude_catalog_term -> term_taxonomy_id ) );
2016-12-08 10:56:45 +00:00
}
2017-11-23 14:17:21 +00:00
$outofstock_term = get_term_by ( 'name' , 'outofstock' , 'product_visibility' );
if ( $outofstock_term ) {
2017-03-31 11:42:07 +00:00
$wpdb -> query ( $wpdb -> prepare ( " INSERT IGNORE INTO { $wpdb -> term_relationships } SELECT post_id, %d, 0 FROM { $wpdb -> postmeta } WHERE meta_key = '_stock_status' AND meta_value = 'outofstock'; " , $outofstock_term -> term_taxonomy_id ) );
2016-12-08 10:56:45 +00:00
}
2016-12-09 15:43:25 +00:00
2017-11-23 14:17:21 +00:00
$rating_term = get_term_by ( 'name' , 'rated-1' , 'product_visibility' );
if ( $rating_term ) {
2017-03-31 11:42:07 +00:00
$wpdb -> query ( $wpdb -> prepare ( " INSERT IGNORE INTO { $wpdb -> term_relationships } SELECT post_id, %d, 0 FROM { $wpdb -> postmeta } WHERE meta_key = '_wc_average_rating' AND ROUND( meta_value ) = 1; " , $rating_term -> term_taxonomy_id ) );
2016-12-09 15:43:25 +00:00
}
2017-11-23 14:17:21 +00:00
$rating_term = get_term_by ( 'name' , 'rated-2' , 'product_visibility' );
if ( $rating_term ) {
2017-03-31 11:42:07 +00:00
$wpdb -> query ( $wpdb -> prepare ( " INSERT IGNORE INTO { $wpdb -> term_relationships } SELECT post_id, %d, 0 FROM { $wpdb -> postmeta } WHERE meta_key = '_wc_average_rating' AND ROUND( meta_value ) = 2; " , $rating_term -> term_taxonomy_id ) );
2016-12-09 15:43:25 +00:00
}
2017-11-23 14:17:21 +00:00
$rating_term = get_term_by ( 'name' , 'rated-3' , 'product_visibility' );
if ( $rating_term ) {
2017-03-31 11:42:07 +00:00
$wpdb -> query ( $wpdb -> prepare ( " INSERT IGNORE INTO { $wpdb -> term_relationships } SELECT post_id, %d, 0 FROM { $wpdb -> postmeta } WHERE meta_key = '_wc_average_rating' AND ROUND( meta_value ) = 3; " , $rating_term -> term_taxonomy_id ) );
2016-12-09 15:43:25 +00:00
}
2017-11-23 14:17:21 +00:00
$rating_term = get_term_by ( 'name' , 'rated-4' , 'product_visibility' );
if ( $rating_term ) {
2017-03-31 11:42:07 +00:00
$wpdb -> query ( $wpdb -> prepare ( " INSERT IGNORE INTO { $wpdb -> term_relationships } SELECT post_id, %d, 0 FROM { $wpdb -> postmeta } WHERE meta_key = '_wc_average_rating' AND ROUND( meta_value ) = 4; " , $rating_term -> term_taxonomy_id ) );
2016-12-09 15:43:25 +00:00
}
2017-11-23 14:17:21 +00:00
$rating_term = get_term_by ( 'name' , 'rated-5' , 'product_visibility' );
if ( $rating_term ) {
2017-03-31 11:42:07 +00:00
$wpdb -> query ( $wpdb -> prepare ( " INSERT IGNORE INTO { $wpdb -> term_relationships } SELECT post_id, %d, 0 FROM { $wpdb -> postmeta } WHERE meta_key = '_wc_average_rating' AND ROUND( meta_value ) = 5; " , $rating_term -> term_taxonomy_id ) );
2016-12-09 15:43:25 +00:00
}
2016-12-08 10:56:45 +00:00
}
2016-12-13 13:38:20 +00:00
/**
* Update DB Version .
*/
2017-03-15 16:55:07 +00:00
function wc_update_300_db_version () {
WC_Install :: update_db_version ( '3.0.0' );
2016-12-13 13:38:20 +00:00
}
2017-06-01 18:26:35 +00:00
/**
* Add an index to the downloadable product permissions table to improve performance of update_user_by_order_id .
*/
function wc_update_310_downloadable_products () {
global $wpdb ;
$index_exists = $wpdb -> get_row ( " SHOW INDEX FROM { $wpdb -> prefix } woocommerce_downloadable_product_permissions WHERE column_name = 'order_id' and key_name = 'order_id' " );
if ( is_null ( $index_exists ) ) {
$wpdb -> query ( " ALTER TABLE { $wpdb -> prefix } woocommerce_downloadable_product_permissions ADD INDEX order_id (order_id) " );
}
}
2017-06-08 11:18:07 +00:00
/**
* Find old order notes and ensure they have the correct type for exclusion .
*/
function wc_update_310_old_comments () {
global $wpdb ;
$wpdb -> query ( " UPDATE $wpdb->comments comments LEFT JOIN $wpdb->posts as posts ON comments.comment_post_ID = posts.ID SET comment_type = 'order_note' WHERE posts.post_type = 'shop_order' AND comment_type = ''; " );
}
2017-06-01 18:26:35 +00:00
/**
* Update DB Version .
*/
function wc_update_310_db_version () {
WC_Install :: update_db_version ( '3.1.0' );
}
2017-06-28 11:57:37 +00:00
2017-08-15 16:01:28 +00:00
/**
* Update shop_manager capabilities .
*/
function wc_update_312_shop_manager_capabilities () {
$role = get_role ( 'shop_manager' );
$role -> remove_cap ( 'unfiltered_html' );
}
/**
* Update DB Version .
*/
function wc_update_312_db_version () {
WC_Install :: update_db_version ( '3.1.2' );
}
2017-06-28 11:57:37 +00:00
/**
* Update state codes for Mexico .
*/
function wc_update_320_mexican_states () {
global $wpdb ;
$mx_states = array (
'Distrito Federal' => 'CMX' ,
'Jalisco' => 'JAL' ,
'Nuevo Leon' => 'NLE' ,
'Aguascalientes' => 'AGS' ,
'Baja California' => 'BCN' ,
'Baja California Sur' => 'BCS' ,
'Campeche' => 'CAM' ,
'Chiapas' => 'CHP' ,
'Chihuahua' => 'CHH' ,
'Coahuila' => 'COA' ,
'Colima' => 'COL' ,
'Durango' => 'DGO' ,
'Guanajuato' => 'GTO' ,
'Guerrero' => 'GRO' ,
'Hidalgo' => 'HGO' ,
'Estado de Mexico' => 'MEX' ,
'Michoacan' => 'MIC' ,
'Morelos' => 'MOR' ,
'Nayarit' => 'NAY' ,
'Oaxaca' => 'OAX' ,
'Puebla' => 'PUE' ,
'Queretaro' => 'QRO' ,
'Quintana Roo' => 'ROO' ,
'San Luis Potosi' => 'SLP' ,
'Sinaloa' => 'SIN' ,
'Sonora' => 'SON' ,
'Tabasco' => 'TAB' ,
'Tamaulipas' => 'TMP' ,
'Tlaxcala' => 'TLA' ,
'Veracruz' => 'VER' ,
'Yucatan' => 'YUC' ,
'Zacatecas' => 'ZAC' ,
);
foreach ( $mx_states as $old => $new ) {
2017-10-05 11:49:10 +00:00
$wpdb -> query (
$wpdb -> prepare (
2017-11-23 12:41:31 +00:00
" UPDATE $wpdb->postmeta
SET meta_value = % s
WHERE meta_key IN ( '_billing_state' , '_shipping_state' )
AND meta_value = % s " ,
2017-10-05 11:49:10 +00:00
$new , $old
2017-06-28 11:57:37 +00:00
)
);
$wpdb -> update (
" { $wpdb -> prefix } woocommerce_shipping_zone_locations " ,
array (
'location_code' => 'MX:' . $new ,
),
array (
'location_code' => 'MX:' . $old ,
)
);
$wpdb -> update (
" { $wpdb -> prefix } woocommerce_tax_rates " ,
array (
'tax_rate_state' => strtoupper ( $new ),
),
array (
'tax_rate_state' => strtoupper ( $old ),
)
);
}
}
/**
* Update DB Version .
*/
function wc_update_320_db_version () {
WC_Install :: update_db_version ( '3.2.0' );
}
2017-11-07 19:16:44 +00:00
/**
* Update image settings to use new aspect ratios and widths .
*/
function wc_update_330_image_options () {
$old_thumbnail_size = get_option ( 'shop_catalog_image_size' , array () );
$old_single_size = get_option ( 'shop_single_image_size' , array () );
if ( ! empty ( $old_thumbnail_size [ 'width' ] ) ) {
2018-01-25 12:34:28 +00:00
$width = absint ( $old_thumbnail_size [ 'width' ] );
$height = absint ( $old_thumbnail_size [ 'height' ] );
$hard_crop = ! empty ( $old_thumbnail_size [ 'crop' ] );
if ( ! $width ) {
$width = 300 ;
}
if ( ! $height ) {
$height = $width ;
}
2017-11-07 19:16:44 +00:00
2018-01-25 12:34:28 +00:00
update_option ( 'woocommerce_thumbnail_image_width' , $width );
// Calculate cropping mode from old image options.
if ( ! $hard_crop ) {
update_option ( 'woocommerce_thumbnail_cropping' , 'uncropped' );
} elseif ( $width === $height ) {
update_option ( 'woocommerce_thumbnail_cropping' , '1:1' );
} else {
$ratio = $width / $height ;
$fraction = wc_decimal_to_fraction ( $ratio );
2017-11-07 19:16:44 +00:00
2018-01-25 12:34:28 +00:00
if ( $fraction ) {
update_option ( 'woocommerce_thumbnail_cropping' , 'custom' );
update_option ( 'woocommerce_thumbnail_cropping_custom_width' , $fraction [ 0 ] );
update_option ( 'woocommerce_thumbnail_cropping_custom_height' , $fraction [ 1 ] );
}
}
2017-11-07 19:16:44 +00:00
}
2018-01-25 12:34:28 +00:00
// Single is uncropped.
2017-11-07 19:16:44 +00:00
if ( ! empty ( $old_single_size [ 'width' ] ) ) {
update_option ( 'woocommerce_single_image_width' , absint ( $old_single_size [ 'width' ] ) );
}
}
2017-11-16 15:44:01 +00:00
/**
* Migrate webhooks from post type to CRUD .
*/
function wc_update_330_webhooks () {
register_post_type ( 'shop_webhook' );
// Map statuses from post_type to Webhooks CRUD.
$statuses = array (
'publish' => 'active' ,
'draft' => 'paused' ,
'pending' => 'disabled' ,
);
$posts = get_posts ( array (
'posts_per_page' => - 1 ,
'post_type' => 'shop_webhook' ,
'post_status' => 'any' ,
) );
foreach ( $posts as $post ) {
$webhook = new WC_Webhook ();
$webhook -> set_name ( $post -> post_title );
$webhook -> set_status ( isset ( $statuses [ $post -> post_status ] ) ? $statuses [ $post -> post_status ] : 'disabled' );
$webhook -> set_delivery_url ( get_post_meta ( $post -> ID , '_delivery_url' , true ) );
$webhook -> set_secret ( get_post_meta ( $post -> ID , '_secret' , true ) );
$webhook -> set_topic ( get_post_meta ( $post -> ID , '_topic' , true ) );
$webhook -> set_api_version ( get_post_meta ( $post -> ID , '_api_version' , true ) );
2018-01-31 17:09:21 +00:00
$webhook -> set_user_id ( $post -> post_author );
2017-11-16 15:44:01 +00:00
$webhook -> set_pending_delivery ( false );
$webhook -> save ();
wp_delete_post ( $post -> ID , true );
}
unregister_post_type ( 'shop_webhook' );
2017-12-07 20:21:52 +00:00
}
2017-11-28 17:09:10 +00:00
2017-11-23 15:44:17 +00:00
/**
* Assign default cat to all products with no cats .
*/
function wc_update_330_set_default_product_cat () {
global $wpdb ;
$default_category = get_option ( 'default_product_cat' , 0 );
if ( $default_category ) {
$result = $wpdb -> query ( $wpdb -> prepare ( "
INSERT INTO { $wpdb -> term_relationships } ( object_id , term_taxonomy_id )
SELECT DISTINCT posts . ID , % s FROM { $wpdb -> posts } posts
LEFT JOIN
(
SELECT object_id FROM { $wpdb -> term_relationships } term_relationships
LEFT JOIN { $wpdb -> term_taxonomy } term_taxonomy ON term_relationships . term_taxonomy_id = term_taxonomy . term_taxonomy_id
WHERE term_taxonomy . taxonomy = 'product_cat'
) AS tax_query
ON posts . ID = tax_query . object_id
WHERE posts . post_type = 'product'
AND tax_query . object_id IS NULL
" , $default_category ) );
wp_cache_flush ();
delete_transient ( 'wc_term_counts' );
wp_update_term_count_now ( array ( $default_category ), 'product_cat' );
}
}
2017-11-20 22:21:08 +00:00
/**
* Update product stock status to use the new onbackorder status .
*/
function wc_update_330_product_stock_status () {
global $wpdb ;
if ( 'yes' !== get_option ( 'woocommerce_manage_stock' ) ) {
return ;
}
$min_stock_amount = ( int ) get_option ( 'woocommerce_notify_no_stock_amount' , 0 );
// Get all products that have stock management enabled, stock less than or equal to min stock amount, and backorders enabled.
$post_ids = $wpdb -> get_col ( $wpdb -> prepare ( "
SELECT t1 . post_id FROM $wpdb -> postmeta t1
INNER JOIN $wpdb -> postmeta t2
ON t1 . post_id = t2 . post_id
AND t1 . meta_key = '_manage_stock' AND t1 . meta_value = 'yes'
2017-11-20 22:24:55 +00:00
AND t2 . meta_key = '_stock' AND t2 . meta_value <= % d
2017-11-20 22:21:08 +00:00
INNER JOIN $wpdb -> postmeta t3
ON t2 . post_id = t3 . post_id
AND t3 . meta_key = '_backorders' AND ( t3 . meta_value = 'yes' OR t3 . meta_value = 'notify' )
2017-11-22 22:03:26 +00:00
" , $min_stock_amount ) ); // WPCS: db call ok, unprepared SQL ok, cache ok.
2017-11-20 22:21:08 +00:00
2017-11-21 22:08:17 +00:00
if ( empty ( $post_ids ) ) {
return ;
}
$post_ids = array_map ( 'absint' , $post_ids );
2017-11-20 22:21:08 +00:00
// Set the status to onbackorder for those products.
$wpdb -> query ( "
UPDATE $wpdb -> postmeta
SET meta_value = 'onbackorder'
2017-11-22 22:03:26 +00:00
WHERE meta_key = '_stock_status' AND post_id IN ( " . implode( ',', $post_ids ) . ' )
' ); // WPCS: db call ok, unprepared SQL ok, cache ok.
2017-11-20 22:21:08 +00:00
}
2017-11-07 19:16:44 +00:00
/**
2017-12-05 17:23:29 +00:00
* Clear addons page transients
2017-11-07 19:16:44 +00:00
*/
2017-12-05 17:23:29 +00:00
function wc_update_330_clear_transients () {
delete_transient ( 'wc_addons_sections' );
delete_transient ( 'wc_addons_featured' );
2017-11-07 19:16:44 +00:00
}
2018-01-23 02:51:01 +00:00
/**
* Set PayPal ' s sandbox credentials .
*/
function wc_update_330_set_paypal_sandbox_credentials () {
$paypal_settings = get_option ( 'woocommerce_paypal_settings' );
if ( isset ( $paypal_settings [ 'testmode' ] ) && 'yes' === $paypal_settings [ 'testmode' ] ) {
foreach ( array ( 'api_username' , 'api_password' , 'api_signature' ) as $credential ) {
if ( ! empty ( $paypal_settings [ $credential ] ) ) {
$paypal_settings [ 'sandbox_' . $credential ] = $paypal_settings [ $credential ];
}
}
update_option ( 'woocommerce_paypal_settings' , $paypal_settings );
}
}
2018-01-31 12:33:30 +00:00
/**
* Update DB Version .
*/
function wc_update_330_db_version () {
WC_Install :: update_db_version ( '3.3.0' );
}
2018-04-09 21:15:09 +00:00
/**
* Update state codes for Ireland .
*/
function wc_update_340_irish_states () {
global $wpdb ;
$ie_states = array (
'CK' => 'CO' ,
'DN' => 'D' ,
'GY' => 'G' ,
'TY' => 'TA' ,
);
foreach ( $ie_states as $old => $new ) {
$wpdb -> query (
$wpdb -> prepare (
" UPDATE $wpdb->postmeta
SET meta_value = % s
WHERE meta_key IN ( '_billing_state' , '_shipping_state' )
AND meta_value = % s " ,
$new , $old
)
);
$wpdb -> update (
" { $wpdb -> prefix } woocommerce_shipping_zone_locations " ,
array (
'location_code' => 'IE:' . $new ,
),
array (
'location_code' => 'IE:' . $old ,
)
);
$wpdb -> update (
" { $wpdb -> prefix } woocommerce_tax_rates " ,
array (
'tax_rate_state' => strtoupper ( $new ),
),
array (
'tax_rate_state' => strtoupper ( $old ),
)
);
}
}
2018-04-16 18:04:57 +00:00
/**
* Update DB Version .
*/
function wc_update_340_db_version () {
WC_Install :: update_db_version ( '3.4.0' );
}
2018-04-11 18:23:12 +00:00
/**
* Copy order customer_id from post meta to post_author and set post_author to 0 for refunds .
2018-04-16 14:15:42 +00:00
*
2018-04-17 14:05:46 +00:00
* 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 .
2018-04-11 18:23:12 +00:00
*/
2018-04-17 14:05:46 +00:00
function wc_update_350_order_customer_id ( $updater = false ) {
2018-04-11 18:23:12 +00:00
global $wpdb ;
2018-04-16 18:04:57 +00:00
$post_types = ( array ) apply_filters ( 'woocommerce_update_350_order_customer_id_post_types' , array ( 'shop_order' ) );
2018-04-16 14:15:42 +00:00
$post_types_placeholders = implode ( ', ' , array_fill ( 0 , count ( $post_types ), '%s' ) );
2018-04-11 18:23:12 +00:00
2018-04-17 14:05:46 +00:00
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))'
);
2018-04-11 18:23:12 +00:00
2018-04-17 14:05:46 +00:00
$wpdb -> query (
" INSERT IGNORE INTO customers_map (SELECT post_id, meta_value FROM wp_postmeta WHERE meta_key = '_customer_user') "
);
2018-04-16 14:15:42 +00:00
2018-04-17 14:05:46 +00:00
$wpdb -> query ( 'SET sql_safe_updates=1' );
2018-04-16 14:15:42 +00:00
2018-04-17 14:05:46 +00:00
$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
)
);
2018-04-16 14:15:42 +00:00
2018-04-17 14:05:46 +00:00
$wpdb -> update ( $wpdb -> posts , array ( 'post_author' => 0 ), array ( 'post_type' => 'shop_order_refund' ) );
} else {
2018-04-17 18:16:05 +00:00
// If running the update from the wp-admin, copy data in batches being careful not to use more memory than allowed.
2018-04-17 14:05:46 +00:00
$admin_orders_sql = '' ;
2018-04-19 13:14:02 +00:00
$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
)
);
2018-04-17 14:05:46 +00:00
2018-04-19 13:14:02 +00:00
// 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 );
}
2018-04-16 14:15:42 +00:00
2018-04-17 14:05:46 +00:00
if ( ! empty ( $admin_orders ) ) {
$admin_orders_sql .= ' AND ID NOT IN (' . implode ( ', ' , $admin_orders ) . ') ' ;
2018-04-16 14:15:42 +00:00
}
2018-04-17 14:05:46 +00:00
// 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 ;
2018-04-16 14:15:42 +00:00
}
2018-04-17 14:05:46 +00:00
$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 ) . ')'
);
2018-04-16 14:15:42 +00:00
2018-04-17 14:05:46 +00:00
// Exit loop if no _customer_user metas exist for the list of orders to update.
if ( ! $orders_meta_data ) {
break ;
}
2018-04-16 14:15:42 +00:00
2018-04-17 14:05:46 +00:00
// Update post_author for a batch of orders.
foreach ( $orders_meta_data as $order_meta ) {
2018-04-17 18:16:05 +00:00
// Stop update execution and re-enqueue it if near memory limit.
if ( $updater instanceof WC_Background_Updater && $updater -> is_memory_exceeded () ) {
2018-04-17 14:05:46 +00:00
return - 1 ;
}
$wpdb -> update ( $wpdb -> posts , array ( 'post_author' => $order_meta -> customer_id ), array ( 'ID' => $order_meta -> post_id ) );
}
2018-04-16 14:15:42 +00:00
}
2018-04-17 14:05:46 +00:00
// Set post_author to 0 instead of 1 on all shop_order_refunds.
while ( true ) {
2018-04-17 18:16:05 +00:00
// Stop update execution and re-enqueue it if near memory limit.
if ( $updater instanceof WC_Background_Updater && $updater -> is_memory_exceeded () ) {
2018-04-17 14:05:46 +00:00
return - 1 ;
}
$updated_rows = $wpdb -> query ( " UPDATE { $wpdb -> posts } SET post_author = 0 WHERE post_type = 'shop_order_refund' LIMIT 1000 " );
2018-04-16 14:15:42 +00:00
2018-04-17 14:05:46 +00:00
if ( ! $updated_rows ) {
break ;
}
2018-04-16 14:15:42 +00:00
}
}
2018-04-17 14:05:46 +00:00
wp_cache_flush ();
2018-04-11 18:23:12 +00:00
}
2018-04-17 14:05:46 +00:00