2011-08-09 15:16:18 +00:00
< ? php
/**
2011-08-10 17:11:11 +00:00
* WooCommerce Install
2012-08-14 12:21:34 +00:00
*
* Plugin install script which adds default pages , taxonomies , and database tables to WordPress . Runs on activation and upgrade .
2011-08-09 15:16:18 +00:00
*
2011-08-10 17:11:11 +00:00
* @ author WooThemes
2011-08-09 15:16:18 +00:00
* @ category Admin
2012-08-14 12:21:34 +00:00
* @ package WooCommerce / Admin / Install
* @ version 1.6 . 4
2011-08-09 15:16:18 +00:00
*/
/**
2012-08-14 12:21:34 +00:00
* Runs the installer .
*
* @ access public
* @ return void
2011-08-09 15:16:18 +00:00
*/
2011-12-12 16:34:56 +00:00
function do_install_woocommerce () {
2011-11-18 00:38:46 +00:00
global $woocommerce_settings , $woocommerce ;
2012-08-14 12:21:34 +00:00
2011-08-09 15:16:18 +00:00
// Do install
2011-08-10 17:11:11 +00:00
woocommerce_default_options ();
woocommerce_tables_install ();
2012-09-20 15:35:15 +00:00
woocommerce_init_roles ();
2012-10-10 09:21:04 +00:00
// Setup default permalinks
$permalinks = get_option ( 'woocommerce_permalinks' );
$shop_page_id = woocommerce_get_page_id ( 'shop' );
if ( empty ( $permalinks ) && $shop_page_id > 0 ) {
$base_slug = $shop_page_id > 0 && get_page ( $shop_page_id ) ? get_page_uri ( $shop_page_id ) : 'shop' ;
$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' );
if ( 'yes' == get_option ( 'woocommerce_prepend_shop_page_to_products' ) ) {
$product_base = trailingslashit ( $base_slug );
} else {
if ( ( $product_slug = get_option ( 'woocommerce_product_slug' ) ) !== false && ! empty ( $product_slug ) ) {
$product_base = trailingslashit ( $product_slug );
} else {
$product_base = trailingslashit ( _x ( 'product' , 'slug' , 'woocommerce' ) );
}
}
if ( get_option ( 'woocommerce_prepend_category_to_products' ) == 'yes' )
$product_base .= trailingslashit ( '%product_cat%' );
$permalinks = array (
'product_base' => untrailingslashit ( $product_base ),
'category_base' => untrailingslashit ( $category_base . $category_slug ),
'attribute_base' => untrailingslashit ( $category_base ),
'tag_base' => untrailingslashit ( $category_base . $tag_slug )
);
update_option ( 'woocommerce_permalinks' , $permalinks );
}
2012-08-14 12:21:34 +00:00
2012-02-17 21:25:06 +00:00
// Register post types
$woocommerce -> init_taxonomy ();
// Add default taxonomies
2011-08-10 17:11:11 +00:00
woocommerce_default_taxonomies ();
2012-08-14 12:21:34 +00:00
2011-11-09 15:15:30 +00:00
// Install folder for uploading files and prevent hotlinking
2012-05-17 11:58:17 +00:00
$upload_dir = wp_upload_dir ();
$downloads_url = $upload_dir [ 'basedir' ] . '/woocommerce_uploads' ;
2012-08-14 12:21:34 +00:00
2012-05-17 11:58:17 +00:00
if ( wp_mkdir_p ( $downloads_url ) && ! file_exists ( $downloads_url . '/.htaccess' ) ) {
if ( $file_handle = @ fopen ( $downloads_url . '/.htaccess' , 'w' ) ) {
2012-09-06 15:16:16 +00:00
fwrite ( $file_handle , 'deny from all' );
fclose ( $file_handle );
2012-05-17 11:58:17 +00:00
}
}
2012-08-14 12:21:34 +00:00
2011-11-16 09:50:48 +00:00
// Install folder for logs
2012-09-06 15:16:16 +00:00
$logs_url = WP_PLUGIN_DIR . " / " . plugin_basename ( dirname ( dirname ( __FILE__ ) ) ) . '/logs' ;
2012-08-14 12:21:34 +00:00
2012-05-17 11:58:17 +00:00
if ( wp_mkdir_p ( $logs_url ) && ! file_exists ( $logs_url . '/.htaccess' ) ) {
if ( $file_handle = @ fopen ( $logs_url . '/.htaccess' , 'w' ) ) {
2012-09-06 15:16:16 +00:00
fwrite ( $file_handle , 'deny from all' );
fclose ( $file_handle );
2012-05-17 11:58:17 +00:00
}
}
2012-08-14 12:21:34 +00:00
2012-02-18 13:25:51 +00:00
// Clear transient cache
$woocommerce -> clear_product_transients ();
2012-08-14 12:21:34 +00:00
2012-05-01 18:28:45 +00:00
// Recompile LESS styles if they are custom
2012-09-06 15:16:16 +00:00
if ( get_option ( 'woocommerce_frontend_css' ) == 'yes' ) {
2012-08-14 12:21:34 +00:00
2012-05-01 18:28:45 +00:00
// Handle Colour Settings
2012-05-17 11:58:17 +00:00
$colors = get_option ( 'woocommerce_frontend_css_colors' );
2012-08-14 12:21:34 +00:00
2012-05-01 18:28:45 +00:00
if ( (
! empty ( $colors [ 'primary' ] ) &&
! empty ( $colors [ 'secondary' ] ) &&
! empty ( $colors [ 'highlight' ] ) &&
! empty ( $colors [ 'content_bg' ] ) &&
2012-08-14 12:21:34 +00:00
! empty ( $colors [ 'subtext' ] )
2012-05-01 18:28:45 +00:00
) && (
$colors [ 'primary' ] != '#ad74a2' ||
$colors [ 'secondary' ] != '#f7f6f7' ||
$colors [ 'highlight' ] != '#85ad74' ||
$colors [ 'content_bg' ] != '#ffffff' ||
$colors [ 'subtext' ] != '#777777'
) ) {
2012-08-14 12:21:34 +00:00
// Write less file
2012-05-01 18:28:45 +00:00
woocommerce_compile_less_styles ();
2012-08-14 12:21:34 +00:00
2012-05-01 18:28:45 +00:00
}
2012-08-14 12:21:34 +00:00
2012-05-01 18:28:45 +00:00
}
2012-08-14 12:21:34 +00:00
2011-08-09 15:16:18 +00:00
// Update version
2012-09-06 15:16:16 +00:00
update_option ( 'woocommerce_db_version' , $woocommerce -> version );
2011-08-09 15:16:18 +00:00
}
2012-08-14 12:21:34 +00:00
2011-08-09 15:16:18 +00:00
/**
* Default options
2012-08-14 12:21:34 +00:00
*
2011-08-09 15:16:18 +00:00
* Sets up the default options used on the settings page
2012-08-14 12:21:34 +00:00
*
* @ access public
* @ return void
2011-08-09 15:16:18 +00:00
*/
2011-08-10 17:11:11 +00:00
function woocommerce_default_options () {
2011-09-13 14:17:58 +00:00
global $woocommerce_settings ;
2012-08-14 12:21:34 +00:00
2011-09-26 18:05:29 +00:00
// Include settings so that we can run through defaults
2012-05-19 19:04:34 +00:00
include_once ( 'settings/settings-init.php' );
2012-08-14 12:21:34 +00:00
2012-09-06 15:16:16 +00:00
foreach ( $woocommerce_settings as $section ) {
2012-08-14 12:21:34 +00:00
2012-05-17 11:58:17 +00:00
foreach ( $section as $value ) {
2012-08-14 12:21:34 +00:00
2012-05-17 11:58:17 +00:00
if ( isset ( $value [ 'std' ] ) && isset ( $value [ 'id' ] ) ) {
2012-08-14 12:21:34 +00:00
2012-05-17 11:58:17 +00:00
if ( $value [ 'type' ] == 'image_width' ) {
2012-08-14 12:21:34 +00:00
2012-09-06 15:16:16 +00:00
add_option ( $value [ 'id' ] . '_width' , $value [ 'std' ] );
add_option ( $value [ 'id' ] . '_height' , $value [ 'std' ] );
2012-08-14 12:21:34 +00:00
2012-05-17 11:58:17 +00:00
} else {
2012-08-14 12:21:34 +00:00
2012-09-06 15:16:16 +00:00
add_option ( $value [ 'id' ], $value [ 'std' ] );
2012-08-14 12:21:34 +00:00
2012-05-17 11:58:17 +00:00
}
2012-08-14 12:21:34 +00:00
2012-05-17 11:58:17 +00:00
}
2012-08-14 12:21:34 +00:00
2012-05-17 11:58:17 +00:00
}
2012-08-14 12:21:34 +00:00
2012-05-17 11:58:17 +00:00
}
2011-09-26 18:05:29 +00:00
2012-05-17 11:58:17 +00:00
add_option ( 'woocommerce_shop_slug' , 'shop' );
2011-08-09 15:16:18 +00:00
}
2012-08-14 12:21:34 +00:00
2011-09-24 21:14:52 +00:00
/**
* Create a page
2012-08-14 12:21:34 +00:00
*
* @ access public
* @ param mixed $slug Slug for the new page
* @ param mixed $option Option name to store the page ' s ID
* @ param string $page_title ( default : '' ) Title for the new page
* @ param string $page_content ( default : '' ) Content for the new page
* @ param int $post_parent ( default : 0 ) Parent for the new page
* @ return void
2011-09-24 21:14:52 +00:00
*/
function woocommerce_create_page ( $slug , $option , $page_title = '' , $page_content = '' , $post_parent = 0 ) {
global $wpdb ;
2012-08-14 12:21:34 +00:00
$option_value = get_option ( $option );
if ( $option_value > 0 && get_post ( $option_value ) )
2012-05-17 11:58:17 +00:00
return ;
2012-08-14 12:21:34 +00:00
2012-09-06 15:16:16 +00:00
$page_found = $wpdb -> get_var ( " SELECT ID FROM " . $wpdb -> posts . " WHERE post_name = ' $slug ' LIMIT 1; " );
if ( $page_found ) {
2012-08-14 12:21:34 +00:00
if ( ! $option_value )
2012-05-17 11:58:17 +00:00
update_option ( $option , $page_found );
2011-09-24 21:14:52 +00:00
return ;
2012-09-06 15:16:16 +00:00
}
2012-08-14 12:21:34 +00:00
2011-09-24 21:14:52 +00:00
$page_data = array (
2012-05-17 11:58:17 +00:00
'post_status' => 'publish' ,
'post_type' => 'page' ,
'post_author' => 1 ,
'post_name' => $slug ,
'post_title' => $page_title ,
'post_content' => $page_content ,
'post_parent' => $post_parent ,
'comment_status' => 'closed'
2011-09-24 21:14:52 +00:00
);
2012-05-17 11:58:17 +00:00
$page_id = wp_insert_post ( $page_data );
2012-08-14 12:21:34 +00:00
2012-05-17 11:58:17 +00:00
update_option ( $option , $page_id );
2011-09-24 21:14:52 +00:00
}
2012-08-14 12:21:34 +00:00
2011-08-09 15:16:18 +00:00
/**
2012-08-14 12:21:34 +00:00
* Create pages that the plugin relies on , storing page id ' s in variables .
*
* @ access public
* @ return void
2011-08-09 15:16:18 +00:00
*/
2011-08-10 17:11:11 +00:00
function woocommerce_create_pages () {
2012-08-14 12:21:34 +00:00
2011-09-24 21:14:52 +00:00
// Shop page
2012-09-06 15:16:16 +00:00
woocommerce_create_page ( esc_sql ( _x ( 'shop' , 'page_slug' , 'woocommerce' ) ), 'woocommerce_shop_page_id' , __ ( 'Shop' , 'woocommerce' ), '' );
2012-08-14 12:21:34 +00:00
2011-09-24 21:14:52 +00:00
// Cart page
2012-09-06 15:16:16 +00:00
woocommerce_create_page ( esc_sql ( _x ( 'cart' , 'page_slug' , 'woocommerce' ) ), 'woocommerce_cart_page_id' , __ ( 'Cart' , 'woocommerce' ), '[woocommerce_cart]' );
2012-08-14 12:21:34 +00:00
2011-09-24 21:14:52 +00:00
// Checkout page
2012-09-06 15:16:16 +00:00
woocommerce_create_page ( esc_sql ( _x ( 'checkout' , 'page_slug' , 'woocommerce' ) ), 'woocommerce_checkout_page_id' , __ ( 'Checkout' , 'woocommerce' ), '[woocommerce_checkout]' );
2012-08-14 12:21:34 +00:00
2011-09-24 21:14:52 +00:00
// Order tracking page
2012-09-06 15:16:16 +00:00
woocommerce_create_page ( esc_sql ( _x ( 'order-tracking' , 'page_slug' , 'woocommerce' ) ), 'woocommerce_order_tracking_page_id' , __ ( 'Track your order' , 'woocommerce' ), '[woocommerce_order_tracking]' );
2012-08-14 12:21:34 +00:00
2011-09-24 21:14:52 +00:00
// My Account page
2012-09-06 15:16:16 +00:00
woocommerce_create_page ( esc_sql ( _x ( 'my-account' , 'page_slug' , 'woocommerce' ) ), 'woocommerce_myaccount_page_id' , __ ( 'My Account' , 'woocommerce' ), '[woocommerce_my_account]' );
2011-08-09 15:16:18 +00:00
2012-10-10 09:21:04 +00:00
// Lost password page
woocommerce_create_page ( esc_sql ( _x ( 'lost-password' , 'page_slug' , 'woocommerce' ) ), 'woocommerce_lost_password_page_id' , __ ( 'Lost Password' , 'woocommerce' ), '[woocommerce_lost_password]' , woocommerce_get_page_id ( 'myaccount' ) );
2011-09-24 21:14:52 +00:00
// Edit address page
2012-09-06 15:16:16 +00:00
woocommerce_create_page ( esc_sql ( _x ( 'edit-address' , 'page_slug' , 'woocommerce' ) ), 'woocommerce_edit_address_page_id' , __ ( 'Edit My Address' , 'woocommerce' ), '[woocommerce_edit_address]' , woocommerce_get_page_id ( 'myaccount' ) );
2012-08-14 12:21:34 +00:00
2011-09-24 21:14:52 +00:00
// View order page
2012-09-06 15:16:16 +00:00
woocommerce_create_page ( esc_sql ( _x ( 'view-order' , 'page_slug' , 'woocommerce' ) ), 'woocommerce_view_order_page_id' , __ ( 'View Order' , 'woocommerce' ), '[woocommerce_view_order]' , woocommerce_get_page_id ( 'myaccount' ) );
2011-08-09 15:16:18 +00:00
2011-09-24 21:14:52 +00:00
// Change password page
2012-09-06 15:16:16 +00:00
woocommerce_create_page ( esc_sql ( _x ( 'change-password' , 'page_slug' , 'woocommerce' ) ), 'woocommerce_change_password_page_id' , __ ( 'Change Password' , 'woocommerce' ), '[woocommerce_change_password]' , woocommerce_get_page_id ( 'myaccount' ) );
2011-08-09 15:16:18 +00:00
2011-09-24 21:14:52 +00:00
// Pay page
2012-09-06 15:16:16 +00:00
woocommerce_create_page ( esc_sql ( _x ( 'pay' , 'page_slug' , 'woocommerce' ) ), 'woocommerce_pay_page_id' , __ ( 'Checkout → Pay' , 'woocommerce' ), '[woocommerce_pay]' , woocommerce_get_page_id ( 'checkout' ) );
2012-08-14 12:21:34 +00:00
2011-09-24 21:14:52 +00:00
// Thanks page
2012-09-06 15:16:16 +00:00
woocommerce_create_page ( esc_sql ( _x ( 'order-received' , 'page_slug' , 'woocommerce' ) ), 'woocommerce_thanks_page_id' , __ ( 'Order Received' , 'woocommerce' ), '[woocommerce_thankyou]' , woocommerce_get_page_id ( 'checkout' ) );
2012-08-14 12:21:34 +00:00
2011-08-09 15:16:18 +00:00
}
2012-08-14 12:21:34 +00:00
2011-08-09 15:16:18 +00:00
/**
2012-08-14 12:21:34 +00:00
* Set up the database tables which the plugin needs to function .
*
* @ access public
* @ return void
2011-08-09 15:16:18 +00:00
*/
2011-08-10 17:11:11 +00:00
function woocommerce_tables_install () {
2012-01-24 16:56:10 +00:00
global $wpdb , $woocommerce ;
2012-08-14 12:21:34 +00:00
2011-11-16 12:15:41 +00:00
$wpdb -> hide_errors ();
2011-08-10 17:11:11 +00:00
$collate = '' ;
2012-10-06 00:10:19 +00:00
if ( $wpdb -> has_cap ( 'collation' ) ) {
2012-09-06 15:16:16 +00:00
if ( ! empty ( $wpdb -> charset ) )
$collate .= " DEFAULT CHARACTER SET $wpdb->charset " ;
if ( ! empty ( $wpdb -> collate ) )
$collate .= " COLLATE $wpdb->collate " ;
2011-08-09 15:16:18 +00:00
}
2012-08-14 12:21:34 +00:00
2012-09-06 15:16:16 +00:00
require_once ( ABSPATH . 'wp-admin/includes/upgrade.php' );
/**
* Data Upgrades - Prepare existing tables
**/
if ( version_compare ( get_option ( 'woocommerce_db_version' ), '1.7' , '<' ) ) {
// remove the existing primary key so we can add the new download_id column
$wpdb -> query ( " ALTER TABLE " . $wpdb -> prefix . " woocommerce_downloadable_product_permissions DROP PRIMARY KEY " );
}
2012-04-10 01:00:02 +00:00
2011-11-17 00:30:46 +00:00
// Table for storing attribute taxonomies - these are user defined
2012-04-10 01:00:02 +00:00
$sql = "
CREATE TABLE " . $wpdb->prefix . " woocommerce_attribute_taxonomies (
attribute_id bigint ( 20 ) NOT NULL auto_increment ,
attribute_name varchar ( 200 ) NOT NULL ,
attribute_label longtext NULL ,
attribute_type varchar ( 200 ) NOT NULL ,
2012-10-09 14:57:02 +00:00
attribute_orderby varchar ( 200 ) NOT NULL ,
2012-04-10 01:00:02 +00:00
PRIMARY KEY ( attribute_id )
) $collate ;
" ;
2011-09-29 13:04:09 +00:00
dbDelta ( $sql );
2012-08-14 12:21:34 +00:00
2012-09-06 15:16:16 +00:00
// Term meta table - sadly WordPress does not have termmeta so we need our own
$sql = "
CREATE TABLE " . $wpdb->prefix . " woocommerce_termmeta (
meta_id bigint ( 20 ) NOT NULL AUTO_INCREMENT ,
woocommerce_term_id bigint ( 20 ) NOT NULL ,
meta_key varchar ( 255 ) NULL ,
meta_value longtext NULL ,
PRIMARY KEY ( meta_id )
) $collate ;
" ;
dbDelta ( $sql );
2011-11-17 00:30:46 +00:00
// Table for storing user and guest download permissions
2012-09-06 15:16:16 +00:00
// KEY(order_id, product_id, download_id) used for organizing downloads on the My Account page
2012-04-10 01:00:02 +00:00
$sql = "
CREATE TABLE " . $wpdb->prefix . " woocommerce_downloadable_product_permissions (
2012-08-28 15:21:54 +00:00
download_id varchar ( 32 ) NOT NULL ,
2012-04-10 01:00:02 +00:00
product_id bigint ( 20 ) NOT NULL ,
order_id bigint ( 20 ) NOT NULL DEFAULT 0 ,
order_key varchar ( 200 ) NOT NULL ,
user_email varchar ( 200 ) NOT NULL ,
user_id bigint ( 20 ) NULL ,
downloads_remaining varchar ( 9 ) NULL ,
access_granted datetime NOT NULL default '0000-00-00 00:00:00' ,
access_expires datetime NULL default null ,
download_count bigint ( 20 ) NOT NULL DEFAULT 0 ,
2012-08-28 15:21:54 +00:00
PRIMARY KEY ( product_id , order_id , order_key , download_id ),
KEY ( order_id , product_id , download_id )
2012-04-10 01:00:02 +00:00
) $collate ;
" ;
2011-09-29 13:04:09 +00:00
dbDelta ( $sql );
2012-08-14 12:21:34 +00:00
2012-09-06 15:16:16 +00:00
/**
* Data Upgrades
**/
if ( version_compare ( get_option ( 'woocommerce_db_version' ), '1.7' , '<' ) ) {
2012-08-28 15:21:54 +00:00
// upgrade existing meta data
2012-09-06 15:16:16 +00:00
$existing_file_paths = $wpdb -> get_results ( " SELECT * FROM " . $wpdb -> postmeta . " WHERE meta_key = '_file_path' " );
if ( $existing_file_paths ) {
foreach ( $existing_file_paths as $existing_file_path ) {
$existing_file_path -> meta_value = trim ( $existing_file_path -> meta_value );
if ( $existing_file_path -> meta_value )
$file_paths = maybe_serialize ( array ( md5 ( $existing_file_path -> meta_value ) => $existing_file_path -> meta_value ) );
else
$file_paths = '' ;
$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 ( $existing_file_path -> meta_value ), $existing_file_path -> post_id ) );
}
}
2012-08-28 15:21:54 +00:00
}
2012-09-07 19:49:42 +00:00
if ( version_compare ( get_option ( 'woocommerce_db_version' ), '1.0' , '>' ) && version_compare ( get_option ( 'woocommerce_db_version' ), '1.4' , '<' ) ) {
2012-08-14 12:21:34 +00:00
2012-01-24 16:56:10 +00:00
// Update woocommerce_downloadable_product_permissions table to include order ID's as well as keys
2012-09-06 15:16:16 +00:00
$results = $wpdb -> get_results ( " SELECT * FROM " . $wpdb -> prefix . " woocommerce_downloadable_product_permissions WHERE order_id = 0; " );
2012-08-14 12:21:34 +00:00
2012-05-17 11:58:17 +00:00
if ( $results ) foreach ( $results as $result ) {
2012-08-14 12:21:34 +00:00
if ( ! $result -> order_key )
2012-05-17 11:58:17 +00:00
continue ;
2012-08-14 12:21:34 +00:00
2012-05-17 11:58:17 +00:00
$order_id = $wpdb -> get_var ( $wpdb -> prepare ( " SELECT post_id FROM { $wpdb -> postmeta } WHERE meta_key = '_order_key' AND meta_value = '%s' LIMIT 1; " , $result -> order_key ) );
2012-08-14 12:21:34 +00:00
2012-05-17 11:58:17 +00:00
if ( $order_id ) {
2012-08-14 12:21:34 +00:00
$wpdb -> update ( $wpdb -> prefix . " woocommerce_downloadable_product_permissions " , array (
'order_id' => $order_id ,
), array (
2012-01-24 16:56:10 +00:00
'product_id' => $result -> product_id ,
'order_key' => $result -> order_key
), array ( '%s' ), array ( '%s' , '%s' ) );
2012-08-14 12:21:34 +00:00
2012-05-17 11:58:17 +00:00
}
2012-08-14 12:21:34 +00:00
2012-05-17 11:58:17 +00:00
}
2012-08-14 12:21:34 +00:00
2012-01-24 16:56:10 +00:00
// Upgrade old meta keys for product data
$meta = array ( 'sku' , 'downloadable' , 'virtual' , 'price' , 'visibility' , 'stock' , 'stock_status' , 'backorders' , 'manage_stock' , 'sale_price' , 'regular_price' , 'weight' , 'length' , 'width' , 'height' , 'tax_status' , 'tax_class' , 'upsell_ids' , 'crosssell_ids' , 'sale_price_dates_from' , 'sale_price_dates_to' , 'min_variation_price' , 'max_variation_price' , 'featured' , 'product_attributes' , 'file_path' , 'download_limit' , 'product_url' , 'min_variation_price' , 'max_variation_price' );
2012-08-14 12:21:34 +00:00
2012-01-24 16:56:10 +00:00
$wpdb -> query ( "
2012-08-14 12:21:34 +00:00
UPDATE { $wpdb -> postmeta }
2012-05-17 11:58:17 +00:00
LEFT JOIN { $wpdb -> posts } ON ( { $wpdb -> postmeta } . post_id = { $wpdb -> posts } . ID )
SET meta_key = CONCAT ( '_' , meta_key )
WHERE meta_key IN ( '" . implode( "' , '", $meta ) . "' )
AND { $wpdb -> posts } . post_type IN ( 'product' , 'product_variation' )
2012-01-24 16:56:10 +00:00
" );
}
2011-08-09 15:16:18 +00:00
}
2012-08-14 12:21:34 +00:00
2011-08-09 15:16:18 +00:00
/**
2012-08-14 12:21:34 +00:00
* Add the default terms for WC taxonomies - product types and order statuses . Modify this at your own risk .
*
* @ access public
* @ return void
2011-08-09 15:16:18 +00:00
*/
2011-08-10 17:11:11 +00:00
function woocommerce_default_taxonomies () {
2012-08-14 12:21:34 +00:00
2011-08-09 15:16:18 +00:00
$product_types = array (
'simple' ,
'grouped' ,
2011-11-08 16:15:36 +00:00
'variable' ,
'external'
2011-08-09 15:16:18 +00:00
);
2012-08-14 12:21:34 +00:00
2012-05-17 11:58:17 +00:00
foreach ( $product_types as $type ) {
if ( ! get_term_by ( 'slug' , sanitize_title ( $type ), 'product_type' ) ) {
wp_insert_term ( $type , 'product_type' );
2011-08-09 15:16:18 +00:00
}
}
2012-08-14 12:21:34 +00:00
2011-08-09 15:16:18 +00:00
$order_status = array (
'pending' ,
2011-09-22 19:50:58 +00:00
'failed' ,
2011-08-09 15:16:18 +00:00
'on-hold' ,
'processing' ,
'completed' ,
'refunded' ,
'cancelled'
);
2012-08-14 12:21:34 +00:00
2012-05-17 11:58:17 +00:00
foreach ( $order_status as $status ) {
if ( ! get_term_by ( 'slug' , sanitize_title ( $status ), 'shop_order_status' ) ) {
wp_insert_term ( $status , 'shop_order_status' );
2011-08-09 15:16:18 +00:00
}
}
2012-08-14 12:21:34 +00:00
// Upgrade from old downloadable/virtual product types
2012-05-17 11:58:17 +00:00
$downloadable_type = get_term_by ( 'slug' , 'downloadable' , 'product_type' );
if ( $downloadable_type ) {
2011-11-05 19:03:03 +00:00
$products = get_objects_in_term ( $downloadable_type -> term_id , 'product_type' );
2012-05-17 11:58:17 +00:00
foreach ( $products as $product ) {
2011-12-24 16:57:36 +00:00
update_post_meta ( $product , '_downloadable' , 'yes' );
update_post_meta ( $product , '_virtual' , 'yes' );
2011-11-05 19:03:03 +00:00
wp_set_object_terms ( $product , 'simple' , 'product_type' );
2012-05-17 11:58:17 +00:00
}
}
2012-08-14 12:21:34 +00:00
2012-05-17 11:58:17 +00:00
$virtual_type = get_term_by ( 'slug' , 'virtual' , 'product_type' );
if ( $virtual_type ) {
2011-11-05 19:03:03 +00:00
$products = get_objects_in_term ( $virtual_type -> term_id , 'product_type' );
2012-05-17 11:58:17 +00:00
foreach ( $products as $product ) {
2011-12-24 16:57:36 +00:00
update_post_meta ( $product , '_downloadable' , 'no' );
update_post_meta ( $product , '_virtual' , 'yes' );
2011-11-05 19:03:03 +00:00
wp_set_object_terms ( $product , 'simple' , 'product_type' );
2012-05-17 11:58:17 +00:00
}
}
2011-08-09 15:16:18 +00:00
}