// 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.
* 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';" ) ) {
$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 ) );
$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 ) );
$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 ) );
}
}
/**
* Update DB Version.
*/
function wc_update_300_db_version() {
WC_Install::update_db_version( '3.0.0' );
}
/**
* 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)" );
}
}
/**
* 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 = '';" );
}
/**
* Update DB Version.
*/
function wc_update_310_db_version() {
WC_Install::update_db_version( '3.1.0' );
}
/**
* 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' );
}
/**
* 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 ) {
$wpdb->query(
$wpdb->prepare(
"UPDATE $wpdb->postmeta
SET meta_value = %s
WHERE meta_key IN ( '_billing_state', '_shipping_state' )
* Renames ordering meta to be consistent across taxonomies.
*/
function wc_update_360_term_meta() {
global $wpdb;
$wpdb->query( "UPDATE {$wpdb->termmeta} SET meta_key = 'order' WHERE meta_key LIKE 'order_pa_%';" );
}
/**
* Add new user_order_remaining_expires to speed up user download permission fetching.
*
* @return void
*/
function wc_update_360_downloadable_product_permissions_index() {
global $wpdb;
$index_exists = $wpdb->get_row( "SHOW INDEX FROM {$wpdb->prefix}woocommerce_downloadable_product_permissions WHERE key_name = 'user_order_remaining_expires'" );
if ( is_null( $index_exists ) ) {
$wpdb->query( "ALTER TABLE {$wpdb->prefix}woocommerce_downloadable_product_permissions ADD INDEX user_order_remaining_expires (user_id,order_id,downloads_remaining,access_expires)" );