Merge pull request #19253 from woocommerce/includes-admin-phpcs-fixes

Use phpcbf to fix coding standard violations in includes/admin
This commit is contained in:
Claudio Sanches 2018-03-05 16:46:52 -03:00 committed by GitHub
commit 869fb52927
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
113 changed files with 7278 additions and 6459 deletions

View File

@ -52,8 +52,8 @@ class WC_Admin_Addons {
$paramters = array(
'category' => $category,
'term' => $term,
'country' => $country,
'term' => $term,
'country' => $country,
);
return '?' . http_build_query( $paramters );
@ -69,7 +69,7 @@ class WC_Admin_Addons {
* @return array of extensions
*/
public static function get_extension_data( $category, $term, $country ) {
$parameters = self::build_parameter_string( $category, $term, $country );
$parameters = self::build_parameter_string( $category, $term, $country );
$raw_extensions = wp_remote_get(
'https://woocommerce.com/wp-json/wccom-extensions/1.0/search' . $parameters
);
@ -166,12 +166,14 @@ class WC_Admin_Addons {
$utm_content = 'nostorefront';
}
$url = add_query_arg( array(
'utm_source' => 'addons',
'utm_medium' => 'product',
'utm_campaign' => 'woocommerceplugin',
'utm_content' => $utm_content,
), $url );
$url = add_query_arg(
array(
'utm_source' => 'addons',
'utm_medium' => 'product',
'utm_campaign' => 'woocommerceplugin',
'utm_content' => $utm_content,
), $url
);
echo '<a href="' . esc_url( $url ) . '" class="add-new-h2">' . esc_html( $text ) . '</a>' . "\n";
}
@ -284,7 +286,7 @@ class WC_Admin_Addons {
public static function output_small_light_block( $block ) {
?>
<div class="addons-small-light-block">
<img class="addons-img" src="<?php echo esc_url( $block->image ) ?>" />
<img class="addons-img" src="<?php echo esc_url( $block->image ); ?>" />
<div class="addons-small-light-block-content">
<h1><?php echo esc_html( $block->title ); ?></h1>
<p><?php echo esc_html( $block->description ); ?></p>
@ -355,9 +357,11 @@ class WC_Admin_Addons {
}
$button_url = wp_nonce_url(
add_query_arg( array(
'install-addon' => 'woocommerce-services',
) ),
add_query_arg(
array(
'install-addon' => 'woocommerce-services',
)
),
'install-addon_woocommerce-services'
);
@ -377,22 +381,26 @@ class WC_Admin_Addons {
'image' => WC()->plugin_url() . '/assets/images/wcs-truck-banner-3x.png',
'title' => __( 'Show Canada Post shipping rates', 'woocommerce' ),
'description' => __( 'Display live rates from Canada Post at checkout to make shipping a breeze. Powered by WooCommerce Services.', 'woocommerce' ),
'logos' => array_merge( $defaults['logos'], array(
array(
'link' => WC()->plugin_url() . '/assets/images/wcs-canada-post-logo.jpg',
'alt' => 'Canada Post logo',
),
) ),
'logos' => array_merge(
$defaults['logos'], array(
array(
'link' => WC()->plugin_url() . '/assets/images/wcs-canada-post-logo.jpg',
'alt' => 'Canada Post logo',
),
)
),
);
break;
case 'US':
$local_defaults = array(
'logos' => array_merge( $defaults['logos'], array(
array(
'link' => WC()->plugin_url() . '/assets/images/wcs-usps-logo.png',
'alt' => 'USPS logo',
),
) ),
'logos' => array_merge(
$defaults['logos'], array(
array(
'link' => WC()->plugin_url() . '/assets/images/wcs-usps-logo.png',
'alt' => 'USPS logo',
),
)
),
);
break;
default:
@ -479,7 +487,7 @@ class WC_Admin_Addons {
public static function output_button( $url, $text, $theme, $plugin = '' ) {
$theme = __( 'Free', 'woocommerce' ) === $text ? 'addons-button-outline-green' : $theme;
$theme = is_plugin_active( $plugin ) ? 'addons-button-installed' : $theme;
$text = is_plugin_active( $plugin ) ? __( 'Installed', 'woocommerce' ) : $text;
$text = is_plugin_active( $plugin ) ? __( 'Installed', 'woocommerce' ) : $text;
?>
<a
class="addons-button <?php echo esc_attr( $theme ); ?>"
@ -506,13 +514,13 @@ class WC_Admin_Addons {
$sections = self::get_sections();
$theme = wp_get_theme();
$current_section = isset( $_GET['section'] ) ? sanitize_text_field( $_GET['section'] ) : '_featured';
$addons = array();
$addons = array();
if ( '_featured' !== $current_section ) {
$category = isset( $_GET['section'] ) ? $_GET['section'] : null;
$term = isset( $_GET['search'] ) ? $_GET['search'] : null;
$country = WC()->countries->get_base_country();
$addons = self::get_extension_data( $category, $term, $country );
$term = isset( $_GET['search'] ) ? $_GET['search'] : null;
$country = WC()->countries->get_base_country();
$addons = self::get_extension_data( $category, $term, $country );
}
/**
@ -523,7 +531,7 @@ class WC_Admin_Addons {
* @uses $theme
* @uses $current_section
*/
include_once( dirname( __FILE__ ) . '/views/html-admin-page-addons.php' );
include_once dirname( __FILE__ ) . '/views/html-admin-page-addons.php';
}
/**

View File

@ -21,11 +21,13 @@ class WC_Admin_API_Keys_Table_List extends WP_List_Table {
* Initialize the API key table list.
*/
public function __construct() {
parent::__construct( array(
'singular' => 'key',
'plural' => 'keys',
'ajax' => false,
) );
parent::__construct(
array(
'singular' => 'key',
'plural' => 'keys',
'ajax' => false,
)
);
}
/**
@ -85,9 +87,15 @@ class WC_Admin_API_Keys_Table_List extends WP_List_Table {
/* translators: %s: API key ID. */
'id' => sprintf( __( 'ID: %d', 'woocommerce' ), $key['key_id'] ),
'edit' => '<a href="' . esc_url( $url ) . '">' . __( 'View/Edit', 'woocommerce' ) . '</a>',
'trash' => '<a class="submitdelete" aria-label="' . esc_attr__( 'Revoke API key', 'woocommerce' ) . '" href="' . esc_url( wp_nonce_url( add_query_arg( array(
'revoke-key' => $key['key_id'],
), admin_url( 'admin.php?page=wc-settings&tab=api&section=keys' ) ), 'revoke' ) ) . '">' . esc_html__( 'Revoke', 'woocommerce' ) . '</a>',
'trash' => '<a class="submitdelete" aria-label="' . esc_attr__( 'Revoke API key', 'woocommerce' ) . '" href="' . esc_url(
wp_nonce_url(
add_query_arg(
array(
'revoke-key' => $key['key_id'],
), admin_url( 'admin.php?page=wc-settings&tab=api&section=keys' )
), 'revoke'
)
) . '">' . esc_html__( 'Revoke', 'woocommerce' ) . '</a>',
);
$row_actions = array();
@ -212,10 +220,12 @@ class WC_Admin_API_Keys_Table_List extends WP_List_Table {
$this->items = $keys;
// Set the pagination.
$this->set_pagination_args( array(
'total_items' => $count,
'per_page' => $per_page,
'total_pages' => ceil( $count / $per_page ),
) );
$this->set_pagination_args(
array(
'total_items' => $count,
'per_page' => $per_page,
'total_pages' => ceil( $count / $per_page ),
)
);
}
}

View File

@ -57,10 +57,12 @@ class WC_Admin_API_Keys {
$keys_table_list = new WC_Admin_API_Keys_Table_List();
// Add screen option.
add_screen_option( 'per_page', array(
'default' => 10,
'option' => 'woocommerce_keys_per_page',
) );
add_screen_option(
'per_page', array(
'default' => 10,
'option' => 'woocommerce_keys_per_page',
)
);
}
}
@ -117,11 +119,14 @@ class WC_Admin_API_Keys {
return $empty;
}
$key = $wpdb->get_row( $wpdb->prepare( "
SELECT key_id, user_id, description, permissions, truncated_key, last_access
FROM {$wpdb->prefix}woocommerce_api_keys
WHERE key_id = %d
", $key_id ), ARRAY_A );
$key = $wpdb->get_row(
$wpdb->prepare(
"SELECT key_id, user_id, description, permissions, truncated_key, last_access
FROM {$wpdb->prefix}woocommerce_api_keys
WHERE key_id = %d",
$key_id
), ARRAY_A
);
if ( is_null( $key ) ) {
return $empty;

View File

@ -14,384 +14,400 @@ if ( ! defined( 'ABSPATH' ) ) {
if ( ! class_exists( 'WC_Admin_Assets', false ) ) :
/**
* WC_Admin_Assets Class.
*/
class WC_Admin_Assets {
/**
* Hook in tabs.
* WC_Admin_Assets Class.
*/
public function __construct() {
add_action( 'admin_enqueue_scripts', array( $this, 'admin_styles' ) );
add_action( 'admin_enqueue_scripts', array( $this, 'admin_scripts' ) );
}
class WC_Admin_Assets {
/**
* Enqueue styles.
*/
public function admin_styles() {
global $wp_scripts;
$screen = get_current_screen();
$screen_id = $screen ? $screen->id : '';
// Register admin styles
wp_register_style( 'woocommerce_admin_menu_styles', WC()->plugin_url() . '/assets/css/menu.css', array(), WC_VERSION );
wp_register_style( 'woocommerce_admin_styles', WC()->plugin_url() . '/assets/css/admin.css', array(), WC_VERSION );
wp_register_style( 'jquery-ui-style', WC()->plugin_url() . '/assets/css/jquery-ui.min.css', array(), WC_VERSION );
wp_register_style( 'woocommerce_admin_dashboard_styles', WC()->plugin_url() . '/assets/css/dashboard.css', array(), WC_VERSION );
wp_register_style( 'woocommerce_admin_print_reports_styles', WC()->plugin_url() . '/assets/css/reports-print.css', array(), WC_VERSION, 'print' );
// Add RTL support for admin styles
wp_style_add_data( 'woocommerce_admin_menu_styles', 'rtl', 'replace' );
wp_style_add_data( 'woocommerce_admin_styles', 'rtl', 'replace' );
wp_style_add_data( 'woocommerce_admin_dashboard_styles', 'rtl', 'replace' );
wp_style_add_data( 'woocommerce_admin_print_reports_styles', 'rtl', 'replace' );
// Sitewide menu CSS
wp_enqueue_style( 'woocommerce_admin_menu_styles' );
// Admin styles for WC pages only
if ( in_array( $screen_id, wc_get_screen_ids() ) ) {
wp_enqueue_style( 'woocommerce_admin_styles' );
wp_enqueue_style( 'jquery-ui-style' );
wp_enqueue_style( 'wp-color-picker' );
}
if ( in_array( $screen_id, array( 'dashboard' ) ) ) {
wp_enqueue_style( 'woocommerce_admin_dashboard_styles' );
}
if ( in_array( $screen_id, array( 'woocommerce_page_wc-reports', 'toplevel_page_wc-reports' ) ) ) {
wp_enqueue_style( 'woocommerce_admin_print_reports_styles' );
/**
* Hook in tabs.
*/
public function __construct() {
add_action( 'admin_enqueue_scripts', array( $this, 'admin_styles' ) );
add_action( 'admin_enqueue_scripts', array( $this, 'admin_scripts' ) );
}
/**
* @deprecated 2.3
* Enqueue styles.
*/
if ( has_action( 'woocommerce_admin_css' ) ) {
do_action( 'woocommerce_admin_css' );
wc_deprecated_function( 'The woocommerce_admin_css action', '2.3', 'admin_enqueue_scripts' );
}
}
public function admin_styles() {
global $wp_scripts;
$screen = get_current_screen();
$screen_id = $screen ? $screen->id : '';
/**
* Enqueue scripts.
*/
public function admin_scripts() {
global $wp_query, $post;
// Register admin styles
wp_register_style( 'woocommerce_admin_menu_styles', WC()->plugin_url() . '/assets/css/menu.css', array(), WC_VERSION );
wp_register_style( 'woocommerce_admin_styles', WC()->plugin_url() . '/assets/css/admin.css', array(), WC_VERSION );
wp_register_style( 'jquery-ui-style', WC()->plugin_url() . '/assets/css/jquery-ui.min.css', array(), WC_VERSION );
wp_register_style( 'woocommerce_admin_dashboard_styles', WC()->plugin_url() . '/assets/css/dashboard.css', array(), WC_VERSION );
wp_register_style( 'woocommerce_admin_print_reports_styles', WC()->plugin_url() . '/assets/css/reports-print.css', array(), WC_VERSION, 'print' );
$screen = get_current_screen();
$screen_id = $screen ? $screen->id : '';
$wc_screen_id = sanitize_title( __( 'WooCommerce', 'woocommerce' ) );
$suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
// Add RTL support for admin styles
wp_style_add_data( 'woocommerce_admin_menu_styles', 'rtl', 'replace' );
wp_style_add_data( 'woocommerce_admin_styles', 'rtl', 'replace' );
wp_style_add_data( 'woocommerce_admin_dashboard_styles', 'rtl', 'replace' );
wp_style_add_data( 'woocommerce_admin_print_reports_styles', 'rtl', 'replace' );
// Register scripts
wp_register_script( 'woocommerce_admin', WC()->plugin_url() . '/assets/js/admin/woocommerce_admin' . $suffix . '.js', array( 'jquery', 'jquery-blockui', 'jquery-ui-sortable', 'jquery-ui-widget', 'jquery-ui-core', 'jquery-tiptip' ), WC_VERSION );
wp_register_script( 'jquery-blockui', WC()->plugin_url() . '/assets/js/jquery-blockui/jquery.blockUI' . $suffix . '.js', array( 'jquery' ), '2.70', true );
wp_register_script( 'jquery-tiptip', WC()->plugin_url() . '/assets/js/jquery-tiptip/jquery.tipTip' . $suffix . '.js', array( 'jquery' ), WC_VERSION, true );
wp_register_script( 'round', WC()->plugin_url() . '/assets/js/round/round' . $suffix . '.js', array( 'jquery' ), WC_VERSION );
wp_register_script( 'wc-admin-meta-boxes', WC()->plugin_url() . '/assets/js/admin/meta-boxes' . $suffix . '.js', array( 'jquery', 'jquery-ui-datepicker', 'jquery-ui-sortable', 'accounting', 'round', 'wc-enhanced-select', 'plupload-all', 'stupidtable', 'jquery-tiptip' ), WC_VERSION );
wp_register_script( 'zeroclipboard', WC()->plugin_url() . '/assets/js/zeroclipboard/jquery.zeroclipboard' . $suffix . '.js', array( 'jquery' ), WC_VERSION );
wp_register_script( 'qrcode', WC()->plugin_url() . '/assets/js/jquery-qrcode/jquery.qrcode' . $suffix . '.js', array( 'jquery' ), WC_VERSION );
wp_register_script( 'stupidtable', WC()->plugin_url() . '/assets/js/stupidtable/stupidtable' . $suffix . '.js', array( 'jquery' ), WC_VERSION );
wp_register_script( 'serializejson', WC()->plugin_url() . '/assets/js/jquery-serializejson/jquery.serializejson' . $suffix . '.js', array( 'jquery' ), '2.8.1' );
wp_register_script( 'flot', WC()->plugin_url() . '/assets/js/jquery-flot/jquery.flot' . $suffix . '.js', array( 'jquery' ), WC_VERSION );
wp_register_script( 'flot-resize', WC()->plugin_url() . '/assets/js/jquery-flot/jquery.flot.resize' . $suffix . '.js', array( 'jquery', 'flot' ), WC_VERSION );
wp_register_script( 'flot-time', WC()->plugin_url() . '/assets/js/jquery-flot/jquery.flot.time' . $suffix . '.js', array( 'jquery', 'flot' ), WC_VERSION );
wp_register_script( 'flot-pie', WC()->plugin_url() . '/assets/js/jquery-flot/jquery.flot.pie' . $suffix . '.js', array( 'jquery', 'flot' ), WC_VERSION );
wp_register_script( 'flot-stack', WC()->plugin_url() . '/assets/js/jquery-flot/jquery.flot.stack' . $suffix . '.js', array( 'jquery', 'flot' ), WC_VERSION );
wp_register_script( 'wc-settings-tax', WC()->plugin_url() . '/assets/js/admin/settings-views-html-settings-tax' . $suffix . '.js', array( 'jquery', 'wp-util', 'underscore', 'backbone', 'jquery-blockui' ), WC_VERSION );
wp_register_script( 'wc-backbone-modal', WC()->plugin_url() . '/assets/js/admin/backbone-modal' . $suffix . '.js', array( 'underscore', 'backbone', 'wp-util' ), WC_VERSION );
wp_register_script( 'wc-shipping-zones', WC()->plugin_url() . '/assets/js/admin/wc-shipping-zones' . $suffix . '.js', array( 'jquery', 'wp-util', 'underscore', 'backbone', 'jquery-ui-sortable', 'wc-enhanced-select', 'wc-backbone-modal' ), WC_VERSION );
wp_register_script( 'wc-shipping-zone-methods', WC()->plugin_url() . '/assets/js/admin/wc-shipping-zone-methods' . $suffix . '.js', array( 'jquery', 'wp-util', 'underscore', 'backbone', 'jquery-ui-sortable', 'wc-backbone-modal' ), WC_VERSION );
wp_register_script( 'wc-shipping-classes', WC()->plugin_url() . '/assets/js/admin/wc-shipping-classes' . $suffix . '.js', array( 'jquery', 'wp-util', 'underscore', 'backbone' ), WC_VERSION );
wp_register_script( 'wc-clipboard', WC()->plugin_url() . '/assets/js/admin/wc-clipboard' . $suffix . '.js', array( 'jquery' ), WC_VERSION );
wp_register_script( 'select2', WC()->plugin_url() . '/assets/js/select2/select2.full' . $suffix . '.js', array( 'jquery' ), '4.0.3' );
wp_register_script( 'selectWoo', WC()->plugin_url() . '/assets/js/selectWoo/selectWoo.full' . $suffix . '.js', array( 'jquery' ), '1.0.3' );
wp_register_script( 'wc-enhanced-select', WC()->plugin_url() . '/assets/js/admin/wc-enhanced-select' . $suffix . '.js', array( 'jquery', 'selectWoo' ), WC_VERSION );
wp_localize_script( 'wc-enhanced-select', 'wc_enhanced_select_params', array(
'i18n_no_matches' => _x( 'No matches found', 'enhanced select', 'woocommerce' ),
'i18n_ajax_error' => _x( 'Loading failed', 'enhanced select', 'woocommerce' ),
'i18n_input_too_short_1' => _x( 'Please enter 1 or more characters', 'enhanced select', 'woocommerce' ),
'i18n_input_too_short_n' => _x( 'Please enter %qty% or more characters', 'enhanced select', 'woocommerce' ),
'i18n_input_too_long_1' => _x( 'Please delete 1 character', 'enhanced select', 'woocommerce' ),
'i18n_input_too_long_n' => _x( 'Please delete %qty% characters', 'enhanced select', 'woocommerce' ),
'i18n_selection_too_long_1' => _x( 'You can only select 1 item', 'enhanced select', 'woocommerce' ),
'i18n_selection_too_long_n' => _x( 'You can only select %qty% items', 'enhanced select', 'woocommerce' ),
'i18n_load_more' => _x( 'Loading more results&hellip;', 'enhanced select', 'woocommerce' ),
'i18n_searching' => _x( 'Searching&hellip;', 'enhanced select', 'woocommerce' ),
'ajax_url' => admin_url( 'admin-ajax.php' ),
'search_products_nonce' => wp_create_nonce( 'search-products' ),
'search_customers_nonce' => wp_create_nonce( 'search-customers' ),
'search_categories_nonce' => wp_create_nonce( 'search-categories' ),
) );
// Sitewide menu CSS
wp_enqueue_style( 'woocommerce_admin_menu_styles' );
wp_register_script( 'accounting', WC()->plugin_url() . '/assets/js/accounting/accounting' . $suffix . '.js', array( 'jquery' ), '0.4.2' );
wp_localize_script( 'accounting', 'accounting_params', array(
'mon_decimal_point' => wc_get_price_decimal_separator(),
) );
wp_register_script( 'wc-orders', WC()->plugin_url() . '/assets/js/admin/wc-orders' . $suffix . '.js', array( 'jquery', 'wp-util', 'underscore', 'backbone', 'jquery-blockui' ), WC_VERSION );
wp_localize_script( 'wc-orders', 'wc_orders_params', array(
'ajax_url' => admin_url( 'admin-ajax.php' ),
'preview_nonce' => wp_create_nonce( 'woocommerce-preview-order' ),
) );
// WooCommerce admin pages.
if ( in_array( $screen_id, wc_get_screen_ids() ) ) {
wp_enqueue_script( 'iris' );
wp_enqueue_script( 'woocommerce_admin' );
wp_enqueue_script( 'wc-enhanced-select' );
wp_enqueue_script( 'jquery-ui-sortable' );
wp_enqueue_script( 'jquery-ui-autocomplete' );
$locale = localeconv();
$decimal = isset( $locale['decimal_point'] ) ? $locale['decimal_point'] : '.';
$params = array(
/* translators: %s: decimal */
'i18n_decimal_error' => sprintf( __( 'Please enter in decimal (%s) format without thousand separators.', 'woocommerce' ), $decimal ),
/* translators: %s: price decimal separator */
'i18n_mon_decimal_error' => sprintf( __( 'Please enter in monetary decimal (%s) format without thousand separators and currency symbols.', 'woocommerce' ), wc_get_price_decimal_separator() ),
'i18n_country_iso_error' => __( 'Please enter in country code with two capital letters.', 'woocommerce' ),
'i18_sale_less_than_regular_error' => __( 'Please enter in a value less than the regular price.', 'woocommerce' ),
'i18_delete_product_notice' => __( 'This product has produced sales and may be linked to existing orders. Are you sure you want to delete it?', 'woocommerce' ),
'decimal_point' => $decimal,
'mon_decimal_point' => wc_get_price_decimal_separator(),
'strings' => array(
'import_products' => __( 'Import', 'woocommerce' ),
'export_products' => __( 'Export', 'woocommerce' ),
),
'urls' => array(
'import_products' => esc_url_raw( admin_url( 'edit.php?post_type=product&page=product_importer' ) ),
'export_products' => esc_url_raw( admin_url( 'edit.php?post_type=product&page=product_exporter' ) ),
),
);
wp_localize_script( 'woocommerce_admin', 'woocommerce_admin', $params );
}
// Edit product category pages
if ( in_array( $screen_id, array( 'edit-product_cat' ) ) ) {
wp_enqueue_media();
}
// Products
if ( in_array( $screen_id, array( 'edit-product' ) ) ) {
wp_enqueue_script( 'woocommerce_quick-edit', WC()->plugin_url() . '/assets/js/admin/quick-edit' . $suffix . '.js', array( 'jquery', 'woocommerce_admin' ), WC_VERSION );
$params = array(
'strings' => array(
'allow_reviews' => esc_js( __( 'Enable reviews', 'woocommerce' ) ),
),
);
wp_localize_script( 'woocommerce_quick-edit', 'woocommerce_quick_edit', $params );
}
// Meta boxes
if ( in_array( $screen_id, array( 'product', 'edit-product' ) ) ) {
wp_enqueue_media();
wp_register_script( 'wc-admin-product-meta-boxes', WC()->plugin_url() . '/assets/js/admin/meta-boxes-product' . $suffix . '.js', array( 'wc-admin-meta-boxes', 'media-models' ), WC_VERSION );
wp_register_script( 'wc-admin-variation-meta-boxes', WC()->plugin_url() . '/assets/js/admin/meta-boxes-product-variation' . $suffix . '.js', array( 'wc-admin-meta-boxes', 'serializejson', 'media-models' ), WC_VERSION );
wp_enqueue_script( 'wc-admin-product-meta-boxes' );
wp_enqueue_script( 'wc-admin-variation-meta-boxes' );
$params = array(
'post_id' => isset( $post->ID ) ? $post->ID : '',
'plugin_url' => WC()->plugin_url(),
'ajax_url' => admin_url( 'admin-ajax.php' ),
'woocommerce_placeholder_img_src' => wc_placeholder_img_src(),
'add_variation_nonce' => wp_create_nonce( 'add-variation' ),
'link_variation_nonce' => wp_create_nonce( 'link-variations' ),
'delete_variations_nonce' => wp_create_nonce( 'delete-variations' ),
'load_variations_nonce' => wp_create_nonce( 'load-variations' ),
'save_variations_nonce' => wp_create_nonce( 'save-variations' ),
'bulk_edit_variations_nonce' => wp_create_nonce( 'bulk-edit-variations' ),
'i18n_link_all_variations' => esc_js( sprintf( __( 'Are you sure you want to link all variations? This will create a new variation for each and every possible combination of variation attributes (max %d per run).', 'woocommerce' ), defined( 'WC_MAX_LINKED_VARIATIONS' ) ? WC_MAX_LINKED_VARIATIONS : 50 ) ),
'i18n_enter_a_value' => esc_js( __( 'Enter a value', 'woocommerce' ) ),
'i18n_enter_menu_order' => esc_js( __( 'Variation menu order (determines position in the list of variations)', 'woocommerce' ) ),
'i18n_enter_a_value_fixed_or_percent' => esc_js( __( 'Enter a value (fixed or %)', 'woocommerce' ) ),
'i18n_delete_all_variations' => esc_js( __( 'Are you sure you want to delete all variations? This cannot be undone.', 'woocommerce' ) ),
'i18n_last_warning' => esc_js( __( 'Last warning, are you sure?', 'woocommerce' ) ),
'i18n_choose_image' => esc_js( __( 'Choose an image', 'woocommerce' ) ),
'i18n_set_image' => esc_js( __( 'Set variation image', 'woocommerce' ) ),
'i18n_variation_added' => esc_js( __( "variation added", 'woocommerce' ) ),
'i18n_variations_added' => esc_js( __( "variations added", 'woocommerce' ) ),
'i18n_no_variations_added' => esc_js( __( "No variations added", 'woocommerce' ) ),
'i18n_remove_variation' => esc_js( __( 'Are you sure you want to remove this variation?', 'woocommerce' ) ),
'i18n_scheduled_sale_start' => esc_js( __( 'Sale start date (YYYY-MM-DD format or leave blank)', 'woocommerce' ) ),
'i18n_scheduled_sale_end' => esc_js( __( 'Sale end date (YYYY-MM-DD format or leave blank)', 'woocommerce' ) ),
'i18n_edited_variations' => esc_js( __( 'Save changes before changing page?', 'woocommerce' ) ),
'i18n_variation_count_single' => esc_js( __( '%qty% variation', 'woocommerce' ) ),
'i18n_variation_count_plural' => esc_js( __( '%qty% variations', 'woocommerce' ) ),
'variations_per_page' => absint( apply_filters( 'woocommerce_admin_meta_boxes_variations_per_page', 15 ) ),
);
wp_localize_script( 'wc-admin-variation-meta-boxes', 'woocommerce_admin_meta_boxes_variations', $params );
}
if ( in_array( str_replace( 'edit-', '', $screen_id ), wc_get_order_types( 'order-meta-boxes' ) ) ) {
$default_location = wc_get_customer_default_location();
wp_enqueue_script( 'wc-admin-order-meta-boxes', WC()->plugin_url() . '/assets/js/admin/meta-boxes-order' . $suffix . '.js', array( 'wc-admin-meta-boxes', 'wc-backbone-modal', 'selectWoo', 'wc-clipboard' ), WC_VERSION );
wp_localize_script( 'wc-admin-order-meta-boxes', 'woocommerce_admin_meta_boxes_order', array(
'countries' => json_encode( array_merge( WC()->countries->get_allowed_country_states(), WC()->countries->get_shipping_country_states() ) ),
'i18n_select_state_text' => esc_attr__( 'Select an option&hellip;', 'woocommerce' ),
'default_country' => isset( $default_location['country'] ) ? $default_location['country'] : '',
'default_state' => isset( $default_location['state'] ) ? $default_location['state'] : '',
'placeholder_name' => esc_attr__( 'Name (required)', 'woocommerce' ),
'placeholder_value' => esc_attr__( 'Value (required)', 'woocommerce' ),
) );
}
if ( in_array( $screen_id, array( 'shop_coupon', 'edit-shop_coupon' ) ) ) {
wp_enqueue_script( 'wc-admin-coupon-meta-boxes', WC()->plugin_url() . '/assets/js/admin/meta-boxes-coupon' . $suffix . '.js', array( 'wc-admin-meta-boxes' ), WC_VERSION );
}
if ( in_array( str_replace( 'edit-', '', $screen_id ), array_merge( array( 'shop_coupon', 'product' ), wc_get_order_types( 'order-meta-boxes' ) ) ) ) {
$post_id = isset( $post->ID ) ? $post->ID : '';
$currency = '';
if ( $post_id && in_array( get_post_type( $post_id ), wc_get_order_types( 'order-meta-boxes' ) ) && ( $order = wc_get_order( $post_id ) ) ) {
$currency = $order->get_currency();
// Admin styles for WC pages only
if ( in_array( $screen_id, wc_get_screen_ids() ) ) {
wp_enqueue_style( 'woocommerce_admin_styles' );
wp_enqueue_style( 'jquery-ui-style' );
wp_enqueue_style( 'wp-color-picker' );
}
$params = array(
'remove_item_notice' => __( "Are you sure you want to remove the selected items? If you have previously reduced this item's stock, or this order was submitted by a customer, you will need to manually restore the item's stock.", 'woocommerce' ),
'i18n_select_items' => __( 'Please select some items.', 'woocommerce' ),
'i18n_do_refund' => __( 'Are you sure you wish to process this refund? This action cannot be undone.', 'woocommerce' ),
'i18n_delete_refund' => __( 'Are you sure you wish to delete this refund? This action cannot be undone.', 'woocommerce' ),
'i18n_delete_tax' => __( 'Are you sure you wish to delete this tax column? This action cannot be undone.', 'woocommerce' ),
'remove_item_meta' => __( 'Remove this item meta?', 'woocommerce' ),
'remove_attribute' => __( 'Remove this attribute?', 'woocommerce' ),
'name_label' => __( 'Name', 'woocommerce' ),
'remove_label' => __( 'Remove', 'woocommerce' ),
'click_to_toggle' => __( 'Click to toggle', 'woocommerce' ),
'values_label' => __( 'Value(s)', 'woocommerce' ),
'text_attribute_tip' => __( 'Enter some text, or some attributes by pipe (|) separating values.', 'woocommerce' ),
'visible_label' => __( 'Visible on the product page', 'woocommerce' ),
'used_for_variations_label' => __( 'Used for variations', 'woocommerce' ),
'new_attribute_prompt' => __( 'Enter a name for the new attribute term:', 'woocommerce' ),
'calc_totals' => __( 'Recalculate totals? This will calculate taxes based on the customers country (or the store base country) and update totals.', 'woocommerce' ),
'copy_billing' => __( 'Copy billing information to shipping information? This will remove any currently entered shipping information.', 'woocommerce' ),
'load_billing' => __( "Load the customer's billing information? This will remove any currently entered billing information.", 'woocommerce' ),
'load_shipping' => __( "Load the customer's shipping information? This will remove any currently entered shipping information.", 'woocommerce' ),
'featured_label' => __( 'Featured', 'woocommerce' ),
'prices_include_tax' => esc_attr( get_option( 'woocommerce_prices_include_tax' ) ),
'tax_based_on' => esc_attr( get_option( 'woocommerce_tax_based_on' ) ),
'round_at_subtotal' => esc_attr( get_option( 'woocommerce_tax_round_at_subtotal' ) ),
'no_customer_selected' => __( 'No customer selected', 'woocommerce' ),
'plugin_url' => WC()->plugin_url(),
'ajax_url' => admin_url( 'admin-ajax.php' ),
'order_item_nonce' => wp_create_nonce( 'order-item' ),
'add_attribute_nonce' => wp_create_nonce( 'add-attribute' ),
'save_attributes_nonce' => wp_create_nonce( 'save-attributes' ),
'calc_totals_nonce' => wp_create_nonce( 'calc-totals' ),
'get_customer_details_nonce' => wp_create_nonce( 'get-customer-details' ),
'search_products_nonce' => wp_create_nonce( 'search-products' ),
'grant_access_nonce' => wp_create_nonce( 'grant-access' ),
'revoke_access_nonce' => wp_create_nonce( 'revoke-access' ),
'add_order_note_nonce' => wp_create_nonce( 'add-order-note' ),
'delete_order_note_nonce' => wp_create_nonce( 'delete-order-note' ),
'calendar_image' => WC()->plugin_url() . '/assets/images/calendar.png',
'post_id' => isset( $post->ID ) ? $post->ID : '',
'base_country' => WC()->countries->get_base_country(),
'currency_format_num_decimals' => wc_get_price_decimals(),
'currency_format_symbol' => get_woocommerce_currency_symbol( $currency ),
'currency_format_decimal_sep' => esc_attr( wc_get_price_decimal_separator() ),
'currency_format_thousand_sep' => esc_attr( wc_get_price_thousand_separator() ),
'currency_format' => esc_attr( str_replace( array( '%1$s', '%2$s' ), array( '%s', '%v' ), get_woocommerce_price_format() ) ), // For accounting JS
'rounding_precision' => wc_get_rounding_precision(),
'tax_rounding_mode' => wc_get_tax_rounding_mode(),
'product_types' => array_unique( array_merge( array( 'simple', 'grouped', 'variable', 'external' ), array_keys( wc_get_product_types() ) ) ),
'i18n_download_permission_fail' => __( 'Could not grant access - the user may already have permission for this file or billing email is not set. Ensure the billing email is set, and the order has been saved.', 'woocommerce' ),
'i18n_permission_revoke' => __( 'Are you sure you want to revoke access to this download?', 'woocommerce' ),
'i18n_tax_rate_already_exists' => __( 'You cannot add the same tax rate twice!', 'woocommerce' ),
'i18n_delete_note' => __( 'Are you sure you wish to delete this note? This action cannot be undone.', 'woocommerce' ),
'i18n_apply_coupon' => __( 'Enter a coupon code to apply to this order.', 'woocommerce' ),
'i18n_add_fee' => __( 'Enter a fixed amount or percentage to apply as a fee.', 'woocommerce' ),
);
if ( in_array( $screen_id, array( 'dashboard' ) ) ) {
wp_enqueue_style( 'woocommerce_admin_dashboard_styles' );
}
wp_localize_script( 'wc-admin-meta-boxes', 'woocommerce_admin_meta_boxes', $params );
if ( in_array( $screen_id, array( 'woocommerce_page_wc-reports', 'toplevel_page_wc-reports' ) ) ) {
wp_enqueue_style( 'woocommerce_admin_print_reports_styles' );
}
/**
* @deprecated 2.3
*/
if ( has_action( 'woocommerce_admin_css' ) ) {
do_action( 'woocommerce_admin_css' );
wc_deprecated_function( 'The woocommerce_admin_css action', '2.3', 'admin_enqueue_scripts' );
}
}
// Term ordering - only when sorting by term_order
if ( ( strstr( $screen_id, 'edit-pa_' ) || ( ! empty( $_GET['taxonomy'] ) && in_array( $_GET['taxonomy'], apply_filters( 'woocommerce_sortable_taxonomies', array( 'product_cat' ) ) ) ) ) && ! isset( $_GET['orderby'] ) ) {
wp_register_script( 'woocommerce_term_ordering', WC()->plugin_url() . '/assets/js/admin/term-ordering' . $suffix . '.js', array( 'jquery-ui-sortable' ), WC_VERSION );
wp_enqueue_script( 'woocommerce_term_ordering' );
/**
* Enqueue scripts.
*/
public function admin_scripts() {
global $wp_query, $post;
$taxonomy = isset( $_GET['taxonomy'] ) ? wc_clean( $_GET['taxonomy'] ) : '';
$screen = get_current_screen();
$screen_id = $screen ? $screen->id : '';
$wc_screen_id = sanitize_title( __( 'WooCommerce', 'woocommerce' ) );
$suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
$woocommerce_term_order_params = array(
'taxonomy' => $taxonomy,
);
wp_localize_script( 'woocommerce_term_ordering', 'woocommerce_term_ordering_params', $woocommerce_term_order_params );
}
// Product sorting - only when sorting by menu order on the products page
if ( current_user_can( 'edit_others_pages' ) && 'edit-product' === $screen_id && isset( $wp_query->query['orderby'] ) && 'menu_order title' === $wp_query->query['orderby'] ) {
wp_register_script( 'woocommerce_product_ordering', WC()->plugin_url() . '/assets/js/admin/product-ordering' . $suffix . '.js', array( 'jquery-ui-sortable' ), WC_VERSION, true );
wp_enqueue_script( 'woocommerce_product_ordering' );
}
// Reports Pages
if ( in_array( $screen_id, apply_filters( 'woocommerce_reports_screen_ids', array( $wc_screen_id . '_page_wc-reports', 'toplevel_page_wc-reports', 'dashboard' ) ) ) ) {
wp_register_script( 'wc-reports', WC()->plugin_url() . '/assets/js/admin/reports' . $suffix . '.js', array( 'jquery', 'jquery-ui-datepicker' ), WC_VERSION );
wp_enqueue_script( 'wc-reports' );
wp_enqueue_script( 'flot' );
wp_enqueue_script( 'flot-resize' );
wp_enqueue_script( 'flot-time' );
wp_enqueue_script( 'flot-pie' );
wp_enqueue_script( 'flot-stack' );
}
// API settings
if ( $wc_screen_id . '_page_wc-settings' === $screen_id && isset( $_GET['section'] ) && 'keys' == $_GET['section'] ) {
wp_register_script( 'wc-api-keys', WC()->plugin_url() . '/assets/js/admin/api-keys' . $suffix . '.js', array( 'jquery', 'woocommerce_admin', 'underscore', 'backbone', 'wp-util', 'qrcode', 'wc-clipboard' ), WC_VERSION, true );
wp_enqueue_script( 'wc-api-keys' );
// Register scripts
wp_register_script( 'woocommerce_admin', WC()->plugin_url() . '/assets/js/admin/woocommerce_admin' . $suffix . '.js', array( 'jquery', 'jquery-blockui', 'jquery-ui-sortable', 'jquery-ui-widget', 'jquery-ui-core', 'jquery-tiptip' ), WC_VERSION );
wp_register_script( 'jquery-blockui', WC()->plugin_url() . '/assets/js/jquery-blockui/jquery.blockUI' . $suffix . '.js', array( 'jquery' ), '2.70', true );
wp_register_script( 'jquery-tiptip', WC()->plugin_url() . '/assets/js/jquery-tiptip/jquery.tipTip' . $suffix . '.js', array( 'jquery' ), WC_VERSION, true );
wp_register_script( 'round', WC()->plugin_url() . '/assets/js/round/round' . $suffix . '.js', array( 'jquery' ), WC_VERSION );
wp_register_script( 'wc-admin-meta-boxes', WC()->plugin_url() . '/assets/js/admin/meta-boxes' . $suffix . '.js', array( 'jquery', 'jquery-ui-datepicker', 'jquery-ui-sortable', 'accounting', 'round', 'wc-enhanced-select', 'plupload-all', 'stupidtable', 'jquery-tiptip' ), WC_VERSION );
wp_register_script( 'zeroclipboard', WC()->plugin_url() . '/assets/js/zeroclipboard/jquery.zeroclipboard' . $suffix . '.js', array( 'jquery' ), WC_VERSION );
wp_register_script( 'qrcode', WC()->plugin_url() . '/assets/js/jquery-qrcode/jquery.qrcode' . $suffix . '.js', array( 'jquery' ), WC_VERSION );
wp_register_script( 'stupidtable', WC()->plugin_url() . '/assets/js/stupidtable/stupidtable' . $suffix . '.js', array( 'jquery' ), WC_VERSION );
wp_register_script( 'serializejson', WC()->plugin_url() . '/assets/js/jquery-serializejson/jquery.serializejson' . $suffix . '.js', array( 'jquery' ), '2.8.1' );
wp_register_script( 'flot', WC()->plugin_url() . '/assets/js/jquery-flot/jquery.flot' . $suffix . '.js', array( 'jquery' ), WC_VERSION );
wp_register_script( 'flot-resize', WC()->plugin_url() . '/assets/js/jquery-flot/jquery.flot.resize' . $suffix . '.js', array( 'jquery', 'flot' ), WC_VERSION );
wp_register_script( 'flot-time', WC()->plugin_url() . '/assets/js/jquery-flot/jquery.flot.time' . $suffix . '.js', array( 'jquery', 'flot' ), WC_VERSION );
wp_register_script( 'flot-pie', WC()->plugin_url() . '/assets/js/jquery-flot/jquery.flot.pie' . $suffix . '.js', array( 'jquery', 'flot' ), WC_VERSION );
wp_register_script( 'flot-stack', WC()->plugin_url() . '/assets/js/jquery-flot/jquery.flot.stack' . $suffix . '.js', array( 'jquery', 'flot' ), WC_VERSION );
wp_register_script( 'wc-settings-tax', WC()->plugin_url() . '/assets/js/admin/settings-views-html-settings-tax' . $suffix . '.js', array( 'jquery', 'wp-util', 'underscore', 'backbone', 'jquery-blockui' ), WC_VERSION );
wp_register_script( 'wc-backbone-modal', WC()->plugin_url() . '/assets/js/admin/backbone-modal' . $suffix . '.js', array( 'underscore', 'backbone', 'wp-util' ), WC_VERSION );
wp_register_script( 'wc-shipping-zones', WC()->plugin_url() . '/assets/js/admin/wc-shipping-zones' . $suffix . '.js', array( 'jquery', 'wp-util', 'underscore', 'backbone', 'jquery-ui-sortable', 'wc-enhanced-select', 'wc-backbone-modal' ), WC_VERSION );
wp_register_script( 'wc-shipping-zone-methods', WC()->plugin_url() . '/assets/js/admin/wc-shipping-zone-methods' . $suffix . '.js', array( 'jquery', 'wp-util', 'underscore', 'backbone', 'jquery-ui-sortable', 'wc-backbone-modal' ), WC_VERSION );
wp_register_script( 'wc-shipping-classes', WC()->plugin_url() . '/assets/js/admin/wc-shipping-classes' . $suffix . '.js', array( 'jquery', 'wp-util', 'underscore', 'backbone' ), WC_VERSION );
wp_register_script( 'wc-clipboard', WC()->plugin_url() . '/assets/js/admin/wc-clipboard' . $suffix . '.js', array( 'jquery' ), WC_VERSION );
wp_register_script( 'select2', WC()->plugin_url() . '/assets/js/select2/select2.full' . $suffix . '.js', array( 'jquery' ), '4.0.3' );
wp_register_script( 'selectWoo', WC()->plugin_url() . '/assets/js/selectWoo/selectWoo.full' . $suffix . '.js', array( 'jquery' ), '1.0.3' );
wp_register_script( 'wc-enhanced-select', WC()->plugin_url() . '/assets/js/admin/wc-enhanced-select' . $suffix . '.js', array( 'jquery', 'selectWoo' ), WC_VERSION );
wp_localize_script(
'wc-api-keys',
'woocommerce_admin_api_keys',
'wc-enhanced-select',
'wc_enhanced_select_params',
array(
'ajax_url' => admin_url( 'admin-ajax.php' ),
'update_api_nonce' => wp_create_nonce( 'update-api-key' ),
'clipboard_failed' => esc_html__( 'Copying to clipboard failed. Please press Ctrl/Cmd+C to copy.', 'woocommerce' ),
'i18n_no_matches' => _x( 'No matches found', 'enhanced select', 'woocommerce' ),
'i18n_ajax_error' => _x( 'Loading failed', 'enhanced select', 'woocommerce' ),
'i18n_input_too_short_1' => _x( 'Please enter 1 or more characters', 'enhanced select', 'woocommerce' ),
'i18n_input_too_short_n' => _x( 'Please enter %qty% or more characters', 'enhanced select', 'woocommerce' ),
'i18n_input_too_long_1' => _x( 'Please delete 1 character', 'enhanced select', 'woocommerce' ),
'i18n_input_too_long_n' => _x( 'Please delete %qty% characters', 'enhanced select', 'woocommerce' ),
'i18n_selection_too_long_1' => _x( 'You can only select 1 item', 'enhanced select', 'woocommerce' ),
'i18n_selection_too_long_n' => _x( 'You can only select %qty% items', 'enhanced select', 'woocommerce' ),
'i18n_load_more' => _x( 'Loading more results&hellip;', 'enhanced select', 'woocommerce' ),
'i18n_searching' => _x( 'Searching&hellip;', 'enhanced select', 'woocommerce' ),
'ajax_url' => admin_url( 'admin-ajax.php' ),
'search_products_nonce' => wp_create_nonce( 'search-products' ),
'search_customers_nonce' => wp_create_nonce( 'search-customers' ),
'search_categories_nonce' => wp_create_nonce( 'search-categories' ),
)
);
}
// System status.
if ( $wc_screen_id . '_page_wc-status' === $screen_id ) {
wp_register_script( 'wc-admin-system-status', WC()->plugin_url() . '/assets/js/admin/system-status' . $suffix . '.js', array( 'wc-clipboard' ), WC_VERSION );
wp_enqueue_script( 'wc-admin-system-status' );
wp_register_script( 'accounting', WC()->plugin_url() . '/assets/js/accounting/accounting' . $suffix . '.js', array( 'jquery' ), '0.4.2' );
wp_localize_script(
'wc-admin-system-status',
'woocommerce_admin_system_status',
'accounting',
'accounting_params',
array(
'delete_log_confirmation' => esc_js( __( 'Are you sure you want to delete this log?', 'woocommerce' ) ),
'mon_decimal_point' => wc_get_price_decimal_separator(),
)
);
}
if ( in_array( $screen_id, array( 'user-edit', 'profile' ) ) ) {
wp_register_script( 'wc-users', WC()->plugin_url() . '/assets/js/admin/users' . $suffix . '.js', array( 'jquery', 'wc-enhanced-select', 'selectWoo' ), WC_VERSION, true );
wp_enqueue_script( 'wc-users' );
wp_register_script( 'wc-orders', WC()->plugin_url() . '/assets/js/admin/wc-orders' . $suffix . '.js', array( 'jquery', 'wp-util', 'underscore', 'backbone', 'jquery-blockui' ), WC_VERSION );
wp_localize_script(
'wc-users',
'wc_users_params',
'wc-orders',
'wc_orders_params',
array(
'countries' => json_encode( array_merge( WC()->countries->get_allowed_country_states(), WC()->countries->get_shipping_country_states() ) ),
'i18n_select_state_text' => esc_attr__( 'Select an option&hellip;', 'woocommerce' ),
'ajax_url' => admin_url( 'admin-ajax.php' ),
'preview_nonce' => wp_create_nonce( 'woocommerce-preview-order' ),
)
);
// WooCommerce admin pages.
if ( in_array( $screen_id, wc_get_screen_ids() ) ) {
wp_enqueue_script( 'iris' );
wp_enqueue_script( 'woocommerce_admin' );
wp_enqueue_script( 'wc-enhanced-select' );
wp_enqueue_script( 'jquery-ui-sortable' );
wp_enqueue_script( 'jquery-ui-autocomplete' );
$locale = localeconv();
$decimal = isset( $locale['decimal_point'] ) ? $locale['decimal_point'] : '.';
$params = array(
/* translators: %s: decimal */
'i18n_decimal_error' => sprintf( __( 'Please enter in decimal (%s) format without thousand separators.', 'woocommerce' ), $decimal ),
/* translators: %s: price decimal separator */
'i18n_mon_decimal_error' => sprintf( __( 'Please enter in monetary decimal (%s) format without thousand separators and currency symbols.', 'woocommerce' ), wc_get_price_decimal_separator() ),
'i18n_country_iso_error' => __( 'Please enter in country code with two capital letters.', 'woocommerce' ),
'i18_sale_less_than_regular_error' => __( 'Please enter in a value less than the regular price.', 'woocommerce' ),
'i18_delete_product_notice' => __( 'This product has produced sales and may be linked to existing orders. Are you sure you want to delete it?', 'woocommerce' ),
'decimal_point' => $decimal,
'mon_decimal_point' => wc_get_price_decimal_separator(),
'strings' => array(
'import_products' => __( 'Import', 'woocommerce' ),
'export_products' => __( 'Export', 'woocommerce' ),
),
'urls' => array(
'import_products' => esc_url_raw( admin_url( 'edit.php?post_type=product&page=product_importer' ) ),
'export_products' => esc_url_raw( admin_url( 'edit.php?post_type=product&page=product_exporter' ) ),
),
);
wp_localize_script( 'woocommerce_admin', 'woocommerce_admin', $params );
}
// Edit product category pages
if ( in_array( $screen_id, array( 'edit-product_cat' ) ) ) {
wp_enqueue_media();
}
// Products
if ( in_array( $screen_id, array( 'edit-product' ) ) ) {
wp_enqueue_script( 'woocommerce_quick-edit', WC()->plugin_url() . '/assets/js/admin/quick-edit' . $suffix . '.js', array( 'jquery', 'woocommerce_admin' ), WC_VERSION );
$params = array(
'strings' => array(
'allow_reviews' => esc_js( __( 'Enable reviews', 'woocommerce' ) ),
),
);
wp_localize_script( 'woocommerce_quick-edit', 'woocommerce_quick_edit', $params );
}
// Meta boxes
if ( in_array( $screen_id, array( 'product', 'edit-product' ) ) ) {
wp_enqueue_media();
wp_register_script( 'wc-admin-product-meta-boxes', WC()->plugin_url() . '/assets/js/admin/meta-boxes-product' . $suffix . '.js', array( 'wc-admin-meta-boxes', 'media-models' ), WC_VERSION );
wp_register_script( 'wc-admin-variation-meta-boxes', WC()->plugin_url() . '/assets/js/admin/meta-boxes-product-variation' . $suffix . '.js', array( 'wc-admin-meta-boxes', 'serializejson', 'media-models' ), WC_VERSION );
wp_enqueue_script( 'wc-admin-product-meta-boxes' );
wp_enqueue_script( 'wc-admin-variation-meta-boxes' );
$params = array(
'post_id' => isset( $post->ID ) ? $post->ID : '',
'plugin_url' => WC()->plugin_url(),
'ajax_url' => admin_url( 'admin-ajax.php' ),
'woocommerce_placeholder_img_src' => wc_placeholder_img_src(),
'add_variation_nonce' => wp_create_nonce( 'add-variation' ),
'link_variation_nonce' => wp_create_nonce( 'link-variations' ),
'delete_variations_nonce' => wp_create_nonce( 'delete-variations' ),
'load_variations_nonce' => wp_create_nonce( 'load-variations' ),
'save_variations_nonce' => wp_create_nonce( 'save-variations' ),
'bulk_edit_variations_nonce' => wp_create_nonce( 'bulk-edit-variations' ),
'i18n_link_all_variations' => esc_js( sprintf( __( 'Are you sure you want to link all variations? This will create a new variation for each and every possible combination of variation attributes (max %d per run).', 'woocommerce' ), defined( 'WC_MAX_LINKED_VARIATIONS' ) ? WC_MAX_LINKED_VARIATIONS : 50 ) ),
'i18n_enter_a_value' => esc_js( __( 'Enter a value', 'woocommerce' ) ),
'i18n_enter_menu_order' => esc_js( __( 'Variation menu order (determines position in the list of variations)', 'woocommerce' ) ),
'i18n_enter_a_value_fixed_or_percent' => esc_js( __( 'Enter a value (fixed or %)', 'woocommerce' ) ),
'i18n_delete_all_variations' => esc_js( __( 'Are you sure you want to delete all variations? This cannot be undone.', 'woocommerce' ) ),
'i18n_last_warning' => esc_js( __( 'Last warning, are you sure?', 'woocommerce' ) ),
'i18n_choose_image' => esc_js( __( 'Choose an image', 'woocommerce' ) ),
'i18n_set_image' => esc_js( __( 'Set variation image', 'woocommerce' ) ),
'i18n_variation_added' => esc_js( __( 'variation added', 'woocommerce' ) ),
'i18n_variations_added' => esc_js( __( 'variations added', 'woocommerce' ) ),
'i18n_no_variations_added' => esc_js( __( 'No variations added', 'woocommerce' ) ),
'i18n_remove_variation' => esc_js( __( 'Are you sure you want to remove this variation?', 'woocommerce' ) ),
'i18n_scheduled_sale_start' => esc_js( __( 'Sale start date (YYYY-MM-DD format or leave blank)', 'woocommerce' ) ),
'i18n_scheduled_sale_end' => esc_js( __( 'Sale end date (YYYY-MM-DD format or leave blank)', 'woocommerce' ) ),
'i18n_edited_variations' => esc_js( __( 'Save changes before changing page?', 'woocommerce' ) ),
'i18n_variation_count_single' => esc_js( __( '%qty% variation', 'woocommerce' ) ),
'i18n_variation_count_plural' => esc_js( __( '%qty% variations', 'woocommerce' ) ),
'variations_per_page' => absint( apply_filters( 'woocommerce_admin_meta_boxes_variations_per_page', 15 ) ),
);
wp_localize_script( 'wc-admin-variation-meta-boxes', 'woocommerce_admin_meta_boxes_variations', $params );
}
if ( in_array( str_replace( 'edit-', '', $screen_id ), wc_get_order_types( 'order-meta-boxes' ) ) ) {
$default_location = wc_get_customer_default_location();
wp_enqueue_script( 'wc-admin-order-meta-boxes', WC()->plugin_url() . '/assets/js/admin/meta-boxes-order' . $suffix . '.js', array( 'wc-admin-meta-boxes', 'wc-backbone-modal', 'selectWoo', 'wc-clipboard' ), WC_VERSION );
wp_localize_script(
'wc-admin-order-meta-boxes',
'woocommerce_admin_meta_boxes_order',
array(
'countries' => json_encode( array_merge( WC()->countries->get_allowed_country_states(), WC()->countries->get_shipping_country_states() ) ),
'i18n_select_state_text' => esc_attr__( 'Select an option&hellip;', 'woocommerce' ),
'default_country' => isset( $default_location['country'] ) ? $default_location['country'] : '',
'default_state' => isset( $default_location['state'] ) ? $default_location['state'] : '',
'placeholder_name' => esc_attr__( 'Name (required)', 'woocommerce' ),
'placeholder_value' => esc_attr__( 'Value (required)', 'woocommerce' ),
)
);
}
if ( in_array( $screen_id, array( 'shop_coupon', 'edit-shop_coupon' ) ) ) {
wp_enqueue_script( 'wc-admin-coupon-meta-boxes', WC()->plugin_url() . '/assets/js/admin/meta-boxes-coupon' . $suffix . '.js', array( 'wc-admin-meta-boxes' ), WC_VERSION );
}
if ( in_array( str_replace( 'edit-', '', $screen_id ), array_merge( array( 'shop_coupon', 'product' ), wc_get_order_types( 'order-meta-boxes' ) ) ) ) {
$post_id = isset( $post->ID ) ? $post->ID : '';
$currency = '';
if ( $post_id && in_array( get_post_type( $post_id ), wc_get_order_types( 'order-meta-boxes' ) ) && ( $order = wc_get_order( $post_id ) ) ) {
$currency = $order->get_currency();
}
$params = array(
'remove_item_notice' => __( "Are you sure you want to remove the selected items? If you have previously reduced this item's stock, or this order was submitted by a customer, you will need to manually restore the item's stock.", 'woocommerce' ),
'i18n_select_items' => __( 'Please select some items.', 'woocommerce' ),
'i18n_do_refund' => __( 'Are you sure you wish to process this refund? This action cannot be undone.', 'woocommerce' ),
'i18n_delete_refund' => __( 'Are you sure you wish to delete this refund? This action cannot be undone.', 'woocommerce' ),
'i18n_delete_tax' => __( 'Are you sure you wish to delete this tax column? This action cannot be undone.', 'woocommerce' ),
'remove_item_meta' => __( 'Remove this item meta?', 'woocommerce' ),
'remove_attribute' => __( 'Remove this attribute?', 'woocommerce' ),
'name_label' => __( 'Name', 'woocommerce' ),
'remove_label' => __( 'Remove', 'woocommerce' ),
'click_to_toggle' => __( 'Click to toggle', 'woocommerce' ),
'values_label' => __( 'Value(s)', 'woocommerce' ),
'text_attribute_tip' => __( 'Enter some text, or some attributes by pipe (|) separating values.', 'woocommerce' ),
'visible_label' => __( 'Visible on the product page', 'woocommerce' ),
'used_for_variations_label' => __( 'Used for variations', 'woocommerce' ),
'new_attribute_prompt' => __( 'Enter a name for the new attribute term:', 'woocommerce' ),
'calc_totals' => __( 'Recalculate totals? This will calculate taxes based on the customers country (or the store base country) and update totals.', 'woocommerce' ),
'copy_billing' => __( 'Copy billing information to shipping information? This will remove any currently entered shipping information.', 'woocommerce' ),
'load_billing' => __( "Load the customer's billing information? This will remove any currently entered billing information.", 'woocommerce' ),
'load_shipping' => __( "Load the customer's shipping information? This will remove any currently entered shipping information.", 'woocommerce' ),
'featured_label' => __( 'Featured', 'woocommerce' ),
'prices_include_tax' => esc_attr( get_option( 'woocommerce_prices_include_tax' ) ),
'tax_based_on' => esc_attr( get_option( 'woocommerce_tax_based_on' ) ),
'round_at_subtotal' => esc_attr( get_option( 'woocommerce_tax_round_at_subtotal' ) ),
'no_customer_selected' => __( 'No customer selected', 'woocommerce' ),
'plugin_url' => WC()->plugin_url(),
'ajax_url' => admin_url( 'admin-ajax.php' ),
'order_item_nonce' => wp_create_nonce( 'order-item' ),
'add_attribute_nonce' => wp_create_nonce( 'add-attribute' ),
'save_attributes_nonce' => wp_create_nonce( 'save-attributes' ),
'calc_totals_nonce' => wp_create_nonce( 'calc-totals' ),
'get_customer_details_nonce' => wp_create_nonce( 'get-customer-details' ),
'search_products_nonce' => wp_create_nonce( 'search-products' ),
'grant_access_nonce' => wp_create_nonce( 'grant-access' ),
'revoke_access_nonce' => wp_create_nonce( 'revoke-access' ),
'add_order_note_nonce' => wp_create_nonce( 'add-order-note' ),
'delete_order_note_nonce' => wp_create_nonce( 'delete-order-note' ),
'calendar_image' => WC()->plugin_url() . '/assets/images/calendar.png',
'post_id' => isset( $post->ID ) ? $post->ID : '',
'base_country' => WC()->countries->get_base_country(),
'currency_format_num_decimals' => wc_get_price_decimals(),
'currency_format_symbol' => get_woocommerce_currency_symbol( $currency ),
'currency_format_decimal_sep' => esc_attr( wc_get_price_decimal_separator() ),
'currency_format_thousand_sep' => esc_attr( wc_get_price_thousand_separator() ),
'currency_format' => esc_attr( str_replace( array( '%1$s', '%2$s' ), array( '%s', '%v' ), get_woocommerce_price_format() ) ), // For accounting JS
'rounding_precision' => wc_get_rounding_precision(),
'tax_rounding_mode' => wc_get_tax_rounding_mode(),
'product_types' => array_unique( array_merge( array( 'simple', 'grouped', 'variable', 'external' ), array_keys( wc_get_product_types() ) ) ),
'i18n_download_permission_fail' => __( 'Could not grant access - the user may already have permission for this file or billing email is not set. Ensure the billing email is set, and the order has been saved.', 'woocommerce' ),
'i18n_permission_revoke' => __( 'Are you sure you want to revoke access to this download?', 'woocommerce' ),
'i18n_tax_rate_already_exists' => __( 'You cannot add the same tax rate twice!', 'woocommerce' ),
'i18n_delete_note' => __( 'Are you sure you wish to delete this note? This action cannot be undone.', 'woocommerce' ),
'i18n_apply_coupon' => __( 'Enter a coupon code to apply to this order.', 'woocommerce' ),
'i18n_add_fee' => __( 'Enter a fixed amount or percentage to apply as a fee.', 'woocommerce' ),
);
wp_localize_script( 'wc-admin-meta-boxes', 'woocommerce_admin_meta_boxes', $params );
}
// Term ordering - only when sorting by term_order
if ( ( strstr( $screen_id, 'edit-pa_' ) || ( ! empty( $_GET['taxonomy'] ) && in_array( $_GET['taxonomy'], apply_filters( 'woocommerce_sortable_taxonomies', array( 'product_cat' ) ) ) ) ) && ! isset( $_GET['orderby'] ) ) {
wp_register_script( 'woocommerce_term_ordering', WC()->plugin_url() . '/assets/js/admin/term-ordering' . $suffix . '.js', array( 'jquery-ui-sortable' ), WC_VERSION );
wp_enqueue_script( 'woocommerce_term_ordering' );
$taxonomy = isset( $_GET['taxonomy'] ) ? wc_clean( $_GET['taxonomy'] ) : '';
$woocommerce_term_order_params = array(
'taxonomy' => $taxonomy,
);
wp_localize_script( 'woocommerce_term_ordering', 'woocommerce_term_ordering_params', $woocommerce_term_order_params );
}
// Product sorting - only when sorting by menu order on the products page
if ( current_user_can( 'edit_others_pages' ) && 'edit-product' === $screen_id && isset( $wp_query->query['orderby'] ) && 'menu_order title' === $wp_query->query['orderby'] ) {
wp_register_script( 'woocommerce_product_ordering', WC()->plugin_url() . '/assets/js/admin/product-ordering' . $suffix . '.js', array( 'jquery-ui-sortable' ), WC_VERSION, true );
wp_enqueue_script( 'woocommerce_product_ordering' );
}
// Reports Pages
if ( in_array( $screen_id, apply_filters( 'woocommerce_reports_screen_ids', array( $wc_screen_id . '_page_wc-reports', 'toplevel_page_wc-reports', 'dashboard' ) ) ) ) {
wp_register_script( 'wc-reports', WC()->plugin_url() . '/assets/js/admin/reports' . $suffix . '.js', array( 'jquery', 'jquery-ui-datepicker' ), WC_VERSION );
wp_enqueue_script( 'wc-reports' );
wp_enqueue_script( 'flot' );
wp_enqueue_script( 'flot-resize' );
wp_enqueue_script( 'flot-time' );
wp_enqueue_script( 'flot-pie' );
wp_enqueue_script( 'flot-stack' );
}
// API settings
if ( $wc_screen_id . '_page_wc-settings' === $screen_id && isset( $_GET['section'] ) && 'keys' == $_GET['section'] ) {
wp_register_script( 'wc-api-keys', WC()->plugin_url() . '/assets/js/admin/api-keys' . $suffix . '.js', array( 'jquery', 'woocommerce_admin', 'underscore', 'backbone', 'wp-util', 'qrcode', 'wc-clipboard' ), WC_VERSION, true );
wp_enqueue_script( 'wc-api-keys' );
wp_localize_script(
'wc-api-keys',
'woocommerce_admin_api_keys',
array(
'ajax_url' => admin_url( 'admin-ajax.php' ),
'update_api_nonce' => wp_create_nonce( 'update-api-key' ),
'clipboard_failed' => esc_html__( 'Copying to clipboard failed. Please press Ctrl/Cmd+C to copy.', 'woocommerce' ),
)
);
}
// System status.
if ( $wc_screen_id . '_page_wc-status' === $screen_id ) {
wp_register_script( 'wc-admin-system-status', WC()->plugin_url() . '/assets/js/admin/system-status' . $suffix . '.js', array( 'wc-clipboard' ), WC_VERSION );
wp_enqueue_script( 'wc-admin-system-status' );
wp_localize_script(
'wc-admin-system-status',
'woocommerce_admin_system_status',
array(
'delete_log_confirmation' => esc_js( __( 'Are you sure you want to delete this log?', 'woocommerce' ) ),
)
);
}
if ( in_array( $screen_id, array( 'user-edit', 'profile' ) ) ) {
wp_register_script( 'wc-users', WC()->plugin_url() . '/assets/js/admin/users' . $suffix . '.js', array( 'jquery', 'wc-enhanced-select', 'selectWoo' ), WC_VERSION, true );
wp_enqueue_script( 'wc-users' );
wp_localize_script(
'wc-users',
'wc_users_params',
array(
'countries' => json_encode( array_merge( WC()->countries->get_allowed_country_states(), WC()->countries->get_shipping_country_states() ) ),
'i18n_select_state_text' => esc_attr__( 'Select an option&hellip;', 'woocommerce' ),
)
);
}
}
}
}
endif;

View File

@ -39,15 +39,15 @@ class WC_Admin_Attributes {
}
switch ( $action ) {
case 'add' :
case 'add':
$result = self::process_add_attribute();
break;
case 'edit' :
break;
case 'edit':
$result = self::process_edit_attribute();
break;
case 'delete' :
break;
case 'delete':
$result = self::process_delete_attribute();
break;
break;
}
if ( is_wp_error( $result ) ) {
@ -69,11 +69,11 @@ class WC_Admin_Attributes {
*/
private static function get_posted_attribute() {
$attribute = array(
'attribute_label' => isset( $_POST['attribute_label'] ) ? wc_clean( stripslashes( $_POST['attribute_label'] ) ) : '',
'attribute_name' => isset( $_POST['attribute_name'] ) ? wc_sanitize_taxonomy_name( stripslashes( $_POST['attribute_name'] ) ) : '',
'attribute_type' => isset( $_POST['attribute_type'] ) ? wc_clean( $_POST['attribute_type'] ) : 'select',
'attribute_label' => isset( $_POST['attribute_label'] ) ? wc_clean( stripslashes( $_POST['attribute_label'] ) ) : '',
'attribute_name' => isset( $_POST['attribute_name'] ) ? wc_sanitize_taxonomy_name( stripslashes( $_POST['attribute_name'] ) ) : '',
'attribute_type' => isset( $_POST['attribute_type'] ) ? wc_clean( $_POST['attribute_type'] ) : 'select',
'attribute_orderby' => isset( $_POST['attribute_orderby'] ) ? wc_clean( $_POST['attribute_orderby'] ) : '',
'attribute_public' => isset( $_POST['attribute_public'] ) ? 1 : 0,
'attribute_public' => isset( $_POST['attribute_public'] ) ? 1 : 0,
);
if ( empty( $attribute['attribute_type'] ) ) {
@ -166,11 +166,11 @@ class WC_Admin_Attributes {
$edit = absint( $_GET['edit'] );
$attribute_to_edit = $wpdb->get_row( "SELECT attribute_type, attribute_label, attribute_name, attribute_orderby, attribute_public FROM " . $wpdb->prefix . "woocommerce_attribute_taxonomies WHERE attribute_id = '$edit'" );
$attribute_to_edit = $wpdb->get_row( 'SELECT attribute_type, attribute_label, attribute_name, attribute_orderby, attribute_public FROM ' . $wpdb->prefix . "woocommerce_attribute_taxonomies WHERE attribute_id = '$edit'" );
?>
<div class="wrap woocommerce">
<h1><?php esc_html_e( 'Edit attribute', 'woocommerce' ) ?></h1>
<h1><?php esc_html_e( 'Edit attribute', 'woocommerce' ); ?></h1>
<?php
if ( ! $attribute_to_edit ) {
@ -262,7 +262,7 @@ class WC_Admin_Attributes {
<p class="description"><?php esc_html_e( 'Determines the sort order of the terms on the frontend shop product pages. If using custom ordering, you can drag and drop the terms in this attribute.', 'woocommerce' ); ?></p>
</td>
</tr>
<?php do_action( 'woocommerce_after_edit_attribute_fields' ) ?>
<?php do_action( 'woocommerce_after_edit_attribute_fields' ); ?>
</tbody>
</table>
<p class="submit"><button type="submit" name="save_attribute" id="submit" class="button-primary" value="<?php esc_attr_e( 'Update', 'woocommerce' ); ?>"><?php esc_html_e( 'Update', 'woocommerce' ); ?></button></p>
@ -303,7 +303,8 @@ class WC_Admin_Attributes {
<?php
if ( $attribute_taxonomies = wc_get_attribute_taxonomies() ) :
foreach ( $attribute_taxonomies as $tax ) :
?><tr>
?>
<tr>
<td>
<strong><a href="edit-tags.php?taxonomy=<?php echo esc_html( wc_attribute_taxonomy_name( $tax->attribute_name ) ); ?>&amp;post_type=product"><?php echo esc_html( $tax->attribute_label ); ?></a></strong>
@ -313,60 +314,65 @@ class WC_Admin_Attributes {
<?php if ( wc_has_custom_attribute_types() ) : ?>
<td><?php echo esc_html( wc_get_attribute_type_label( $tax->attribute_type ) ); ?> <?php echo $tax->attribute_public ? esc_html__( '(Public)', 'woocommerce' ) : ''; ?></td>
<?php endif; ?>
<td><?php
switch ( $tax->attribute_orderby ) {
case 'name' :
esc_html_e( 'Name', 'woocommerce' );
break;
case 'name_num' :
esc_html_e( 'Name (numeric)', 'woocommerce' );
break;
case 'id' :
esc_html_e( 'Term ID', 'woocommerce' );
break;
default:
esc_html_e( 'Custom ordering', 'woocommerce' );
break;
}
?>
<td>
<?php
switch ( $tax->attribute_orderby ) {
case 'name':
esc_html_e( 'Name', 'woocommerce' );
break;
case 'name_num':
esc_html_e( 'Name (numeric)', 'woocommerce' );
break;
case 'id':
esc_html_e( 'Term ID', 'woocommerce' );
break;
default:
esc_html_e( 'Custom ordering', 'woocommerce' );
break;
}
?>
</td>
<td class="attribute-terms">
<?php
$taxonomy = wc_attribute_taxonomy_name( $tax->attribute_name );
<?php
$taxonomy = wc_attribute_taxonomy_name( $tax->attribute_name );
if ( taxonomy_exists( $taxonomy ) ) {
if ( 'menu_order' === wc_attribute_orderby( $taxonomy ) ) {
$terms = get_terms( $taxonomy, 'hide_empty=0&menu_order=ASC' );
if ( taxonomy_exists( $taxonomy ) ) {
if ( 'menu_order' === wc_attribute_orderby( $taxonomy ) ) {
$terms = get_terms( $taxonomy, 'hide_empty=0&menu_order=ASC' );
} else {
$terms = get_terms( $taxonomy, 'hide_empty=0&menu_order=false' );
}
switch ( $tax->attribute_orderby ) {
case 'name_num':
usort( $terms, '_wc_get_product_terms_name_num_usort_callback' );
break;
case 'parent':
usort( $terms, '_wc_get_product_terms_parent_usort_callback' );
break;
}
$terms_string = implode( ', ', wp_list_pluck( $terms, 'name' ) );
if ( $terms_string ) {
echo esc_html( $terms_string );
} else {
echo '<span class="na">&ndash;</span>';
}
} else {
$terms = get_terms( $taxonomy, 'hide_empty=0&menu_order=false' );
echo '<span class="na">&ndash;</span>';
}
switch ( $tax->attribute_orderby ) {
case 'name_num' :
usort( $terms, '_wc_get_product_terms_name_num_usort_callback' );
break;
case 'parent' :
usort( $terms, '_wc_get_product_terms_parent_usort_callback' );
break;
}
$terms_string = implode( ', ', wp_list_pluck( $terms, 'name' ) );
if ( $terms_string ) {
echo esc_html( $terms_string );
} else {
echo '<span class="na">&ndash;</span>';
}
} else {
echo '<span class="na">&ndash;</span>';
}
?>
<br /><a href="edit-tags.php?taxonomy=<?php echo esc_html( wc_attribute_taxonomy_name( $tax->attribute_name ) ); ?>&amp;post_type=product" class="configure-terms"><?php esc_html_e( 'Configure terms', 'woocommerce' ); ?></a>
?>
<br /><a href="edit-tags.php?taxonomy=<?php echo esc_html( wc_attribute_taxonomy_name( $tax->attribute_name ) ); ?>&amp;post_type=product" class="configure-terms"><?php esc_html_e( 'Configure terms', 'woocommerce' ); ?></a>
</td>
</tr>
<?php
endforeach;
else :
?><tr><td colspan="6"><?php esc_html_e( 'No attributes currently exist.', 'woocommerce' ) ?></td></tr><?php
?>
<tr>
<td colspan="6"><?php esc_html_e( 'No attributes currently exist.', 'woocommerce' ); ?></td>
</tr>
<?php
endif;
?>
</tbody>
@ -379,7 +385,7 @@ class WC_Admin_Attributes {
<h2><?php esc_html_e( 'Add new attribute', 'woocommerce' ); ?></h2>
<p><?php esc_html_e( 'Attributes let you define extra product data, such as size or color. You can use these attributes in the shop sidebar using the "layered nav" widgets.', 'woocommerce' ); ?></p>
<form action="edit.php?post_type=product&amp;page=product_attributes" method="post">
<?php do_action( 'woocommerce_before_add_attribute_fields' ) ?>
<?php do_action( 'woocommerce_before_add_attribute_fields' ); ?>
<div class="form-field">
<label for="attribute_label"><?php esc_html_e( 'Name', 'woocommerce' ); ?></label>
@ -442,7 +448,7 @@ class WC_Admin_Attributes {
<p class="description"><?php esc_html_e( 'Determines the sort order of the terms on the frontend shop product pages. If using custom ordering, you can drag and drop the terms in this attribute.', 'woocommerce' ); ?></p>
</div>
<?php do_action( 'woocommerce_after_add_attribute_fields' ) ?>
<?php do_action( 'woocommerce_after_add_attribute_fields' ); ?>
<p class="submit"><button type="submit" name="add_new_attribute" id="submit" class="button button-primary" value="<?php esc_attr_e( 'Add attribute', 'woocommerce' ); ?>"><?php esc_html_e( 'Add attribute', 'woocommerce' ); ?></button></p>
<?php wp_nonce_field( 'woocommerce-add-new_attribute' ); ?>

View File

@ -14,84 +14,84 @@ if ( ! defined( 'ABSPATH' ) ) {
if ( ! class_exists( 'WC_Admin_Customize', false ) ) :
/**
* WC_Admin_Customize Class.
*/
class WC_Admin_Customize {
/**
* Initialize customize actions.
* WC_Admin_Customize Class.
*/
public function __construct() {
// Include custom items to customizer nav menu settings.
add_filter( 'customize_nav_menu_available_item_types', array( $this, 'register_customize_nav_menu_item_types' ) );
add_filter( 'customize_nav_menu_available_items', array( $this, 'register_customize_nav_menu_items' ), 10, 4 );
}
class WC_Admin_Customize {
/**
* Register customize new nav menu item types.
* This will register WooCommerce account endpoints as a nav menu item type.
*
* @since 3.1.0
* @param array $item_types Menu item types.
* @return array
*/
public function register_customize_nav_menu_item_types( $item_types ) {
$item_types[] = array(
'title' => __( 'WooCommerce endpoints', 'woocommerce' ),
'type_label' => __( 'WooCommerce endpoint', 'woocommerce' ),
'type' => 'woocommerce_nav',
'object' => 'woocommerce_endpoint',
);
return $item_types;
}
/**
* Register account endpoints to customize nav menu items.
*
* @since 3.1.0
* @param array $items List of nav menu items.
* @param string $type Nav menu type.
* @param string $object Nav menu object.
* @param integer $page Page number.
* @return array
*/
public function register_customize_nav_menu_items( $items = array(), $type = '', $object = '', $page = 0 ) {
if ( 'woocommerce_endpoint' !== $object ) {
return $items;
/**
* Initialize customize actions.
*/
public function __construct() {
// Include custom items to customizer nav menu settings.
add_filter( 'customize_nav_menu_available_item_types', array( $this, 'register_customize_nav_menu_item_types' ) );
add_filter( 'customize_nav_menu_available_items', array( $this, 'register_customize_nav_menu_items' ), 10, 4 );
}
// Don't allow pagination since all items are loaded at once.
if ( 0 < $page ) {
return $items;
}
// Get items from account menu.
$endpoints = wc_get_account_menu_items();
// Remove dashboard item.
if ( isset( $endpoints['dashboard'] ) ) {
unset( $endpoints['dashboard'] );
}
// Include missing lost password.
$endpoints['lost-password'] = __( 'Lost password', 'woocommerce' );
$endpoints = apply_filters( 'woocommerce_custom_nav_menu_items', $endpoints );
foreach ( $endpoints as $endpoint => $title ) {
$items[] = array(
'id' => $endpoint,
'title' => $title,
'type_label' => __( 'Custom Link', 'woocommerce' ),
'url' => esc_url_raw( wc_get_account_endpoint_url( $endpoint ) ),
/**
* Register customize new nav menu item types.
* This will register WooCommerce account endpoints as a nav menu item type.
*
* @since 3.1.0
* @param array $item_types Menu item types.
* @return array
*/
public function register_customize_nav_menu_item_types( $item_types ) {
$item_types[] = array(
'title' => __( 'WooCommerce endpoints', 'woocommerce' ),
'type_label' => __( 'WooCommerce endpoint', 'woocommerce' ),
'type' => 'woocommerce_nav',
'object' => 'woocommerce_endpoint',
);
return $item_types;
}
return $items;
/**
* Register account endpoints to customize nav menu items.
*
* @since 3.1.0
* @param array $items List of nav menu items.
* @param string $type Nav menu type.
* @param string $object Nav menu object.
* @param integer $page Page number.
* @return array
*/
public function register_customize_nav_menu_items( $items = array(), $type = '', $object = '', $page = 0 ) {
if ( 'woocommerce_endpoint' !== $object ) {
return $items;
}
// Don't allow pagination since all items are loaded at once.
if ( 0 < $page ) {
return $items;
}
// Get items from account menu.
$endpoints = wc_get_account_menu_items();
// Remove dashboard item.
if ( isset( $endpoints['dashboard'] ) ) {
unset( $endpoints['dashboard'] );
}
// Include missing lost password.
$endpoints['lost-password'] = __( 'Lost password', 'woocommerce' );
$endpoints = apply_filters( 'woocommerce_custom_nav_menu_items', $endpoints );
foreach ( $endpoints as $endpoint => $title ) {
$items[] = array(
'id' => $endpoint,
'title' => $title,
'type_label' => __( 'Custom Link', 'woocommerce' ),
'url' => esc_url_raw( wc_get_account_endpoint_url( $endpoint ) ),
);
}
return $items;
}
}
}
endif;

View File

@ -14,103 +14,105 @@ if ( ! defined( 'ABSPATH' ) ) {
if ( ! class_exists( 'WC_Admin_Dashboard', false ) ) :
/**
* WC_Admin_Dashboard Class.
*/
class WC_Admin_Dashboard {
/**
* Hook in tabs.
* WC_Admin_Dashboard Class.
*/
public function __construct() {
// Only hook in admin parts if the user has admin access
if ( current_user_can( 'view_woocommerce_reports' ) || current_user_can( 'manage_woocommerce' ) || current_user_can( 'publish_shop_orders' ) ) {
// If on network admin, only load the widget that works in that context and skip the rest.
if ( is_multisite() && is_network_admin() ) {
add_action( 'wp_network_dashboard_setup', array( $this, 'register_network_order_widget' ) );
} else {
add_action( 'wp_dashboard_setup', array( $this, 'init' ) );
class WC_Admin_Dashboard {
/**
* Hook in tabs.
*/
public function __construct() {
// Only hook in admin parts if the user has admin access
if ( current_user_can( 'view_woocommerce_reports' ) || current_user_can( 'manage_woocommerce' ) || current_user_can( 'publish_shop_orders' ) ) {
// If on network admin, only load the widget that works in that context and skip the rest.
if ( is_multisite() && is_network_admin() ) {
add_action( 'wp_network_dashboard_setup', array( $this, 'register_network_order_widget' ) );
} else {
add_action( 'wp_dashboard_setup', array( $this, 'init' ) );
}
}
}
}
/**
* Init dashboard widgets.
*/
public function init() {
if ( current_user_can( 'publish_shop_orders' ) && post_type_supports( 'product', 'comments' ) ) {
wp_add_dashboard_widget( 'woocommerce_dashboard_recent_reviews', __( 'WooCommerce recent reviews', 'woocommerce' ), array( $this, 'recent_reviews' ) );
/**
* Init dashboard widgets.
*/
public function init() {
if ( current_user_can( 'publish_shop_orders' ) && post_type_supports( 'product', 'comments' ) ) {
wp_add_dashboard_widget( 'woocommerce_dashboard_recent_reviews', __( 'WooCommerce recent reviews', 'woocommerce' ), array( $this, 'recent_reviews' ) );
}
wp_add_dashboard_widget( 'woocommerce_dashboard_status', __( 'WooCommerce status', 'woocommerce' ), array( $this, 'status_widget' ) );
// Network Order Widget.
if ( is_multisite() ) {
$this->register_network_order_widget();
}
}
wp_add_dashboard_widget( 'woocommerce_dashboard_status', __( 'WooCommerce status', 'woocommerce' ), array( $this, 'status_widget' ) );
// Network Order Widget.
if ( is_multisite() ) {
$this->register_network_order_widget();
/**
* Register the network order dashboard widget.
*/
public function register_network_order_widget() {
wp_add_dashboard_widget( 'woocommerce_network_orders', __( 'WooCommerce network orders', 'woocommerce' ), array( $this, 'network_orders' ) );
}
}
/**
* Register the network order dashboard widget.
*/
public function register_network_order_widget() {
wp_add_dashboard_widget( 'woocommerce_network_orders', __( 'WooCommerce network orders', 'woocommerce' ), array( $this, 'network_orders' ) );
}
/**
* Get top seller from DB.
*
* @return object
*/
private function get_top_seller() {
global $wpdb;
/**
* Get top seller from DB.
* @return object
*/
private function get_top_seller() {
global $wpdb;
$query = array();
$query['fields'] = "SELECT SUM( order_item_meta.meta_value ) as qty, order_item_meta_2.meta_value as product_id
$query = array();
$query['fields'] = "SELECT SUM( order_item_meta.meta_value ) as qty, order_item_meta_2.meta_value as product_id
FROM {$wpdb->posts} as posts";
$query['join'] = "INNER JOIN {$wpdb->prefix}woocommerce_order_items AS order_items ON posts.ID = order_id ";
$query['join'] .= "INNER JOIN {$wpdb->prefix}woocommerce_order_itemmeta AS order_item_meta ON order_items.order_item_id = order_item_meta.order_item_id ";
$query['join'] .= "INNER JOIN {$wpdb->prefix}woocommerce_order_itemmeta AS order_item_meta_2 ON order_items.order_item_id = order_item_meta_2.order_item_id ";
$query['where'] = "WHERE posts.post_type IN ( '" . implode( "','", wc_get_order_types( 'order-count' ) ) . "' ) ";
$query['where'] .= "AND posts.post_status IN ( 'wc-" . implode( "','wc-", apply_filters( 'woocommerce_reports_order_statuses', array( 'completed', 'processing', 'on-hold' ) ) ) . "' ) ";
$query['where'] .= "AND order_item_meta.meta_key = '_qty' ";
$query['where'] .= "AND order_item_meta_2.meta_key = '_product_id' ";
$query['where'] .= "AND posts.post_date >= '" . date( 'Y-m-01', current_time( 'timestamp' ) ) . "' ";
$query['where'] .= "AND posts.post_date <= '" . date( 'Y-m-d H:i:s', current_time( 'timestamp' ) ) . "' ";
$query['groupby'] = "GROUP BY product_id";
$query['orderby'] = "ORDER BY qty DESC";
$query['limits'] = "LIMIT 1";
$query['join'] = "INNER JOIN {$wpdb->prefix}woocommerce_order_items AS order_items ON posts.ID = order_id ";
$query['join'] .= "INNER JOIN {$wpdb->prefix}woocommerce_order_itemmeta AS order_item_meta ON order_items.order_item_id = order_item_meta.order_item_id ";
$query['join'] .= "INNER JOIN {$wpdb->prefix}woocommerce_order_itemmeta AS order_item_meta_2 ON order_items.order_item_id = order_item_meta_2.order_item_id ";
$query['where'] = "WHERE posts.post_type IN ( '" . implode( "','", wc_get_order_types( 'order-count' ) ) . "' ) ";
$query['where'] .= "AND posts.post_status IN ( 'wc-" . implode( "','wc-", apply_filters( 'woocommerce_reports_order_statuses', array( 'completed', 'processing', 'on-hold' ) ) ) . "' ) ";
$query['where'] .= "AND order_item_meta.meta_key = '_qty' ";
$query['where'] .= "AND order_item_meta_2.meta_key = '_product_id' ";
$query['where'] .= "AND posts.post_date >= '" . date( 'Y-m-01', current_time( 'timestamp' ) ) . "' ";
$query['where'] .= "AND posts.post_date <= '" . date( 'Y-m-d H:i:s', current_time( 'timestamp' ) ) . "' ";
$query['groupby'] = 'GROUP BY product_id';
$query['orderby'] = 'ORDER BY qty DESC';
$query['limits'] = 'LIMIT 1';
return $wpdb->get_row( implode( ' ', apply_filters( 'woocommerce_dashboard_status_widget_top_seller_query', $query ) ) );
}
return $wpdb->get_row( implode( ' ', apply_filters( 'woocommerce_dashboard_status_widget_top_seller_query', $query ) ) );
}
/**
* Get sales report data.
* @return object
*/
private function get_sales_report_data() {
include_once( dirname( __FILE__ ) . '/reports/class-wc-report-sales-by-date.php' );
/**
* Get sales report data.
*
* @return object
*/
private function get_sales_report_data() {
include_once dirname( __FILE__ ) . '/reports/class-wc-report-sales-by-date.php';
$sales_by_date = new WC_Report_Sales_By_Date();
$sales_by_date->start_date = strtotime( date( 'Y-m-01', current_time( 'timestamp' ) ) );
$sales_by_date->end_date = current_time( 'timestamp' );
$sales_by_date->chart_groupby = 'day';
$sales_by_date->group_by_query = 'YEAR(posts.post_date), MONTH(posts.post_date), DAY(posts.post_date)';
$sales_by_date = new WC_Report_Sales_By_Date();
$sales_by_date->start_date = strtotime( date( 'Y-m-01', current_time( 'timestamp' ) ) );
$sales_by_date->end_date = current_time( 'timestamp' );
$sales_by_date->chart_groupby = 'day';
$sales_by_date->group_by_query = 'YEAR(posts.post_date), MONTH(posts.post_date), DAY(posts.post_date)';
return $sales_by_date->get_report_data();
}
return $sales_by_date->get_report_data();
}
/**
* Show status widget.
*/
public function status_widget() {
include_once( dirname( __FILE__ ) . '/reports/class-wc-admin-report.php' );
/**
* Show status widget.
*/
public function status_widget() {
include_once dirname( __FILE__ ) . '/reports/class-wc-admin-report.php';
$reports = new WC_Admin_Report();
$reports = new WC_Admin_Report();
echo '<ul class="wc_status_list">';
echo '<ul class="wc_status_list">';
if ( current_user_can( 'view_woocommerce_reports' ) && ( $report_data = $this->get_sales_report_data() ) ) {
?>
<li class="sales-this-month">
if ( current_user_can( 'view_woocommerce_reports' ) && ( $report_data = $this->get_sales_report_data() ) ) {
?>
<li class="sales-this-month">
<a href="<?php echo admin_url( 'admin.php?page=wc-reports&tab=orders&range=month' ); ?>">
<?php echo $reports->sales_sparkline( '', max( 7, date( 'd', current_time( 'timestamp' ) ) ) ); ?>
<?php
@ -118,16 +120,16 @@ class WC_Admin_Dashboard {
printf(
__( '%s net sales this month', 'woocommerce' ),
'<strong>' . wc_price( $report_data->net_sales ) . '</strong>'
);
?>
</a>
</li>
<?php
}
);
?>
</a>
</li>
<?php
}
if ( current_user_can( 'view_woocommerce_reports' ) && ( $top_seller = $this->get_top_seller() ) && $top_seller->qty ) {
?>
<li class="best-seller-this-month">
if ( current_user_can( 'view_woocommerce_reports' ) && ( $top_seller = $this->get_top_seller() ) && $top_seller->qty ) {
?>
<li class="best-seller-this-month">
<a href="<?php echo admin_url( 'admin.php?page=wc-reports&tab=orders&report=sales_by_product&range=month&product_ids=' . $top_seller->product_id ); ?>">
<?php echo $reports->sales_sparkline( $top_seller->product_id, max( 7, date( 'd', current_time( 'timestamp' ) ) ), 'count' ); ?>
<?php
@ -137,36 +139,36 @@ class WC_Admin_Dashboard {
'<strong>' . get_the_title( $top_seller->product_id ) . '</strong>',
$top_seller->qty
);
?>
</a>
</li>
<?php
?>
</a>
</li>
<?php
}
$this->status_widget_order_rows();
$this->status_widget_stock_rows();
do_action( 'woocommerce_after_dashboard_status_widget', $reports );
echo '</ul>';
}
$this->status_widget_order_rows();
$this->status_widget_stock_rows();
/**
* Show order data is status widget.
*/
private function status_widget_order_rows() {
if ( ! current_user_can( 'edit_shop_orders' ) ) {
return;
}
$on_hold_count = 0;
$processing_count = 0;
do_action( 'woocommerce_after_dashboard_status_widget', $reports );
echo '</ul>';
}
/**
* Show order data is status widget.
*/
private function status_widget_order_rows() {
if ( ! current_user_can( 'edit_shop_orders' ) ) {
return;
}
$on_hold_count = 0;
$processing_count = 0;
foreach ( wc_get_order_types( 'order-count' ) as $type ) {
$counts = (array) wp_count_posts( $type );
$on_hold_count += isset( $counts['wc-on-hold'] ) ? $counts['wc-on-hold'] : 0;
$processing_count += isset( $counts['wc-processing'] ) ? $counts['wc-processing'] : 0;
}
?>
<li class="processing-orders">
foreach ( wc_get_order_types( 'order-count' ) as $type ) {
$counts = (array) wp_count_posts( $type );
$on_hold_count += isset( $counts['wc-on-hold'] ) ? $counts['wc-on-hold'] : 0;
$processing_count += isset( $counts['wc-processing'] ) ? $counts['wc-processing'] : 0;
}
?>
<li class="processing-orders">
<a href="<?php echo admin_url( 'edit.php?post_status=wc-processing&post_type=shop_order' ); ?>">
<?php
/* translators: %s: order count */
@ -175,10 +177,10 @@ class WC_Admin_Dashboard {
$processing_count
);
?>
</a>
</li>
<li class="on-hold-orders">
<a href="<?php echo admin_url( 'edit.php?post_status=wc-on-hold&post_type=shop_order' ); ?>">
</a>
</li>
<li class="on-hold-orders">
<a href="<?php echo admin_url( 'edit.php?post_status=wc-on-hold&post_type=shop_order' ); ?>">
<?php
/* translators: %s: order count */
printf(
@ -186,54 +188,58 @@ class WC_Admin_Dashboard {
$on_hold_count
);
?>
</a>
</li>
<?php
}
/**
* Show stock data is status widget.
*/
private function status_widget_stock_rows() {
global $wpdb;
// Get products using a query - this is too advanced for get_posts :(
$stock = absint( max( get_option( 'woocommerce_notify_low_stock_amount' ), 1 ) );
$nostock = absint( max( get_option( 'woocommerce_notify_no_stock_amount' ), 0 ) );
$transient_name = 'wc_low_stock_count';
if ( false === ( $lowinstock_count = get_transient( $transient_name ) ) ) {
$query_from = apply_filters( 'woocommerce_report_low_in_stock_query_from', "FROM {$wpdb->posts} as posts
INNER JOIN {$wpdb->postmeta} AS postmeta ON posts.ID = postmeta.post_id
INNER JOIN {$wpdb->postmeta} AS postmeta2 ON posts.ID = postmeta2.post_id
WHERE 1=1
AND posts.post_type IN ( 'product', 'product_variation' )
AND posts.post_status = 'publish'
AND postmeta2.meta_key = '_manage_stock' AND postmeta2.meta_value = 'yes'
AND postmeta.meta_key = '_stock' AND CAST(postmeta.meta_value AS SIGNED) <= '{$stock}'
AND postmeta.meta_key = '_stock' AND CAST(postmeta.meta_value AS SIGNED) > '{$nostock}'
" );
$lowinstock_count = absint( $wpdb->get_var( "SELECT COUNT( DISTINCT posts.ID ) {$query_from};" ) );
set_transient( $transient_name, $lowinstock_count, DAY_IN_SECONDS * 30 );
</a>
</li>
<?php
}
$transient_name = 'wc_outofstock_count';
/**
* Show stock data is status widget.
*/
private function status_widget_stock_rows() {
global $wpdb;
if ( false === ( $outofstock_count = get_transient( $transient_name ) ) ) {
$query_from = apply_filters( 'woocommerce_report_out_of_stock_query_from', "FROM {$wpdb->posts} as posts
INNER JOIN {$wpdb->postmeta} AS postmeta ON posts.ID = postmeta.post_id
INNER JOIN {$wpdb->postmeta} AS postmeta2 ON posts.ID = postmeta2.post_id
WHERE 1=1
AND posts.post_type IN ( 'product', 'product_variation' )
AND posts.post_status = 'publish'
AND postmeta2.meta_key = '_manage_stock' AND postmeta2.meta_value = 'yes'
AND postmeta.meta_key = '_stock' AND CAST(postmeta.meta_value AS SIGNED) <= '{$nostock}'
" );
$outofstock_count = absint( $wpdb->get_var( "SELECT COUNT( DISTINCT posts.ID ) {$query_from};" ) );
set_transient( $transient_name, $outofstock_count, DAY_IN_SECONDS * 30 );
}
?>
<li class="low-in-stock">
// Get products using a query - this is too advanced for get_posts :(
$stock = absint( max( get_option( 'woocommerce_notify_low_stock_amount' ), 1 ) );
$nostock = absint( max( get_option( 'woocommerce_notify_no_stock_amount' ), 0 ) );
$transient_name = 'wc_low_stock_count';
if ( false === ( $lowinstock_count = get_transient( $transient_name ) ) ) {
$query_from = apply_filters(
'woocommerce_report_low_in_stock_query_from',
"FROM {$wpdb->posts} as posts
INNER JOIN {$wpdb->postmeta} AS postmeta ON posts.ID = postmeta.post_id
INNER JOIN {$wpdb->postmeta} AS postmeta2 ON posts.ID = postmeta2.post_id
WHERE 1=1
AND posts.post_type IN ( 'product', 'product_variation' )
AND posts.post_status = 'publish'
AND postmeta2.meta_key = '_manage_stock' AND postmeta2.meta_value = 'yes'
AND postmeta.meta_key = '_stock' AND CAST(postmeta.meta_value AS SIGNED) <= '{$stock}'
AND postmeta.meta_key = '_stock' AND CAST(postmeta.meta_value AS SIGNED) > '{$nostock}'"
);
$lowinstock_count = absint( $wpdb->get_var( "SELECT COUNT( DISTINCT posts.ID ) {$query_from};" ) );
set_transient( $transient_name, $lowinstock_count, DAY_IN_SECONDS * 30 );
}
$transient_name = 'wc_outofstock_count';
if ( false === ( $outofstock_count = get_transient( $transient_name ) ) ) {
$query_from = apply_filters(
'woocommerce_report_out_of_stock_query_from',
"FROM {$wpdb->posts} as posts
INNER JOIN {$wpdb->postmeta} AS postmeta ON posts.ID = postmeta.post_id
INNER JOIN {$wpdb->postmeta} AS postmeta2 ON posts.ID = postmeta2.post_id
WHERE 1=1
AND posts.post_type IN ( 'product', 'product_variation' )
AND posts.post_status = 'publish'
AND postmeta2.meta_key = '_manage_stock' AND postmeta2.meta_value = 'yes'
AND postmeta.meta_key = '_stock' AND CAST(postmeta.meta_value AS SIGNED) <= '{$nostock}'"
);
$outofstock_count = absint( $wpdb->get_var( "SELECT COUNT( DISTINCT posts.ID ) {$query_from};" ) );
set_transient( $transient_name, $outofstock_count, DAY_IN_SECONDS * 30 );
}
?>
<li class="low-in-stock">
<a href="<?php echo admin_url( 'admin.php?page=wc-reports&tab=stock&report=low_in_stock' ); ?>">
<?php
/* translators: %s: order count */
@ -242,10 +248,10 @@ class WC_Admin_Dashboard {
$lowinstock_count
);
?>
</a>
</li>
<li class="out-of-stock">
<a href="<?php echo admin_url( 'admin.php?page=wc-reports&tab=stock&report=out_of_stock' ); ?>">
</a>
</li>
<li class="out-of-stock">
<a href="<?php echo admin_url( 'admin.php?page=wc-reports&tab=stock&report=out_of_stock' ); ?>">
<?php
/* translators: %s: order count */
printf(
@ -253,78 +259,81 @@ class WC_Admin_Dashboard {
$outofstock_count
);
?>
</a>
</li>
<?php
}
/**
* Recent reviews widget.
*/
public function recent_reviews() {
global $wpdb;
$query_from = apply_filters( 'woocommerce_report_recent_reviews_query_from', "FROM {$wpdb->comments} comments
LEFT JOIN {$wpdb->posts} posts ON (comments.comment_post_ID = posts.ID)
WHERE comments.comment_approved = '1'
AND comments.comment_type = ''
AND posts.post_password = ''
AND posts.post_type = 'product'
AND comments.comment_parent = 0
ORDER BY comments.comment_date_gmt DESC
LIMIT 5
" );
$comments = $wpdb->get_results( "
SELECT posts.ID, posts.post_title, comments.comment_author, comments.comment_ID, comments.comment_content
{$query_from};
" );
if ( $comments ) {
echo '<ul>';
foreach ( $comments as $comment ) {
echo '<li>';
echo get_avatar( $comment->comment_author, '32' );
$rating = intval( get_comment_meta( $comment->comment_ID, 'rating', true ) );
/* translators: %s: rating */
echo '<div class="star-rating"><span style="width:' . ( $rating * 20 ) . '%">' . sprintf( __( '%s out of 5', 'woocommerce' ), $rating ) . '</span></div>';
/* translators: %s: review author */
echo '<h4 class="meta"><a href="' . get_permalink( $comment->ID ) . '#comment-' . absint( $comment->comment_ID ) . '">' . esc_html( apply_filters( 'woocommerce_admin_dashboard_recent_reviews', $comment->post_title, $comment ) ) . '</a> ' . sprintf( __( 'reviewed by %s', 'woocommerce' ), esc_html( $comment->comment_author ) ) . '</h4>';
echo '<blockquote>' . wp_kses_data( $comment->comment_content ) . '</blockquote></li>';
}
echo '</ul>';
} else {
echo '<p>' . __( 'There are no product reviews yet.', 'woocommerce' ) . '</p>';
</a>
</li>
<?php
}
}
/**
* Network orders widget.
*/
public function network_orders() {
$suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
/**
* Recent reviews widget.
*/
public function recent_reviews() {
global $wpdb;
wp_enqueue_style( 'wc-network-orders', WC()->plugin_url() . '/assets/css/network-order-widget.css', array(), WC_VERSION );
$query_from = apply_filters(
'woocommerce_report_recent_reviews_query_from',
"FROM {$wpdb->comments} comments
LEFT JOIN {$wpdb->posts} posts ON (comments.comment_post_ID = posts.ID)
WHERE comments.comment_approved = '1'
AND comments.comment_type = ''
AND posts.post_password = ''
AND posts.post_type = 'product'
AND comments.comment_parent = 0
ORDER BY comments.comment_date_gmt DESC
LIMIT 5"
);
wp_enqueue_script( 'wc-network-orders', WC()->plugin_url() . '/assets/js/admin/network-orders' . $suffix . '.js', array( 'jquery', 'underscore' ), WC_VERSION, true );
$comments = $wpdb->get_results(
"SELECT posts.ID, posts.post_title, comments.comment_author, comments.comment_ID, comments.comment_content {$query_from};"
);
$user = wp_get_current_user();
$blogs = get_blogs_of_user( $user->ID );
$blog_ids = wp_list_pluck( $blogs, 'userblog_id' );
if ( $comments ) {
echo '<ul>';
foreach ( $comments as $comment ) {
wp_localize_script( 'wc-network-orders', 'woocommerce_network_orders', array(
'nonce' => wp_create_nonce( 'wp_rest' ),
'sites' => array_values( $blog_ids ),
'order_endpoint' => get_rest_url( null, 'wc/v2/orders/network' ),
) );
?>
<div class="post-type-shop_order">
echo '<li>';
echo get_avatar( $comment->comment_author, '32' );
$rating = intval( get_comment_meta( $comment->comment_ID, 'rating', true ) );
/* translators: %s: rating */
echo '<div class="star-rating"><span style="width:' . ( $rating * 20 ) . '%">' . sprintf( __( '%s out of 5', 'woocommerce' ), $rating ) . '</span></div>';
/* translators: %s: review author */
echo '<h4 class="meta"><a href="' . get_permalink( $comment->ID ) . '#comment-' . absint( $comment->comment_ID ) . '">' . esc_html( apply_filters( 'woocommerce_admin_dashboard_recent_reviews', $comment->post_title, $comment ) ) . '</a> ' . sprintf( __( 'reviewed by %s', 'woocommerce' ), esc_html( $comment->comment_author ) ) . '</h4>';
echo '<blockquote>' . wp_kses_data( $comment->comment_content ) . '</blockquote></li>';
}
echo '</ul>';
} else {
echo '<p>' . __( 'There are no product reviews yet.', 'woocommerce' ) . '</p>';
}
}
/**
* Network orders widget.
*/
public function network_orders() {
$suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
wp_enqueue_style( 'wc-network-orders', WC()->plugin_url() . '/assets/css/network-order-widget.css', array(), WC_VERSION );
wp_enqueue_script( 'wc-network-orders', WC()->plugin_url() . '/assets/js/admin/network-orders' . $suffix . '.js', array( 'jquery', 'underscore' ), WC_VERSION, true );
$user = wp_get_current_user();
$blogs = get_blogs_of_user( $user->ID );
$blog_ids = wp_list_pluck( $blogs, 'userblog_id' );
wp_localize_script(
'wc-network-orders', 'woocommerce_network_orders', array(
'nonce' => wp_create_nonce( 'wp_rest' ),
'sites' => array_values( $blog_ids ),
'order_endpoint' => get_rest_url( null, 'wc/v2/orders/network' ),
)
);
?>
<div class="post-type-shop_order">
<div id="woocommerce-network-order-table-loading" class="woocommerce-network-order-table-loading is-active">
<p>
<span class="spinner is-active"></span> <?php esc_html_e( 'Loading network orders', 'woocommerce' ); ?>
@ -367,9 +376,9 @@ class WC_Admin_Dashboard {
</script>
</div>
<?php
}
}
}
}
endif;

View File

@ -88,7 +88,7 @@ class WC_Admin_Duplicate_Product {
}
if ( isset( $_GET['post'] ) ) {
$notify_url = wp_nonce_url( admin_url( "edit.php?post_type=product&action=duplicate_product&post=" . absint( $_GET['post'] ) ), 'woocommerce-duplicate-product_' . $_GET['post'] );
$notify_url = wp_nonce_url( admin_url( 'edit.php?post_type=product&action=duplicate_product&post=' . absint( $_GET['post'] ) ), 'woocommerce-duplicate-product_' . $_GET['post'] );
?>
<div id="duplicate-action"><a class="submitduplicate duplication" href="<?php echo esc_url( $notify_url ); ?>"><?php _e( 'Copy to a new draft', 'woocommerce' ); ?></a></div>
<?php

View File

@ -73,17 +73,21 @@ class WC_Admin_Exporters {
public function admin_scripts() {
$suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
wp_register_script( 'wc-product-export', WC()->plugin_url() . '/assets/js/admin/wc-product-export' . $suffix . '.js', array( 'jquery' ), WC_VERSION );
wp_localize_script( 'wc-product-export', 'wc_product_export_params', array(
'export_nonce' => wp_create_nonce( 'wc-product-export' ),
) );
wp_localize_script(
'wc-product-export',
'wc_product_export_params',
array(
'export_nonce' => wp_create_nonce( 'wc-product-export' ),
)
);
}
/**
* Export page UI.
*/
public function product_exporter() {
include_once( WC_ABSPATH . 'includes/export/class-wc-product-csv-exporter.php' );
include_once( dirname( __FILE__ ) . '/views/html-admin-page-product-export.php' );
include_once WC_ABSPATH . 'includes/export/class-wc-product-csv-exporter.php';
include_once dirname( __FILE__ ) . '/views/html-admin-page-product-export.php';
}
/**
@ -91,7 +95,7 @@ class WC_Admin_Exporters {
*/
public function download_export_file() {
if ( isset( $_GET['action'], $_GET['nonce'] ) && wp_verify_nonce( wp_unslash( $_GET['nonce'] ), 'product-csv' ) && 'download_product_csv' === wp_unslash( $_GET['action'] ) ) { // WPCS: input var ok, sanitization ok.
include_once( WC_ABSPATH . 'includes/export/class-wc-product-csv-exporter.php' );
include_once WC_ABSPATH . 'includes/export/class-wc-product-csv-exporter.php';
$exporter = new WC_Product_CSV_Exporter();
if ( ! empty( $_GET['filename'] ) ) { // WPCS: input var ok.
@ -112,7 +116,7 @@ class WC_Admin_Exporters {
wp_die( -1 );
}
include_once( WC_ABSPATH . 'includes/export/class-wc-product-csv-exporter.php' );
include_once WC_ABSPATH . 'includes/export/class-wc-product-csv-exporter.php';
$step = isset( $_POST['step'] ) ? absint( $_POST['step'] ) : 1; // WPCS: input var ok, sanitization ok.
$exporter = new WC_Product_CSV_Exporter();
@ -140,20 +144,31 @@ class WC_Admin_Exporters {
$exporter->set_page( $step );
$exporter->generate_file();
$query_args = apply_filters( 'woocommerce_export_get_ajax_query_args', array( 'nonce' => wp_create_nonce( 'product-csv' ), 'action' => 'download_product_csv', 'filename' => $exporter->get_filename() ) );
$query_args = apply_filters(
'woocommerce_export_get_ajax_query_args',
array(
'nonce' => wp_create_nonce( 'product-csv' ),
'action' => 'download_product_csv',
'filename' => $exporter->get_filename(),
)
);
if ( 100 === $exporter->get_percent_complete() ) {
wp_send_json_success( array(
'step' => 'done',
'percentage' => 100,
'url' => add_query_arg( $query_args, admin_url( 'edit.php?post_type=product&page=product_exporter' ) ),
) );
wp_send_json_success(
array(
'step' => 'done',
'percentage' => 100,
'url' => add_query_arg( $query_args, admin_url( 'edit.php?post_type=product&page=product_exporter' ) ),
)
);
} else {
wp_send_json_success( array(
'step' => ++$step,
'percentage' => $exporter->get_percent_complete(),
'columns' => $exporter->get_column_names(),
) );
wp_send_json_success(
array(
'step' => ++$step,
'percentage' => $exporter->get_percent_complete(),
'columns' => $exporter->get_column_names(),
)
);
}
}
}

View File

@ -36,55 +36,63 @@ class WC_Admin_Help {
return;
}
$screen->add_help_tab( array(
'id' => 'woocommerce_support_tab',
'title' => __( 'Help &amp; Support', 'woocommerce' ),
'content' =>
'<h2>' . __( 'Help &amp; Support', 'woocommerce' ) . '</h2>' .
'<p>' . sprintf(
/* translators: %s: Documentation URL */
__( 'Should you need help understanding, using, or extending WooCommerce, <a href="%s">please read our documentation</a>. You will find all kinds of resources including snippets, tutorials and much more.', 'woocommerce' ),
'https://docs.woocommerce.com/documentation/plugins/woocommerce/?utm_source=helptab&utm_medium=product&utm_content=docs&utm_campaign=woocommerceplugin'
) . '</p>' .
'<p>' . sprintf(
/* translators: %s: Forum URL */
__( 'For further assistance with WooCommerce core you can use the <a href="%1$s">community forum</a>. If you need help with premium extensions sold by WooCommerce, please <a href="%2$s">use our helpdesk</a>.', 'woocommerce' ),
'https://wordpress.org/support/plugin/woocommerce',
'https://woocommerce.com/my-account/tickets/?utm_source=helptab&utm_medium=product&utm_content=tickets&utm_campaign=woocommerceplugin'
) . '</p>' .
'<p>' . __( 'Before asking for help we recommend checking the system status page to identify any problems with your configuration.', 'woocommerce' ) . '</p>' .
'<p><a href="' . admin_url( 'admin.php?page=wc-status' ) . '" class="button button-primary">' . __( 'System status', 'woocommerce' ) . '</a> <a href="https://wordpress.org/support/plugin/woocommerce" class="button">' . __( 'Community forum', 'woocommerce' ) . '</a> <a href="https://woocommerce.com/my-account/tickets/?utm_source=helptab&utm_medium=product&utm_content=tickets&utm_campaign=woocommerceplugin" class="button">' . __( 'WooCommerce helpdesk', 'woocommerce' ) . '</a></p>',
) );
$screen->add_help_tab(
array(
'id' => 'woocommerce_support_tab',
'title' => __( 'Help &amp; Support', 'woocommerce' ),
'content' =>
'<h2>' . __( 'Help &amp; Support', 'woocommerce' ) . '</h2>' .
'<p>' . sprintf(
/* translators: %s: Documentation URL */
__( 'Should you need help understanding, using, or extending WooCommerce, <a href="%s">please read our documentation</a>. You will find all kinds of resources including snippets, tutorials and much more.', 'woocommerce' ),
'https://docs.woocommerce.com/documentation/plugins/woocommerce/?utm_source=helptab&utm_medium=product&utm_content=docs&utm_campaign=woocommerceplugin'
) . '</p>' .
'<p>' . sprintf(
/* translators: %s: Forum URL */
__( 'For further assistance with WooCommerce core you can use the <a href="%1$s">community forum</a>. If you need help with premium extensions sold by WooCommerce, please <a href="%2$s">use our helpdesk</a>.', 'woocommerce' ),
'https://wordpress.org/support/plugin/woocommerce',
'https://woocommerce.com/my-account/tickets/?utm_source=helptab&utm_medium=product&utm_content=tickets&utm_campaign=woocommerceplugin'
) . '</p>' .
'<p>' . __( 'Before asking for help we recommend checking the system status page to identify any problems with your configuration.', 'woocommerce' ) . '</p>' .
'<p><a href="' . admin_url( 'admin.php?page=wc-status' ) . '" class="button button-primary">' . __( 'System status', 'woocommerce' ) . '</a> <a href="https://wordpress.org/support/plugin/woocommerce" class="button">' . __( 'Community forum', 'woocommerce' ) . '</a> <a href="https://woocommerce.com/my-account/tickets/?utm_source=helptab&utm_medium=product&utm_content=tickets&utm_campaign=woocommerceplugin" class="button">' . __( 'WooCommerce helpdesk', 'woocommerce' ) . '</a></p>',
)
);
$screen->add_help_tab( array(
'id' => 'woocommerce_bugs_tab',
'title' => __( 'Found a bug?', 'woocommerce' ),
'content' =>
'<h2>' . __( 'Found a bug?', 'woocommerce' ) . '</h2>' .
/* translators: 1: GitHub issues URL 2: GitHub contribution guide URL 3: System status report URL */
'<p>' . sprintf( __( 'If you find a bug within WooCommerce core you can create a ticket via <a href="%1$s">Github issues</a>. Ensure you read the <a href="%2$s">contribution guide</a> prior to submitting your report. To help us solve your issue, please be as descriptive as possible and include your <a href="%3$s">system status report</a>.', 'woocommerce' ), 'https://github.com/woocommerce/woocommerce/issues?state=open', 'https://github.com/woocommerce/woocommerce/blob/master/.github/CONTRIBUTING.md', admin_url( 'admin.php?page=wc-status' ) ) . '</p>' .
'<p><a href="https://github.com/woocommerce/woocommerce/issues?state=open" class="button button-primary">' . __( 'Report a bug', 'woocommerce' ) . '</a> <a href="' . admin_url( 'admin.php?page=wc-status' ) . '" class="button">' . __( 'System status', 'woocommerce' ) . '</a></p>',
$screen->add_help_tab(
array(
'id' => 'woocommerce_bugs_tab',
'title' => __( 'Found a bug?', 'woocommerce' ),
'content' =>
'<h2>' . __( 'Found a bug?', 'woocommerce' ) . '</h2>' .
/* translators: 1: GitHub issues URL 2: GitHub contribution guide URL 3: System status report URL */
'<p>' . sprintf( __( 'If you find a bug within WooCommerce core you can create a ticket via <a href="%1$s">Github issues</a>. Ensure you read the <a href="%2$s">contribution guide</a> prior to submitting your report. To help us solve your issue, please be as descriptive as possible and include your <a href="%3$s">system status report</a>.', 'woocommerce' ), 'https://github.com/woocommerce/woocommerce/issues?state=open', 'https://github.com/woocommerce/woocommerce/blob/master/.github/CONTRIBUTING.md', admin_url( 'admin.php?page=wc-status' ) ) . '</p>' .
'<p><a href="https://github.com/woocommerce/woocommerce/issues?state=open" class="button button-primary">' . __( 'Report a bug', 'woocommerce' ) . '</a> <a href="' . admin_url( 'admin.php?page=wc-status' ) . '" class="button">' . __( 'System status', 'woocommerce' ) . '</a></p>',
) );
)
);
$screen->add_help_tab( array(
'id' => 'woocommerce_education_tab',
'title' => __( 'Education', 'woocommerce' ),
'content' =>
'<h2>' . __( 'Education', 'woocommerce' ) . '</h2>' .
'<p>' . __( 'If you would like to learn about using WooCommerce from an expert, consider following a WooCommerce course offered by one of our educational partners.', 'woocommerce' ) . '</p>' .
'<p><a href="https://woocommerce.com/educational-partners/?utm_source=helptab&utm_medium=product&utm_content=edupartners&utm_campaign=woocommerceplugin" class="button button-primary">' . __( 'View education partners', 'woocommerce' ) . '</a></p>',
) );
$screen->add_help_tab(
array(
'id' => 'woocommerce_education_tab',
'title' => __( 'Education', 'woocommerce' ),
'content' =>
'<h2>' . __( 'Education', 'woocommerce' ) . '</h2>' .
'<p>' . __( 'If you would like to learn about using WooCommerce from an expert, consider following a WooCommerce course offered by one of our educational partners.', 'woocommerce' ) . '</p>' .
'<p><a href="https://woocommerce.com/educational-partners/?utm_source=helptab&utm_medium=product&utm_content=edupartners&utm_campaign=woocommerceplugin" class="button button-primary">' . __( 'View education partners', 'woocommerce' ) . '</a></p>',
)
);
$screen->add_help_tab( array(
'id' => 'woocommerce_onboard_tab',
'title' => __( 'Setup wizard', 'woocommerce' ),
'content' =>
'<h2>' . __( 'Setup wizard', 'woocommerce' ) . '</h2>' .
'<p>' . __( 'If you need to access the setup wizard again, please click on the button below.', 'woocommerce' ) . '</p>' .
'<p><a href="' . admin_url( 'index.php?page=wc-setup' ) . '" class="button button-primary">' . __( 'Setup wizard', 'woocommerce' ) . '</a></p>',
$screen->add_help_tab(
array(
'id' => 'woocommerce_onboard_tab',
'title' => __( 'Setup wizard', 'woocommerce' ),
'content' =>
'<h2>' . __( 'Setup wizard', 'woocommerce' ) . '</h2>' .
'<p>' . __( 'If you need to access the setup wizard again, please click on the button below.', 'woocommerce' ) . '</p>' .
'<p><a href="' . admin_url( 'index.php?page=wc-setup' ) . '" class="button button-primary">' . __( 'Setup wizard', 'woocommerce' ) . '</a></p>',
) );
)
);
$screen->set_help_sidebar(
'<p><strong>' . __( 'For more information:', 'woocommerce' ) . '</strong></p>' .

View File

@ -89,8 +89,8 @@ class WC_Admin_Importers {
exit;
}
include_once( WC_ABSPATH . 'includes/import/class-wc-product-csv-importer.php' );
include_once( WC_ABSPATH . 'includes/admin/importers/class-wc-product-csv-importer-controller.php' );
include_once WC_ABSPATH . 'includes/import/class-wc-product-csv-importer.php';
include_once WC_ABSPATH . 'includes/admin/importers/class-wc-product-csv-importer-controller.php';
$importer = new WC_Product_CSV_Importer_Controller();
$importer->dispatch();
@ -102,7 +102,7 @@ class WC_Admin_Importers {
public function register_importers() {
if ( defined( 'WP_LOAD_IMPORTERS' ) ) {
add_action( 'import_start', array( $this, 'post_importer_compatibility' ) );
register_importer( 'woocommerce_product_csv', __( 'WooCommerce products (CSV)', 'woocommerce' ), __( 'Import <strong>products</strong> to your store via a csv file.', 'woocommerce' ), array( $this, 'product_importer' ) );
register_importer( 'woocommerce_product_csv', __( 'WooCommerce products (CSV)', 'woocommerce' ), __( 'Import <strong>products</strong> to your store via a csv file.', 'woocommerce' ), array( $this, 'product_importer' ) );
register_importer( 'woocommerce_tax_rate_csv', __( 'WooCommerce tax rates (CSV)', 'woocommerce' ), __( 'Import <strong>tax rates</strong> to your store via a csv file.', 'woocommerce' ), array( $this, 'tax_rates_importer' ) );
}
}
@ -123,7 +123,7 @@ class WC_Admin_Importers {
}
// includes
require( dirname( __FILE__ ) . '/importers/class-wc-tax-rate-importer.php' );
require dirname( __FILE__ ) . '/importers/class-wc-tax-rate-importer.php';
// Dispatch
$importer = new WC_Tax_Rate_Importer();
@ -158,25 +158,29 @@ class WC_Admin_Importers {
// Create the taxonomy
if ( ! in_array( $attribute_name, wc_get_attribute_taxonomies() ) ) {
wc_create_attribute( array(
'name' => $attribute_name,
'slug' => $attribute_name,
'type' => 'select',
'order_by' => 'menu_order',
'has_archives' => false,
) );
wc_create_attribute(
array(
'name' => $attribute_name,
'slug' => $attribute_name,
'type' => 'select',
'order_by' => 'menu_order',
'has_archives' => false,
)
);
}
// Register the taxonomy now so that the import works!
register_taxonomy(
$term['domain'],
apply_filters( 'woocommerce_taxonomy_objects_' . $term['domain'], array( 'product' ) ),
apply_filters( 'woocommerce_taxonomy_args_' . $term['domain'], array(
'hierarchical' => true,
'show_ui' => false,
'query_var' => true,
'rewrite' => false,
) )
apply_filters(
'woocommerce_taxonomy_args_' . $term['domain'], array(
'hierarchical' => true,
'show_ui' => false,
'query_var' => true,
'rewrite' => false,
)
)
);
}
}
@ -198,8 +202,8 @@ class WC_Admin_Importers {
wp_die( -1 );
}
include_once( WC_ABSPATH . 'includes/admin/importers/class-wc-product-csv-importer-controller.php' );
include_once( WC_ABSPATH . 'includes/import/class-wc-product-csv-importer.php' );
include_once WC_ABSPATH . 'includes/admin/importers/class-wc-product-csv-importer-controller.php';
include_once WC_ABSPATH . 'includes/import/class-wc-product-csv-importer.php';
$file = wc_clean( $_POST['file'] );
$params = array(
@ -228,36 +232,40 @@ class WC_Admin_Importers {
if ( 100 === $percent_complete ) {
// Clear temp meta.
$wpdb->delete( $wpdb->postmeta, array( 'meta_key' => '_original_id' ) );
$wpdb->query( "
DELETE {$wpdb->posts}, {$wpdb->postmeta}, {$wpdb->term_relationships}
$wpdb->query(
"DELETE {$wpdb->posts}, {$wpdb->postmeta}, {$wpdb->term_relationships}
FROM {$wpdb->posts}
LEFT JOIN {$wpdb->term_relationships} ON ( {$wpdb->posts}.ID = {$wpdb->term_relationships}.object_id )
LEFT JOIN {$wpdb->postmeta} ON ( {$wpdb->posts}.ID = {$wpdb->postmeta}.post_id )
LEFT JOIN {$wpdb->term_taxonomy} ON ( {$wpdb->term_taxonomy}.term_taxonomy_id = {$wpdb->term_relationships}.term_taxonomy_id )
LEFT JOIN {$wpdb->terms} ON ( {$wpdb->terms}.term_id = {$wpdb->term_taxonomy}.term_id )
WHERE {$wpdb->posts}.post_type IN ( 'product', 'product_variation' )
AND {$wpdb->posts}.post_status = 'importing'
" );
AND {$wpdb->posts}.post_status = 'importing'"
);
// Send success.
wp_send_json_success( array(
'position' => 'done',
'percentage' => 100,
'url' => add_query_arg( array( 'nonce' => wp_create_nonce( 'product-csv' ) ), admin_url( 'edit.php?post_type=product&page=product_importer&step=done' ) ),
'imported' => count( $results['imported'] ),
'failed' => count( $results['failed'] ),
'updated' => count( $results['updated'] ),
'skipped' => count( $results['skipped'] ),
) );
wp_send_json_success(
array(
'position' => 'done',
'percentage' => 100,
'url' => add_query_arg( array( 'nonce' => wp_create_nonce( 'product-csv' ) ), admin_url( 'edit.php?post_type=product&page=product_importer&step=done' ) ),
'imported' => count( $results['imported'] ),
'failed' => count( $results['failed'] ),
'updated' => count( $results['updated'] ),
'skipped' => count( $results['skipped'] ),
)
);
} else {
wp_send_json_success( array(
'position' => $importer->get_file_position(),
'percentage' => $percent_complete,
'imported' => count( $results['imported'] ),
'failed' => count( $results['failed'] ),
'updated' => count( $results['updated'] ),
'skipped' => count( $results['skipped'] ),
) );
wp_send_json_success(
array(
'position' => $importer->get_file_position(),
'percentage' => $percent_complete,
'imported' => count( $results['imported'] ),
'failed' => count( $results['failed'] ),
'updated' => count( $results['updated'] ),
'skipped' => count( $results['skipped'] ),
)
);
}
}
}

View File

@ -13,7 +13,7 @@ if ( ! defined( 'ABSPATH' ) ) {
}
if ( ! class_exists( 'WP_List_Table' ) ) {
require_once( ABSPATH . 'wp-admin/includes/class-wp-list-table.php' );
require_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php';
}
class WC_Admin_Log_Table_List extends WP_List_Table {
@ -22,11 +22,13 @@ class WC_Admin_Log_Table_List extends WP_List_Table {
* Initialize the log table list.
*/
public function __construct() {
parent::__construct( array(
'singular' => 'log',
'plural' => 'logs',
'ajax' => false,
) );
parent::__construct(
array(
'singular' => 'log',
'plural' => 'logs',
'ajax' => false,
)
);
}
/**
@ -37,14 +39,38 @@ class WC_Admin_Log_Table_List extends WP_List_Table {
public function level_dropdown() {
$levels = array(
array( 'value' => WC_Log_Levels::EMERGENCY, 'label' => __( 'Emergency', 'woocommerce' ) ),
array( 'value' => WC_Log_Levels::ALERT, 'label' => __( 'Alert', 'woocommerce' ) ),
array( 'value' => WC_Log_Levels::CRITICAL, 'label' => __( 'Critical', 'woocommerce' ) ),
array( 'value' => WC_Log_Levels::ERROR, 'label' => __( 'Error', 'woocommerce' ) ),
array( 'value' => WC_Log_Levels::WARNING, 'label' => __( 'Warning', 'woocommerce' ) ),
array( 'value' => WC_Log_Levels::NOTICE, 'label' => __( 'Notice', 'woocommerce' ) ),
array( 'value' => WC_Log_Levels::INFO, 'label' => __( 'Info', 'woocommerce' ) ),
array( 'value' => WC_Log_Levels::DEBUG, 'label' => __( 'Debug', 'woocommerce' ) ),
array(
'value' => WC_Log_Levels::EMERGENCY,
'label' => __( 'Emergency', 'woocommerce' ),
),
array(
'value' => WC_Log_Levels::ALERT,
'label' => __( 'Alert', 'woocommerce' ),
),
array(
'value' => WC_Log_Levels::CRITICAL,
'label' => __( 'Critical', 'woocommerce' ),
),
array(
'value' => WC_Log_Levels::ERROR,
'label' => __( 'Error', 'woocommerce' ),
),
array(
'value' => WC_Log_Levels::WARNING,
'label' => __( 'Warning', 'woocommerce' ),
),
array(
'value' => WC_Log_Levels::NOTICE,
'label' => __( 'Notice', 'woocommerce' ),
),
array(
'value' => WC_Log_Levels::INFO,
'label' => __( 'Info', 'woocommerce' ),
),
array(
'value' => WC_Log_Levels::DEBUG,
'label' => __( 'Debug', 'woocommerce' ),
),
);
$selected_level = isset( $_REQUEST['level'] ) ? $_REQUEST['level'] : '';
@ -52,13 +78,16 @@ class WC_Admin_Log_Table_List extends WP_List_Table {
<label for="filter-by-level" class="screen-reader-text"><?php _e( 'Filter by level', 'woocommerce' ); ?></label>
<select name="level" id="filter-by-level">
<option<?php selected( $selected_level, '' ); ?> value=""><?php _e( 'All levels', 'woocommerce' ); ?></option>
<?php foreach ( $levels as $l ) {
printf( '<option%1$s value="%2$s">%3$s</option>',
<?php
foreach ( $levels as $l ) {
printf(
'<option%1$s value="%2$s">%3$s</option>',
selected( $selected_level, $l['value'], false ),
esc_attr( $l['value'] ),
esc_html( $l['label'] )
);
} ?>
}
?>
</select>
<?php
}
@ -72,9 +101,9 @@ class WC_Admin_Log_Table_List extends WP_List_Table {
return array(
'cb' => '<input type="checkbox" />',
'timestamp' => __( 'Timestamp', 'woocommerce' ),
'level' => __( 'Level', 'woocommerce' ),
'message' => __( 'Message', 'woocommerce' ),
'source' => __( 'Source', 'woocommerce' ),
'level' => __( 'Level', 'woocommerce' ),
'message' => __( 'Message', 'woocommerce' ),
'source' => __( 'Source', 'woocommerce' ),
);
}
@ -95,10 +124,12 @@ class WC_Admin_Log_Table_List extends WP_List_Table {
* @return string
*/
public function column_timestamp( $log ) {
return esc_html( mysql2date(
get_option( 'date_format' ) . ' ' . get_option( 'time_format' ),
$log['timestamp']
) );
return esc_html(
mysql2date(
get_option( 'date_format' ) . ' ' . get_option( 'time_format' ),
$log['timestamp']
)
);
}
/**
@ -111,17 +142,17 @@ class WC_Admin_Log_Table_List extends WP_List_Table {
$level_key = WC_Log_Levels::get_severity_level( $log['level'] );
$levels = array(
'emergency' => __( 'Emergency', 'woocommerce' ),
'alert' => __( 'Alert', 'woocommerce' ),
'critical' => __( 'Critical', 'woocommerce' ),
'error' => __( 'Error', 'woocommerce' ),
'warning' => __( 'Warning', 'woocommerce' ),
'notice' => __( 'Notice', 'woocommerce' ),
'info' => __( 'Info', 'woocommerce' ),
'debug' => __( 'Debug', 'woocommerce' ),
'alert' => __( 'Alert', 'woocommerce' ),
'critical' => __( 'Critical', 'woocommerce' ),
'error' => __( 'Error', 'woocommerce' ),
'warning' => __( 'Warning', 'woocommerce' ),
'notice' => __( 'Notice', 'woocommerce' ),
'info' => __( 'Info', 'woocommerce' ),
'debug' => __( 'Debug', 'woocommerce' ),
);
if ( isset( $levels[ $level_key ] ) ) {
$level = $levels[ $level_key ];
$level = $levels[ $level_key ];
$level_class = sanitize_html_class( 'log-level--' . $level_key );
return '<span class="log-level ' . $level_class . '">' . esc_html( $level ) . '</span>';
} else {
@ -183,8 +214,8 @@ class WC_Admin_Log_Table_List extends WP_List_Table {
protected function get_sortable_columns() {
return array(
'timestamp' => array( 'timestamp', true ),
'level' => array( 'level', true ),
'source' => array( 'source', true ),
'level' => array( 'level', true ),
'source' => array( 'source', true ),
);
}
@ -196,12 +227,12 @@ class WC_Admin_Log_Table_List extends WP_List_Table {
protected function source_dropdown() {
global $wpdb;
$sources = $wpdb->get_col( "
SELECT DISTINCT source
$sources = $wpdb->get_col(
"SELECT DISTINCT source
FROM {$wpdb->prefix}woocommerce_log
WHERE source != ''
ORDER BY source ASC
" );
ORDER BY source ASC"
);
if ( ! empty( $sources ) ) {
$selected_source = isset( $_REQUEST['source'] ) ? $_REQUEST['source'] : '';
@ -209,13 +240,16 @@ class WC_Admin_Log_Table_List extends WP_List_Table {
<label for="filter-by-source" class="screen-reader-text"><?php _e( 'Filter by source', 'woocommerce' ); ?></label>
<select name="source" id="filter-by-source">
<option<?php selected( $selected_source, '' ); ?> value=""><?php _e( 'All sources', 'woocommerce' ); ?></option>
<?php foreach ( $sources as $s ) {
printf( '<option%1$s value="%2$s">%3$s</option>',
<?php
foreach ( $sources as $s ) {
printf(
'<option%1$s value="%2$s">%3$s</option>',
selected( $selected_source, $s, false ),
esc_attr( $s ),
esc_html( $s )
);
} ?>
}
?>
</select>
<?php
}
@ -249,11 +283,13 @@ class WC_Admin_Log_Table_List extends WP_List_Table {
$query_count = "SELECT COUNT(log_id) FROM {$wpdb->prefix}woocommerce_log {$where}";
$total_items = $wpdb->get_var( $query_count );
$this->set_pagination_args( array(
'total_items' => $total_items,
'per_page' => $per_page,
'total_pages' => ceil( $total_items / $per_page ),
) );
$this->set_pagination_args(
array(
'total_items' => $total_items,
'per_page' => $per_page,
'total_pages' => ceil( $total_items / $per_page ),
)
);
}
/**
@ -280,7 +316,7 @@ class WC_Admin_Log_Table_List extends WP_List_Table {
protected function get_items_query_offset() {
global $wpdb;
$per_page = $this->get_items_per_page( 'woocommerce_status_log_items_per_page', 10 );
$per_page = $this->get_items_per_page( 'woocommerce_status_log_items_per_page', 10 );
$current_page = $this->get_pagenum();
if ( 1 < $current_page ) {
$offset = $per_page * ( $current_page - 1 );

View File

@ -353,12 +353,14 @@ class WC_Admin_Menus {
}
// Add an option to visit the store.
$wp_admin_bar->add_node( array(
'parent' => 'site-name',
'id' => 'view-store',
'title' => __( 'Visit Store', 'woocommerce' ),
'href' => wc_get_page_permalink( 'shop' ),
) );
$wp_admin_bar->add_node(
array(
'parent' => 'site-name',
'id' => 'view-store',
'title' => __( 'Visit Store', 'woocommerce' ),
'href' => wc_get_page_permalink( 'shop' ),
)
);
}
}

View File

@ -31,7 +31,7 @@ class WC_Admin_Meta_Boxes {
*
* @var array
*/
public static $meta_box_errors = array();
public static $meta_box_errors = array();
/**
* Constructor.
@ -74,6 +74,7 @@ class WC_Admin_Meta_Boxes {
/**
* Add an error message.
*
* @param string $text
*/
public static function add_error( $text ) {
@ -177,7 +178,7 @@ class WC_Admin_Meta_Boxes {
/**
* Check if we're saving, the trigger an action based on the post type.
*
* @param int $post_id
* @param int $post_id
* @param object $post
*/
public function save_meta_boxes( $post_id, $post ) {

View File

@ -19,12 +19,14 @@ class WC_Admin_Notices {
/**
* Stores notices.
*
* @var array
*/
private static $notices = array();
/**
* Array of notices - name => callback.
*
* @var array
*/
private static $core_notices = array(
@ -62,6 +64,7 @@ class WC_Admin_Notices {
/**
* Get notices
*
* @return array
*/
public static function get_notices() {
@ -91,6 +94,7 @@ class WC_Admin_Notices {
/**
* Show a notice.
*
* @param string $name
*/
public static function add_notice( $name ) {
@ -99,6 +103,7 @@ class WC_Admin_Notices {
/**
* Remove a notice from being displayed.
*
* @param string $name
*/
public static function remove_notice( $name ) {
@ -108,7 +113,8 @@ class WC_Admin_Notices {
/**
* See if a notice is being shown.
* @param string $name
*
* @param string $name
* @return boolean
*/
public static function has_notice( $name ) {
@ -162,6 +168,7 @@ class WC_Admin_Notices {
/**
* Add a custom notice.
*
* @param string $name
* @param string $notice_html
*/
@ -182,7 +189,7 @@ class WC_Admin_Notices {
$notice_html = get_option( 'woocommerce_admin_notice_' . $notice );
if ( $notice_html ) {
include( 'views/html-notice-custom.php' );
include 'views/html-notice-custom.php';
}
}
}
@ -196,12 +203,12 @@ class WC_Admin_Notices {
if ( version_compare( get_option( 'woocommerce_db_version' ), WC_VERSION, '<' ) ) {
$updater = new WC_Background_Updater();
if ( $updater->is_updating() || ! empty( $_GET['do_update_woocommerce'] ) ) {
include( 'views/html-notice-updating.php' );
include 'views/html-notice-updating.php';
} else {
include( 'views/html-notice-update.php' );
include 'views/html-notice-update.php';
}
} else {
include( 'views/html-notice-updated.php' );
include 'views/html-notice-updated.php';
}
}
@ -209,7 +216,7 @@ class WC_Admin_Notices {
* If we have just installed, show a message with the install pages button.
*/
public static function install_notice() {
include( 'views/html-notice-install.php' );
include 'views/html-notice-install.php';
}
/**
@ -221,7 +228,7 @@ class WC_Admin_Notices {
wc_deprecated_function( 'WC_Admin_Notices::theme_check_notice', '3.3.0' );
if ( ! current_theme_supports( 'woocommerce' ) ) {
include( 'views/html-notice-theme-support.php' );
include 'views/html-notice-theme-support.php';
}
}
@ -257,7 +264,7 @@ class WC_Admin_Notices {
}
if ( $outdated ) {
include( 'views/html-notice-template-check.php' );
include 'views/html-notice-template-check.php';
} else {
self::remove_notice( 'template_files' );
}
@ -278,7 +285,7 @@ class WC_Admin_Notices {
}
if ( $enabled ) {
include( 'views/html-notice-legacy-shipping.php' );
include 'views/html-notice-legacy-shipping.php';
} else {
self::remove_notice( 'template_files' );
}
@ -293,7 +300,7 @@ class WC_Admin_Notices {
$method_count = wc_get_shipping_method_count();
if ( $product_count->publish > 0 && 0 === $method_count ) {
include( 'views/html-notice-no-shipping-methods.php' );
include 'views/html-notice-no-shipping-methods.php';
}
if ( $method_count > 0 ) {
@ -313,7 +320,7 @@ class WC_Admin_Notices {
return;
}
if ( empty( $_GET['action'] ) ) {
include( 'views/html-notice-simplify-commerce.php' );
include 'views/html-notice-simplify-commerce.php';
}
}
@ -321,7 +328,7 @@ class WC_Admin_Notices {
* Notice shown when regenerating thumbnails background process is running.
*/
public static function regenerating_thumbnails_notice() {
include( 'views/html-notice-regenerating-thumbnails.php' );
include 'views/html-notice-regenerating-thumbnails.php';
}
}

View File

@ -73,7 +73,7 @@ class WC_Admin_Permalink_Settings {
*/
public function product_category_slug_input() {
?>
<input name="woocommerce_product_category_slug" type="text" class="regular-text code" value="<?php echo esc_attr( $this->permalinks['category_base'] ); ?>" placeholder="<?php echo esc_attr_x( 'product-category', 'slug', 'woocommerce' ) ?>" />
<input name="woocommerce_product_category_slug" type="text" class="regular-text code" value="<?php echo esc_attr( $this->permalinks['category_base'] ); ?>" placeholder="<?php echo esc_attr_x( 'product-category', 'slug', 'woocommerce' ); ?>" />
<?php
}
@ -82,7 +82,7 @@ class WC_Admin_Permalink_Settings {
*/
public function product_tag_slug_input() {
?>
<input name="woocommerce_product_tag_slug" type="text" class="regular-text code" value="<?php echo esc_attr( $this->permalinks['tag_base'] ); ?>" placeholder="<?php echo esc_attr_x( 'product-tag', 'slug', 'woocommerce' ) ?>" />
<input name="woocommerce_product_tag_slug" type="text" class="regular-text code" value="<?php echo esc_attr( $this->permalinks['tag_base'] ); ?>" placeholder="<?php echo esc_attr_x( 'product-tag', 'slug', 'woocommerce' ); ?>" />
<?php
}
@ -102,9 +102,9 @@ class WC_Admin_Permalink_Settings {
/* translators: %s: Home URL */
echo wp_kses_post( wpautop( sprintf( __( 'If you like, you may enter custom structures for your product URLs here. For example, using <code>shop</code> would make your product links like <code>%sshop/sample-product/</code>. This setting affects product URLs only, not things such as product categories.', 'woocommerce' ), esc_url( home_url( '/' ) ) ) ) );
$shop_page_id = wc_get_page_id( 'shop' );
$base_slug = urldecode( ( $shop_page_id > 0 && get_post( $shop_page_id ) ) ? get_page_uri( $shop_page_id ) : _x( 'shop', 'default-slug', 'woocommerce' ) );
$product_base = _x( 'product', 'default-slug', 'woocommerce' );
$shop_page_id = wc_get_page_id( 'shop' );
$base_slug = urldecode( ( $shop_page_id > 0 && get_post( $shop_page_id ) ) ? get_page_uri( $shop_page_id ) : _x( 'shop', 'default-slug', 'woocommerce' ) );
$product_base = _x( 'product', 'default-slug', 'woocommerce' );
$structures = array(
0 => '',

View File

@ -33,9 +33,9 @@ class WC_Admin_Pointers {
}
switch ( $screen->id ) {
case 'product' :
case 'product':
$this->create_product_tutorial();
break;
break;
}
}
@ -49,8 +49,8 @@ class WC_Admin_Pointers {
// These pointers will chain - they will not be shown at once.
$pointers = array(
'pointers' => array(
'title' => array(
'target' => "#title",
'title' => array(
'target' => '#title',
'next' => 'content',
'next_trigger' => array(
'target' => '#title',
@ -65,8 +65,8 @@ class WC_Admin_Pointers {
),
),
),
'content' => array(
'target' => "#wp-content-editor-container",
'content' => array(
'target' => '#wp-content-editor-container',
'next' => 'product-type',
'next_trigger' => array(),
'options' => array(
@ -78,14 +78,14 @@ class WC_Admin_Pointers {
),
),
),
'product-type' => array(
'target' => "#product-type",
'product-type' => array(
'target' => '#product-type',
'next' => 'virtual',
'next_trigger' => array(
'target' => "#product-type",
'target' => '#product-type',
'event' => 'change blur click',
),
'options' => array(
'options' => array(
'content' => '<h3>' . esc_html__( 'Choose product type', 'woocommerce' ) . '</h3>' .
'<p>' . esc_html__( 'Choose a type for this product. Simple is suitable for most physical goods and services (we recommend setting up a simple product for now).', 'woocommerce' ) . '</p>' .
'<p>' . esc_html__( 'Variable is for more complex products such as t-shirts with multiple sizes.', 'woocommerce' ) . '</p>' .
@ -97,14 +97,14 @@ class WC_Admin_Pointers {
),
),
),
'virtual' => array(
'target' => "#_virtual",
'virtual' => array(
'target' => '#_virtual',
'next' => 'downloadable',
'next_trigger' => array(
'target' => "#_virtual",
'target' => '#_virtual',
'event' => 'change',
),
'options' => array(
'options' => array(
'content' => '<h3>' . esc_html__( 'Virtual products', 'woocommerce' ) . '</h3>' .
'<p>' . esc_html__( 'Check the "Virtual" box if this is a non-physical item, for example a service, which does not need shipping.', 'woocommerce' ) . '</p>',
'position' => array(
@ -113,14 +113,14 @@ class WC_Admin_Pointers {
),
),
),
'downloadable' => array(
'target' => "#_downloadable",
'downloadable' => array(
'target' => '#_downloadable',
'next' => 'regular_price',
'next_trigger' => array(
'target' => "#_downloadable",
'target' => '#_downloadable',
'event' => 'change',
),
'options' => array(
'options' => array(
'content' => '<h3>' . esc_html__( 'Downloadable products', 'woocommerce' ) . '</h3>' .
'<p>' . esc_html__( 'If purchasing this product gives a customer access to a downloadable file, e.g. software, check this box.', 'woocommerce' ) . '</p>',
'position' => array(
@ -129,14 +129,14 @@ class WC_Admin_Pointers {
),
),
),
'regular_price' => array(
'target' => "#_regular_price",
'regular_price' => array(
'target' => '#_regular_price',
'next' => 'postexcerpt',
'next_trigger' => array(
'target' => "#_regular_price",
'target' => '#_regular_price',
'event' => 'input',
),
'options' => array(
'options' => array(
'content' => '<h3>' . esc_html__( 'Prices', 'woocommerce' ) . '</h3>' .
'<p>' . esc_html__( 'Next you need to give your product a price.', 'woocommerce' ) . '</p>',
'position' => array(
@ -145,14 +145,14 @@ class WC_Admin_Pointers {
),
),
),
'postexcerpt' => array(
'target' => "#postexcerpt",
'postexcerpt' => array(
'target' => '#postexcerpt',
'next' => 'postimagediv',
'next_trigger' => array(
'target' => "#postexcerpt",
'target' => '#postexcerpt',
'event' => 'input',
),
'options' => array(
'options' => array(
'content' => '<h3>' . esc_html__( 'Product short description', 'woocommerce' ) . '</h3>' .
'<p>' . esc_html__( 'Add a quick summary for your product here. This will appear on the product page under the product name.', 'woocommerce' ) . '</p>',
'position' => array(
@ -161,9 +161,9 @@ class WC_Admin_Pointers {
),
),
),
'postimagediv' => array(
'target' => "#postimagediv",
'next' => 'product_tag',
'postimagediv' => array(
'target' => '#postimagediv',
'next' => 'product_tag',
'options' => array(
'content' => '<h3>' . esc_html__( 'Product images', 'woocommerce' ) . '</h3>' .
'<p>' . esc_html__( "Upload or assign an image to your product here. This image will be shown in your store's catalog.", 'woocommerce' ) . '</p>',
@ -173,9 +173,9 @@ class WC_Admin_Pointers {
),
),
),
'product_tag' => array(
'target' => "#tagsdiv-product_tag",
'next' => 'product_catdiv',
'product_tag' => array(
'target' => '#tagsdiv-product_tag',
'next' => 'product_catdiv',
'options' => array(
'content' => '<h3>' . esc_html__( 'Product tags', 'woocommerce' ) . '</h3>' .
'<p>' . esc_html__( 'You can optionally "tag" your products here. Tags are a method of labeling your products to make them easier for customers to find.', 'woocommerce' ) . '</p>',
@ -186,8 +186,8 @@ class WC_Admin_Pointers {
),
),
'product_catdiv' => array(
'target' => "#product_catdiv",
'next' => 'submitdiv',
'target' => '#product_catdiv',
'next' => 'submitdiv',
'options' => array(
'content' => '<h3>' . esc_html__( 'Product categories', 'woocommerce' ) . '</h3>' .
'<p>' . esc_html__( 'Optionally assign categories to your products to make them easier to browse through and find in your store.', 'woocommerce' ) . '</p>',
@ -197,9 +197,9 @@ class WC_Admin_Pointers {
),
),
),
'submitdiv' => array(
'target' => "#submitdiv",
'next' => '',
'submitdiv' => array(
'target' => '#submitdiv',
'next' => '',
'options' => array(
'content' => '<h3>' . esc_html__( 'Publish your product!', 'woocommerce' ) . '</h3>' .
'<p>' . esc_html__( 'When you are finished editing your product, hit the "Publish" button to publish your product to your store.', 'woocommerce' ) . '</p>',
@ -217,14 +217,15 @@ class WC_Admin_Pointers {
/**
* Enqueue pointers and add script to page.
*
* @param array $pointers
*/
public function enqueue_pointers( $pointers ) {
$pointers = wp_json_encode( $pointers );
wp_enqueue_style( 'wp-pointer' );
wp_enqueue_script( 'wp-pointer' );
wc_enqueue_js( "
jQuery( function( $ ) {
wc_enqueue_js(
"jQuery( function( $ ) {
var wc_pointers = {$pointers};
setTimeout( init_wc_pointers, 800 );
@ -277,8 +278,8 @@ class WC_Admin_Pointers {
});
}
}
});
" );
});"
);
}
}

View File

@ -28,10 +28,10 @@ class WC_Admin_Post_Types {
* Constructor.
*/
public function __construct() {
include_once( dirname( __FILE__ ) . '/class-wc-admin-meta-boxes.php' );
include_once dirname( __FILE__ ) . '/class-wc-admin-meta-boxes.php';
if ( ! function_exists( 'duplicate_post_plugin_activation' ) ) {
include_once( 'class-wc-admin-duplicate-product.php' );
include_once 'class-wc-admin-duplicate-product.php';
}
// Load correct list table classes for current screen.
@ -65,7 +65,7 @@ class WC_Admin_Post_Types {
// Bulk / quick edit.
add_action( 'bulk_edit_custom_box', array( $this, 'bulk_edit' ), 10, 2 );
add_action( 'quick_edit_custom_box', array( $this, 'quick_edit' ), 10, 2 );
add_action( 'quick_edit_custom_box', array( $this, 'quick_edit' ), 10, 2 );
add_action( 'save_post', array( $this, 'bulk_and_quick_edit_hook' ), 10, 2 );
add_action( 'woocommerce_product_bulk_and_quick_edit', array( $this, 'bulk_and_quick_edit_save_post' ), 10, 2 );
}
@ -88,16 +88,16 @@ class WC_Admin_Post_Types {
}
switch ( $screen_id ) {
case 'edit-shop_order' :
include_once( 'list-tables/class-wc-admin-list-table-orders.php' );
case 'edit-shop_order':
include_once 'list-tables/class-wc-admin-list-table-orders.php';
new WC_Admin_List_Table_Orders();
break;
case 'edit-shop_coupon' :
include_once( 'list-tables/class-wc-admin-list-table-coupons.php' );
case 'edit-shop_coupon':
include_once 'list-tables/class-wc-admin-list-table-coupons.php';
new WC_Admin_List_Table_Coupons();
break;
case 'edit-product' :
include_once( 'list-tables/class-wc-admin-list-table-products.php' );
case 'edit-product':
include_once 'list-tables/class-wc-admin-list-table-products.php';
new WC_Admin_List_Table_Products();
break;
}
@ -117,18 +117,18 @@ class WC_Admin_Post_Types {
global $post;
$messages['product'] = array(
0 => '', // Unused. Messages start at index 1.
1 => sprintf( __( 'Product updated. <a href="%s">View Product</a>', 'woocommerce' ), esc_url( get_permalink( $post->ID ) ) ),
2 => __( 'Custom field updated.', 'woocommerce' ),
3 => __( 'Custom field deleted.', 'woocommerce' ),
4 => __( 'Product updated.', 'woocommerce' ),
5 => __( 'Revision restored.', 'woocommerce' ),
0 => '', // Unused. Messages start at index 1.
1 => sprintf( __( 'Product updated. <a href="%s">View Product</a>', 'woocommerce' ), esc_url( get_permalink( $post->ID ) ) ),
2 => __( 'Custom field updated.', 'woocommerce' ),
3 => __( 'Custom field deleted.', 'woocommerce' ),
4 => __( 'Product updated.', 'woocommerce' ),
5 => __( 'Revision restored.', 'woocommerce' ),
/* translators: %s: product url */
6 => sprintf( __( 'Product published. <a href="%s">View Product</a>', 'woocommerce' ), esc_url( get_permalink( $post->ID ) ) ),
7 => __( 'Product saved.', 'woocommerce' ),
6 => sprintf( __( 'Product published. <a href="%s">View Product</a>', 'woocommerce' ), esc_url( get_permalink( $post->ID ) ) ),
7 => __( 'Product saved.', 'woocommerce' ),
/* translators: %s: product url */
8 => sprintf( __( 'Product submitted. <a target="_blank" href="%s">Preview product</a>', 'woocommerce' ), esc_url( add_query_arg( 'preview', 'true', get_permalink( $post->ID ) ) ) ),
9 => sprintf(
8 => sprintf( __( 'Product submitted. <a target="_blank" href="%s">Preview product</a>', 'woocommerce' ), esc_url( add_query_arg( 'preview', 'true', get_permalink( $post->ID ) ) ) ),
9 => sprintf(
/* translators: 1: date 2: product url */
__( 'Product scheduled for: %1$s. <a target="_blank" href="%2$s">Preview product</a>', 'woocommerce' ),
'<strong>' . date_i18n( __( 'M j, Y @ G:i', 'woocommerce' ), strtotime( $post->post_date ) ), esc_url( get_permalink( $post->ID ) ) . '</strong>'
@ -138,16 +138,16 @@ class WC_Admin_Post_Types {
);
$messages['shop_order'] = array(
0 => '', // Unused. Messages start at index 1.
1 => __( 'Order updated.', 'woocommerce' ),
2 => __( 'Custom field updated.', 'woocommerce' ),
3 => __( 'Custom field deleted.', 'woocommerce' ),
4 => __( 'Order updated.', 'woocommerce' ),
5 => __( 'Revision restored.', 'woocommerce' ),
6 => __( 'Order updated.', 'woocommerce' ),
7 => __( 'Order saved.', 'woocommerce' ),
8 => __( 'Order submitted.', 'woocommerce' ),
9 => sprintf(
0 => '', // Unused. Messages start at index 1.
1 => __( 'Order updated.', 'woocommerce' ),
2 => __( 'Custom field updated.', 'woocommerce' ),
3 => __( 'Custom field deleted.', 'woocommerce' ),
4 => __( 'Order updated.', 'woocommerce' ),
5 => __( 'Revision restored.', 'woocommerce' ),
6 => __( 'Order updated.', 'woocommerce' ),
7 => __( 'Order saved.', 'woocommerce' ),
8 => __( 'Order submitted.', 'woocommerce' ),
9 => sprintf(
/* translators: %s: date */
__( 'Order scheduled for: %s.', 'woocommerce' ),
'<strong>' . date_i18n( __( 'M j, Y @ G:i', 'woocommerce' ), strtotime( $post->post_date ) ) . '</strong>'
@ -157,16 +157,16 @@ class WC_Admin_Post_Types {
);
$messages['shop_coupon'] = array(
0 => '', // Unused. Messages start at index 1.
1 => __( 'Coupon updated.', 'woocommerce' ),
2 => __( 'Custom field updated.', 'woocommerce' ),
3 => __( 'Custom field deleted.', 'woocommerce' ),
4 => __( 'Coupon updated.', 'woocommerce' ),
5 => __( 'Revision restored.', 'woocommerce' ),
6 => __( 'Coupon updated.', 'woocommerce' ),
7 => __( 'Coupon saved.', 'woocommerce' ),
8 => __( 'Coupon submitted.', 'woocommerce' ),
9 => sprintf(
0 => '', // Unused. Messages start at index 1.
1 => __( 'Coupon updated.', 'woocommerce' ),
2 => __( 'Custom field updated.', 'woocommerce' ),
3 => __( 'Custom field deleted.', 'woocommerce' ),
4 => __( 'Coupon updated.', 'woocommerce' ),
5 => __( 'Revision restored.', 'woocommerce' ),
6 => __( 'Coupon updated.', 'woocommerce' ),
7 => __( 'Coupon saved.', 'woocommerce' ),
8 => __( 'Coupon submitted.', 'woocommerce' ),
9 => sprintf(
/* translators: %s: date */
__( 'Coupon scheduled for: %s.', 'woocommerce' ),
'<strong>' . date_i18n( __( 'M j, Y @ G:i', 'woocommerce' ), strtotime( $post->post_date ) ) . '</strong>'
@ -238,11 +238,13 @@ class WC_Admin_Post_Types {
return;
}
$shipping_class = get_terms( 'product_shipping_class', array(
'hide_empty' => false,
) );
$shipping_class = get_terms(
'product_shipping_class', array(
'hide_empty' => false,
)
);
include( WC()->plugin_path() . '/includes/admin/views/html-bulk-edit-product.php' );
include WC()->plugin_path() . '/includes/admin/views/html-bulk-edit-product.php';
}
/**
@ -256,11 +258,13 @@ class WC_Admin_Post_Types {
return;
}
$shipping_class = get_terms( 'product_shipping_class', array(
'hide_empty' => false,
) );
$shipping_class = get_terms(
'product_shipping_class', array(
'hide_empty' => false,
)
);
include( WC()->plugin_path() . '/includes/admin/views/html-quick-edit-product.php' );
include WC()->plugin_path() . '/includes/admin/views/html-quick-edit-product.php';
}
/**
@ -497,7 +501,7 @@ class WC_Admin_Post_Types {
}
// Handle price - remove dates and set to lowest.
$change_price_product_types = apply_filters( 'woocommerce_bulk_edit_save_price_product_types', array( 'simple', 'external' ) );
$change_price_product_types = apply_filters( 'woocommerce_bulk_edit_save_price_product_types', array( 'simple', 'external' ) );
$can_product_type_change_price = false;
foreach ( $change_price_product_types as $product_type ) {
if ( $product->is_type( $product_type ) ) {
@ -521,7 +525,7 @@ class WC_Admin_Post_Types {
break;
case 2:
if ( $is_percentage ) {
$percent = $regular_price / 100;
$percent = $regular_price / 100;
$new_price = $old_regular_price + ( round( $old_regular_price * $percent, wc_get_price_decimals() ) );
} else {
$new_price = $old_regular_price + $regular_price;
@ -529,7 +533,7 @@ class WC_Admin_Post_Types {
break;
case 3:
if ( $is_percentage ) {
$percent = $regular_price / 100;
$percent = $regular_price / 100;
$new_price = max( 0, $old_regular_price - ( round( $old_regular_price * $percent, wc_get_price_decimals() ) ) );
} else {
$new_price = max( 0, $old_regular_price - $regular_price );
@ -542,7 +546,7 @@ class WC_Admin_Post_Types {
if ( isset( $new_price ) && $new_price !== $old_regular_price ) {
$price_changed = true;
$new_price = round( $new_price, wc_get_price_decimals() );
$new_price = round( $new_price, wc_get_price_decimals() );
$product->set_regular_price( $new_price );
}
}
@ -559,7 +563,7 @@ class WC_Admin_Post_Types {
break;
case 2:
if ( $is_percentage ) {
$percent = $sale_price / 100;
$percent = $sale_price / 100;
$new_price = $old_sale_price + ( $old_sale_price * $percent );
} else {
$new_price = $old_sale_price + $sale_price;
@ -567,7 +571,7 @@ class WC_Admin_Post_Types {
break;
case 3:
if ( $is_percentage ) {
$percent = $sale_price / 100;
$percent = $sale_price / 100;
$new_price = max( 0, $old_sale_price - ( $old_sale_price * $percent ) );
} else {
$new_price = max( 0, $old_sale_price - $sale_price );
@ -575,7 +579,7 @@ class WC_Admin_Post_Types {
break;
case 4:
if ( $is_percentage ) {
$percent = $sale_price / 100;
$percent = $sale_price / 100;
$new_price = max( 0, $product->regular_price - ( $product->regular_price * $percent ) );
} else {
$new_price = max( 0, $product->regular_price - $sale_price );
@ -588,7 +592,7 @@ class WC_Admin_Post_Types {
if ( isset( $new_price ) && $new_price !== $old_sale_price ) {
$price_changed = true;
$new_price = ! empty( $new_price ) || '0' === $new_price ? round( $new_price, wc_get_price_decimals() ) : '';
$new_price = ! empty( $new_price ) || '0' === $new_price ? round( $new_price, wc_get_price_decimals() ) : '';
$product->set_sale_price( $new_price );
}
}
@ -732,14 +736,17 @@ class WC_Admin_Post_Types {
$visibility_options = wc_get_product_visibility_options();
?>
<div class="misc-pub-section" id="catalog-visibility">
<?php esc_html_e( 'Catalog visibility:', 'woocommerce' ); ?> <strong id="catalog-visibility-display"><?php
<?php esc_html_e( 'Catalog visibility:', 'woocommerce' ); ?>
<strong id="catalog-visibility-display">
<?php
echo isset( $visibility_options[ $current_visibility ] ) ? esc_html( $visibility_options[ $current_visibility ] ) : esc_html( $current_visibility );
echo isset( $visibility_options[ $current_visibility ] ) ? esc_html( $visibility_options[ $current_visibility ] ) : esc_html( $current_visibility );
if ( 'yes' === $current_featured ) {
echo ', ' . esc_html__( 'Featured', 'woocommerce' );
}
?></strong>
if ( 'yes' === $current_featured ) {
echo ', ' . esc_html__( 'Featured', 'woocommerce' );
}
?>
</strong>
<a href="#catalog-visibility" class="edit-catalog-visibility hide-if-no-js"><?php esc_html_e( 'Edit', 'woocommerce' ); ?></a>

View File

@ -14,229 +14,230 @@ if ( ! defined( 'ABSPATH' ) ) {
if ( ! class_exists( 'WC_Admin_Profile', false ) ) :
/**
* WC_Admin_Profile Class.
*/
class WC_Admin_Profile {
/**
* Hook in tabs.
* WC_Admin_Profile Class.
*/
public function __construct() {
add_action( 'show_user_profile', array( $this, 'add_customer_meta_fields' ) );
add_action( 'edit_user_profile', array( $this, 'add_customer_meta_fields' ) );
class WC_Admin_Profile {
add_action( 'personal_options_update', array( $this, 'save_customer_meta_fields' ) );
add_action( 'edit_user_profile_update', array( $this, 'save_customer_meta_fields' ) );
}
/**
* Hook in tabs.
*/
public function __construct() {
add_action( 'show_user_profile', array( $this, 'add_customer_meta_fields' ) );
add_action( 'edit_user_profile', array( $this, 'add_customer_meta_fields' ) );
/**
* Get Address Fields for the edit user pages.
*
* @return array Fields to display which are filtered through woocommerce_customer_meta_fields before being returned
*/
public function get_customer_meta_fields() {
$show_fields = apply_filters('woocommerce_customer_meta_fields', array(
'billing' => array(
'title' => __( 'Customer billing address', 'woocommerce' ),
'fields' => array(
'billing_first_name' => array(
'label' => __( 'First name', 'woocommerce' ),
'description' => '',
),
'billing_last_name' => array(
'label' => __( 'Last name', 'woocommerce' ),
'description' => '',
),
'billing_company' => array(
'label' => __( 'Company', 'woocommerce' ),
'description' => '',
),
'billing_address_1' => array(
'label' => __( 'Address line 1', 'woocommerce' ),
'description' => '',
),
'billing_address_2' => array(
'label' => __( 'Address line 2', 'woocommerce' ),
'description' => '',
),
'billing_city' => array(
'label' => __( 'City', 'woocommerce' ),
'description' => '',
),
'billing_postcode' => array(
'label' => __( 'Postcode / ZIP', 'woocommerce' ),
'description' => '',
),
'billing_country' => array(
'label' => __( 'Country', 'woocommerce' ),
'description' => '',
'class' => 'js_field-country',
'type' => 'select',
'options' => array( '' => __( 'Select a country&hellip;', 'woocommerce' ) ) + WC()->countries->get_allowed_countries(),
),
'billing_state' => array(
'label' => __( 'State / County', 'woocommerce' ),
'description' => __( 'State / County or state code', 'woocommerce' ),
'class' => 'js_field-state',
),
'billing_phone' => array(
'label' => __( 'Phone', 'woocommerce' ),
'description' => '',
),
'billing_email' => array(
'label' => __( 'Email address', 'woocommerce' ),
'description' => '',
),
),
),
'shipping' => array(
'title' => __( 'Customer shipping address', 'woocommerce' ),
'fields' => array(
'copy_billing' => array(
'label' => __( 'Copy from billing address', 'woocommerce' ),
'description' => '',
'class' => 'js_copy-billing',
'type' => 'button',
'text' => __( 'Copy', 'woocommerce' ),
),
'shipping_first_name' => array(
'label' => __( 'First name', 'woocommerce' ),
'description' => '',
),
'shipping_last_name' => array(
'label' => __( 'Last name', 'woocommerce' ),
'description' => '',
),
'shipping_company' => array(
'label' => __( 'Company', 'woocommerce' ),
'description' => '',
),
'shipping_address_1' => array(
'label' => __( 'Address line 1', 'woocommerce' ),
'description' => '',
),
'shipping_address_2' => array(
'label' => __( 'Address line 2', 'woocommerce' ),
'description' => '',
),
'shipping_city' => array(
'label' => __( 'City', 'woocommerce' ),
'description' => '',
),
'shipping_postcode' => array(
'label' => __( 'Postcode / ZIP', 'woocommerce' ),
'description' => '',
),
'shipping_country' => array(
'label' => __( 'Country', 'woocommerce' ),
'description' => '',
'class' => 'js_field-country',
'type' => 'select',
'options' => array( '' => __( 'Select a country&hellip;', 'woocommerce' ) ) + WC()->countries->get_allowed_countries(),
),
'shipping_state' => array(
'label' => __( 'State / County', 'woocommerce' ),
'description' => __( 'State / County or state code', 'woocommerce' ),
'class' => 'js_field-state',
),
),
),
) );
return $show_fields;
}
/**
* Show Address Fields on edit user pages.
*
* @param WP_User $user
*/
public function add_customer_meta_fields( $user ) {
if ( ! current_user_can( 'manage_woocommerce' ) ) {
return;
add_action( 'personal_options_update', array( $this, 'save_customer_meta_fields' ) );
add_action( 'edit_user_profile_update', array( $this, 'save_customer_meta_fields' ) );
}
$show_fields = $this->get_customer_meta_fields();
/**
* Get Address Fields for the edit user pages.
*
* @return array Fields to display which are filtered through woocommerce_customer_meta_fields before being returned
*/
public function get_customer_meta_fields() {
$show_fields = apply_filters(
'woocommerce_customer_meta_fields', array(
'billing' => array(
'title' => __( 'Customer billing address', 'woocommerce' ),
'fields' => array(
'billing_first_name' => array(
'label' => __( 'First name', 'woocommerce' ),
'description' => '',
),
'billing_last_name' => array(
'label' => __( 'Last name', 'woocommerce' ),
'description' => '',
),
'billing_company' => array(
'label' => __( 'Company', 'woocommerce' ),
'description' => '',
),
'billing_address_1' => array(
'label' => __( 'Address line 1', 'woocommerce' ),
'description' => '',
),
'billing_address_2' => array(
'label' => __( 'Address line 2', 'woocommerce' ),
'description' => '',
),
'billing_city' => array(
'label' => __( 'City', 'woocommerce' ),
'description' => '',
),
'billing_postcode' => array(
'label' => __( 'Postcode / ZIP', 'woocommerce' ),
'description' => '',
),
'billing_country' => array(
'label' => __( 'Country', 'woocommerce' ),
'description' => '',
'class' => 'js_field-country',
'type' => 'select',
'options' => array( '' => __( 'Select a country&hellip;', 'woocommerce' ) ) + WC()->countries->get_allowed_countries(),
),
'billing_state' => array(
'label' => __( 'State / County', 'woocommerce' ),
'description' => __( 'State / County or state code', 'woocommerce' ),
'class' => 'js_field-state',
),
'billing_phone' => array(
'label' => __( 'Phone', 'woocommerce' ),
'description' => '',
),
'billing_email' => array(
'label' => __( 'Email address', 'woocommerce' ),
'description' => '',
),
),
),
'shipping' => array(
'title' => __( 'Customer shipping address', 'woocommerce' ),
'fields' => array(
'copy_billing' => array(
'label' => __( 'Copy from billing address', 'woocommerce' ),
'description' => '',
'class' => 'js_copy-billing',
'type' => 'button',
'text' => __( 'Copy', 'woocommerce' ),
),
'shipping_first_name' => array(
'label' => __( 'First name', 'woocommerce' ),
'description' => '',
),
'shipping_last_name' => array(
'label' => __( 'Last name', 'woocommerce' ),
'description' => '',
),
'shipping_company' => array(
'label' => __( 'Company', 'woocommerce' ),
'description' => '',
),
'shipping_address_1' => array(
'label' => __( 'Address line 1', 'woocommerce' ),
'description' => '',
),
'shipping_address_2' => array(
'label' => __( 'Address line 2', 'woocommerce' ),
'description' => '',
),
'shipping_city' => array(
'label' => __( 'City', 'woocommerce' ),
'description' => '',
),
'shipping_postcode' => array(
'label' => __( 'Postcode / ZIP', 'woocommerce' ),
'description' => '',
),
'shipping_country' => array(
'label' => __( 'Country', 'woocommerce' ),
'description' => '',
'class' => 'js_field-country',
'type' => 'select',
'options' => array( '' => __( 'Select a country&hellip;', 'woocommerce' ) ) + WC()->countries->get_allowed_countries(),
),
'shipping_state' => array(
'label' => __( 'State / County', 'woocommerce' ),
'description' => __( 'State / County or state code', 'woocommerce' ),
'class' => 'js_field-state',
),
),
),
)
);
return $show_fields;
}
foreach ( $show_fields as $fieldset_key => $fieldset ) :
?>
<h2><?php echo $fieldset['title']; ?></h2>
<table class="form-table" id="<?php echo esc_attr( 'fieldset-' . $fieldset_key ); ?>">
<?php
foreach ( $fieldset['fields'] as $key => $field ) :
?>
<tr>
<th><label for="<?php echo esc_attr( $key ); ?>"><?php echo esc_html( $field['label'] ); ?></label></th>
<td>
<?php if ( ! empty( $field['type'] ) && 'select' === $field['type'] ) : ?>
<select name="<?php echo esc_attr( $key ); ?>" id="<?php echo esc_attr( $key ); ?>" class="<?php echo esc_attr( $field['class'] ); ?>" style="width: 25em;">
<?php
$selected = esc_attr( get_user_meta( $user->ID, $key, true ) );
foreach ( $field['options'] as $option_key => $option_value ) : ?>
<option value="<?php echo esc_attr( $option_key ); ?>" <?php selected( $selected, $option_key, true ); ?>><?php echo esc_attr( $option_value ); ?></option>
<?php endforeach; ?>
</select>
<?php elseif ( ! empty( $field['type'] ) && 'checkbox' === $field['type'] ) : ?>
<input type="checkbox" name="<?php echo esc_attr( $key ); ?>" id="<?php echo esc_attr( $key ); ?>" value="1" class="<?php echo esc_attr( $field['class'] ); ?>" <?php checked( (int) get_user_meta( $user->ID, $key, true ), 1, true ); ?> />
<?php elseif ( ! empty( $field['type'] ) && 'button' === $field['type'] ) : ?>
<button type="button" id="<?php echo esc_attr( $key ); ?>" class="button <?php echo esc_attr( $field['class'] ); ?>"><?php echo esc_html( $field['text'] ); ?></button>
<?php else : ?>
<input type="text" name="<?php echo esc_attr( $key ); ?>" id="<?php echo esc_attr( $key ); ?>" value="<?php echo esc_attr( $this->get_user_meta( $user->ID, $key ) ); ?>" class="<?php echo ( ! empty( $field['class'] ) ? esc_attr( $field['class'] ) : 'regular-text' ); ?>" />
<?php endif; ?>
<br/>
<span class="description"><?php echo wp_kses_post( $field['description'] ); ?></span>
</td>
</tr>
<?php
endforeach;
/**
* Show Address Fields on edit user pages.
*
* @param WP_User $user
*/
public function add_customer_meta_fields( $user ) {
if ( ! current_user_can( 'manage_woocommerce' ) ) {
return;
}
$show_fields = $this->get_customer_meta_fields();
foreach ( $show_fields as $fieldset_key => $fieldset ) :
?>
</table>
<?php
endforeach;
}
<h2><?php echo $fieldset['title']; ?></h2>
<table class="form-table" id="<?php echo esc_attr( 'fieldset-' . $fieldset_key ); ?>">
<?php foreach ( $fieldset['fields'] as $key => $field ) : ?>
<tr>
<th>
<label for="<?php echo esc_attr( $key ); ?>"><?php echo esc_html( $field['label'] ); ?></label>
</th>
<td>
<?php if ( ! empty( $field['type'] ) && 'select' === $field['type'] ) : ?>
<select name="<?php echo esc_attr( $key ); ?>" id="<?php echo esc_attr( $key ); ?>" class="<?php echo esc_attr( $field['class'] ); ?>" style="width: 25em;">
<?php
$selected = esc_attr( get_user_meta( $user->ID, $key, true ) );
foreach ( $field['options'] as $option_key => $option_value ) :
?>
<option value="<?php echo esc_attr( $option_key ); ?>" <?php selected( $selected, $option_key, true ); ?>><?php echo esc_attr( $option_value ); ?></option>
<?php endforeach; ?>
</select>
<?php elseif ( ! empty( $field['type'] ) && 'checkbox' === $field['type'] ) : ?>
<input type="checkbox" name="<?php echo esc_attr( $key ); ?>" id="<?php echo esc_attr( $key ); ?>" value="1" class="<?php echo esc_attr( $field['class'] ); ?>" <?php checked( (int) get_user_meta( $user->ID, $key, true ), 1, true ); ?> />
<?php elseif ( ! empty( $field['type'] ) && 'button' === $field['type'] ) : ?>
<button type="button" id="<?php echo esc_attr( $key ); ?>" class="button <?php echo esc_attr( $field['class'] ); ?>"><?php echo esc_html( $field['text'] ); ?></button>
<?php else : ?>
<input type="text" name="<?php echo esc_attr( $key ); ?>" id="<?php echo esc_attr( $key ); ?>" value="<?php echo esc_attr( $this->get_user_meta( $user->ID, $key ) ); ?>" class="<?php echo ( ! empty( $field['class'] ) ? esc_attr( $field['class'] ) : 'regular-text' ); ?>" />
<?php endif; ?>
<br/>
<span class="description"><?php echo wp_kses_post( $field['description'] ); ?></span>
</td>
</tr>
<?php endforeach; ?>
</table>
<?php
endforeach;
}
/**
* Save Address Fields on edit user pages.
*
* @param int $user_id User ID of the user being saved
*/
public function save_customer_meta_fields( $user_id ) {
$save_fields = $this->get_customer_meta_fields();
/**
* Save Address Fields on edit user pages.
*
* @param int $user_id User ID of the user being saved
*/
public function save_customer_meta_fields( $user_id ) {
$save_fields = $this->get_customer_meta_fields();
foreach ( $save_fields as $fieldset ) {
foreach ( $save_fields as $fieldset ) {
foreach ( $fieldset['fields'] as $key => $field ) {
foreach ( $fieldset['fields'] as $key => $field ) {
if ( isset( $field['type'] ) && 'checkbox' === $field['type'] ) {
update_user_meta( $user_id, $key, isset( $_POST[ $key ] ) );
} elseif ( isset( $_POST[ $key ] ) ) {
update_user_meta( $user_id, $key, wc_clean( $_POST[ $key ] ) );
if ( isset( $field['type'] ) && 'checkbox' === $field['type'] ) {
update_user_meta( $user_id, $key, isset( $_POST[ $key ] ) );
} elseif ( isset( $_POST[ $key ] ) ) {
update_user_meta( $user_id, $key, wc_clean( $_POST[ $key ] ) );
}
}
}
}
}
/**
* Get user meta for a given key, with fallbacks to core user info for pre-existing fields.
*
* @since 3.1.0
* @param int $user_id User ID of the user being edited
* @param string $key Key for user meta field
* @return string
*/
protected function get_user_meta( $user_id, $key ) {
$value = get_user_meta( $user_id, $key, true );
$existing_fields = array( 'billing_first_name', 'billing_last_name' );
if ( ! $value && in_array( $key, $existing_fields ) ) {
$value = get_user_meta( $user_id, str_replace( 'billing_', '', $key ), true );
} elseif ( ! $value && ( 'billing_email' === $key ) ) {
$user = get_userdata( $user_id );
$value = $user->user_email;
/**
* Get user meta for a given key, with fallbacks to core user info for pre-existing fields.
*
* @since 3.1.0
* @param int $user_id User ID of the user being edited
* @param string $key Key for user meta field
* @return string
*/
protected function get_user_meta( $user_id, $key ) {
$value = get_user_meta( $user_id, $key, true );
$existing_fields = array( 'billing_first_name', 'billing_last_name' );
if ( ! $value && in_array( $key, $existing_fields ) ) {
$value = get_user_meta( $user_id, str_replace( 'billing_', '', $key ), true );
} elseif ( ! $value && ( 'billing_email' === $key ) ) {
$user = get_userdata( $user_id );
$value = $user->user_email;
}
return $value;
}
return $value;
}
}
endif;

View File

@ -32,8 +32,8 @@ class WC_Admin_Reports {
$current_tab = ! empty( $_GET['tab'] ) ? sanitize_title( $_GET['tab'] ) : $first_tab[0];
$current_report = isset( $_GET['report'] ) ? sanitize_title( $_GET['report'] ) : current( array_keys( $reports[ $current_tab ]['reports'] ) );
include_once( dirname( __FILE__ ) . '/reports/class-wc-admin-report.php' );
include_once( dirname( __FILE__ ) . '/views/html-admin-page-reports.php' );
include_once dirname( __FILE__ ) . '/reports/class-wc-admin-report.php';
include_once dirname( __FILE__ ) . '/views/html-admin-page-reports.php';
}
/**
@ -43,16 +43,16 @@ class WC_Admin_Reports {
*/
public static function get_reports() {
$reports = array(
'orders' => array(
'title' => __( 'Orders', 'woocommerce' ),
'orders' => array(
'title' => __( 'Orders', 'woocommerce' ),
'reports' => array(
'sales_by_date' => array(
'sales_by_date' => array(
'title' => __( 'Sales by date', 'woocommerce' ),
'description' => '',
'hide_title' => true,
'callback' => array( __CLASS__, 'get_report' ),
),
'sales_by_product' => array(
'sales_by_product' => array(
'title' => __( 'Sales by product', 'woocommerce' ),
'description' => '',
'hide_title' => true,
@ -64,13 +64,13 @@ class WC_Admin_Reports {
'hide_title' => true,
'callback' => array( __CLASS__, 'get_report' ),
),
'coupon_usage' => array(
'coupon_usage' => array(
'title' => __( 'Coupons by date', 'woocommerce' ),
'description' => '',
'hide_title' => true,
'callback' => array( __CLASS__, 'get_report' ),
),
'downloads' => array(
'downloads' => array(
'title' => __( 'Customer downloads', 'woocommerce' ),
'description' => '',
'hide_title' => true,
@ -79,9 +79,9 @@ class WC_Admin_Reports {
),
),
'customers' => array(
'title' => __( 'Customers', 'woocommerce' ),
'title' => __( 'Customers', 'woocommerce' ),
'reports' => array(
'customers' => array(
'customers' => array(
'title' => __( 'Customers vs. guests', 'woocommerce' ),
'description' => '',
'hide_title' => true,
@ -96,7 +96,7 @@ class WC_Admin_Reports {
),
),
'stock' => array(
'title' => __( 'Stock', 'woocommerce' ),
'title' => __( 'Stock', 'woocommerce' ),
'reports' => array(
'low_in_stock' => array(
'title' => __( 'Low in stock', 'woocommerce' ),
@ -122,7 +122,7 @@ class WC_Admin_Reports {
if ( wc_tax_enabled() ) {
$reports['taxes'] = array(
'title' => __( 'Taxes', 'woocommerce' ),
'title' => __( 'Taxes', 'woocommerce' ),
'reports' => array(
'taxes_by_code' => array(
'title' => __( 'Taxes by code', 'woocommerce' ),
@ -167,7 +167,7 @@ class WC_Admin_Reports {
$name = sanitize_title( str_replace( '_', '-', $name ) );
$class = 'WC_Report_' . str_replace( '-', '_', $name );
include_once( apply_filters( 'wc_admin_reports_path', 'reports/class-wc-report-' . $name . '.php', $name, $class ) );
include_once apply_filters( 'wc_admin_reports_path', 'reports/class-wc-report-' . $name . '.php', $name, $class );
if ( ! class_exists( $class ) ) {
return;

View File

@ -88,16 +88,18 @@ class WC_Admin_Setup_Wizard {
* @return boolean
*/
protected function is_default_theme() {
return wc_is_active_theme( array(
'twentyseventeen',
'twentysixteen',
'twentyfifteen',
'twentyfourteen',
'twentythirteen',
'twentyeleven',
'twentytwelve',
'twentyten',
) );
return wc_is_active_theme(
array(
'twentyseventeen',
'twentysixteen',
'twentyfifteen',
'twentyfourteen',
'twentythirteen',
'twentyeleven',
'twentytwelve',
'twentyten',
)
);
}
/**
@ -185,28 +187,36 @@ class WC_Admin_Setup_Wizard {
wp_register_script( 'jquery-blockui', WC()->plugin_url() . '/assets/js/jquery-blockui/jquery.blockUI' . $suffix . '.js', array( 'jquery' ), '2.70', true );
wp_register_script( 'selectWoo', WC()->plugin_url() . '/assets/js/selectWoo/selectWoo.full' . $suffix . '.js', array( 'jquery' ), '1.0.0' );
wp_register_script( 'wc-enhanced-select', WC()->plugin_url() . '/assets/js/admin/wc-enhanced-select' . $suffix . '.js', array( 'jquery', 'selectWoo' ), WC_VERSION );
wp_localize_script( 'wc-enhanced-select', 'wc_enhanced_select_params', array(
'i18n_no_matches' => _x( 'No matches found', 'enhanced select', 'woocommerce' ),
'i18n_ajax_error' => _x( 'Loading failed', 'enhanced select', 'woocommerce' ),
'i18n_input_too_short_1' => _x( 'Please enter 1 or more characters', 'enhanced select', 'woocommerce' ),
'i18n_input_too_short_n' => _x( 'Please enter %qty% or more characters', 'enhanced select', 'woocommerce' ),
'i18n_input_too_long_1' => _x( 'Please delete 1 character', 'enhanced select', 'woocommerce' ),
'i18n_input_too_long_n' => _x( 'Please delete %qty% characters', 'enhanced select', 'woocommerce' ),
'i18n_selection_too_long_1' => _x( 'You can only select 1 item', 'enhanced select', 'woocommerce' ),
'i18n_selection_too_long_n' => _x( 'You can only select %qty% items', 'enhanced select', 'woocommerce' ),
'i18n_load_more' => _x( 'Loading more results&hellip;', 'enhanced select', 'woocommerce' ),
'i18n_searching' => _x( 'Searching&hellip;', 'enhanced select', 'woocommerce' ),
'ajax_url' => admin_url( 'admin-ajax.php' ),
'search_products_nonce' => wp_create_nonce( 'search-products' ),
'search_customers_nonce' => wp_create_nonce( 'search-customers' ),
) );
wp_localize_script(
'wc-enhanced-select',
'wc_enhanced_select_params',
array(
'i18n_no_matches' => _x( 'No matches found', 'enhanced select', 'woocommerce' ),
'i18n_ajax_error' => _x( 'Loading failed', 'enhanced select', 'woocommerce' ),
'i18n_input_too_short_1' => _x( 'Please enter 1 or more characters', 'enhanced select', 'woocommerce' ),
'i18n_input_too_short_n' => _x( 'Please enter %qty% or more characters', 'enhanced select', 'woocommerce' ),
'i18n_input_too_long_1' => _x( 'Please delete 1 character', 'enhanced select', 'woocommerce' ),
'i18n_input_too_long_n' => _x( 'Please delete %qty% characters', 'enhanced select', 'woocommerce' ),
'i18n_selection_too_long_1' => _x( 'You can only select 1 item', 'enhanced select', 'woocommerce' ),
'i18n_selection_too_long_n' => _x( 'You can only select %qty% items', 'enhanced select', 'woocommerce' ),
'i18n_load_more' => _x( 'Loading more results&hellip;', 'enhanced select', 'woocommerce' ),
'i18n_searching' => _x( 'Searching&hellip;', 'enhanced select', 'woocommerce' ),
'ajax_url' => admin_url( 'admin-ajax.php' ),
'search_products_nonce' => wp_create_nonce( 'search-products' ),
'search_customers_nonce' => wp_create_nonce( 'search-customers' ),
)
);
wp_enqueue_style( 'woocommerce_admin_styles', WC()->plugin_url() . '/assets/css/admin.css', array(), WC_VERSION );
wp_enqueue_style( 'wc-setup', WC()->plugin_url() . '/assets/css/wc-setup.css', array( 'dashicons', 'install' ), WC_VERSION );
wp_register_script( 'wc-setup', WC()->plugin_url() . '/assets/js/admin/wc-setup' . $suffix . '.js', array( 'jquery', 'wc-enhanced-select', 'jquery-blockui', 'wp-util' ), WC_VERSION );
wp_localize_script( 'wc-setup', 'wc_setup_params', array(
'pending_jetpack_install' => $pending_jetpack ? 'yes' : 'no',
) );
wp_localize_script(
'wc-setup',
'wc_setup_params',
array(
'pending_jetpack_install' => $pending_jetpack ? 'yes' : 'no',
)
);
// @codingStandardsIgnoreStart
if ( ! empty( $_POST['save_step'] ) && isset( $this->steps[ $this->step ]['handler'] ) ) {
@ -601,10 +611,13 @@ class WC_Admin_Setup_Wizard {
add_action( 'shutdown', array( $this, 'run_deferred_actions' ) );
}
array_push( $this->deferred_actions, array(
'func' => array( 'WC_Install', 'background_installer' ),
'args' => array( $plugin_id, $plugin_info ),
) );
array_push(
$this->deferred_actions,
array(
'func' => array( 'WC_Install', 'background_installer' ),
'args' => array( $plugin_id, $plugin_info ),
)
);
// Set the background installation flag for this plugin.
update_option( 'woocommerce_setup_background_installing_' . $plugin_id, true );
@ -620,21 +633,27 @@ class WC_Admin_Setup_Wizard {
if ( empty( $this->deferred_actions ) ) {
add_action( 'shutdown', array( $this, 'run_deferred_actions' ) );
}
array_push( $this->deferred_actions, array(
'func' => array( 'WC_Install', 'theme_background_installer' ),
'args' => array( $theme_id ),
) );
array_push(
$this->deferred_actions,
array(
'func' => array( 'WC_Install', 'theme_background_installer' ),
'args' => array( $theme_id ),
)
);
}
/**
* Helper method to install Jetpack.
*/
protected function install_jetpack() {
$this->install_plugin( 'jetpack', array(
'file' => 'jetpack/jetpack.php',
'name' => __( 'Jetpack', 'woocommerce' ),
'repo-slug' => 'jetpack',
) );
$this->install_plugin(
'jetpack',
array(
'file' => 'jetpack/jetpack.php',
'name' => __( 'Jetpack', 'woocommerce' ),
'repo-slug' => 'jetpack',
)
);
}
/**
@ -642,11 +661,14 @@ class WC_Admin_Setup_Wizard {
*/
protected function install_woocommerce_services() {
$this->install_jetpack();
$this->install_plugin( 'woocommerce-services', array(
'file' => 'woocommerce-services/woocommerce-services.php',
'name' => __( 'WooCommerce Services', 'woocommerce' ),
'repo-slug' => 'woocommerce-services',
) );
$this->install_plugin(
'woocommerce-services',
array(
'file' => 'woocommerce-services/woocommerce-services.php',
'name' => __( 'WooCommerce Services', 'woocommerce' ),
'repo-slug' => 'woocommerce-services',
)
);
}
/**
@ -853,10 +875,12 @@ class WC_Admin_Setup_Wizard {
<p>
<label for="weight_unit">
<?php
printf( wp_kses(
__( '<strong>Weight unit</strong>—used to calculate shipping rates, and more.', 'woocommerce' ),
array( 'strong' => array() )
) );
printf(
wp_kses(
__( '<strong>Weight unit</strong>—used to calculate shipping rates, and more.', 'woocommerce' ),
array( 'strong' => array() )
)
);
?>
</label>
</p>
@ -871,10 +895,12 @@ class WC_Admin_Setup_Wizard {
<p>
<label for="dimension_unit">
<?php
printf( wp_kses(
__( '<strong>Dimension unit</strong>—helps for accurate package selection.', 'woocommerce' ),
array( 'strong' => array() )
) );
printf(
wp_kses(
__( '<strong>Dimension unit</strong>—helps for accurate package selection.', 'woocommerce' ),
array( 'strong' => array() )
)
);
?>
</label>
</p>

View File

@ -19,14 +19,14 @@ class WC_Admin_Status {
* Handles output of the reports page in admin.
*/
public static function output() {
include_once( dirname( __FILE__ ) . '/views/html-admin-page-status.php' );
include_once dirname( __FILE__ ) . '/views/html-admin-page-status.php';
}
/**
* Handles output of report.
*/
public static function status_report() {
include_once( dirname( __FILE__ ) . '/views/html-admin-page-status-report.php' );
include_once dirname( __FILE__ ) . '/views/html-admin-page-status-report.php';
}
/**
@ -36,13 +36,16 @@ class WC_Admin_Status {
$tools = self::get_tools();
if ( ! empty( $_GET['action'] ) && ! empty( $_REQUEST['_wpnonce'] ) && wp_verify_nonce( $_REQUEST['_wpnonce'], 'debug_action' ) ) {
$tools_controller = new WC_REST_System_Status_Tools_Controller;
$tools_controller = new WC_REST_System_Status_Tools_Controller();
$action = wc_clean( $_GET['action'] );
if ( array_key_exists( $action, $tools ) ) {
$response = $tools_controller->execute_tool( $action );
} else {
$response = array( 'success' => false, 'message' => __( 'Tool does not exist.', 'woocommerce' ) );
$response = array(
'success' => false,
'message' => __( 'Tool does not exist.', 'woocommerce' ),
);
}
if ( $response['success'] ) {
@ -57,15 +60,16 @@ class WC_Admin_Status {
echo '<div class="updated inline"><p>' . __( 'Your changes have been saved.', 'woocommerce' ) . '</p></div>';
}
include_once( dirname( __FILE__ ) . '/views/html-admin-page-status-tools.php' );
include_once dirname( __FILE__ ) . '/views/html-admin-page-status-tools.php';
}
/**
* Get tools.
*
* @return array of tools
*/
public static function get_tools() {
$tools_controller = new WC_REST_System_Status_Tools_Controller;
$tools_controller = new WC_REST_System_Status_Tools_Controller();
return $tools_controller->get_tools();
}
@ -99,7 +103,7 @@ class WC_Admin_Status {
self::remove_log();
}
include_once( 'views/html-admin-page-status-logs.php' );
include_once 'views/html-admin-page-status-logs.php';
}
/**
@ -120,11 +124,12 @@ class WC_Admin_Status {
$log_table_list = new WC_Admin_Log_Table_List();
$log_table_list->prepare_items();
include_once( 'views/html-admin-page-status-logs-db.php' );
include_once 'views/html-admin-page-status-logs-db.php';
}
/**
* Retrieve metadata from a file. Based on WP Core's get_file_data function.
*
* @since 2.1.1
* @param string $file Path to the file
* @return string
@ -153,7 +158,7 @@ class WC_Admin_Status {
$version = _cleanup_header_comment( $match[1] );
}
return $version ;
return $version;
}
/**
@ -168,6 +173,7 @@ class WC_Admin_Status {
/**
* Scan the template files.
*
* @param string $template_path
* @return array
*/
@ -180,7 +186,7 @@ class WC_Admin_Status {
foreach ( $files as $key => $value ) {
if ( ! in_array( $value, array( ".", ".." ) ) ) {
if ( ! in_array( $value, array( '.', '..' ) ) ) {
if ( is_dir( $template_path . DIRECTORY_SEPARATOR . $value ) ) {
$sub_files = self::scan_template_files( $template_path . DIRECTORY_SEPARATOR . $value );
@ -198,6 +204,7 @@ class WC_Admin_Status {
/**
* Scan the log files.
*
* @return array
*/
public static function scan_log_files() {
@ -221,41 +228,48 @@ class WC_Admin_Status {
/**
* Get latest version of a theme by slug.
*
* @param object $theme WP_Theme object.
* @return string Version number if found.
*/
public static function get_latest_theme_version( $theme ) {
include_once( ABSPATH . 'wp-admin/includes/theme.php' );
include_once ABSPATH . 'wp-admin/includes/theme.php';
$api = themes_api( 'theme_information', array(
'slug' => $theme->get_stylesheet(),
'fields' => array(
'sections' => false,
'tags' => false,
),
) );
$api = themes_api(
'theme_information',
array(
'slug' => $theme->get_stylesheet(),
'fields' => array(
'sections' => false,
'tags' => false,
),
)
);
$update_theme_version = 0;
// Check .org for updates.
if ( is_object( $api ) && ! is_wp_error( $api ) ) {
$update_theme_version = $api->version;
// Check WooThemes Theme Version.
} elseif ( strstr( $theme->{'Author URI'}, 'woothemes' ) ) {
$theme_dir = substr( strtolower( str_replace( ' ','', $theme->Name ) ), 0, 45 );
} elseif ( strstr( $theme->{'Author URI'}, 'woothemes' ) ) { // Check WooThemes Theme Version.
$theme_dir = substr( strtolower( str_replace( ' ', '', $theme->Name ) ), 0, 45 );
if ( false === ( $theme_version_data = get_transient( $theme_dir . '_version_data' ) ) ) {
$theme_changelog = wp_safe_remote_get( 'http://dzv365zjfbd8v.cloudfront.net/changelogs/' . $theme_dir . '/changelog.txt' );
$cl_lines = explode( "\n", wp_remote_retrieve_body( $theme_changelog ) );
$cl_lines = explode( "\n", wp_remote_retrieve_body( $theme_changelog ) );
if ( ! empty( $cl_lines ) ) {
foreach ( $cl_lines as $line_num => $cl_line ) {
if ( preg_match( '/^[0-9]/', $cl_line ) ) {
$theme_date = str_replace( '.' , '-' , trim( substr( $cl_line , 0 , strpos( $cl_line , '-' ) ) ) );
$theme_version = preg_replace( '~[^0-9,.]~' , '' ,stristr( $cl_line , "version" ) );
$theme_update = trim( str_replace( "*" , "" , $cl_lines[ $line_num + 1 ] ) );
$theme_version_data = array( 'date' => $theme_date , 'version' => $theme_version , 'update' => $theme_update , 'changelog' => $theme_changelog );
set_transient( $theme_dir . '_version_data', $theme_version_data , DAY_IN_SECONDS );
$theme_date = str_replace( '.', '-', trim( substr( $cl_line, 0, strpos( $cl_line, '-' ) ) ) );
$theme_version = preg_replace( '~[^0-9,.]~', '', stristr( $cl_line, 'version' ) );
$theme_update = trim( str_replace( '*', '', $cl_lines[ $line_num + 1 ] ) );
$theme_version_data = array(
'date' => $theme_date,
'version' => $theme_version,
'update' => $theme_update,
'changelog' => $theme_changelog,
);
set_transient( $theme_dir . '_version_data', $theme_version_data, DAY_IN_SECONDS );
break;
}
}

View File

@ -59,8 +59,8 @@ class WC_Admin_Taxonomies {
/**
* Order term when created (put in position 0).
*
* @param mixed $term_id
* @param mixed $tt_id
* @param mixed $term_id
* @param mixed $tt_id
* @param string $taxonomy
*/
public function create_term( $term_id, $tt_id = '', $taxonomy = '' ) {
@ -132,9 +132,9 @@ class WC_Admin_Taxonomies {
// Create the media frame.
file_frame = wp.media.frames.downloadable_file = wp.media({
title: '<?php _e( "Choose an image", "woocommerce" ); ?>',
title: '<?php _e( 'Choose an image', 'woocommerce' ); ?>',
button: {
text: '<?php _e( "Use image", "woocommerce" ); ?>'
text: '<?php _e( 'Use image', 'woocommerce' ); ?>'
},
multiple: false
});
@ -242,9 +242,9 @@ class WC_Admin_Taxonomies {
// Create the media frame.
file_frame = wp.media.frames.downloadable_file = wp.media({
title: '<?php _e( "Choose an image", "woocommerce" ); ?>',
title: '<?php _e( 'Choose an image', 'woocommerce' ); ?>',
button: {
text: '<?php _e( "Use image", "woocommerce" ); ?>'
text: '<?php _e( 'Use image', 'woocommerce' ); ?>'
},
multiple: false
});
@ -280,8 +280,8 @@ class WC_Admin_Taxonomies {
/**
* save_category_fields function.
*
* @param mixed $term_id Term ID being saved
* @param mixed $tt_id
* @param mixed $term_id Term ID being saved
* @param mixed $tt_id
* @param string $taxonomy
*/
public function save_category_fields( $term_id, $tt_id = '', $taxonomy = '' ) {
@ -310,7 +310,7 @@ class WC_Admin_Taxonomies {
?>
<div class="form-wrap edit-term-notes">
<p>
<strong><?php _e( 'Note:', 'woocommerce' ) ?></strong><br>
<strong><?php _e( 'Note:', 'woocommerce' ); ?></strong><br>
<?php
printf(
/* translators: %s: default category */
@ -346,7 +346,7 @@ class WC_Admin_Taxonomies {
$new_columns['thumb'] = __( 'Image', 'woocommerce' );
$columns = array_merge( $new_columns, $columns );
$columns = array_merge( $new_columns, $columns );
$columns['handle'] = '';
return $columns;
@ -355,7 +355,7 @@ class WC_Admin_Taxonomies {
/**
* Adjust row actions.
*
* @param array $actions Array of actions.
* @param array $actions Array of actions.
* @param object $term Term object.
* @return array
*/
@ -393,7 +393,7 @@ class WC_Admin_Taxonomies {
*
* @param string $columns
* @param string $column
* @param int $id
* @param int $id
*
* @return string
*/

View File

@ -21,11 +21,13 @@ class WC_Admin_Webhooks_Table_List extends WP_List_Table {
* Initialize the webhook table list.
*/
public function __construct() {
parent::__construct( array(
'singular' => 'webhook',
'plural' => 'webhooks',
'ajax' => false,
) );
parent::__construct(
array(
'singular' => 'webhook',
'plural' => 'webhooks',
'ajax' => false,
)
);
}
/**
@ -79,9 +81,15 @@ class WC_Admin_Webhooks_Table_List extends WP_List_Table {
'id' => sprintf( __( 'ID: %d', 'woocommerce' ), $webhook->get_id() ),
'edit' => '<a href="' . esc_url( $edit_link ) . '">' . esc_html__( 'Edit', 'woocommerce' ) . '</a>',
/* translators: %s: webhook name */
'delete' => '<a class="submitdelete" aria-label="' . esc_attr( sprintf( __( 'Delete "%s" permanently', 'woocommerce' ), $webhook->get_name() ) ) . '" href="' . esc_url( wp_nonce_url( add_query_arg( array(
'delete' => $webhook->get_id(),
), admin_url( 'admin.php?page=wc-settings&tab=api&section=webhooks' ) ), 'delete-webhook' ) ) . '">' . esc_html__( 'Delete permanently', 'woocommerce' ) . '</a>',
'delete' => '<a class="submitdelete" aria-label="' . esc_attr( sprintf( __( 'Delete "%s" permanently', 'woocommerce' ), $webhook->get_name() ) ) . '" href="' . esc_url(
wp_nonce_url(
add_query_arg(
array(
'delete' => $webhook->get_id(),
), admin_url( 'admin.php?page=wc-settings&tab=api&section=webhooks' )
), 'delete-webhook'
)
) . '">' . esc_html__( 'Delete permanently', 'woocommerce' ) . '</a>',
);
$actions = apply_filters( 'webhook_row_actions', $actions, $webhook );
@ -237,9 +245,12 @@ class WC_Admin_Webhooks_Table_List extends WP_List_Table {
echo '<p class="search-box">';
echo '<label class="screen-reader-text" for="' . esc_attr( $input_id ) . '">' . esc_html( $text ) . ':</label>';
echo '<input type="search" id="' . esc_attr( $input_id ) . '" name="s" value="' . esc_attr( $search_query ) . '" />';
submit_button( $text, '', '', false, array(
'id' => 'search-submit',
) );
submit_button(
$text, '', '', false,
array(
'id' => 'search-submit',
)
);
echo '</p>';
}
@ -276,10 +287,12 @@ class WC_Admin_Webhooks_Table_List extends WP_List_Table {
$total_items = count( $data_store->search_webhooks( $args ) );
// Set the pagination.
$this->set_pagination_args( array(
'total_items' => $total_items,
'per_page' => $per_page,
'total_pages' => ceil( $total_items / $per_page ),
) );
$this->set_pagination_args(
array(
'total_items' => $total_items,
'per_page' => $per_page,
'total_pages' => ceil( $total_items / $per_page ),
)
);
}
}

View File

@ -276,10 +276,13 @@ class WC_Admin_Webhooks {
$webhooks_table_list = new WC_Admin_Webhooks_Table_List();
// Add screen option.
add_screen_option( 'per_page', array(
'default' => 10,
'option' => 'woocommerce_webhooks_per_page',
) );
add_screen_option(
'per_page',
array(
'default' => 10,
'option' => 'woocommerce_webhooks_per_page',
)
);
}
}

View File

@ -44,46 +44,46 @@ class WC_Admin {
* Include any classes we need within admin.
*/
public function includes() {
include_once( dirname( __FILE__ ) . '/wc-admin-functions.php' );
include_once( dirname( __FILE__ ) . '/wc-meta-box-functions.php' );
include_once( dirname( __FILE__ ) . '/class-wc-admin-post-types.php' );
include_once( dirname( __FILE__ ) . '/class-wc-admin-taxonomies.php' );
include_once( dirname( __FILE__ ) . '/class-wc-admin-menus.php' );
include_once( dirname( __FILE__ ) . '/class-wc-admin-customize.php' );
include_once( dirname( __FILE__ ) . '/class-wc-admin-notices.php' );
include_once( dirname( __FILE__ ) . '/class-wc-admin-assets.php' );
include_once( dirname( __FILE__ ) . '/class-wc-admin-api-keys.php' );
include_once( dirname( __FILE__ ) . '/class-wc-admin-webhooks.php' );
include_once( dirname( __FILE__ ) . '/class-wc-admin-pointers.php' );
include_once( dirname( __FILE__ ) . '/class-wc-admin-importers.php' );
include_once( dirname( __FILE__ ) . '/class-wc-admin-exporters.php' );
include_once dirname( __FILE__ ) . '/wc-admin-functions.php';
include_once dirname( __FILE__ ) . '/wc-meta-box-functions.php';
include_once dirname( __FILE__ ) . '/class-wc-admin-post-types.php';
include_once dirname( __FILE__ ) . '/class-wc-admin-taxonomies.php';
include_once dirname( __FILE__ ) . '/class-wc-admin-menus.php';
include_once dirname( __FILE__ ) . '/class-wc-admin-customize.php';
include_once dirname( __FILE__ ) . '/class-wc-admin-notices.php';
include_once dirname( __FILE__ ) . '/class-wc-admin-assets.php';
include_once dirname( __FILE__ ) . '/class-wc-admin-api-keys.php';
include_once dirname( __FILE__ ) . '/class-wc-admin-webhooks.php';
include_once dirname( __FILE__ ) . '/class-wc-admin-pointers.php';
include_once dirname( __FILE__ ) . '/class-wc-admin-importers.php';
include_once dirname( __FILE__ ) . '/class-wc-admin-exporters.php';
// Help Tabs
if ( apply_filters( 'woocommerce_enable_admin_help_tab', true ) ) {
include_once( dirname( __FILE__ ) . '/class-wc-admin-help.php' );
include_once dirname( __FILE__ ) . '/class-wc-admin-help.php';
}
// Setup/welcome
if ( ! empty( $_GET['page'] ) ) {
switch ( $_GET['page'] ) {
case 'wc-setup' :
include_once( dirname( __FILE__ ) . '/class-wc-admin-setup-wizard.php' );
break;
case 'wc-setup':
include_once dirname( __FILE__ ) . '/class-wc-admin-setup-wizard.php';
break;
}
}
// Importers
if ( defined( 'WP_LOAD_IMPORTERS' ) ) {
include_once( dirname( __FILE__ ) . '/class-wc-admin-importers.php' );
include_once dirname( __FILE__ ) . '/class-wc-admin-importers.php';
}
// Helper
include_once( dirname( __FILE__ ) . '/helper/class-wc-helper-options.php' );
include_once( dirname( __FILE__ ) . '/helper/class-wc-helper-api.php' );
include_once( dirname( __FILE__ ) . '/helper/class-wc-helper-updater.php' );
include_once( dirname( __FILE__ ) . '/helper/class-wc-helper-plugin-info.php' );
include_once( dirname( __FILE__ ) . '/helper/class-wc-helper-compat.php' );
include_once( dirname( __FILE__ ) . '/helper/class-wc-helper.php' );
include_once dirname( __FILE__ ) . '/helper/class-wc-helper-options.php';
include_once dirname( __FILE__ ) . '/helper/class-wc-helper-api.php';
include_once dirname( __FILE__ ) . '/helper/class-wc-helper-updater.php';
include_once dirname( __FILE__ ) . '/helper/class-wc-helper-plugin-info.php';
include_once dirname( __FILE__ ) . '/helper/class-wc-helper-compat.php';
include_once dirname( __FILE__ ) . '/helper/class-wc-helper.php';
}
/**
@ -95,25 +95,25 @@ class WC_Admin {
}
switch ( $screen->id ) {
case 'dashboard' :
case 'dashboard-network' :
include( 'class-wc-admin-dashboard.php' );
break;
case 'options-permalink' :
include( 'class-wc-admin-permalink-settings.php' );
break;
case 'plugins' :
include ( 'plugin-updates/class-wc-plugins-screen-updates.php' );
break;
case 'update-core' :
include( 'plugin-updates/class-wc-updates-screen-updates.php' );
break;
case 'users' :
case 'user' :
case 'profile' :
case 'user-edit' :
include( 'class-wc-admin-profile.php' );
break;
case 'dashboard':
case 'dashboard-network':
include 'class-wc-admin-dashboard.php';
break;
case 'options-permalink':
include 'class-wc-admin-permalink-settings.php';
break;
case 'plugins':
include 'plugin-updates/class-wc-plugins-screen-updates.php';
break;
case 'update-core':
include 'plugin-updates/class-wc-updates-screen-updates.php';
break;
case 'users':
case 'user':
case 'profile':
case 'user-edit':
include 'class-wc-admin-profile.php';
break;
}
}
@ -160,7 +160,7 @@ class WC_Admin {
public function prevent_admin_access() {
$prevent_access = false;
if ( 'yes' === get_option( 'woocommerce_lock_down_admin', 'yes' ) && ! is_ajax() && basename( $_SERVER["SCRIPT_FILENAME"] ) !== 'admin-post.php' ) {
if ( 'yes' === get_option( 'woocommerce_lock_down_admin', 'yes' ) && ! is_ajax() && basename( $_SERVER['SCRIPT_FILENAME'] ) !== 'admin-post.php' ) {
$has_cap = false;
$access_caps = array( 'edit_posts', 'manage_woocommerce', 'view_admin_dashboard' );
@ -193,21 +193,21 @@ class WC_Admin {
}
// load the mailer class
$mailer = WC()->mailer();
$mailer = WC()->mailer();
// get the preview email subject
$email_heading = __( 'HTML email template', 'woocommerce' );
// get the preview email content
ob_start();
include( 'views/html-email-template-preview.php' );
$message = ob_get_clean();
include 'views/html-email-template-preview.php';
$message = ob_get_clean();
// create a new email
$email = new WC_Email();
$email = new WC_Email();
// wrap the content with the email template and then add styles
$message = apply_filters( 'woocommerce_mail_content', $email->style_inline( $mailer->wrap_message( $email_heading, $message ) ) );
$message = apply_filters( 'woocommerce_mail_content', $email->style_inline( $mailer->wrap_message( $email_heading, $message ) ) );
// print the preview email
echo $message;
@ -242,12 +242,12 @@ class WC_Admin {
sprintf( '<strong>%s</strong>', esc_html__( 'WooCommerce', 'woocommerce' ) ),
'<a href="https://wordpress.org/support/plugin/woocommerce/reviews?rate=5#new-post" target="_blank" class="wc-rating-link" data-rated="' . esc_attr__( 'Thanks :)', 'woocommerce' ) . '">&#9733;&#9733;&#9733;&#9733;&#9733;</a>'
);
wc_enqueue_js( "
jQuery( 'a.wc-rating-link' ).click( function() {
wc_enqueue_js(
"jQuery( 'a.wc-rating-link' ).click( function() {
jQuery.post( '" . WC()->ajax_url() . "', { action: 'woocommerce_rated' } );
jQuery( this ).parent().text( jQuery( this ).data( 'rated' ) );
});
" );
});"
);
} else {
$footer_text = __( 'Thank you for selling with WooCommerce.', 'woocommerce' );
}
@ -264,9 +264,11 @@ class WC_Admin {
public function setup_wizard_check_jetpack() {
$jetpack_active = class_exists( 'Jetpack' );
wp_send_json_success( array(
'is_active' => $jetpack_active ? 'yes' : 'no',
) );
wp_send_json_success(
array(
'is_active' => $jetpack_active ? 'yes' : 'no',
)
);
}
}

View File

@ -26,7 +26,7 @@ class WC_Helper_API {
* Perform an HTTP request to the Helper API.
*
* @param string $endpoint The endpoint to request.
* @param array $args Additional data for the request. Set authenticated to a truthy value to enable auth.
* @param array $args Additional data for the request. Set authenticated to a truthy value to enable auth.
*
* @return array|WP_Error The response from wp_safe_remote_request()
*/
@ -53,7 +53,7 @@ class WC_Helper_API {
* Adds authentication headers to an HTTP request.
*
* @param string $url The request URI.
* @param array $args By-ref, the args that will be passed to wp_remote_request().
* @param array $args By-ref, the args that will be passed to wp_remote_request().
* @return bool Were the headers added?
*/
private static function _authenticate( $url, &$args ) {
@ -86,7 +86,7 @@ class WC_Helper_API {
}
$args['headers'] = array(
'Authorization' => 'Bearer ' . $auth['access_token'],
'Authorization' => 'Bearer ' . $auth['access_token'],
'X-Woo-Signature' => $signature,
);
@ -97,7 +97,7 @@ class WC_Helper_API {
* Wrapper for self::request().
*
* @param string $endpoint The helper API endpoint to request.
* @param array $args Arguments passed to wp_remote_request().
* @param array $args Arguments passed to wp_remote_request().
*
* @return array The response object from wp_safe_remote_request().
*/
@ -110,7 +110,7 @@ class WC_Helper_API {
* Wrapper for self::request().
*
* @param string $endpoint The helper API endpoint to request.
* @param array $args Arguments passed to wp_remote_request().
* @param array $args Arguments passed to wp_remote_request().
*
* @return array The response object from wp_safe_remote_request().
*/

View File

@ -70,12 +70,15 @@ class WC_Helper_Compat {
return;
}
$request = WC_Helper_API::post( 'oauth/migrate', array(
'body' => array(
'home_url' => home_url(),
'master_key' => $master_key,
),
) );
$request = WC_Helper_API::post(
'oauth/migrate',
array(
'body' => array(
'home_url' => home_url(),
'master_key' => $master_key,
),
)
);
if ( is_wp_error( $request ) || wp_remote_retrieve_response_code( $request ) !== 200 ) {
WC_Helper::log( 'Call to oauth/migrate returned a non-200 response code' );
@ -89,13 +92,16 @@ class WC_Helper_Compat {
}
// Obtain an access token.
$request = WC_Helper_API::post( 'oauth/access_token', array(
'body' => array(
'request_token' => $request_token,
'home_url' => home_url(),
'migrate' => true,
),
) );
$request = WC_Helper_API::post(
'oauth/access_token',
array(
'body' => array(
'request_token' => $request_token,
'home_url' => home_url(),
'migrate' => true,
),
)
);
if ( is_wp_error( $request ) || wp_remote_retrieve_response_code( $request ) !== 200 ) {
WC_Helper::log( 'Call to oauth/access_token returned a non-200 response code' );
@ -108,13 +114,16 @@ class WC_Helper_Compat {
return;
}
WC_Helper_Options::update( 'auth', array(
'access_token' => $access_token['access_token'],
'access_token_secret' => $access_token['access_token_secret'],
'site_id' => $access_token['site_id'],
'user_id' => null, // Set this later
'updated' => time(),
) );
WC_Helper_Options::update(
'auth',
array(
'access_token' => $access_token['access_token'],
'access_token_secret' => $access_token['access_token_secret'],
'site_id' => $access_token['site_id'],
'user_id' => null, // Set this later
'updated' => time(),
)
);
// Obtain the connected user info.
if ( ! WC_Helper::_flush_authentication_cache() ) {
@ -128,7 +137,7 @@ class WC_Helper_Compat {
* Attempt to deactivate the legacy helper plugin.
*/
public static function deactivate_plugin() {
include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
include_once ABSPATH . 'wp-admin/includes/plugin.php';
if ( ! function_exists( 'deactivate_plugins' ) ) {
return;
}
@ -175,11 +184,13 @@ class WC_Helper_Compat {
* Render the legacy helper compat view.
*/
public static function render_compat_menu() {
$helper_url = add_query_arg( array(
'page' => 'wc-addons',
'section' => 'helper',
), admin_url( 'admin.php' ) );
include( WC_Helper::get_view_filename( 'html-helper-compat.php' ) );
$helper_url = add_query_arg(
array(
'page' => 'wc-addons',
'section' => 'helper',
), admin_url( 'admin.php' )
);
include WC_Helper::get_view_filename( 'html-helper-compat.php' );
}
}

View File

@ -23,12 +23,12 @@ class WC_Helper_Options {
* is not thread-safe, use with caution.
*
* @param string $key The key to update.
* @param mixed $value The new option value.
* @param mixed $value The new option value.
*
* @return bool True if the option has been updated.
*/
public static function update( $key, $value ) {
$options = get_option( self::$option_name, array() );
$options = get_option( self::$option_name, array() );
$options[ $key ] = $value;
return update_option( self::$option_name, $options, true );
}
@ -39,7 +39,7 @@ class WC_Helper_Options {
* @see self::update
*
* @param string $key The key to fetch.
* @param mixed $default The default option to return if the key does not exist.
* @param mixed $default The default option to return if the key does not exist.
*
* @return mixed An option or the default.
*/

View File

@ -45,7 +45,7 @@ class WC_Helper_Plugin_Info {
// Look through update data by slug.
$update_data = WC_Helper_Updater::get_update_data();
$products = wp_list_filter( $update_data, array( 'slug' => $clean_slug ) );
$products = wp_list_filter( $update_data, array( 'slug' => $clean_slug ) );
if ( empty( $products ) ) {
return $response;
@ -55,9 +55,13 @@ class WC_Helper_Plugin_Info {
$product_id = array_shift( $product_id );
// Fetch the product information from the Helper API.
$request = WC_Helper_API::get( add_query_arg( array(
'product_id' => absint( $product_id ),
), 'info' ), array( 'authenticated' => true ) );
$request = WC_Helper_API::get(
add_query_arg(
array(
'product_id' => absint( $product_id ),
), 'info'
), array( 'authenticated' => true )
);
$results = json_decode( wp_remote_retrieve_body( $request ), true );
if ( ! empty( $results ) ) {

View File

@ -36,16 +36,16 @@ class WC_Helper_Updater {
continue;
}
$data = $update_data[ $plugin['_product_id'] ];
$data = $update_data[ $plugin['_product_id'] ];
$filename = $plugin['_filename'];
$item = array(
'id' => 'woocommerce-com-' . $plugin['_product_id'],
'slug' => 'woocommerce-com-' . $data['slug'],
'plugin' => $filename,
'new_version' => $data['version'],
'url' => $data['url'],
'package' => '',
'id' => 'woocommerce-com-' . $plugin['_product_id'],
'slug' => 'woocommerce-com-' . $data['slug'],
'plugin' => $filename,
'new_version' => $data['version'],
'url' => $data['url'],
'package' => '',
'upgrade_notice' => $data['upgrade_notice'],
);
@ -85,10 +85,10 @@ class WC_Helper_Updater {
$slug = $theme['_stylesheet'];
$item = array(
'theme' => $slug,
'theme' => $slug,
'new_version' => $data['version'],
'url' => $data['url'],
'package' => '',
'url' => $data['url'],
'package' => '',
);
if ( self::_has_active_subscription( $theme['_product_id'] ) ) {
@ -122,7 +122,7 @@ class WC_Helper_Updater {
foreach ( WC_Helper::get_subscriptions() as $subscription ) {
$payload[ $subscription['product_id'] ] = array(
'product_id' => $subscription['product_id'],
'file_id' => '',
'file_id' => '',
);
}
@ -171,16 +171,18 @@ class WC_Helper_Updater {
}
$data = array(
'hash' => $hash,
'updated' => time(),
'hash' => $hash,
'updated' => time(),
'products' => array(),
'errors' => array(),
'errors' => array(),
);
$request = WC_Helper_API::post( 'update-check', array(
'body' => json_encode( array( 'products' => $payload ) ),
'authenticated' => true,
) );
$request = WC_Helper_API::post(
'update-check', array(
'body' => json_encode( array( 'products' => $payload ) ),
'authenticated' => true,
)
);
if ( wp_remote_retrieve_response_code( $request ) !== 200 ) {
$data['errors'][] = 'http-error';
@ -250,7 +252,7 @@ class WC_Helper_Updater {
return 0;
}
$count = 0;
$count = 0;
$update_data = self::get_update_data();
if ( empty( $update_data ) ) {

File diff suppressed because it is too large Load Diff

View File

@ -1,35 +1,35 @@
<?php defined( 'ABSPATH' ) or exit(); ?>
<div class="wrap woocommerce wc_addons_wrap wc-helper">
<?php include( WC_Helper::get_view_filename( 'html-section-nav.php' ) ); ?>
<?php require WC_Helper::get_view_filename( 'html-section-nav.php' ); ?>
<h1 class="screen-reader-text"><?php _e( 'WooCommerce Extensions', 'woocommerce' ); ?></h1>
<?php include( WC_Helper::get_view_filename( 'html-section-notices.php' ) ); ?>
<?php require WC_Helper::get_view_filename( 'html-section-notices.php' ); ?>
<div class="subscriptions-header">
<h2><?php _e( 'Subscriptions', 'woocommerce' ); ?></h2>
<?php include( WC_Helper::get_view_filename( 'html-section-account.php' ) ); ?>
<?php require WC_Helper::get_view_filename( 'html-section-account.php' ); ?>
<p><?php printf( __( 'Below is a list of extensions available on your WooCommerce.com account. To receive extension updates please make sure the extension is installed, and its subscription activated and connected to your WooCommerce.com account. Extensions can be activated from the <a href="%s">Plugins</a> screen.', 'woocommerce' ), admin_url( 'plugins.php' ) ); ?></p>
</div>
<ul class="subscription-filter">
<label><?php _e( 'Sort by:', 'woocommerce' ); ?> <span class="chevron dashicons dashicons-arrow-up-alt2"></span></label>
<?php
$filters = array_keys( WC_Helper::get_filters() );
$last_filter = array_pop( $filters );
$filters = array_keys( WC_Helper::get_filters() );
$last_filter = array_pop( $filters );
$current_filter = WC_Helper::get_current_filter();
$counts = WC_Helper::get_filters_counts();
$counts = WC_Helper::get_filters_counts();
?>
<?php foreach ( WC_Helper::get_filters() as $key => $label ) : ?>
<?php
// Don't show empty filters.
if ( empty( $counts[ $key ] ) ) {
continue;
}
<?php
foreach ( WC_Helper::get_filters() as $key => $label ) :
// Don't show empty filters.
if ( empty( $counts[ $key ] ) ) {
continue;
}
$url = admin_url( 'admin.php?page=wc-addons&section=helper&filter=' . $key );
$class_html = $current_filter === $key ? 'class="current"' : '';
$url = admin_url( 'admin.php?page=wc-addons&section=helper&filter=' . $key );
$class_html = $current_filter === $key ? 'class="current"' : '';
?>
<li>
<a <?php echo $class_html; ?> href="<?php echo esc_url( $url ); ?>">
@ -47,8 +47,9 @@
<tr class="wp-list-table__row is-ext-header">
<td class="wp-list-table__ext-details">
<div class="wp-list-table__ext-title">
<a href="<?php echo esc_url( $subscription['product_url'] ); ?>" target="_blank"><?php
echo esc_html( $subscription['product_name'] ); ?></a>
<a href="<?php echo esc_url( $subscription['product_url'] ); ?>" target="_blank">
<?php echo esc_html( $subscription['product_name'] ); ?>
</a>
</div>
<div class="wp-list-table__ext-description">
@ -80,7 +81,7 @@
<br/>
<span class="subscription">
<?php
<?php
if ( ! $subscription['active'] && $subscription['maxed'] ) {
/* translators: %1$d: sites active, %2$d max sites active */
printf( __( 'Subscription: Not available - %1$d of %2$d already in use', 'woocommerce' ), absint( $subscription['sites_active'] ), absint( $subscription['sites_max'] ) );
@ -97,7 +98,7 @@
} elseif ( isset( $subscription['master_user_email'] ) ) {
printf( '</br>' . __( 'Shared by %s', 'woocommerce' ), esc_html( $subscription['master_user_email'] ) );
}
?>
?>
</span>
</div>
</td>

View File

@ -75,7 +75,7 @@ class WC_Product_CSV_Importer_Controller {
*/
public static function get_importer( $file, $args = array() ) {
$importer_class = apply_filters( 'woocommerce_product_csv_importer_class', 'WC_Product_CSV_Importer' );
$args = apply_filters( 'woocommerce_product_csv_importer_args', $args, $importer_class );
$args = apply_filters( 'woocommerce_product_csv_importer_args', $args, $importer_class );
return new $importer_class( $file, $args );
}
@ -84,7 +84,7 @@ class WC_Product_CSV_Importer_Controller {
*/
public function __construct() {
$default_steps = array(
'upload' => array(
'upload' => array(
'name' => __( 'Upload CSV file', 'woocommerce' ),
'view' => array( $this, 'upload_form' ),
'handler' => array( $this, 'upload_form_handler' ),
@ -94,12 +94,12 @@ class WC_Product_CSV_Importer_Controller {
'view' => array( $this, 'mapping_form' ),
'handler' => '',
),
'import' => array(
'import' => array(
'name' => __( 'Import', 'woocommerce' ),
'view' => array( $this, 'import' ),
'handler' => '',
),
'done' => array(
'done' => array(
'name' => __( 'Done!', 'woocommerce' ),
'view' => array( $this, 'done' ),
'handler' => '',
@ -121,6 +121,7 @@ class WC_Product_CSV_Importer_Controller {
/**
* Get the URL for the next step's screen.
*
* @param string step slug (default: current step)
* @return string URL for next step if a next step exists.
* Admin URL if it's the last step.
@ -159,21 +160,21 @@ class WC_Product_CSV_Importer_Controller {
* Output header view.
*/
protected function output_header() {
include( dirname( __FILE__ ) . '/views/html-csv-import-header.php' );
include dirname( __FILE__ ) . '/views/html-csv-import-header.php';
}
/**
* Output steps view.
*/
protected function output_steps() {
include( dirname( __FILE__ ) . '/views/html-csv-import-steps.php' );
include dirname( __FILE__ ) . '/views/html-csv-import-steps.php';
}
/**
* Output footer view.
*/
protected function output_footer() {
include( dirname( __FILE__ ) . '/views/html-csv-import-footer.php' );
include dirname( __FILE__ ) . '/views/html-csv-import-footer.php';
}
/**
@ -234,7 +235,7 @@ class WC_Product_CSV_Importer_Controller {
$size = size_format( $bytes );
$upload_dir = wp_upload_dir();
include( dirname( __FILE__ ) . '/views/html-product-csv-import-form.php' );
include dirname( __FILE__ ) . '/views/html-product-csv-import-form.php';
}
/**
@ -263,7 +264,12 @@ class WC_Product_CSV_Importer_Controller {
* @return string|WP_Error
*/
public function handle_upload() {
$valid_filetypes = apply_filters( 'woocommerce_csv_product_import_valid_filetypes', array( 'csv' => 'text/csv', 'txt' => 'text/plain' ) );
$valid_filetypes = apply_filters(
'woocommerce_csv_product_import_valid_filetypes', array(
'csv' => 'text/csv',
'txt' => 'text/plain',
)
);
if ( empty( $_POST['file_url'] ) ) {
if ( ! isset( $_FILES['import'] ) ) {
@ -275,8 +281,11 @@ class WC_Product_CSV_Importer_Controller {
return new WP_Error( 'woocommerce_product_csv_importer_upload_file_invalid', __( 'Invalid file type. The importer supports CSV and TXT file formats.', 'woocommerce' ) );
}
$overrides = array( 'test_form' => false, 'mimes' => $valid_filetypes );
$upload = wp_handle_upload( $_FILES['import'], $overrides );
$overrides = array(
'test_form' => false,
'mimes' => $valid_filetypes,
);
$upload = wp_handle_upload( $_FILES['import'], $overrides );
if ( isset( $upload['error'] ) ) {
return new WP_Error( 'woocommerce_product_csv_importer_upload_error', $upload['error'] );
@ -318,7 +327,7 @@ class WC_Product_CSV_Importer_Controller {
* Mapping step.
*/
protected function mapping_form() {
$args = array(
$args = array(
'lines' => 1,
'delimiter' => $this->delimiter,
);
@ -344,7 +353,7 @@ class WC_Product_CSV_Importer_Controller {
return;
}
include_once( dirname( __FILE__ ) . '/views/html-csv-import-mapping.php' );
include_once dirname( __FILE__ ) . '/views/html-csv-import-mapping.php';
}
/**
@ -367,19 +376,21 @@ class WC_Product_CSV_Importer_Controller {
exit;
}
wp_localize_script( 'wc-product-import', 'wc_product_import_params', array(
'import_nonce' => wp_create_nonce( 'wc-product-import' ),
'mapping' => array(
'from' => $mapping_from,
'to' => $mapping_to,
),
'file' => $this->file,
'update_existing' => $this->update_existing,
'delimiter' => $this->delimiter,
) );
wp_localize_script(
'wc-product-import', 'wc_product_import_params', array(
'import_nonce' => wp_create_nonce( 'wc-product-import' ),
'mapping' => array(
'from' => $mapping_from,
'to' => $mapping_to,
),
'file' => $this->file,
'update_existing' => $this->update_existing,
'delimiter' => $this->delimiter,
)
);
wp_enqueue_script( 'wc-product-import' );
include_once( dirname( __FILE__ ) . '/views/html-csv-import-progress.php' );
include_once dirname( __FILE__ ) . '/views/html-csv-import-progress.php';
}
/**
@ -392,7 +403,7 @@ class WC_Product_CSV_Importer_Controller {
$skipped = isset( $_GET['products-skipped'] ) ? absint( $_GET['products-skipped'] ) : 0;
$errors = array_filter( (array) get_user_option( 'product_import_error_log' ) );
include_once( dirname( __FILE__ ) . '/views/html-csv-import-done.php' );
include_once dirname( __FILE__ ) . '/views/html-csv-import-done.php';
}
/**
@ -419,69 +430,78 @@ class WC_Product_CSV_Importer_Controller {
* @return array
*/
protected function auto_map_columns( $raw_headers, $num_indexes = true ) {
$weight_unit = get_option( 'woocommerce_weight_unit' );
$dimension_unit = get_option( 'woocommerce_dimension_unit' );
$weight_unit = get_option( 'woocommerce_weight_unit' );
$dimension_unit = get_option( 'woocommerce_dimension_unit' );
include( dirname( __FILE__ ) . '/mappings/mappings.php' );
include dirname( __FILE__ ) . '/mappings/mappings.php';
/**
* @hooked wc_importer_generic_mappings - 10
* @hooked wc_importer_wordpress_mappings - 10
* @hooked wc_importer_default_english_mappings - 100
*/
$default_columns = $this->normalize_columns_names( apply_filters( 'woocommerce_csv_product_import_mapping_default_columns', array(
__( 'ID', 'woocommerce' ) => 'id',
__( 'Type', 'woocommerce' ) => 'type',
__( 'SKU', 'woocommerce' ) => 'sku',
__( 'Name', 'woocommerce' ) => 'name',
__( 'Published', 'woocommerce' ) => 'published',
__( 'Is featured?', 'woocommerce' ) => 'featured',
__( 'Visibility in catalog', 'woocommerce' ) => 'catalog_visibility',
__( 'Short description', 'woocommerce' ) => 'short_description',
__( 'Description', 'woocommerce' ) => 'description',
__( 'Date sale price starts', 'woocommerce' ) => 'date_on_sale_from',
__( 'Date sale price ends', 'woocommerce' ) => 'date_on_sale_to',
__( 'Tax status', 'woocommerce' ) => 'tax_status',
__( 'Tax class', 'woocommerce' ) => 'tax_class',
__( 'In stock?', 'woocommerce' ) => 'stock_status',
__( 'Stock', 'woocommerce' ) => 'stock_quantity',
__( 'Backorders allowed?', 'woocommerce' ) => 'backorders',
__( 'Sold individually?', 'woocommerce' ) => 'sold_individually',
sprintf( __( 'Weight (%s)', 'woocommerce' ), $weight_unit ) => 'weight',
sprintf( __( 'Length (%s)', 'woocommerce' ), $dimension_unit ) => 'length',
sprintf( __( 'Width (%s)', 'woocommerce' ), $dimension_unit ) => 'width',
sprintf( __( 'Height (%s)', 'woocommerce' ), $dimension_unit ) => 'height',
__( 'Allow customer reviews?', 'woocommerce' ) => 'reviews_allowed',
__( 'Purchase note', 'woocommerce' ) => 'purchase_note',
__( 'Sale price', 'woocommerce' ) => 'sale_price',
__( 'Regular price', 'woocommerce' ) => 'regular_price',
__( 'Categories', 'woocommerce' ) => 'category_ids',
__( 'Tags', 'woocommerce' ) => 'tag_ids',
__( 'Shipping class', 'woocommerce' ) => 'shipping_class_id',
__( 'Images', 'woocommerce' ) => 'images',
__( 'Download limit', 'woocommerce' ) => 'download_limit',
__( 'Download expiry days', 'woocommerce' ) => 'download_expiry',
__( 'Parent', 'woocommerce' ) => 'parent_id',
__( 'Upsells', 'woocommerce' ) => 'upsell_ids',
__( 'Cross-sells', 'woocommerce' ) => 'cross_sell_ids',
__( 'Grouped products', 'woocommerce' ) => 'grouped_products',
__( 'External URL', 'woocommerce' ) => 'product_url',
__( 'Button text', 'woocommerce' ) => 'button_text',
__( 'Position', 'woocommerce' ) => 'menu_order',
) ) );
$special_columns = $this->get_special_columns( $this->normalize_columns_names( apply_filters( 'woocommerce_csv_product_import_mapping_special_columns',
array(
__( 'Attribute %d name', 'woocommerce' ) => 'attributes:name',
__( 'Attribute %d value(s)', 'woocommerce' ) => 'attributes:value',
__( 'Attribute %d visible', 'woocommerce' ) => 'attributes:visible',
__( 'Attribute %d global', 'woocommerce' ) => 'attributes:taxonomy',
__( 'Attribute %d default', 'woocommerce' ) => 'attributes:default',
__( 'Download %d name', 'woocommerce' ) => 'downloads:name',
__( 'Download %d URL', 'woocommerce' ) => 'downloads:url',
__( 'Meta: %s', 'woocommerce' ) => 'meta:',
$default_columns = $this->normalize_columns_names(
apply_filters(
'woocommerce_csv_product_import_mapping_default_columns', array(
__( 'ID', 'woocommerce' ) => 'id',
__( 'Type', 'woocommerce' ) => 'type',
__( 'SKU', 'woocommerce' ) => 'sku',
__( 'Name', 'woocommerce' ) => 'name',
__( 'Published', 'woocommerce' ) => 'published',
__( 'Is featured?', 'woocommerce' ) => 'featured',
__( 'Visibility in catalog', 'woocommerce' ) => 'catalog_visibility',
__( 'Short description', 'woocommerce' ) => 'short_description',
__( 'Description', 'woocommerce' ) => 'description',
__( 'Date sale price starts', 'woocommerce' ) => 'date_on_sale_from',
__( 'Date sale price ends', 'woocommerce' ) => 'date_on_sale_to',
__( 'Tax status', 'woocommerce' ) => 'tax_status',
__( 'Tax class', 'woocommerce' ) => 'tax_class',
__( 'In stock?', 'woocommerce' ) => 'stock_status',
__( 'Stock', 'woocommerce' ) => 'stock_quantity',
__( 'Backorders allowed?', 'woocommerce' ) => 'backorders',
__( 'Sold individually?', 'woocommerce' ) => 'sold_individually',
sprintf( __( 'Weight (%s)', 'woocommerce' ), $weight_unit ) => 'weight',
sprintf( __( 'Length (%s)', 'woocommerce' ), $dimension_unit ) => 'length',
sprintf( __( 'Width (%s)', 'woocommerce' ), $dimension_unit ) => 'width',
sprintf( __( 'Height (%s)', 'woocommerce' ), $dimension_unit ) => 'height',
__( 'Allow customer reviews?', 'woocommerce' ) => 'reviews_allowed',
__( 'Purchase note', 'woocommerce' ) => 'purchase_note',
__( 'Sale price', 'woocommerce' ) => 'sale_price',
__( 'Regular price', 'woocommerce' ) => 'regular_price',
__( 'Categories', 'woocommerce' ) => 'category_ids',
__( 'Tags', 'woocommerce' ) => 'tag_ids',
__( 'Shipping class', 'woocommerce' ) => 'shipping_class_id',
__( 'Images', 'woocommerce' ) => 'images',
__( 'Download limit', 'woocommerce' ) => 'download_limit',
__( 'Download expiry days', 'woocommerce' ) => 'download_expiry',
__( 'Parent', 'woocommerce' ) => 'parent_id',
__( 'Upsells', 'woocommerce' ) => 'upsell_ids',
__( 'Cross-sells', 'woocommerce' ) => 'cross_sell_ids',
__( 'Grouped products', 'woocommerce' ) => 'grouped_products',
__( 'External URL', 'woocommerce' ) => 'product_url',
__( 'Button text', 'woocommerce' ) => 'button_text',
__( 'Position', 'woocommerce' ) => 'menu_order',
)
)
) ) );
);
$special_columns = $this->get_special_columns(
$this->normalize_columns_names(
apply_filters(
'woocommerce_csv_product_import_mapping_special_columns',
array(
__( 'Attribute %d name', 'woocommerce' ) => 'attributes:name',
__( 'Attribute %d value(s)', 'woocommerce' ) => 'attributes:value',
__( 'Attribute %d visible', 'woocommerce' ) => 'attributes:visible',
__( 'Attribute %d global', 'woocommerce' ) => 'attributes:taxonomy',
__( 'Attribute %d default', 'woocommerce' ) => 'attributes:default',
__( 'Download %d name', 'woocommerce' ) => 'downloads:name',
__( 'Download %d URL', 'woocommerce' ) => 'downloads:url',
__( 'Meta: %s', 'woocommerce' ) => 'meta:',
)
)
)
);
$headers = array();
foreach ( $raw_headers as $key => $field ) {
@ -599,11 +619,11 @@ class WC_Product_CSV_Importer_Controller {
'name' => __( 'Dimensions', 'woocommerce' ),
'options' => array(
/* translators: %s: dimension unit */
'length' => sprintf( __( 'Length (%s)', 'woocommerce' ), $dimension_unit ),
'length' => sprintf( __( 'Length (%s)', 'woocommerce' ), $dimension_unit ),
/* translators: %s: dimension unit */
'width' => sprintf( __( 'Width (%s)', 'woocommerce' ), $dimension_unit ),
'width' => sprintf( __( 'Width (%s)', 'woocommerce' ), $dimension_unit ),
/* translators: %s: dimension unit */
'height' => sprintf( __( 'Height (%s)', 'woocommerce' ), $dimension_unit ),
'height' => sprintf( __( 'Height (%s)', 'woocommerce' ), $dimension_unit ),
),
),
'category_ids' => __( 'Categories', 'woocommerce' ),
@ -617,8 +637,8 @@ class WC_Product_CSV_Importer_Controller {
'external' => array(
'name' => __( 'External product', 'woocommerce' ),
'options' => array(
'product_url' => __( 'External URL', 'woocommerce' ),
'button_text' => __( 'Button text', 'woocommerce' ),
'product_url' => __( 'External URL', 'woocommerce' ),
'button_text' => __( 'Button text', 'woocommerce' ),
),
),
'downloads' => array(

View File

@ -248,14 +248,16 @@ class WC_Tax_Rate_Importer extends WP_Importer {
$action = 'admin.php?import=woocommerce_tax_rate_csv&step=1';
$bytes = apply_filters( 'import_upload_size_limit', wp_max_upload_size() );
$size = size_format( $bytes );
$bytes = apply_filters( 'import_upload_size_limit', wp_max_upload_size() );
$size = size_format( $bytes );
$upload_dir = wp_upload_dir();
if ( ! empty( $upload_dir['error'] ) ) :
?><div class="error"><p><?php esc_html_e( 'Before you can upload your import file, you will need to fix the following error:', 'woocommerce' ); ?></p>
<p><strong><?php echo esc_html( $upload_dir['error'] ); ?></strong></p></div><?php
else :
?>
<div class="error">
<p><?php esc_html_e( 'Before you can upload your import file, you will need to fix the following error:', 'woocommerce' ); ?></p>
<p><strong><?php echo esc_html( $upload_dir['error'] ); ?></strong></p>
</div>
<?php else : ?>
<form enctype="multipart/form-data" id="import-upload-form" method="post" action="<?php echo esc_attr( wp_nonce_url( $action, 'import-upload' ) ); ?>">
<table class="form-table">
<tbody>

View File

@ -31,9 +31,9 @@ function wc_importer_default_english_mappings( $mappings ) {
return $mappings;
}
$weight_unit = get_option( 'woocommerce_weight_unit' );
$dimension_unit = get_option( 'woocommerce_dimension_unit' );
$new_mappings = array(
$weight_unit = get_option( 'woocommerce_weight_unit' );
$dimension_unit = get_option( 'woocommerce_dimension_unit' );
$new_mappings = array(
'ID' => 'id',
'Type' => 'type',
'SKU' => 'sku',

View File

@ -7,6 +7,6 @@ if ( ! defined( 'ABSPATH' ) ) {
exit;
}
include( dirname( __FILE__ ) . '/default.php' );
include( dirname( __FILE__ ) . '/generic.php' );
include( dirname( __FILE__ ) . '/wordpress.php' );
require dirname( __FILE__ ) . '/default.php';
require dirname( __FILE__ ) . '/generic.php';
require dirname( __FILE__ ) . '/wordpress.php';

View File

@ -9,46 +9,46 @@ if ( ! defined( 'ABSPATH' ) ) {
<div class="wc-progress-form-content woocommerce-importer">
<section class="woocommerce-importer-done">
<?php
$results = array();
$results = array();
if ( 0 < $imported ) {
$results[] = sprintf(
/* translators: %d: products count */
_n( '%s product imported', '%s products imported', $imported, 'woocommerce' ),
'<strong>' . number_format_i18n( $imported ) . '</strong>'
);
}
if ( 0 < $imported ) {
$results[] = sprintf(
/* translators: %d: products count */
_n( '%s product imported', '%s products imported', $imported, 'woocommerce' ),
'<strong>' . number_format_i18n( $imported ) . '</strong>'
);
}
if ( 0 < $updated ) {
$results[] = sprintf(
/* translators: %d: products count */
_n( '%s product updated', '%s products updated', $updated, 'woocommerce' ),
'<strong>' . number_format_i18n( $updated ) . '</strong>'
);
}
if ( 0 < $updated ) {
$results[] = sprintf(
/* translators: %d: products count */
_n( '%s product updated', '%s products updated', $updated, 'woocommerce' ),
'<strong>' . number_format_i18n( $updated ) . '</strong>'
);
}
if ( 0 < $skipped ) {
$results[] = sprintf(
/* translators: %d: products count */
_n( '%s product was skipped', '%s products were skipped', $skipped, 'woocommerce' ),
'<strong>' . number_format_i18n( $skipped ) . '</strong>'
);
}
if ( 0 < $skipped ) {
$results[] = sprintf(
/* translators: %d: products count */
_n( '%s product was skipped', '%s products were skipped', $skipped, 'woocommerce' ),
'<strong>' . number_format_i18n( $skipped ) . '</strong>'
);
}
if ( 0 < $failed ) {
$results [] = sprintf(
/* translators: %d: products count */
_n( 'Failed to import %s product', 'Failed to import %s products', $failed, 'woocommerce' ),
'<strong>' . number_format_i18n( $failed ) . '</strong>'
);
}
if ( 0 < $failed ) {
$results [] = sprintf(
/* translators: %d: products count */
_n( 'Failed to import %s product', 'Failed to import %s products', $failed, 'woocommerce' ),
'<strong>' . number_format_i18n( $failed ) . '</strong>'
);
}
if ( 0 < $failed || 0 < $skipped ) {
$results[] = '<a href="#" class="woocommerce-importer-done-view-errors">' . __( 'View import log', 'woocommerce' ) . '</a>';
}
if ( 0 < $failed || 0 < $skipped ) {
$results[] = '<a href="#" class="woocommerce-importer-done-view-errors">' . __( 'View import log', 'woocommerce' ) . '</a>';
}
/* translators: %d: import results */
echo wp_kses_post( __( 'Import complete!', 'woocommerce' ) . ' ' . implode( '. ', $results ) );
/* translators: %d: import results */
echo wp_kses_post( __( 'Import complete!', 'woocommerce' ) . ' ' . implode( '. ', $results ) );
?>
</section>
<section class="wc-importer-error-log" style="display:none">
@ -61,20 +61,20 @@ if ( ! defined( 'ABSPATH' ) ) {
</thead>
<tbody>
<?php
if ( count( $errors ) ) {
foreach ( $errors as $error ) {
if ( ! is_wp_error( $error ) ) {
continue;
}
$error_data = $error->get_error_data();
?>
<tr>
<th><code><?php echo esc_html( $error_data['row'] ); ?></code></th>
<td><?php echo esc_html( $error->get_error_message() ); ?></td>
</tr>
<?php
if ( count( $errors ) ) {
foreach ( $errors as $error ) {
if ( ! is_wp_error( $error ) ) {
continue;
}
$error_data = $error->get_error_data();
?>
<tr>
<th><code><?php echo esc_html( $error_data['row'] ); ?></code></th>
<td><?php echo esc_html( $error->get_error_message() ); ?></td>
</tr>
<?php
}
}
?>
</tbody>
</table>

View File

@ -9,7 +9,7 @@ if ( ! defined( 'ABSPATH' ) ) {
exit;
}
?>
<form class="wc-progress-form-content woocommerce-importer" method="post" action="<?php echo esc_url( $this->get_next_step_link() ) ?>">
<form class="wc-progress-form-content woocommerce-importer" method="post" action="<?php echo esc_url( $this->get_next_step_link() ); ?>">
<header>
<h2><?php esc_html_e( 'Map CSV fields to products', 'woocommerce' ); ?></h2>
<p><?php esc_html_e( 'Select fields from your CSV file to map against products fields, or to ignore during import.', 'woocommerce' ); ?></p>

View File

@ -8,12 +8,15 @@ if ( ! defined( 'ABSPATH' ) ) {
?>
<ol class="wc-progress-steps">
<?php foreach ( $this->steps as $step_key => $step ) : ?>
<li class="<?php
if ( $step_key === $this->step ) {
echo 'active';
} elseif ( array_search( $this->step, array_keys( $this->steps ) ) > array_search( $step_key, array_keys( $this->steps ) ) ) {
echo 'done';
}
?>"><?php echo esc_html( $step['name'] ); ?></li>
<?php
if ( $step_key === $this->step ) {
$step_class = 'active';
} elseif ( array_search( $this->step, array_keys( $this->steps ) ) > array_search( $step_key, array_keys( $this->steps ) ) ) {
$step_class = 'done';
}
?>
<li class="<?php echo esc_attr( $step_class ); ?>">
<?php echo esc_html( $step['name'] ); ?>
</li>
<?php endforeach; ?>
</ol>

View File

@ -26,10 +26,12 @@ if ( ! defined( 'ABSPATH' ) ) {
<td>
<?php
if ( ! empty( $upload_dir['error'] ) ) {
?><div class="inline error">
?>
<div class="inline error">
<p><?php esc_html_e( 'Before you can upload your import file, you will need to fix the following error:', 'woocommerce' ); ?></p>
<p><strong><?php echo esc_html( $upload_dir['error'] ); ?></strong></p>
</div><?php
</div>
<?php
} else {
?>
<input type="file" id="upload" name="import" size="25" />
@ -99,4 +101,4 @@ if ( ! defined( 'ABSPATH' ) ) {
<button type="submit" class="button button-primary button-next" value="<?php esc_attr_e( 'Continue', 'woocommerce' ); ?>" name="save_step"><?php esc_html_e( 'Continue', 'woocommerce' ); ?></button>
<?php wp_nonce_field( 'woocommerce-csv-importer' ); ?>
</div>
</form>
</form>

View File

@ -66,7 +66,7 @@ abstract class WC_Admin_List_Table {
if ( $post_type === $this->list_table_type && 'bottom' === $which ) {
$counts = (array) wp_count_posts( $post_type );
unset( $counts['auto-draft'] );
$count = array_sum( $counts );
$count = array_sum( $counts );
if ( 0 < $count ) {
return;

View File

@ -17,7 +17,7 @@ if ( class_exists( 'WC_Admin_List_Table_Coupons', false ) ) {
}
if ( ! class_exists( 'WC_Admin_List_Table', false ) ) {
include_once( 'abstract-class-wc-admin-list-table.php' );
include_once 'abstract-class-wc-admin-list-table.php';
}
/**
@ -47,7 +47,7 @@ class WC_Admin_List_Table_Coupons extends WC_Admin_List_Table {
echo '<div class="woocommerce-BlankState">';
echo '<h2 class="woocommerce-BlankState-message">' . esc_html__( 'Coupons are a great way to offer discounts and rewards to your customers. They will appear here once created.', 'woocommerce' ) . '</h2>';
echo '<a class="woocommerce-BlankState-cta button-primary button" target="_blank" href="https://docs.woocommerce.com/document/coupon-management/?utm_source=blankslate&utm_medium=product&utm_content=couponsdoc&utm_campaign=woocommerceplugin">' . esc_html__( 'Learn more about coupons', 'woocommerce' ) . '</a>';
echo '<a class="woocommerce-BlankState-cta button-primary button" href="' . esc_url ( admin_url( 'post-new.php?post_type=shop_coupon' ) ) . '">' . esc_html__( 'Create your first coupon', 'woocommerce' ) . '</a>';
echo '<a class="woocommerce-BlankState-cta button-primary button" href="' . esc_url( admin_url( 'post-new.php?post_type=shop_coupon' ) ) . '">' . esc_html__( 'Create your first coupon', 'woocommerce' ) . '</a>';
echo '</div>';
}

View File

@ -458,8 +458,8 @@ class WC_Admin_List_Table_Products extends WC_Admin_List_Table {
// Search using CRUD.
if ( ! empty( $query_vars['s'] ) ) {
$data_store = WC_Data_Store::load( 'product' );
$ids = $data_store->search_products( wc_clean( $query_vars['s'] ), '', true, true );
$data_store = WC_Data_Store::load( 'product' );
$ids = $data_store->search_products( wc_clean( $query_vars['s'] ), '', true, true );
$query_vars['post__in'] = array_merge( $ids, array( 0 ) );
// So we know we are searching products.
$query_vars['product_search'] = true;

View File

@ -28,7 +28,9 @@ class WC_Meta_Box_Coupon_Data {
wp_nonce_field( 'woocommerce_save_data', 'woocommerce_meta_nonce' );
$coupon = new WC_Coupon( $post->ID );
?>
<style type="text/css">
#edit-slug-box, #minor-publishing-actions { display:none }
</style>
@ -38,8 +40,9 @@ class WC_Meta_Box_Coupon_Data {
<ul class="coupon_data_tabs wc-tabs" style="display:none;">
<?php
$coupon_data_tabs = apply_filters( 'woocommerce_coupon_data_tabs', array(
'general' => array(
$coupon_data_tabs = apply_filters(
'woocommerce_coupon_data_tabs', array(
'general' => array(
'label' => __( 'General', 'woocommerce' ),
'target' => 'general_coupon_data',
'class' => 'general_coupon_data',
@ -49,110 +52,133 @@ class WC_Meta_Box_Coupon_Data {
'target' => 'usage_restriction_coupon_data',
'class' => '',
),
'usage_limit' => array(
'usage_limit' => array(
'label' => __( 'Usage limits', 'woocommerce' ),
'target' => 'usage_limit_coupon_data',
'class' => '',
),
) );
)
);
foreach ( $coupon_data_tabs as $key => $tab ) {
?><li class="<?php echo $key; ?>_options <?php echo $key; ?>_tab <?php echo implode( ' ' , (array) $tab['class'] ); ?>">
<a href="#<?php echo $tab['target']; ?>"><span><?php echo esc_html( $tab['label'] ); ?></span></a>
</li><?php
}
?>
foreach ( $coupon_data_tabs as $key => $tab ) :
?>
<li class="<?php echo $key; ?>_options <?php echo $key; ?>_tab <?php echo implode( ' ', (array) $tab['class'] ); ?>">
<a href="#<?php echo $tab['target']; ?>">
<span><?php echo esc_html( $tab['label'] ); ?></span>
</a>
</li>
<?php endforeach; ?>
</ul>
<div id="general_coupon_data" class="panel woocommerce_options_panel"><?php
<div id="general_coupon_data" class="panel woocommerce_options_panel">
<?php
// Type
woocommerce_wp_select( array(
'id' => 'discount_type',
'label' => __( 'Discount type', 'woocommerce' ),
'options' => wc_get_coupon_types(),
) );
// Type.
woocommerce_wp_select(
array(
'id' => 'discount_type',
'label' => __( 'Discount type', 'woocommerce' ),
'options' => wc_get_coupon_types(),
)
);
// Amount
woocommerce_wp_text_input( array(
'id' => 'coupon_amount',
'label' => __( 'Coupon amount', 'woocommerce' ),
'placeholder' => wc_format_localized_price( 0 ),
'description' => __( 'Value of the coupon.', 'woocommerce' ),
'data_type' => 'price',
'desc_tip' => true,
) );
// Amount.
woocommerce_wp_text_input(
array(
'id' => 'coupon_amount',
'label' => __( 'Coupon amount', 'woocommerce' ),
'placeholder' => wc_format_localized_price( 0 ),
'description' => __( 'Value of the coupon.', 'woocommerce' ),
'data_type' => 'price',
'desc_tip' => true,
)
);
// Free Shipping
// Free Shipping.
if ( wc_shipping_enabled() ) {
woocommerce_wp_checkbox( array(
'id' => 'free_shipping',
'label' => __( 'Allow free shipping', 'woocommerce' ),
'description' => sprintf( __( 'Check this box if the coupon grants free shipping. A <a href="%s" target="_blank">free shipping method</a> must be enabled in your shipping zone and be set to require "a valid free shipping coupon" (see the "Free Shipping Requires" setting).', 'woocommerce' ), 'https://docs.woocommerce.com/document/free-shipping/' ),
) );
woocommerce_wp_checkbox(
array(
'id' => 'free_shipping',
'label' => __( 'Allow free shipping', 'woocommerce' ),
'description' => sprintf( __( 'Check this box if the coupon grants free shipping. A <a href="%s" target="_blank">free shipping method</a> must be enabled in your shipping zone and be set to require "a valid free shipping coupon" (see the "Free Shipping Requires" setting).', 'woocommerce' ), 'https://docs.woocommerce.com/document/free-shipping/' ),
)
);
}
// Expiry date
// Expiry date.
$expiry_date = $coupon->get_date_expires() ? $coupon->get_date_expires()->date( 'Y-m-d' ) : '';
woocommerce_wp_text_input( array(
'id' => 'expiry_date',
'value' => esc_attr( $expiry_date ),
'label' => __( 'Coupon expiry date', 'woocommerce' ),
'placeholder' => 'YYYY-MM-DD',
'description' => '',
'class' => 'date-picker',
'custom_attributes' => array(
'pattern' => apply_filters( 'woocommerce_date_input_html_pattern', '[0-9]{4}-(0[1-9]|1[012])-(0[1-9]|1[0-9]|2[0-9]|3[01])' ),
),
) );
woocommerce_wp_text_input(
array(
'id' => 'expiry_date',
'value' => esc_attr( $expiry_date ),
'label' => __( 'Coupon expiry date', 'woocommerce' ),
'placeholder' => 'YYYY-MM-DD',
'description' => '',
'class' => 'date-picker',
'custom_attributes' => array(
'pattern' => apply_filters( 'woocommerce_date_input_html_pattern', '[0-9]{4}-(0[1-9]|1[012])-(0[1-9]|1[0-9]|2[0-9]|3[01])' ),
),
)
);
do_action( 'woocommerce_coupon_options', $coupon->get_id(), $coupon );
?></div>
<div id="usage_restriction_coupon_data" class="panel woocommerce_options_panel"><?php
?>
</div>
<div id="usage_restriction_coupon_data" class="panel woocommerce_options_panel">
<?php
echo '<div class="options_group">';
// minimum spend
woocommerce_wp_text_input( array(
'id' => 'minimum_amount',
'label' => __( 'Minimum spend', 'woocommerce' ),
'placeholder' => __( 'No minimum', 'woocommerce' ),
'description' => __( 'This field allows you to set the minimum spend (subtotal) allowed to use the coupon.', 'woocommerce' ),
'data_type' => 'price',
'desc_tip' => true,
) );
// minimum spend.
woocommerce_wp_text_input(
array(
'id' => 'minimum_amount',
'label' => __( 'Minimum spend', 'woocommerce' ),
'placeholder' => __( 'No minimum', 'woocommerce' ),
'description' => __( 'This field allows you to set the minimum spend (subtotal) allowed to use the coupon.', 'woocommerce' ),
'data_type' => 'price',
'desc_tip' => true,
)
);
// maximum spend
woocommerce_wp_text_input( array(
'id' => 'maximum_amount',
'label' => __( 'Maximum spend', 'woocommerce' ),
'placeholder' => __( 'No maximum', 'woocommerce' ),
'description' => __( 'This field allows you to set the maximum spend (subtotal) allowed when using the coupon.', 'woocommerce' ),
'data_type' => 'price',
'desc_tip' => true,
) );
// maximum spend.
woocommerce_wp_text_input(
array(
'id' => 'maximum_amount',
'label' => __( 'Maximum spend', 'woocommerce' ),
'placeholder' => __( 'No maximum', 'woocommerce' ),
'description' => __( 'This field allows you to set the maximum spend (subtotal) allowed when using the coupon.', 'woocommerce' ),
'data_type' => 'price',
'desc_tip' => true,
)
);
// Individual use
woocommerce_wp_checkbox( array(
'id' => 'individual_use',
'label' => __( 'Individual use only', 'woocommerce' ),
'description' => __( 'Check this box if the coupon cannot be used in conjunction with other coupons.', 'woocommerce' ),
) );
// Individual use.
woocommerce_wp_checkbox(
array(
'id' => 'individual_use',
'label' => __( 'Individual use only', 'woocommerce' ),
'description' => __( 'Check this box if the coupon cannot be used in conjunction with other coupons.', 'woocommerce' ),
)
);
// Exclude Sale Products
woocommerce_wp_checkbox( array(
'id' => 'exclude_sale_items',
'label' => __( 'Exclude sale items', 'woocommerce' ),
'description' => __( 'Check this box if the coupon should not apply to items on sale. Per-item coupons will only work if the item is not on sale. Per-cart coupons will only work if there are items in the cart that are not on sale.', 'woocommerce' ),
) );
// Exclude Sale Products.
woocommerce_wp_checkbox(
array(
'id' => 'exclude_sale_items',
'label' => __( 'Exclude sale items', 'woocommerce' ),
'description' => __( 'Check this box if the coupon should not apply to items on sale. Per-item coupons will only work if the item is not on sale. Per-cart coupons will only work if there are items in the cart that are not on sale.', 'woocommerce' ),
)
);
echo '</div><div class="options_group">';
// Product ids
// Product ids.
?>
<p class="form-field"><label><?php _e( 'Products', 'woocommerce' ); ?></label>
<select class="wc-product-search" multiple="multiple" style="width: 50%;" name="product_ids[]" data-placeholder="<?php esc_attr_e( 'Search for a product&hellip;', 'woocommerce' ); ?>" data-action="woocommerce_json_search_products_and_variations">
<?php
<p class="form-field">
<label><?php _e( 'Products', 'woocommerce' ); ?></label>
<select class="wc-product-search" multiple="multiple" style="width: 50%;" name="product_ids[]" data-placeholder="<?php esc_attr_e( 'Search for a product&hellip;', 'woocommerce' ); ?>" data-action="woocommerce_json_search_products_and_variations">
<?php
$product_ids = $coupon->get_product_ids();
foreach ( $product_ids as $product_id ) {
@ -161,15 +187,16 @@ class WC_Meta_Box_Coupon_Data {
echo '<option value="' . esc_attr( $product_id ) . '"' . selected( true, true, false ) . '>' . wp_kses_post( $product->get_formatted_name() ) . '</option>';
}
}
?>
</select> <?php echo wc_help_tip( __( 'Products that the coupon will be applied to, or that need to be in the cart in order for the "Fixed cart discount" to be applied.', 'woocommerce' ) ); ?></p>
<?php
?>
</select>
<?php echo wc_help_tip( __( 'Products that the coupon will be applied to, or that need to be in the cart in order for the "Fixed cart discount" to be applied.', 'woocommerce' ) ); ?>
</p>
// Exclude Product ids
?>
<p class="form-field"><label><?php _e( 'Exclude products', 'woocommerce' ); ?></label>
<select class="wc-product-search" multiple="multiple" style="width: 50%;" name="exclude_product_ids[]" data-placeholder="<?php esc_attr_e( 'Search for a product&hellip;', 'woocommerce' ); ?>" data-action="woocommerce_json_search_products_and_variations">
<?php
<?php // Exclude Product ids. ?>
<p class="form-field">
<label><?php _e( 'Exclude products', 'woocommerce' ); ?></label>
<select class="wc-product-search" multiple="multiple" style="width: 50%;" name="exclude_product_ids[]" data-placeholder="<?php esc_attr_e( 'Search for a product&hellip;', 'woocommerce' ); ?>" data-action="woocommerce_json_search_products_and_variations">
<?php
$product_ids = $coupon->get_excluded_product_ids();
foreach ( $product_ids as $product_id ) {
@ -178,17 +205,20 @@ class WC_Meta_Box_Coupon_Data {
echo '<option value="' . esc_attr( $product_id ) . '"' . selected( true, true, false ) . '>' . wp_kses_post( $product->get_formatted_name() ) . '</option>';
}
}
?>
</select> <?php echo wc_help_tip( __( 'Products that the coupon will not be applied to, or that cannot be in the cart in order for the "Fixed cart discount" to be applied.', 'woocommerce' ) ); ?></p>
?>
</select>
<?php echo wc_help_tip( __( 'Products that the coupon will not be applied to, or that cannot be in the cart in order for the "Fixed cart discount" to be applied.', 'woocommerce' ) ); ?>
</p>
<?php
echo '</div><div class="options_group">';
// Categories
// Categories.
?>
<p class="form-field"><label for="product_categories"><?php _e( 'Product categories', 'woocommerce' ); ?></label>
<select id="product_categories" name="product_categories[]" style="width: 50%;" class="wc-enhanced-select" multiple="multiple" data-placeholder="<?php esc_attr_e( 'Any category', 'woocommerce' ); ?>">
<?php
<p class="form-field">
<label for="product_categories"><?php _e( 'Product categories', 'woocommerce' ); ?></label>
<select id="product_categories" name="product_categories[]" style="width: 50%;" class="wc-enhanced-select" multiple="multiple" data-placeholder="<?php esc_attr_e( 'Any category', 'woocommerce' ); ?>">
<?php
$category_ids = $coupon->get_product_categories();
$categories = get_terms( 'product_cat', 'orderby=name&hide_empty=0' );
@ -197,15 +227,15 @@ class WC_Meta_Box_Coupon_Data {
echo '<option value="' . esc_attr( $cat->term_id ) . '"' . selected( in_array( $cat->term_id, $category_ids ), true, false ) . '>' . esc_html( $cat->name ) . '</option>';
}
}
?>
</select> <?php echo wc_help_tip( __( 'Product categories that the coupon will be applied to, or that need to be in the cart in order for the "Fixed cart discount" to be applied.', 'woocommerce' ) ); ?></p>
<?php
?>
</select> <?php echo wc_help_tip( __( 'Product categories that the coupon will be applied to, or that need to be in the cart in order for the "Fixed cart discount" to be applied.', 'woocommerce' ) ); ?>
</p>
// Exclude Categories
?>
<p class="form-field"><label for="exclude_product_categories"><?php _e( 'Exclude categories', 'woocommerce' ); ?></label>
<select id="exclude_product_categories" name="exclude_product_categories[]" style="width: 50%;" class="wc-enhanced-select" multiple="multiple" data-placeholder="<?php esc_attr_e( 'No categories', 'woocommerce' ); ?>">
<?php
<?php // Exclude Categories. ?>
<p class="form-field">
<label for="exclude_product_categories"><?php _e( 'Exclude categories', 'woocommerce' ); ?></label>
<select id="exclude_product_categories" name="exclude_product_categories[]" style="width: 50%;" class="wc-enhanced-select" multiple="multiple" data-placeholder="<?php esc_attr_e( 'No categories', 'woocommerce' ); ?>">
<?php
$category_ids = $coupon->get_excluded_product_categories();
$categories = get_terms( 'product_cat', 'orderby=name&hide_empty=0' );
@ -214,89 +244,93 @@ class WC_Meta_Box_Coupon_Data {
echo '<option value="' . esc_attr( $cat->term_id ) . '"' . selected( in_array( $cat->term_id, $category_ids ), true, false ) . '>' . esc_html( $cat->name ) . '</option>';
}
}
?>
</select> <?php echo wc_help_tip( __( 'Product categories that the coupon will not be applied to, or that cannot be in the cart in order for the "Fixed cart discount" to be applied.', 'woocommerce' ) ); ?></p>
?>
</select>
<?php echo wc_help_tip( __( 'Product categories that the coupon will not be applied to, or that cannot be in the cart in order for the "Fixed cart discount" to be applied.', 'woocommerce' ) ); ?>
</p>
</div>
<div class="options_group">';
<?php
// Customers.
woocommerce_wp_text_input(
array(
'id' => 'customer_email',
'label' => __( 'Email restrictions', 'woocommerce' ),
'placeholder' => __( 'No restrictions', 'woocommerce' ),
'description' => __( 'List of allowed emails to check against the customer billing email when an order is placed. Separate email addresses with commas.', 'woocommerce' ),
'value' => implode( ', ', (array) $coupon->get_email_restrictions() ),
'desc_tip' => true,
'type' => 'email',
'class' => '',
'custom_attributes' => array(
'multiple' => 'multiple',
),
)
);
?>
</div>
<?php do_action( 'woocommerce_coupon_options_usage_restriction', $coupon->get_id(), $coupon ); ?>
</div>
<div id="usage_limit_coupon_data" class="panel woocommerce_options_panel">
<div class="options_group">
<?php
// Usage limit per coupons.
woocommerce_wp_text_input(
array(
'id' => 'usage_limit',
'label' => __( 'Usage limit per coupon', 'woocommerce' ),
'placeholder' => esc_attr__( 'Unlimited usage', 'woocommerce' ),
'description' => __( 'How many times this coupon can be used before it is void.', 'woocommerce' ),
'type' => 'number',
'desc_tip' => true,
'class' => 'short',
'custom_attributes' => array(
'step' => 1,
'min' => 0,
),
'value' => $coupon->get_usage_limit() ? $coupon->get_usage_limit() : '',
)
);
echo '</div><div class="options_group">';
// Usage limit per product.
woocommerce_wp_text_input(
array(
'id' => 'limit_usage_to_x_items',
'label' => __( 'Limit usage to X items', 'woocommerce' ),
'placeholder' => esc_attr__( 'Apply to all qualifying items in cart', 'woocommerce' ),
'description' => __( 'The maximum number of individual items this coupon can apply to when using product discounts. Leave blank to apply to all qualifying items in cart.', 'woocommerce' ),
'desc_tip' => true,
'class' => 'short',
'type' => 'number',
'custom_attributes' => array(
'step' => 1,
'min' => 0,
),
'value' => $coupon->get_limit_usage_to_x_items() ? $coupon->get_limit_usage_to_x_items() : '',
)
);
// Customers
woocommerce_wp_text_input( array(
'id' => 'customer_email',
'label' => __( 'Email restrictions', 'woocommerce' ),
'placeholder' => __( 'No restrictions', 'woocommerce' ),
'description' => __( 'List of allowed emails to check against the customer billing email when an order is placed. Separate email addresses with commas.', 'woocommerce' ),
'value' => implode( ', ', (array) $coupon->get_email_restrictions() ),
'desc_tip' => true,
'type' => 'email',
'class' => '',
'custom_attributes' => array(
'multiple' => 'multiple',
),
) );
echo '</div>';
do_action( 'woocommerce_coupon_options_usage_restriction', $coupon->get_id(), $coupon );
?></div>
<div id="usage_limit_coupon_data" class="panel woocommerce_options_panel"><?php
echo '<div class="options_group">';
// Usage limit per coupons
woocommerce_wp_text_input( array(
'id' => 'usage_limit',
'label' => __( 'Usage limit per coupon', 'woocommerce' ),
'placeholder' => esc_attr__( 'Unlimited usage', 'woocommerce' ),
'description' => __( 'How many times this coupon can be used before it is void.', 'woocommerce' ),
'type' => 'number',
'desc_tip' => true,
'class' => 'short',
'custom_attributes' => array(
'step' => 1,
'min' => 0,
),
'value' => $coupon->get_usage_limit() ? $coupon->get_usage_limit() : '',
) );
// Usage limit per product
woocommerce_wp_text_input( array(
'id' => 'limit_usage_to_x_items',
'label' => __( 'Limit usage to X items', 'woocommerce' ),
'placeholder' => esc_attr__( 'Apply to all qualifying items in cart', 'woocommerce' ),
'description' => __( 'The maximum number of individual items this coupon can apply to when using product discounts. Leave blank to apply to all qualifying items in cart.', 'woocommerce' ),
'desc_tip' => true,
'class' => 'short',
'type' => 'number',
'custom_attributes' => array(
'step' => 1,
'min' => 0,
),
'value' => $coupon->get_limit_usage_to_x_items() ? $coupon->get_limit_usage_to_x_items() : '',
) );
// Usage limit per users
woocommerce_wp_text_input( array(
'id' => 'usage_limit_per_user',
'label' => __( 'Usage limit per user', 'woocommerce' ),
'placeholder' => esc_attr__( 'Unlimited usage', 'woocommerce' ),
'description' => __( 'How many times this coupon can be used by an individual user. Uses billing email for guests, and user ID for logged in users.', 'woocommerce' ),
'desc_tip' => true,
'class' => 'short',
'type' => 'number',
'custom_attributes' => array(
'step' => 1,
'min' => 0,
),
'value' => $coupon->get_usage_limit_per_user() ? $coupon->get_usage_limit_per_user() : '',
) );
echo '</div>';
do_action( 'woocommerce_coupon_options_usage_limit', $coupon->get_id(), $coupon );
?></div>
// Usage limit per users.
woocommerce_wp_text_input(
array(
'id' => 'usage_limit_per_user',
'label' => __( 'Usage limit per user', 'woocommerce' ),
'placeholder' => esc_attr__( 'Unlimited usage', 'woocommerce' ),
'description' => __( 'How many times this coupon can be used by an individual user. Uses billing email for guests, and user ID for logged in users.', 'woocommerce' ),
'desc_tip' => true,
'class' => 'short',
'type' => 'number',
'custom_attributes' => array(
'step' => 1,
'min' => 0,
),
'value' => $coupon->get_usage_limit_per_user() ? $coupon->get_usage_limit_per_user() : '',
)
);
?>
</div>
<?php do_action( 'woocommerce_coupon_options_usage_limit', $coupon->get_id(), $coupon ); ?>
</div>
<?php do_action( 'woocommerce_coupon_data_panels', $coupon->get_id(), $coupon ); ?>
<div class="clear"></div>
</div>
@ -306,11 +340,11 @@ class WC_Meta_Box_Coupon_Data {
/**
* Save meta box data.
*
* @param int $post_id
* @param int $post_id
* @param WP_Post $post
*/
public static function save( $post_id, $post ) {
// Check for dupe coupons
// Check for dupe coupons.
$coupon_code = wc_format_coupon_code( $post->post_title );
$id_from_code = wc_get_coupon_id_by_code( $coupon_code, $post_id );
@ -322,25 +356,27 @@ class WC_Meta_Box_Coupon_Data {
$exclude_product_categories = isset( $_POST['exclude_product_categories'] ) ? (array) $_POST['exclude_product_categories'] : array();
$coupon = new WC_Coupon( $post_id );
$coupon->set_props( array(
'code' => $post->post_title,
'discount_type' => wc_clean( $_POST['discount_type'] ),
'amount' => wc_format_decimal( $_POST['coupon_amount'] ),
'date_expires' => wc_clean( $_POST['expiry_date'] ),
'individual_use' => isset( $_POST['individual_use'] ),
'product_ids' => isset( $_POST['product_ids'] ) ? array_filter( array_map( 'intval', (array) $_POST['product_ids'] ) ) : array(),
'excluded_product_ids' => isset( $_POST['exclude_product_ids'] ) ? array_filter( array_map( 'intval', (array) $_POST['exclude_product_ids'] ) ) : array(),
'usage_limit' => absint( $_POST['usage_limit'] ),
'usage_limit_per_user' => absint( $_POST['usage_limit_per_user'] ),
'limit_usage_to_x_items' => absint( $_POST['limit_usage_to_x_items'] ),
'free_shipping' => isset( $_POST['free_shipping'] ),
'product_categories' => array_filter( array_map( 'intval', $product_categories ) ),
'excluded_product_categories' => array_filter( array_map( 'intval', $exclude_product_categories ) ),
'exclude_sale_items' => isset( $_POST['exclude_sale_items'] ),
'minimum_amount' => wc_format_decimal( $_POST['minimum_amount'] ),
'maximum_amount' => wc_format_decimal( $_POST['maximum_amount'] ),
'email_restrictions' => array_filter( array_map( 'trim', explode( ',', wc_clean( $_POST['customer_email'] ) ) ) ),
) );
$coupon->set_props(
array(
'code' => $post->post_title,
'discount_type' => wc_clean( $_POST['discount_type'] ),
'amount' => wc_format_decimal( $_POST['coupon_amount'] ),
'date_expires' => wc_clean( $_POST['expiry_date'] ),
'individual_use' => isset( $_POST['individual_use'] ),
'product_ids' => isset( $_POST['product_ids'] ) ? array_filter( array_map( 'intval', (array) $_POST['product_ids'] ) ) : array(),
'excluded_product_ids' => isset( $_POST['exclude_product_ids'] ) ? array_filter( array_map( 'intval', (array) $_POST['exclude_product_ids'] ) ) : array(),
'usage_limit' => absint( $_POST['usage_limit'] ),
'usage_limit_per_user' => absint( $_POST['usage_limit_per_user'] ),
'limit_usage_to_x_items' => absint( $_POST['limit_usage_to_x_items'] ),
'free_shipping' => isset( $_POST['free_shipping'] ),
'product_categories' => array_filter( array_map( 'intval', $product_categories ) ),
'excluded_product_categories' => array_filter( array_map( 'intval', $exclude_product_categories ) ),
'exclude_sale_items' => isset( $_POST['exclude_sale_items'] ),
'minimum_amount' => wc_format_decimal( $_POST['minimum_amount'] ),
'maximum_amount' => wc_format_decimal( $_POST['maximum_amount'] ),
'email_restrictions' => array_filter( array_map( 'trim', explode( ',', wc_clean( $_POST['customer_email'] ) ) ) ),
)
);
$coupon->save();
do_action( 'woocommerce_coupon_options_save', $post_id, $coupon );
}

View File

@ -32,11 +32,13 @@ class WC_Meta_Box_Order_Actions {
$theorder = wc_get_order( $post->ID );
}
$order_actions = apply_filters( 'woocommerce_order_actions', array(
'send_order_details' => __( 'Email invoice / order details to customer', 'woocommerce' ),
'send_order_details_admin' => __( 'Resend new order notification', 'woocommerce' ),
'regenerate_download_permissions' => __( 'Regenerate download permissions', 'woocommerce' ),
) );
$order_actions = apply_filters(
'woocommerce_order_actions', array(
'send_order_details' => __( 'Email invoice / order details to customer', 'woocommerce' ),
'send_order_details_admin' => __( 'Resend new order notification', 'woocommerce' ),
'regenerate_download_permissions' => __( 'Regenerate download permissions', 'woocommerce' ),
)
);
?>
<ul class="order_actions submitbox">
@ -62,7 +64,9 @@ class WC_Meta_Box_Order_Actions {
} else {
$delete_text = __( 'Move to trash', 'woocommerce' );
}
?><a class="submitdelete deletion" href="<?php echo esc_url( get_delete_post_link( $post->ID ) ); ?>"><?php echo esc_html( $delete_text ); ?></a><?php
?>
<a class="submitdelete deletion" href="<?php echo esc_url( get_delete_post_link( $post->ID ) ); ?>"><?php echo esc_html( $delete_text ); ?></a>
<?php
}
?>
</div>

View File

@ -4,9 +4,9 @@
*
* Functions for displaying the order data meta box.
*
* @author WooThemes
* @category Admin
* @package WooCommerce/Admin/Meta Boxes
* @author WooThemes
* @category Admin
* @package WooCommerce/Admin/Meta Boxes
* @version 2.2.0
*/
@ -38,97 +38,101 @@ class WC_Meta_Box_Order_Data {
*/
public static function init_address_fields() {
self::$billing_fields = apply_filters( 'woocommerce_admin_billing_fields', array(
'first_name' => array(
'label' => __( 'First name', 'woocommerce' ),
'show' => false,
),
'last_name' => array(
'label' => __( 'Last name', 'woocommerce' ),
'show' => false,
),
'company' => array(
'label' => __( 'Company', 'woocommerce' ),
'show' => false,
),
'address_1' => array(
'label' => __( 'Address line 1', 'woocommerce' ),
'show' => false,
),
'address_2' => array(
'label' => __( 'Address line 2', 'woocommerce' ),
'show' => false,
),
'city' => array(
'label' => __( 'City', 'woocommerce' ),
'show' => false,
),
'postcode' => array(
'label' => __( 'Postcode / ZIP', 'woocommerce' ),
'show' => false,
),
'country' => array(
'label' => __( 'Country', 'woocommerce' ),
'show' => false,
'class' => 'js_field-country select short',
'type' => 'select',
'options' => array( '' => __( 'Select a country&hellip;', 'woocommerce' ) ) + WC()->countries->get_allowed_countries(),
),
'state' => array(
'label' => __( 'State / County', 'woocommerce' ),
'class' => 'js_field-state select short',
'show' => false,
),
'email' => array(
'label' => __( 'Email address', 'woocommerce' ),
),
'phone' => array(
'label' => __( 'Phone', 'woocommerce' ),
),
) );
self::$billing_fields = apply_filters(
'woocommerce_admin_billing_fields', array(
'first_name' => array(
'label' => __( 'First name', 'woocommerce' ),
'show' => false,
),
'last_name' => array(
'label' => __( 'Last name', 'woocommerce' ),
'show' => false,
),
'company' => array(
'label' => __( 'Company', 'woocommerce' ),
'show' => false,
),
'address_1' => array(
'label' => __( 'Address line 1', 'woocommerce' ),
'show' => false,
),
'address_2' => array(
'label' => __( 'Address line 2', 'woocommerce' ),
'show' => false,
),
'city' => array(
'label' => __( 'City', 'woocommerce' ),
'show' => false,
),
'postcode' => array(
'label' => __( 'Postcode / ZIP', 'woocommerce' ),
'show' => false,
),
'country' => array(
'label' => __( 'Country', 'woocommerce' ),
'show' => false,
'class' => 'js_field-country select short',
'type' => 'select',
'options' => array( '' => __( 'Select a country&hellip;', 'woocommerce' ) ) + WC()->countries->get_allowed_countries(),
),
'state' => array(
'label' => __( 'State / County', 'woocommerce' ),
'class' => 'js_field-state select short',
'show' => false,
),
'email' => array(
'label' => __( 'Email address', 'woocommerce' ),
),
'phone' => array(
'label' => __( 'Phone', 'woocommerce' ),
),
)
);
self::$shipping_fields = apply_filters( 'woocommerce_admin_shipping_fields', array(
'first_name' => array(
'label' => __( 'First name', 'woocommerce' ),
'show' => false,
),
'last_name' => array(
'label' => __( 'Last name', 'woocommerce' ),
'show' => false,
),
'company' => array(
'label' => __( 'Company', 'woocommerce' ),
'show' => false,
),
'address_1' => array(
'label' => __( 'Address line 1', 'woocommerce' ),
'show' => false,
),
'address_2' => array(
'label' => __( 'Address line 2', 'woocommerce' ),
'show' => false,
),
'city' => array(
'label' => __( 'City', 'woocommerce' ),
'show' => false,
),
'postcode' => array(
'label' => __( 'Postcode / ZIP', 'woocommerce' ),
'show' => false,
),
'country' => array(
'label' => __( 'Country', 'woocommerce' ),
'show' => false,
'type' => 'select',
'class' => 'js_field-country select short',
'options' => array( '' => __( 'Select a country&hellip;', 'woocommerce' ) ) + WC()->countries->get_shipping_countries(),
),
'state' => array(
'label' => __( 'State / County', 'woocommerce' ),
'class' => 'js_field-state select short',
'show' => false,
),
) );
self::$shipping_fields = apply_filters(
'woocommerce_admin_shipping_fields', array(
'first_name' => array(
'label' => __( 'First name', 'woocommerce' ),
'show' => false,
),
'last_name' => array(
'label' => __( 'Last name', 'woocommerce' ),
'show' => false,
),
'company' => array(
'label' => __( 'Company', 'woocommerce' ),
'show' => false,
),
'address_1' => array(
'label' => __( 'Address line 1', 'woocommerce' ),
'show' => false,
),
'address_2' => array(
'label' => __( 'Address line 2', 'woocommerce' ),
'show' => false,
),
'city' => array(
'label' => __( 'City', 'woocommerce' ),
'show' => false,
),
'postcode' => array(
'label' => __( 'Postcode / ZIP', 'woocommerce' ),
'show' => false,
),
'country' => array(
'label' => __( 'Country', 'woocommerce' ),
'show' => false,
'type' => 'select',
'class' => 'js_field-country select short',
'options' => array( '' => __( 'Select a country&hellip;', 'woocommerce' ) ) + WC()->countries->get_shipping_countries(),
),
'state' => array(
'label' => __( 'State / County', 'woocommerce' ),
'class' => 'js_field-state select short',
'show' => false,
),
)
);
}
/**
@ -165,113 +169,128 @@ class WC_Meta_Box_Order_Data {
<input name="post_title" type="hidden" value="<?php echo empty( $post->post_title ) ? __( 'Order', 'woocommerce' ) : esc_attr( $post->post_title ); ?>" />
<input name="post_status" type="hidden" value="<?php echo esc_attr( $post->post_status ); ?>" />
<div id="order_data" class="panel woocommerce-order-data">
<h2 class="woocommerce-order-data__heading"><?php
<h2 class="woocommerce-order-data__heading">
<?php
/* translators: 1: order type 2: order number */
printf(
esc_html__( '%1$s #%2$s details', 'woocommerce' ),
esc_html( $order_type_object->labels->singular_name ),
esc_html( $order->get_order_number() )
);
?></h2>
<p class="woocommerce-order-data__meta order_number"><?php
$meta_list = array();
if ( $payment_method ) {
/* translators: %s: payment method */
$payment_method_string = sprintf(
__( 'Payment via %s', 'woocommerce' ),
esc_html( isset( $payment_gateways[ $payment_method ] ) ? $payment_gateways[ $payment_method ]->get_title() : $payment_method )
/* translators: 1: order type 2: order number */
printf(
esc_html__( '%1$s #%2$s details', 'woocommerce' ),
esc_html( $order_type_object->labels->singular_name ),
esc_html( $order->get_order_number() )
);
if ( $transaction_id = $order->get_transaction_id() ) {
if ( isset( $payment_gateways[ $payment_method ] ) && ( $url = $payment_gateways[ $payment_method ]->get_transaction_url( $order ) ) ) {
$payment_method_string .= ' (<a href="' . esc_url( $url ) . '" target="_blank">' . esc_html( $transaction_id ) . '</a>)';
} else {
$payment_method_string .= ' (' . esc_html( $transaction_id ) . ')';
?>
</h2>
<p class="woocommerce-order-data__meta order_number">
<?php
$meta_list = array();
if ( $payment_method ) {
/* translators: %s: payment method */
$payment_method_string = sprintf(
__( 'Payment via %s', 'woocommerce' ),
esc_html( isset( $payment_gateways[ $payment_method ] ) ? $payment_gateways[ $payment_method ]->get_title() : $payment_method )
);
if ( $transaction_id = $order->get_transaction_id() ) {
if ( isset( $payment_gateways[ $payment_method ] ) && ( $url = $payment_gateways[ $payment_method ]->get_transaction_url( $order ) ) ) {
$payment_method_string .= ' (<a href="' . esc_url( $url ) . '" target="_blank">' . esc_html( $transaction_id ) . '</a>)';
} else {
$payment_method_string .= ' (' . esc_html( $transaction_id ) . ')';
}
}
$meta_list[] = $payment_method_string;
}
$meta_list[] = $payment_method_string;
}
if ( $order->get_date_paid() ) {
/* translators: 1: date 2: time */
$meta_list[] = sprintf(
__( 'Paid on %1$s @ %2$s', 'woocommerce' ),
wc_format_datetime( $order->get_date_paid() ),
wc_format_datetime( $order->get_date_paid(), get_option( 'time_format' ) )
);
}
if ( $order->get_date_paid() ) {
/* translators: 1: date 2: time */
$meta_list[] = sprintf(
__( 'Paid on %1$s @ %2$s', 'woocommerce' ),
wc_format_datetime( $order->get_date_paid() ),
wc_format_datetime( $order->get_date_paid(), get_option( 'time_format' ) )
);
}
if ( $ip_address = $order->get_customer_ip_address() ) {
/* translators: %s: IP address */
$meta_list[] = sprintf(
__( 'Customer IP: %s', 'woocommerce' ),
'<span class="woocommerce-Order-customerIP">' . esc_html( $ip_address ) . '</span>'
);
}
if ( $ip_address = $order->get_customer_ip_address() ) {
/* translators: %s: IP address */
$meta_list[] = sprintf(
__( 'Customer IP: %s', 'woocommerce' ),
'<span class="woocommerce-Order-customerIP">' . esc_html( $ip_address ) . '</span>'
);
}
echo wp_kses_post( implode( '. ', $meta_list ) );
echo wp_kses_post( implode( '. ', $meta_list ) );
?></p>
?>
</p>
<div class="order_data_column_container">
<div class="order_data_column">
<h3><?php esc_html_e( 'General', 'woocommerce' ); ?></h3>
<p class="form-field form-field-wide"><label for="order_date"><?php _e( 'Date created:', 'woocommerce' ) ?></label>
<p class="form-field form-field-wide">
<label for="order_date"><?php _e( 'Date created:', 'woocommerce' ); ?></label>
<input type="text" class="date-picker" name="order_date" maxlength="10" value="<?php echo esc_attr( date_i18n( 'Y-m-d', strtotime( $post->post_date ) ) ); ?>" pattern="<?php echo esc_attr( apply_filters( 'woocommerce_date_input_html_pattern', '[0-9]{4}-(0[1-9]|1[012])-(0[1-9]|1[0-9]|2[0-9]|3[01])' ) ); ?>" />@
&lrm;
<input type="number" class="hour" placeholder="<?php esc_attr_e( 'h', 'woocommerce' ) ?>" name="order_date_hour" min="0" max="23" step="1" value="<?php echo esc_attr( date_i18n( 'H', strtotime( $post->post_date ) ) ); ?>" pattern="([01]?[0-9]{1}|2[0-3]{1})" />:
<input type="number" class="minute" placeholder="<?php esc_attr_e( 'm', 'woocommerce' ) ?>" name="order_date_minute" min="0" max="59" step="1" value="<?php echo esc_attr( date_i18n( 'i', strtotime( $post->post_date ) ) ); ?>" pattern="[0-5]{1}[0-9]{1}" />
<input type="number" class="hour" placeholder="<?php esc_attr_e( 'h', 'woocommerce' ); ?>" name="order_date_hour" min="0" max="23" step="1" value="<?php echo esc_attr( date_i18n( 'H', strtotime( $post->post_date ) ) ); ?>" pattern="([01]?[0-9]{1}|2[0-3]{1})" />:
<input type="number" class="minute" placeholder="<?php esc_attr_e( 'm', 'woocommerce' ); ?>" name="order_date_minute" min="0" max="59" step="1" value="<?php echo esc_attr( date_i18n( 'i', strtotime( $post->post_date ) ) ); ?>" pattern="[0-5]{1}[0-9]{1}" />
<input type="hidden" name="order_date_second" value="<?php echo esc_attr( date_i18n( 's', strtotime( $post->post_date ) ) ); ?>" />
&lrm;
</p>
<p class="form-field form-field-wide wc-order-status"><label for="order_status"><?php _e( 'Status:', 'woocommerce' ) ?> <?php
if ( $order->needs_payment() ) {
printf( '<a href="%s">%s</a>',
esc_url( $order->get_checkout_payment_url() ),
__( 'Customer payment page &rarr;', 'woocommerce' )
);
}
?></label>
<select id="order_status" name="order_status" class="wc-enhanced-select">
<?php
<p class="form-field form-field-wide wc-order-status">
<label for="order_status">
<?php
_e( 'Status:', 'woocommerce' );
if ( $order->needs_payment() ) {
printf(
'<a href="%s">%s</a>',
esc_url( $order->get_checkout_payment_url() ),
__( 'Customer payment page &rarr;', 'woocommerce' )
);
}
?>
</label>
<select id="order_status" name="order_status" class="wc-enhanced-select">
<?php
$statuses = wc_get_order_statuses();
foreach ( $statuses as $status => $status_name ) {
echo '<option value="' . esc_attr( $status ) . '" ' . selected( $status, 'wc-' . $order->get_status( 'edit' ), false ) . '>' . esc_html( $status_name ) . '</option>';
}
?>
</select></p>
?>
</select>
</p>
<p class="form-field form-field-wide wc-customer-user">
<!--email_off--> <!-- Disable CloudFlare email obfuscation -->
<label for="customer_user"><?php _e( 'Customer:', 'woocommerce' ) ?> <?php
<label for="customer_user">
<?php
_e( 'Customer:', 'woocommerce' );
if ( $order->get_user_id( 'edit' ) ) {
$args = array(
'post_status' => 'all',
'post_type' => 'shop_order',
'_customer_user' => $order->get_user_id( 'edit' ),
);
printf( '<a href="%s">%s</a>',
printf(
'<a href="%s">%s</a>',
esc_url( add_query_arg( $args, admin_url( 'edit.php' ) ) ),
' ' . __( 'View other orders &rarr;', 'woocommerce' )
);
printf( '<a href="%s">%s</a>',
printf(
'<a href="%s">%s</a>',
esc_url( add_query_arg( 'user_id', $order->get_user_id( 'edit' ), admin_url( 'user-edit.php' ) ) ),
' ' . __( 'Profile &rarr;', 'woocommerce' )
);
}
?></label>
?>
</label>
<?php
$user_string = '';
$user_id = '';
if ( $order->get_user_id() ) {
$user_id = absint( $order->get_user_id() );
$user = get_user_by( 'id', $user_id );
$user_id = absint( $order->get_user_id() );
$user = get_user_by( 'id', $user_id );
/* translators: 1: user display name 2: user ID 3: user email */
$user_string = sprintf(
esc_html__( '%1$s (#%2$s &ndash; %3$s)', 'woocommerce' ),
@ -296,43 +315,44 @@ class WC_Meta_Box_Order_Data {
<a href="#" class="load_customer_billing" style="display:none;"><?php esc_html_e( 'Load billing address', 'woocommerce' ); ?></a>
</span>
</h3>
<?php
// Display values
echo '<div class="address">';
<div class="address">
<?php
if ( $order->get_formatted_billing_address() ) {
echo '<p>' . wp_kses( $order->get_formatted_billing_address(), array( 'br' => array() ) ) . '</p>';
// Display values.
if ( $order->get_formatted_billing_address() ) {
echo '<p>' . wp_kses( $order->get_formatted_billing_address(), array( 'br' => array() ) ) . '</p>';
} else {
echo '<p class="none_set"><strong>' . __( 'Address:', 'woocommerce' ) . '</strong> ' . __( 'No billing address set.', 'woocommerce' ) . '</p>';
}
foreach ( self::$billing_fields as $key => $field ) {
if ( isset( $field['show'] ) && false === $field['show'] ) {
continue;
}
$field_name = 'billing_' . $key;
if ( is_callable( array( $order, 'get_' . $field_name ) ) ) {
$field_value = $order->{"get_$field_name"}( 'edit' );
} else {
echo '<p class="none_set"><strong>' . __( 'Address:', 'woocommerce' ) . '</strong> ' . __( 'No billing address set.', 'woocommerce' ) . '</p>';
$field_value = $order->get_meta( '_' . $field_name );
}
foreach ( self::$billing_fields as $key => $field ) {
if ( isset( $field['show'] ) && false === $field['show'] ) {
continue;
}
$field_name = 'billing_' . $key;
if ( is_callable( array( $order, 'get_' . $field_name ) ) ) {
$field_value = $order->{"get_$field_name"}( 'edit' );
} else {
$field_value = $order->get_meta( '_' . $field_name );
}
if ( 'billing_phone' === $field_name ) {
$field_value = wc_make_phone_clickable( $field_value );
} else {
$field_value = make_clickable( esc_html( $field_value ) );
}
echo '<p><strong>' . esc_html( $field['label'] ) . ':</strong> ' . wp_kses_post( $field_value ) . '</p>';
if ( 'billing_phone' === $field_name ) {
$field_value = wc_make_phone_clickable( $field_value );
} else {
$field_value = make_clickable( esc_html( $field_value ) );
}
echo '</div>';
echo '<p><strong>' . esc_html( $field['label'] ) . ':</strong> ' . wp_kses_post( $field_value ) . '</p>';
}
?>
</div>
// Display form
echo '<div class="edit_address">';
<div class="edit_address">
<?php
// Display form.
foreach ( self::$billing_fields as $key => $field ) {
if ( ! isset( $field['type'] ) ) {
$field['type'] = 'text';
@ -341,12 +361,12 @@ class WC_Meta_Box_Order_Data {
$field['id'] = '_billing_' . $key;
}
switch ( $field['type'] ) {
case 'select' :
case 'select':
woocommerce_wp_select( $field );
break;
default :
break;
default:
woocommerce_wp_text_input( $field );
break;
break;
}
}
?>
@ -355,36 +375,39 @@ class WC_Meta_Box_Order_Data {
<select name="_payment_method" id="_payment_method" class="first">
<option value=""><?php esc_html_e( 'N/A', 'woocommerce' ); ?></option>
<?php
$found_method = false;
$found_method = false;
foreach ( $payment_gateways as $gateway ) {
if ( 'yes' === $gateway->enabled ) {
echo '<option value="' . esc_attr( $gateway->id ) . '" ' . selected( $payment_method, $gateway->id, false ) . '>' . esc_html( $gateway->get_title() ) . '</option>';
if ( $payment_method == $gateway->id ) {
$found_method = true;
}
foreach ( $payment_gateways as $gateway ) {
if ( 'yes' === $gateway->enabled ) {
echo '<option value="' . esc_attr( $gateway->id ) . '" ' . selected( $payment_method, $gateway->id, false ) . '>' . esc_html( $gateway->get_title() ) . '</option>';
if ( $payment_method == $gateway->id ) {
$found_method = true;
}
}
}
if ( ! $found_method && ! empty( $payment_method ) ) {
echo '<option value="' . esc_attr( $payment_method ) . '" selected="selected">' . __( 'Other', 'woocommerce' ) . '</option>';
} else {
echo '<option value="other">' . __( 'Other', 'woocommerce' ) . '</option>';
}
if ( ! $found_method && ! empty( $payment_method ) ) {
echo '<option value="' . esc_attr( $payment_method ) . '" selected="selected">' . __( 'Other', 'woocommerce' ) . '</option>';
} else {
echo '<option value="other">' . __( 'Other', 'woocommerce' ) . '</option>';
}
?>
</select>
</p>
<?php
woocommerce_wp_text_input( array( 'id' => '_transaction_id', 'label' => __( 'Transaction ID', 'woocommerce' ) ) );
woocommerce_wp_text_input(
array(
'id' => '_transaction_id',
'label' => __( 'Transaction ID', 'woocommerce' ),
)
);
?>
echo '</div>';
do_action( 'woocommerce_admin_order_data_after_billing_address', $order );
?>
</div>
<?php do_action( 'woocommerce_admin_order_data_after_billing_address', $order ); ?>
</div>
<div class="order_data_column">
<h3>
<?php esc_html_e( 'Shipping', 'woocommerce' ); ?>
<a href="#" class="edit_address"><?php esc_html_e( 'Edit', 'woocommerce' ); ?></a>
@ -393,43 +416,43 @@ class WC_Meta_Box_Order_Data {
<a href="#" class="billing-same-as-shipping" style="display:none;"><?php esc_html_e( 'Copy billing address', 'woocommerce' ); ?></a>
</span>
</h3>
<?php
// Display values
echo '<div class="address">';
<div class="address">
<?php
if ( $order->get_formatted_shipping_address() ) {
echo '<p>' . wp_kses( $order->get_formatted_shipping_address(), array( 'br' => array() ) ) . '</p>';
} else {
echo '<p class="none_set"><strong>' . __( 'Address:', 'woocommerce' ) . '</strong> ' . __( 'No shipping address set.', 'woocommerce' ) . '</p>';
}
// Display values.
if ( $order->get_formatted_shipping_address() ) {
echo '<p>' . wp_kses( $order->get_formatted_shipping_address(), array( 'br' => array() ) ) . '</p>';
} else {
echo '<p class="none_set"><strong>' . __( 'Address:', 'woocommerce' ) . '</strong> ' . __( 'No shipping address set.', 'woocommerce' ) . '</p>';
}
if ( ! empty( self::$shipping_fields ) ) {
foreach ( self::$shipping_fields as $key => $field ) {
if ( isset( $field['show'] ) && false === $field['show'] ) {
continue;
}
$field_name = 'shipping_' . $key;
if ( is_callable( array( $order, 'get_' . $field_name ) ) ) {
$field_value = $order->{"get_$field_name"}( 'edit' );
} else {
$field_value = $order->get_meta( '_' . $field_name );
}
echo '<p><strong>' . esc_html( $field['label'] ) . ':</strong> ' . make_clickable( esc_html( $field_value ) ) . '</p>';
if ( ! empty( self::$shipping_fields ) ) {
foreach ( self::$shipping_fields as $key => $field ) {
if ( isset( $field['show'] ) && false === $field['show'] ) {
continue;
}
$field_name = 'shipping_' . $key;
if ( is_callable( array( $order, 'get_' . $field_name ) ) ) {
$field_value = $order->{"get_$field_name"}( 'edit' );
} else {
$field_value = $order->get_meta( '_' . $field_name );
}
echo '<p><strong>' . esc_html( $field['label'] ) . ':</strong> ' . make_clickable( esc_html( $field_value ) ) . '</p>';
}
}
if ( apply_filters( 'woocommerce_enable_order_notes_field', 'yes' == get_option( 'woocommerce_enable_order_comments', 'yes' ) ) && $post->post_excerpt ) {
echo '<p><strong>' . __( 'Customer provided note:', 'woocommerce' ) . '</strong> ' . nl2br( esc_html( $post->post_excerpt ) ) . '</p>';
}
echo '</div>';
// Display form
echo '<div class="edit_address">';
if ( apply_filters( 'woocommerce_enable_order_notes_field', 'yes' == get_option( 'woocommerce_enable_order_comments', 'yes' ) ) && $post->post_excerpt ) {
echo '<p><strong>' . __( 'Customer provided note:', 'woocommerce' ) . '</strong> ' . nl2br( esc_html( $post->post_excerpt ) ) . '</p>';
}
?>
</div>
<div class="edit_address">
<?php
// Display form.
if ( ! empty( self::$shipping_fields ) ) {
foreach ( self::$shipping_fields as $key => $field ) {
if ( ! isset( $field['type'] ) ) {
@ -440,27 +463,26 @@ class WC_Meta_Box_Order_Data {
}
switch ( $field['type'] ) {
case 'select' :
case 'select':
woocommerce_wp_select( $field );
break;
default :
break;
default:
woocommerce_wp_text_input( $field );
break;
break;
}
}
}
if ( apply_filters( 'woocommerce_enable_order_notes_field', 'yes' == get_option( 'woocommerce_enable_order_comments', 'yes' ) ) ) {
if ( apply_filters( 'woocommerce_enable_order_notes_field', 'yes' == get_option( 'woocommerce_enable_order_comments', 'yes' ) ) ) :
?>
<p class="form-field form-field-wide"><label for="excerpt"><?php _e( 'Customer provided note', 'woocommerce' ) ?>:</label>
<textarea rows="1" cols="40" name="excerpt" tabindex="6" id="excerpt" placeholder="<?php esc_attr_e( 'Customer notes about the order', 'woocommerce' ); ?>"><?php echo wp_kses_post( $post->post_excerpt ); ?></textarea></p>
<?php
}
<p class="form-field form-field-wide">
<label for="excerpt"><?php _e( 'Customer provided note', 'woocommerce' ); ?>:</label>
<textarea rows="1" cols="40" name="excerpt" tabindex="6" id="excerpt" placeholder="<?php esc_attr_e( 'Customer notes about the order', 'woocommerce' ); ?>"><?php echo wp_kses_post( $post->post_excerpt ); ?></textarea>
</p>
<?php endif; ?>
</div>
echo '</div>';
do_action( 'woocommerce_admin_order_data_after_shipping_address', $order );
?>
<?php do_action( 'woocommerce_admin_order_data_after_shipping_address', $order ); ?>
</div>
</div>
<div class="clear"></div>
@ -548,7 +570,7 @@ class WC_Meta_Box_Order_Data {
$payment_method_title = $methods[ $payment_method ]->get_title();
}
$props['payment_method'] = $payment_method;
$props['payment_method'] = $payment_method;
$props['payment_method_title'] = $payment_method_title;
}

View File

@ -26,12 +26,15 @@ class WC_Meta_Box_Order_Downloads {
?>
<div class="order_download_permissions wc-metaboxes-wrapper">
<div class="wc-metaboxes"><?php
$data_store = WC_Data_Store::load( 'customer-download' );
$download_permissions = $data_store->get_downloads( array(
'order_id' => $post->ID,
'orderby' => 'product_id',
) );
<div class="wc-metaboxes">
<?php
$data_store = WC_Data_Store::load( 'customer-download' );
$download_permissions = $data_store->get_downloads(
array(
'order_id' => $post->ID,
'orderby' => 'product_id',
)
);
$product = null;
$loop = 0;
@ -44,27 +47,30 @@ class WC_Meta_Box_Order_Downloads {
$file_counter = 1;
}
// don't show permissions to files that have since been removed
// don't show permissions to files that have since been removed.
if ( ! $product || ! $product->exists() || ! $product->has_file( $download->get_download_id() ) ) {
continue;
}
// Show file title instead of count if set
// Show file title instead of count if set.
$file = $product->get_file( $download->get_download_id() );
$file_count = isset( $file['name'] ) ? $file['name'] : sprintf( __( 'File %d', 'woocommerce' ), $file_counter );
include( 'views/html-order-download-permission.php' );
include 'views/html-order-download-permission.php';
$loop++;
$file_counter++;
}
}
?></div>
?>
</div>
<div class="toolbar">
<p class="buttons">
<select id="grant_access_id" class="wc-product-search" name="grant_access_id[]" multiple="multiple" style="width: 400px;" data-placeholder="<?php esc_attr_e( 'Search for a downloadable product&hellip;', 'woocommerce' ); ?>" data-action="woocommerce_json_search_downloadable_products_and_variations"></select>
<button type="button" class="button grant_access"><?php _e( 'Grant access', 'woocommerce' ); ?></button>
<button type="button" class="button grant_access">
<?php _e( 'Grant access', 'woocommerce' ); ?>
</button>
</p>
<div class="clear"></div>
</div>
@ -76,7 +82,7 @@ class WC_Meta_Box_Order_Downloads {
/**
* Save meta box data.
*
* @param int $post_id
* @param int $post_id
* @param WP_Post $post
*/
public static function save( $post_id, $post ) {

View File

@ -38,7 +38,7 @@ class WC_Meta_Box_Order_Items {
$order = $theorder;
$data = get_post_meta( $post->ID );
include( 'views/html-order-items.php' );
include 'views/html-order-items.php';
}
/**

View File

@ -28,11 +28,11 @@ class WC_Meta_Box_Product_Data {
global $thepostid, $product_object;
$thepostid = $post->ID;
$product_object = $thepostid ? wc_get_product( $thepostid ) : new WC_Product;
$product_object = $thepostid ? wc_get_product( $thepostid ) : new WC_Product();
wp_nonce_field( 'woocommerce_save_data', 'woocommerce_meta_nonce' );
include( 'views/html-product-data-panel.php' );
include 'views/html-product-data-panel.php';
}
/**
@ -41,86 +41,92 @@ class WC_Meta_Box_Product_Data {
private static function output_tabs() {
global $post, $thepostid, $product_object;
include( 'views/html-product-data-general.php' );
include( 'views/html-product-data-inventory.php' );
include( 'views/html-product-data-shipping.php' );
include( 'views/html-product-data-linked-products.php' );
include( 'views/html-product-data-attributes.php' );
include( 'views/html-product-data-advanced.php' );
include 'views/html-product-data-general.php';
include 'views/html-product-data-inventory.php';
include 'views/html-product-data-shipping.php';
include 'views/html-product-data-linked-products.php';
include 'views/html-product-data-attributes.php';
include 'views/html-product-data-advanced.php';
}
/**
* Return array of product type options.
*
* @return array
*/
private static function get_product_type_options() {
return apply_filters( 'product_type_options', array(
'virtual' => array(
'id' => '_virtual',
'wrapper_class' => 'show_if_simple',
'label' => __( 'Virtual', 'woocommerce' ),
'description' => __( 'Virtual products are intangible and are not shipped.', 'woocommerce' ),
'default' => 'no',
),
'downloadable' => array(
'id' => '_downloadable',
'wrapper_class' => 'show_if_simple',
'label' => __( 'Downloadable', 'woocommerce' ),
'description' => __( 'Downloadable products give access to a file upon purchase.', 'woocommerce' ),
'default' => 'no',
),
) );
return apply_filters(
'product_type_options', array(
'virtual' => array(
'id' => '_virtual',
'wrapper_class' => 'show_if_simple',
'label' => __( 'Virtual', 'woocommerce' ),
'description' => __( 'Virtual products are intangible and are not shipped.', 'woocommerce' ),
'default' => 'no',
),
'downloadable' => array(
'id' => '_downloadable',
'wrapper_class' => 'show_if_simple',
'label' => __( 'Downloadable', 'woocommerce' ),
'description' => __( 'Downloadable products give access to a file upon purchase.', 'woocommerce' ),
'default' => 'no',
),
)
);
}
/**
* Return array of tabs to show.
*
* @return array
*/
private static function get_product_data_tabs() {
$tabs = apply_filters( 'woocommerce_product_data_tabs', array(
'general' => array(
'label' => __( 'General', 'woocommerce' ),
'target' => 'general_product_data',
'class' => array( 'hide_if_grouped' ),
'priority' => 10,
),
'inventory' => array(
'label' => __( 'Inventory', 'woocommerce' ),
'target' => 'inventory_product_data',
'class' => array( 'show_if_simple', 'show_if_variable', 'show_if_grouped', 'show_if_external' ),
'priority' => 20,
),
'shipping' => array(
'label' => __( 'Shipping', 'woocommerce' ),
'target' => 'shipping_product_data',
'class' => array( 'hide_if_virtual', 'hide_if_grouped', 'hide_if_external' ),
'priority' => 30,
),
'linked_product' => array(
'label' => __( 'Linked Products', 'woocommerce' ),
'target' => 'linked_product_data',
'class' => array(),
'priority' => 40,
),
'attribute' => array(
'label' => __( 'Attributes', 'woocommerce' ),
'target' => 'product_attributes',
'class' => array(),
'priority' => 50,
),
'variations' => array(
'label' => __( 'Variations', 'woocommerce' ),
'target' => 'variable_product_options',
'class' => array( 'variations_tab', 'show_if_variable' ),
'priority' => 60,
),
'advanced' => array(
'label' => __( 'Advanced', 'woocommerce' ),
'target' => 'advanced_product_data',
'class' => array(),
'priority' => 70,
),
) );
$tabs = apply_filters(
'woocommerce_product_data_tabs', array(
'general' => array(
'label' => __( 'General', 'woocommerce' ),
'target' => 'general_product_data',
'class' => array( 'hide_if_grouped' ),
'priority' => 10,
),
'inventory' => array(
'label' => __( 'Inventory', 'woocommerce' ),
'target' => 'inventory_product_data',
'class' => array( 'show_if_simple', 'show_if_variable', 'show_if_grouped', 'show_if_external' ),
'priority' => 20,
),
'shipping' => array(
'label' => __( 'Shipping', 'woocommerce' ),
'target' => 'shipping_product_data',
'class' => array( 'hide_if_virtual', 'hide_if_grouped', 'hide_if_external' ),
'priority' => 30,
),
'linked_product' => array(
'label' => __( 'Linked Products', 'woocommerce' ),
'target' => 'linked_product_data',
'class' => array(),
'priority' => 40,
),
'attribute' => array(
'label' => __( 'Attributes', 'woocommerce' ),
'target' => 'product_attributes',
'class' => array(),
'priority' => 50,
),
'variations' => array(
'label' => __( 'Variations', 'woocommerce' ),
'target' => 'variable_product_options',
'class' => array( 'variations_tab', 'show_if_variable' ),
'priority' => 60,
),
'advanced' => array(
'label' => __( 'Advanced', 'woocommerce' ),
'target' => 'advanced_product_data',
'class' => array(),
'priority' => 70,
),
)
);
// Sort tabs based on priority.
uasort( $tabs, array( __CLASS__, 'product_data_tabs_sort' ) );
@ -151,6 +157,7 @@ class WC_Meta_Box_Product_Data {
/**
* Filter callback for finding variation attributes.
*
* @param WC_Product_Attribute $attribute
* @return bool
*/
@ -170,7 +177,7 @@ class WC_Meta_Box_Product_Data {
$variations_per_page = absint( apply_filters( 'woocommerce_admin_meta_boxes_variations_per_page', 15 ) );
$variations_total_pages = ceil( $variations_count / $variations_per_page );
include( 'views/html-product-data-variations.php' );
include 'views/html-product-data-variations.php';
}
/**
@ -191,9 +198,9 @@ class WC_Meta_Box_Product_Data {
for ( $i = 0; $i < $file_url_size; $i ++ ) {
if ( ! empty( $file_urls[ $i ] ) ) {
$downloads[] = array(
'name' => wc_clean( $file_names[ $i ] ),
'file' => wp_unslash( trim( $file_urls[ $i ] ) ),
'download_id' => wc_clean( $file_hashes[ $i ] ),
'name' => wc_clean( $file_names[ $i ] ),
'file' => wp_unslash( trim( $file_urls[ $i ] ) ),
'download_id' => wc_clean( $file_hashes[ $i ] ),
);
}
}
@ -203,6 +210,7 @@ class WC_Meta_Box_Product_Data {
/**
* Prepare children for save.
*
* @return array
*/
private static function prepare_children() {
@ -272,9 +280,10 @@ class WC_Meta_Box_Product_Data {
/**
* Prepare attributes for a specific variation or defaults.
* @param array $all_attributes
*
* @param array $all_attributes
* @param string $key_prefix
* @param int $index
* @param int $index
* @return array
*/
private static function prepare_set_attributes( $all_attributes, $key_prefix = 'attribute_', $index = null ) {
@ -309,7 +318,7 @@ class WC_Meta_Box_Product_Data {
/**
* Save meta box data.
*
* @param int $post_id
* @param int $post_id
* @param $post
*/
public static function save( $post_id, $post ) {
@ -330,45 +339,47 @@ class WC_Meta_Box_Product_Data {
}
}
$errors = $product->set_props( array(
'sku' => isset( $_POST['_sku'] ) ? wc_clean( $_POST['_sku'] ) : null,
'purchase_note' => wp_kses_post( stripslashes( $_POST['_purchase_note'] ) ),
'downloadable' => isset( $_POST['_downloadable'] ),
'virtual' => isset( $_POST['_virtual'] ),
'featured' => isset( $_POST['_featured'] ),
'catalog_visibility' => wc_clean( $_POST['_visibility'] ),
'tax_status' => isset( $_POST['_tax_status'] ) ? wc_clean( $_POST['_tax_status'] ) : null,
'tax_class' => isset( $_POST['_tax_class'] ) ? wc_clean( $_POST['_tax_class'] ) : null,
'weight' => wc_clean( $_POST['_weight'] ),
'length' => wc_clean( $_POST['_length'] ),
'width' => wc_clean( $_POST['_width'] ),
'height' => wc_clean( $_POST['_height'] ),
'shipping_class_id' => absint( $_POST['product_shipping_class'] ),
'sold_individually' => ! empty( $_POST['_sold_individually'] ),
'upsell_ids' => isset( $_POST['upsell_ids'] ) ? array_map( 'intval', (array) $_POST['upsell_ids'] ) : array(),
'cross_sell_ids' => isset( $_POST['crosssell_ids'] ) ? array_map( 'intval', (array) $_POST['crosssell_ids'] ) : array(),
'regular_price' => wc_clean( $_POST['_regular_price'] ),
'sale_price' => wc_clean( $_POST['_sale_price'] ),
'date_on_sale_from' => wc_clean( $_POST['_sale_price_dates_from'] ),
'date_on_sale_to' => wc_clean( $_POST['_sale_price_dates_to'] ),
'manage_stock' => ! empty( $_POST['_manage_stock'] ),
'backorders' => isset( $_POST['_backorders'] ) ? wc_clean( $_POST['_backorders'] ) : null,
'stock_status' => wc_clean( $_POST['_stock_status'] ),
'stock_quantity' => $stock,
'download_limit' => '' === $_POST['_download_limit'] ? '' : absint( $_POST['_download_limit'] ),
'download_expiry' => '' === $_POST['_download_expiry'] ? '' : absint( $_POST['_download_expiry'] ),
'downloads' => self::prepare_downloads(
isset( $_POST['_wc_file_names'] ) ? $_POST['_wc_file_names'] : array(),
isset( $_POST['_wc_file_urls'] ) ? $_POST['_wc_file_urls'] : array(),
isset( $_POST['_wc_file_hashes'] ) ? $_POST['_wc_file_hashes'] : array()
),
'product_url' => esc_url_raw( $_POST['_product_url'] ),
'button_text' => wc_clean( $_POST['_button_text'] ),
'children' => 'grouped' === $product_type ? self::prepare_children() : null,
'reviews_allowed' => ! empty( $_POST['comment_status'] ) && 'open' === $_POST['comment_status'],
'attributes' => $attributes,
'default_attributes' => self::prepare_set_attributes( $attributes, 'default_attribute_' ),
) );
$errors = $product->set_props(
array(
'sku' => isset( $_POST['_sku'] ) ? wc_clean( $_POST['_sku'] ) : null,
'purchase_note' => wp_kses_post( stripslashes( $_POST['_purchase_note'] ) ),
'downloadable' => isset( $_POST['_downloadable'] ),
'virtual' => isset( $_POST['_virtual'] ),
'featured' => isset( $_POST['_featured'] ),
'catalog_visibility' => wc_clean( $_POST['_visibility'] ),
'tax_status' => isset( $_POST['_tax_status'] ) ? wc_clean( $_POST['_tax_status'] ) : null,
'tax_class' => isset( $_POST['_tax_class'] ) ? wc_clean( $_POST['_tax_class'] ) : null,
'weight' => wc_clean( $_POST['_weight'] ),
'length' => wc_clean( $_POST['_length'] ),
'width' => wc_clean( $_POST['_width'] ),
'height' => wc_clean( $_POST['_height'] ),
'shipping_class_id' => absint( $_POST['product_shipping_class'] ),
'sold_individually' => ! empty( $_POST['_sold_individually'] ),
'upsell_ids' => isset( $_POST['upsell_ids'] ) ? array_map( 'intval', (array) $_POST['upsell_ids'] ) : array(),
'cross_sell_ids' => isset( $_POST['crosssell_ids'] ) ? array_map( 'intval', (array) $_POST['crosssell_ids'] ) : array(),
'regular_price' => wc_clean( $_POST['_regular_price'] ),
'sale_price' => wc_clean( $_POST['_sale_price'] ),
'date_on_sale_from' => wc_clean( $_POST['_sale_price_dates_from'] ),
'date_on_sale_to' => wc_clean( $_POST['_sale_price_dates_to'] ),
'manage_stock' => ! empty( $_POST['_manage_stock'] ),
'backorders' => isset( $_POST['_backorders'] ) ? wc_clean( $_POST['_backorders'] ) : null,
'stock_status' => wc_clean( $_POST['_stock_status'] ),
'stock_quantity' => $stock,
'download_limit' => '' === $_POST['_download_limit'] ? '' : absint( $_POST['_download_limit'] ),
'download_expiry' => '' === $_POST['_download_expiry'] ? '' : absint( $_POST['_download_expiry'] ),
'downloads' => self::prepare_downloads(
isset( $_POST['_wc_file_names'] ) ? $_POST['_wc_file_names'] : array(),
isset( $_POST['_wc_file_urls'] ) ? $_POST['_wc_file_urls'] : array(),
isset( $_POST['_wc_file_hashes'] ) ? $_POST['_wc_file_hashes'] : array()
),
'product_url' => esc_url_raw( $_POST['_product_url'] ),
'button_text' => wc_clean( $_POST['_button_text'] ),
'children' => 'grouped' === $product_type ? self::prepare_children() : null,
'reviews_allowed' => ! empty( $_POST['comment_status'] ) && 'open' === $_POST['comment_status'],
'attributes' => $attributes,
'default_attributes' => self::prepare_set_attributes( $attributes, 'default_attribute_' ),
)
);
if ( is_wp_error( $errors ) ) {
WC_Admin_Meta_Boxes::add_error( $errors->get_error_message() );
@ -391,12 +402,12 @@ class WC_Meta_Box_Product_Data {
/**
* Save meta box data.
*
* @param int $post_id
* @param int $post_id
* @param WP_Post $post
*/
public static function save_variations( $post_id, $post ) {
if ( isset( $_POST['variable_post_id'] ) ) {
$parent = wc_get_product( $post_id );
$parent = wc_get_product( $post_id );
$parent->set_default_attributes( self::prepare_set_attributes( $parent->get_attributes(), 'default_attribute_' ) );
$parent->save();
@ -423,37 +434,39 @@ class WC_Meta_Box_Product_Data {
}
}
$errors = $variation->set_props( array(
'status' => isset( $_POST['variable_enabled'][ $i ] ) ? 'publish' : 'private',
'menu_order' => wc_clean( $_POST['variation_menu_order'][ $i ] ),
'regular_price' => wc_clean( $_POST['variable_regular_price'][ $i ] ),
'sale_price' => wc_clean( $_POST['variable_sale_price'][ $i ] ),
'virtual' => isset( $_POST['variable_is_virtual'][ $i ] ),
'downloadable' => isset( $_POST['variable_is_downloadable'][ $i ] ),
'date_on_sale_from' => wc_clean( $_POST['variable_sale_price_dates_from'][ $i ] ),
'date_on_sale_to' => wc_clean( $_POST['variable_sale_price_dates_to'][ $i ] ),
'description' => wp_kses_post( $_POST['variable_description'][ $i ] ),
'download_limit' => wc_clean( $_POST['variable_download_limit'][ $i ] ),
'download_expiry' => wc_clean( $_POST['variable_download_expiry'][ $i ] ),
'downloads' => self::prepare_downloads(
isset( $_POST['_wc_variation_file_names'][ $variation_id ] ) ? $_POST['_wc_variation_file_names'][ $variation_id ] : array(),
isset( $_POST['_wc_variation_file_urls'][ $variation_id ] ) ? $_POST['_wc_variation_file_urls'][ $variation_id ] : array(),
isset( $_POST['_wc_variation_file_hashes'][ $variation_id ] ) ? $_POST['_wc_variation_file_hashes'][ $variation_id ] : array()
),
'manage_stock' => isset( $_POST['variable_manage_stock'][ $i ] ),
'stock_quantity' => $stock,
'backorders' => isset( $_POST['variable_backorders'], $_POST['variable_backorders'][ $i ] ) ? wc_clean( $_POST['variable_backorders'][ $i ] ) : null,
'stock_status' => wc_clean( $_POST['variable_stock_status'][ $i ] ),
'image_id' => wc_clean( $_POST['upload_image_id'][ $i ] ),
'attributes' => self::prepare_set_attributes( $parent->get_attributes(), 'attribute_', $i ),
'sku' => isset( $_POST['variable_sku'][ $i ] ) ? wc_clean( $_POST['variable_sku'][ $i ] ) : '',
'weight' => isset( $_POST['variable_weight'][ $i ] ) ? wc_clean( $_POST['variable_weight'][ $i ] ) : '',
'length' => isset( $_POST['variable_length'][ $i ] ) ? wc_clean( $_POST['variable_length'][ $i ] ) : '',
'width' => isset( $_POST['variable_width'][ $i ] ) ? wc_clean( $_POST['variable_width'][ $i ] ) : '',
'height' => isset( $_POST['variable_height'][ $i ] ) ? wc_clean( $_POST['variable_height'][ $i ] ) : '',
'shipping_class_id' => wc_clean( $_POST['variable_shipping_class'][ $i ] ),
'tax_class' => isset( $_POST['variable_tax_class'][ $i ] ) ? wc_clean( $_POST['variable_tax_class'][ $i ] ) : null,
) );
$errors = $variation->set_props(
array(
'status' => isset( $_POST['variable_enabled'][ $i ] ) ? 'publish' : 'private',
'menu_order' => wc_clean( $_POST['variation_menu_order'][ $i ] ),
'regular_price' => wc_clean( $_POST['variable_regular_price'][ $i ] ),
'sale_price' => wc_clean( $_POST['variable_sale_price'][ $i ] ),
'virtual' => isset( $_POST['variable_is_virtual'][ $i ] ),
'downloadable' => isset( $_POST['variable_is_downloadable'][ $i ] ),
'date_on_sale_from' => wc_clean( $_POST['variable_sale_price_dates_from'][ $i ] ),
'date_on_sale_to' => wc_clean( $_POST['variable_sale_price_dates_to'][ $i ] ),
'description' => wp_kses_post( $_POST['variable_description'][ $i ] ),
'download_limit' => wc_clean( $_POST['variable_download_limit'][ $i ] ),
'download_expiry' => wc_clean( $_POST['variable_download_expiry'][ $i ] ),
'downloads' => self::prepare_downloads(
isset( $_POST['_wc_variation_file_names'][ $variation_id ] ) ? $_POST['_wc_variation_file_names'][ $variation_id ] : array(),
isset( $_POST['_wc_variation_file_urls'][ $variation_id ] ) ? $_POST['_wc_variation_file_urls'][ $variation_id ] : array(),
isset( $_POST['_wc_variation_file_hashes'][ $variation_id ] ) ? $_POST['_wc_variation_file_hashes'][ $variation_id ] : array()
),
'manage_stock' => isset( $_POST['variable_manage_stock'][ $i ] ),
'stock_quantity' => $stock,
'backorders' => isset( $_POST['variable_backorders'], $_POST['variable_backorders'][ $i ] ) ? wc_clean( $_POST['variable_backorders'][ $i ] ) : null,
'stock_status' => wc_clean( $_POST['variable_stock_status'][ $i ] ),
'image_id' => wc_clean( $_POST['upload_image_id'][ $i ] ),
'attributes' => self::prepare_set_attributes( $parent->get_attributes(), 'attribute_', $i ),
'sku' => isset( $_POST['variable_sku'][ $i ] ) ? wc_clean( $_POST['variable_sku'][ $i ] ) : '',
'weight' => isset( $_POST['variable_weight'][ $i ] ) ? wc_clean( $_POST['variable_weight'][ $i ] ) : '',
'length' => isset( $_POST['variable_length'][ $i ] ) ? wc_clean( $_POST['variable_length'][ $i ] ) : '',
'width' => isset( $_POST['variable_width'][ $i ] ) ? wc_clean( $_POST['variable_width'][ $i ] ) : '',
'height' => isset( $_POST['variable_height'][ $i ] ) ? wc_clean( $_POST['variable_height'][ $i ] ) : '',
'shipping_class_id' => wc_clean( $_POST['variable_shipping_class'][ $i ] ),
'tax_class' => isset( $_POST['variable_tax_class'][ $i ] ) ? wc_clean( $_POST['variable_tax_class'][ $i ] ) : null,
)
);
if ( is_wp_error( $errors ) ) {
WC_Admin_Meta_Boxes::add_error( $errors->get_error_message() );

View File

@ -28,48 +28,48 @@ class WC_Meta_Box_Product_Images {
global $thepostid, $product_object;
$thepostid = $post->ID;
$product_object = $thepostid ? wc_get_product( $thepostid ) : new WC_Product;
$product_object = $thepostid ? wc_get_product( $thepostid ) : new WC_Product();
wp_nonce_field( 'woocommerce_save_data', 'woocommerce_meta_nonce' );
?>
<div id="product_images_container">
<ul class="product_images">
<?php
$product_image_gallery = $product_object->get_gallery_image_ids( 'edit' );
$product_image_gallery = $product_object->get_gallery_image_ids( 'edit' );
$attachments = array_filter( $product_image_gallery );
$update_meta = false;
$updated_gallery_ids = array();
$attachments = array_filter( $product_image_gallery );
$update_meta = false;
$updated_gallery_ids = array();
if ( ! empty( $attachments ) ) {
foreach ( $attachments as $attachment_id ) {
$attachment = wp_get_attachment_image( $attachment_id, 'thumbnail' );
if ( ! empty( $attachments ) ) {
foreach ( $attachments as $attachment_id ) {
$attachment = wp_get_attachment_image( $attachment_id, 'thumbnail' );
// if attachment is empty skip
if ( empty( $attachment ) ) {
$update_meta = true;
continue;
}
// if attachment is empty skip.
if ( empty( $attachment ) ) {
$update_meta = true;
continue;
}
echo '<li class="image" data-attachment_id="' . esc_attr( $attachment_id ) . '">
echo '<li class="image" data-attachment_id="' . esc_attr( $attachment_id ) . '">
' . $attachment . '
<ul class="actions">
<li><a href="#" class="delete tips" data-tip="' . esc_attr__( 'Delete image', 'woocommerce' ) . '">' . __( 'Delete', 'woocommerce' ) . '</a></li>
</ul>
</li>';
// rebuild ids to be saved
$updated_gallery_ids[] = $attachment_id;
}
// need to update product meta to set new gallery ids
if ( $update_meta ) {
update_post_meta( $post->ID, '_product_image_gallery', implode( ',', $updated_gallery_ids ) );
}
// rebuild ids to be saved.
$updated_gallery_ids[] = $attachment_id;
}
// need to update product meta to set new gallery ids
if ( $update_meta ) {
update_post_meta( $post->ID, '_product_image_gallery', implode( ',', $updated_gallery_ids ) );
}
}
?>
</ul>
<input type="hidden" id="product_image_gallery" name="product_image_gallery" value="<?php echo esc_attr( implode( ',', $updated_gallery_ids ) ) ?>" />
<input type="hidden" id="product_image_gallery" name="product_image_gallery" value="<?php echo esc_attr( implode( ',', $updated_gallery_ids ) ); ?>" />
</div>
<p class="add_product_images hide-if-no-js">
@ -81,7 +81,7 @@ class WC_Meta_Box_Product_Images {
/**
* Save meta box data.
*
* @param int $post_id
* @param int $post_id
* @param WP_Post $post
*/
public static function save( $post_id, $post ) {

View File

@ -28,9 +28,11 @@ class WC_Meta_Box_Product_Reviews {
$current = get_comment_meta( $comment->comment_ID, 'rating', true );
?>
<select name="rating" id="rating">
<?php for ( $rating = 1; $rating <= 5; $rating ++ ) {
<?php
for ( $rating = 1; $rating <= 5; $rating ++ ) {
printf( '<option value="%1$s"%2$s>%1$s</option>', $rating, selected( $current, $rating, false ) );
} ?>
}
?>
</select>
<?php
}
@ -39,7 +41,7 @@ class WC_Meta_Box_Product_Reviews {
* Save meta box data
*
* @param mixed $location
* @param int $comment_id
* @param int $comment_id
*
* @return mixed
*/

View File

@ -7,7 +7,8 @@ if ( ! defined( 'ABSPATH' ) ) {
<h3 class="fixed">
<button type="button" data-permission_id="<?php echo esc_attr( $download->get_id() ); ?>" rel="<?php echo esc_attr( $download->get_product_id() ) . ',' . esc_attr( $download->get_download_id() ); ?>" class="revoke_access button"><?php esc_html_e( 'Revoke access', 'woocommerce' ); ?></button>
<div class="handlediv" aria-label="<?php esc_attr_e( 'Click to toggle', 'woocommerce' ); ?>"></div>
<strong><?php
<strong>
<?php
printf(
'#%s &mdash; %s &mdash; %s: %s &mdash; ',
esc_html( $product->get_id() ),
@ -16,7 +17,8 @@ if ( ! defined( 'ABSPATH' ) ) {
esc_html( wc_get_filename_from_url( $product->get_file_download_path( $download->get_download_id() ) ) )
);
printf( _n( 'Downloaded %s time', 'Downloaded %s times', $download->get_download_count(), 'woocommerce' ), esc_html( $download->get_download_count() ) )
?></strong>
?>
</strong>
</h3>
<table cellpadding="0" cellspacing="0" class="wc-metabox-content">
<tbody>
@ -33,14 +35,16 @@ if ( ! defined( 'ABSPATH' ) ) {
<td>
<label><?php esc_html_e( 'Customer download link', 'woocommerce' ); ?></label>
<?php
$download_link = add_query_arg( array(
'download_file' => $download->get_product_id(),
'order' => $download->get_order_key(),
'email' => urlencode( $download->get_user_email() ),
'key' => $download->get_download_id(),
), trailingslashit( home_url() ) );
$download_link = add_query_arg(
array(
'download_file' => $download->get_product_id(),
'order' => $download->get_order_key(),
'email' => urlencode( $download->get_user_email() ),
'key' => $download->get_download_id(),
), trailingslashit( home_url() )
);
?>
<a id="copy-download-link" class="button" href="<?php echo esc_url( $download_link ) ?>" data-tip="<?php esc_attr_e( 'Copied!', 'woocommerce' ); ?>" data-tip-failed="<?php esc_attr_e( 'Copying to clipboard failed. You should be able to right-click the button and copy.', 'woocommerce' ); ?>"><?php esc_html_e( 'Copy link', 'woocommerce' ); ?></a>
<a id="copy-download-link" class="button" href="<?php echo esc_url( $download_link ); ?>" data-tip="<?php esc_attr_e( 'Copied!', 'woocommerce' ); ?>" data-tip-failed="<?php esc_attr_e( 'Copying to clipboard failed. You should be able to right-click the button and copy.', 'woocommerce' ); ?>"><?php esc_html_e( 'Copy link', 'woocommerce' ); ?></a>
</td>
<td>
<label><?php esc_html_e( 'Customer download log', 'woocommerce' ); ?></label>

View File

@ -33,11 +33,11 @@ if ( ! defined( 'ABSPATH' ) ) {
<td class="line_cost" width="1%">
<div class="view">
<?php
echo wc_price( $item->get_total(), array( 'currency' => $order->get_currency() ) );
echo wc_price( $item->get_total(), array( 'currency' => $order->get_currency() ) );
if ( $refunded = $order->get_total_refunded_for_item( $item_id, 'fee' ) ) {
echo '<small class="refunded">-' . wc_price( $refunded, array( 'currency' => $order->get_currency() ) ) . '</small>';
}
if ( $refunded = $order->get_total_refunded_for_item( $item_id, 'fee' ) ) {
echo '<small class="refunded">-' . wc_price( $refunded, array( 'currency' => $order->get_currency() ) ) . '</small>';
}
?>
</div>
<div class="edit" style="display: none;">
@ -49,32 +49,31 @@ if ( ! defined( 'ABSPATH' ) ) {
</td>
<?php
if ( ( $tax_data = $item->get_taxes() ) && wc_tax_enabled() ) {
foreach ( $order_taxes as $tax_item ) {
$tax_item_id = $tax_item->get_rate_id();
$tax_item_total = isset( $tax_data['total'][ $tax_item_id ] ) ? $tax_data['total'][ $tax_item_id ] : '';
?>
<td class="line_tax" width="1%">
<div class="view">
<?php
echo ( '' !== $tax_item_total ) ? wc_price( wc_round_tax_total( $tax_item_total ), array( 'currency' => $order->get_currency() ) ) : '&ndash;';
if ( ( $tax_data = $item->get_taxes() ) && wc_tax_enabled() ) {
foreach ( $order_taxes as $tax_item ) {
$tax_item_id = $tax_item->get_rate_id();
$tax_item_total = isset( $tax_data['total'][ $tax_item_id ] ) ? $tax_data['total'][ $tax_item_id ] : '';
?>
<td class="line_tax" width="1%">
<div class="view">
<?php
echo ( '' !== $tax_item_total ) ? wc_price( wc_round_tax_total( $tax_item_total ), array( 'currency' => $order->get_currency() ) ) : '&ndash;';
if ( $refunded = $order->get_tax_refunded_for_item( $item_id, $tax_item_id, 'fee' ) ) {
echo '<small class="refunded">-' . wc_price( $refunded, array( 'currency' => $order->get_currency() ) ) . '</small>';
}
?>
</div>
<div class="edit" style="display: none;">
<input type="text" name="line_tax[<?php echo absint( $item_id ); ?>][<?php echo esc_attr( $tax_item_id ); ?>]" placeholder="<?php echo esc_attr( wc_format_localized_price( 0 ) ); ?>" value="<?php echo ( isset( $tax_item_total ) ) ? esc_attr( wc_format_localized_price( $tax_item_total ) ) : ''; ?>" class="line_tax wc_input_price" />
</div>
<div class="refund" style="display: none;">
<input type="text" name="refund_line_tax[<?php echo absint( $item_id ); ?>][<?php echo esc_attr( $tax_item_id ); ?>]" placeholder="<?php echo esc_attr( wc_format_localized_price( 0 ) ); ?>" class="refund_line_tax wc_input_price" data-tax_id="<?php echo esc_attr( $tax_item_id ); ?>" />
</div>
</td>
<?php
}
if ( $refunded = $order->get_tax_refunded_for_item( $item_id, $tax_item_id, 'fee' ) ) {
echo '<small class="refunded">-' . wc_price( $refunded, array( 'currency' => $order->get_currency() ) ) . '</small>';
}
?>
</div>
<div class="edit" style="display: none;">
<input type="text" name="line_tax[<?php echo absint( $item_id ); ?>][<?php echo esc_attr( $tax_item_id ); ?>]" placeholder="<?php echo esc_attr( wc_format_localized_price( 0 ) ); ?>" value="<?php echo ( isset( $tax_item_total ) ) ? esc_attr( wc_format_localized_price( $tax_item_total ) ) : ''; ?>" class="line_tax wc_input_price" />
</div>
<div class="refund" style="display: none;">
<input type="text" name="refund_line_tax[<?php echo absint( $item_id ); ?>][<?php echo esc_attr( $tax_item_id ); ?>]" placeholder="<?php echo esc_attr( wc_format_localized_price( 0 ) ); ?>" class="refund_line_tax wc_input_price" data-tax_id="<?php echo esc_attr( $tax_item_id ); ?>" />
</div>
</td>
<?php
}
}
?>
<td class="wc-order-edit-line-item">
<?php if ( $order->is_editable() ) : ?>

View File

@ -3,18 +3,20 @@ if ( ! defined( 'ABSPATH' ) ) {
exit;
}
$hidden_order_itemmeta = apply_filters( 'woocommerce_hidden_order_itemmeta', array(
'_qty',
'_tax_class',
'_product_id',
'_variation_id',
'_line_subtotal',
'_line_subtotal_tax',
'_line_total',
'_line_tax',
'method_id',
'cost',
) );
$hidden_order_itemmeta = apply_filters(
'woocommerce_hidden_order_itemmeta', array(
'_qty',
'_tax_class',
'_product_id',
'_variation_id',
'_line_subtotal',
'_line_subtotal_tax',
'_line_total',
'_line_tax',
'method_id',
'cost',
)
);
?><div class="view">
<?php if ( $meta_data = $item->get_formatted_meta_data( '' ) ) : ?>
<table cellspacing="0" class="display_meta">

View File

@ -19,28 +19,28 @@ $row_class = apply_filters( 'woocommerce_admin_html_order_item_class', ! empt
</td>
<td class="name" data-sort-value="<?php echo esc_attr( $item->get_name() ); ?>">
<?php
echo $product_link ? '<a href="' . esc_url( $product_link ) . '" class="wc-order-item-name">' . esc_html( $item->get_name() ) . '</a>' : '<div class="wc-order-item-name">' . esc_html( $item->get_name() ) . '</div>';
echo $product_link ? '<a href="' . esc_url( $product_link ) . '" class="wc-order-item-name">' . esc_html( $item->get_name() ) . '</a>' : '<div class="wc-order-item-name">' . esc_html( $item->get_name() ) . '</div>';
if ( $product && $product->get_sku() ) {
echo '<div class="wc-order-item-sku"><strong>' . esc_html__( 'SKU:', 'woocommerce' ) . '</strong> ' . esc_html( $product->get_sku() ) . '</div>';
}
if ( $product && $product->get_sku() ) {
echo '<div class="wc-order-item-sku"><strong>' . esc_html__( 'SKU:', 'woocommerce' ) . '</strong> ' . esc_html( $product->get_sku() ) . '</div>';
}
if ( $item->get_variation_id() ) {
echo '<div class="wc-order-item-variation"><strong>' . esc_html__( 'Variation ID:', 'woocommerce' ) . '</strong> ';
if ( 'product_variation' === get_post_type( $item->get_variation_id() ) ) {
echo esc_html( $item->get_variation_id() );
} else {
/* translators: %s: variation id */
printf( esc_html__( '%s (No longer exists)', 'woocommerce' ), $item->get_variation_id() );
}
echo '</div>';
if ( $item->get_variation_id() ) {
echo '<div class="wc-order-item-variation"><strong>' . esc_html__( 'Variation ID:', 'woocommerce' ) . '</strong> ';
if ( 'product_variation' === get_post_type( $item->get_variation_id() ) ) {
echo esc_html( $item->get_variation_id() );
} else {
/* translators: %s: variation id */
printf( esc_html__( '%s (No longer exists)', 'woocommerce' ), $item->get_variation_id() );
}
echo '</div>';
}
?>
<input type="hidden" class="order_item_id" name="order_item_id[]" value="<?php echo esc_attr( $item_id ); ?>" />
<input type="hidden" name="order_item_tax_class[<?php echo absint( $item_id ); ?>]" value="<?php echo esc_attr( $item->get_tax_class() ); ?>" />
<?php do_action( 'woocommerce_before_order_itemmeta', $item_id, $item, $product ); ?>
<?php include( 'html-order-item-meta.php' ); ?>
<?php require 'html-order-item-meta.php'; ?>
<?php do_action( 'woocommerce_after_order_itemmeta', $item_id, $item, $product ); ?>
</td>
@ -51,9 +51,9 @@ $row_class = apply_filters( 'woocommerce_admin_html_order_item_class', ! empt
<?php
echo wc_price( $order->get_item_total( $item, false, true ), array( 'currency' => $order->get_currency() ) );
if ( $item->get_subtotal() !== $item->get_total() ) {
echo '<span class="wc-order-item-discount">-' . wc_price( wc_format_decimal( $order->get_item_subtotal( $item, false, false ) - $order->get_item_total( $item, false, false ), '' ), array( 'currency' => $order->get_currency() ) ) . '</span>';
}
if ( $item->get_subtotal() !== $item->get_total() ) {
echo '<span class="wc-order-item-discount">-' . wc_price( wc_format_decimal( $order->get_item_subtotal( $item, false, false ) - $order->get_item_total( $item, false, false ), '' ), array( 'currency' => $order->get_currency() ) ) . '</span>';
}
?>
</div>
</td>
@ -62,9 +62,9 @@ $row_class = apply_filters( 'woocommerce_admin_html_order_item_class', ! empt
<?php
echo '<small class="times">&times;</small> ' . esc_html( $item->get_quantity() );
if ( $refunded_qty = $order->get_qty_refunded_for_item( $item_id ) ) {
echo '<small class="refunded">' . ( $refunded_qty * -1 ) . '</small>';
}
if ( $refunded_qty = $order->get_qty_refunded_for_item( $item_id ) ) {
echo '<small class="refunded">' . ( $refunded_qty * -1 ) . '</small>';
}
?>
</div>
<div class="edit" style="display: none;">
@ -77,15 +77,15 @@ $row_class = apply_filters( 'woocommerce_admin_html_order_item_class', ! empt
<td class="line_cost" width="1%" data-sort-value="<?php echo esc_attr( $item->get_total() ); ?>">
<div class="view">
<?php
echo wc_price( $item->get_total(), array( 'currency' => $order->get_currency() ) );
echo wc_price( $item->get_total(), array( 'currency' => $order->get_currency() ) );
if ( $item->get_subtotal() !== $item->get_total() ) {
echo '<span class="wc-order-item-discount">-' . wc_price( wc_format_decimal( $item->get_subtotal() - $item->get_total(), '' ), array( 'currency' => $order->get_currency() ) ) . '</span>';
}
if ( $item->get_subtotal() !== $item->get_total() ) {
echo '<span class="wc-order-item-discount">-' . wc_price( wc_format_decimal( $item->get_subtotal() - $item->get_total(), '' ), array( 'currency' => $order->get_currency() ) ) . '</span>';
}
if ( $refunded = $order->get_total_refunded_for_item( $item_id ) ) {
echo '<small class="refunded">' . wc_price( $refunded, array( 'currency' => $order->get_currency() ) ) . '</small>';
}
if ( $refunded = $order->get_total_refunded_for_item( $item_id ) ) {
echo '<small class="refunded">' . wc_price( $refunded, array( 'currency' => $order->get_currency() ) ) . '</small>';
}
?>
</div>
<div class="edit" style="display: none;">
@ -106,53 +106,53 @@ $row_class = apply_filters( 'woocommerce_admin_html_order_item_class', ! empt
</td>
<?php
if ( ( $tax_data = $item->get_taxes() ) && wc_tax_enabled() ) {
foreach ( $order_taxes as $tax_item ) {
$tax_item_id = $tax_item->get_rate_id();
$tax_item_total = isset( $tax_data['total'][ $tax_item_id ] ) ? $tax_data['total'][ $tax_item_id ] : '';
$tax_item_subtotal = isset( $tax_data['subtotal'][ $tax_item_id ] ) ? $tax_data['subtotal'][ $tax_item_id ] : '';
?>
<td class="line_tax" width="1%">
<div class="view">
<?php
if ( '' !== $tax_item_total ) {
echo wc_price( wc_round_tax_total( $tax_item_total ), array( 'currency' => $order->get_currency() ) );
} else {
echo '&ndash;';
}
if ( ( $tax_data = $item->get_taxes() ) && wc_tax_enabled() ) {
foreach ( $order_taxes as $tax_item ) {
$tax_item_id = $tax_item->get_rate_id();
$tax_item_total = isset( $tax_data['total'][ $tax_item_id ] ) ? $tax_data['total'][ $tax_item_id ] : '';
$tax_item_subtotal = isset( $tax_data['subtotal'][ $tax_item_id ] ) ? $tax_data['subtotal'][ $tax_item_id ] : '';
?>
<td class="line_tax" width="1%">
<div class="view">
<?php
if ( '' !== $tax_item_total ) {
echo wc_price( wc_round_tax_total( $tax_item_total ), array( 'currency' => $order->get_currency() ) );
} else {
echo '&ndash;';
}
if ( $item->get_subtotal() !== $item->get_total() ) {
if ( '' === $tax_item_total ) {
echo '<span class="wc-order-item-discount">&ndash;</span>';
} else {
echo '<span class="wc-order-item-discount">-' . wc_price( wc_round_tax_total( $tax_item_subtotal - $tax_item_total ), array( 'currency' => $order->get_currency() ) ) . '</span>';
}
}
if ( $item->get_subtotal() !== $item->get_total() ) {
if ( '' === $tax_item_total ) {
echo '<span class="wc-order-item-discount">&ndash;</span>';
} else {
echo '<span class="wc-order-item-discount">-' . wc_price( wc_round_tax_total( $tax_item_subtotal - $tax_item_total ), array( 'currency' => $order->get_currency() ) ) . '</span>';
}
}
if ( $refunded = $order->get_tax_refunded_for_item( $item_id, $tax_item_id ) ) {
echo '<small class="refunded">' . wc_price( $refunded, array( 'currency' => $order->get_currency() ) ) . '</small>';
}
?>
</div>
<div class="edit" style="display: none;">
<div class="split-input">
<div class="input">
<label><?php esc_attr_e( 'Pre-discount:', 'woocommerce' ); ?></label>
<input type="text" name="line_subtotal_tax[<?php echo absint( $item_id ); ?>][<?php echo esc_attr( $tax_item_id ); ?>]" placeholder="<?php echo esc_attr( wc_format_localized_price( 0 ) ); ?>" value="<?php echo esc_attr( wc_format_localized_price( $tax_item_subtotal ) ); ?>" class="line_subtotal_tax wc_input_price" data-subtotal_tax="<?php echo esc_attr( wc_format_localized_price( $tax_item_subtotal ) ); ?>" data-tax_id="<?php echo esc_attr( $tax_item_id ); ?>" />
</div>
<div class="input">
<label><?php esc_attr_e( 'Total:', 'woocommerce' ); ?></label>
<input type="text" name="line_tax[<?php echo absint( $item_id ); ?>][<?php echo esc_attr( $tax_item_id ); ?>]" placeholder="<?php echo esc_attr( wc_format_localized_price( 0 ) ); ?>" value="<?php echo esc_attr( wc_format_localized_price( $tax_item_total ) ); ?>" class="line_tax wc_input_price" data-total_tax="<?php echo esc_attr( wc_format_localized_price( $tax_item_total ) ); ?>" data-tax_id="<?php echo esc_attr( $tax_item_id ); ?>" />
</div>
if ( $refunded = $order->get_tax_refunded_for_item( $item_id, $tax_item_id ) ) {
echo '<small class="refunded">' . wc_price( $refunded, array( 'currency' => $order->get_currency() ) ) . '</small>';
}
?>
</div>
<div class="edit" style="display: none;">
<div class="split-input">
<div class="input">
<label><?php esc_attr_e( 'Pre-discount:', 'woocommerce' ); ?></label>
<input type="text" name="line_subtotal_tax[<?php echo absint( $item_id ); ?>][<?php echo esc_attr( $tax_item_id ); ?>]" placeholder="<?php echo esc_attr( wc_format_localized_price( 0 ) ); ?>" value="<?php echo esc_attr( wc_format_localized_price( $tax_item_subtotal ) ); ?>" class="line_subtotal_tax wc_input_price" data-subtotal_tax="<?php echo esc_attr( wc_format_localized_price( $tax_item_subtotal ) ); ?>" data-tax_id="<?php echo esc_attr( $tax_item_id ); ?>" />
</div>
<div class="input">
<label><?php esc_attr_e( 'Total:', 'woocommerce' ); ?></label>
<input type="text" name="line_tax[<?php echo absint( $item_id ); ?>][<?php echo esc_attr( $tax_item_id ); ?>]" placeholder="<?php echo esc_attr( wc_format_localized_price( 0 ) ); ?>" value="<?php echo esc_attr( wc_format_localized_price( $tax_item_total ) ); ?>" class="line_tax wc_input_price" data-total_tax="<?php echo esc_attr( wc_format_localized_price( $tax_item_total ) ); ?>" data-tax_id="<?php echo esc_attr( $tax_item_id ); ?>" />
</div>
</div>
<div class="refund" style="display: none;">
<input type="text" name="refund_line_tax[<?php echo absint( $item_id ); ?>][<?php echo esc_attr( $tax_item_id ); ?>]" placeholder="<?php echo esc_attr( wc_format_localized_price( 0 ) ); ?>" class="refund_line_tax wc_input_price" data-tax_id="<?php echo esc_attr( $tax_item_id ); ?>" />
</div>
</td>
<?php
}
</div>
<div class="refund" style="display: none;">
<input type="text" name="refund_line_tax[<?php echo absint( $item_id ); ?>][<?php echo esc_attr( $tax_item_id ); ?>]" placeholder="<?php echo esc_attr( wc_format_localized_price( 0 ) ); ?>" class="refund_line_tax wc_input_price" data-tax_id="<?php echo esc_attr( $tax_item_id ); ?>" />
</div>
</td>
<?php
}
}
?>
<td class="wc-order-edit-line-item" width="1%">
<div class="wc-order-edit-line-item-actions">

View File

@ -32,64 +32,64 @@ if ( wc_tax_enabled() ) {
<th class="quantity sortable" data-sort="int"><?php esc_html_e( 'Qty', 'woocommerce' ); ?></th>
<th class="line_cost sortable" data-sort="float"><?php esc_html_e( 'Total', 'woocommerce' ); ?></th>
<?php
if ( ! empty( $order_taxes ) ) :
foreach ( $order_taxes as $tax_id => $tax_item ) :
$tax_class = wc_get_tax_class_by_tax_id( $tax_item['rate_id'] );
$tax_class_name = isset( $classes_options[ $tax_class ] ) ? $classes_options[ $tax_class ] : __( 'Tax', 'woocommerce' );
$column_label = ! empty( $tax_item['label'] ) ? $tax_item['label'] : __( 'Tax', 'woocommerce' );
/* translators: %1$s: tax item name %2$s: tax class name */
$column_tip = sprintf( esc_html__( '%1$s (%2$s)', 'woocommerce' ), $tax_item['name'], $tax_class_name );
?>
<th class="line_tax tips" data-tip="<?php echo esc_attr( $column_tip ); ?>">
<?php echo esc_attr( $column_label ); ?>
<input type="hidden" class="order-tax-id" name="order_taxes[<?php echo esc_attr( $tax_id ); ?>]" value="<?php echo esc_attr( $tax_item['rate_id'] ); ?>">
<a class="delete-order-tax" href="#" data-rate_id="<?php echo esc_attr( $tax_id ); ?>"></a>
</th>
<?php
endforeach;
endif;
if ( ! empty( $order_taxes ) ) :
foreach ( $order_taxes as $tax_id => $tax_item ) :
$tax_class = wc_get_tax_class_by_tax_id( $tax_item['rate_id'] );
$tax_class_name = isset( $classes_options[ $tax_class ] ) ? $classes_options[ $tax_class ] : __( 'Tax', 'woocommerce' );
$column_label = ! empty( $tax_item['label'] ) ? $tax_item['label'] : __( 'Tax', 'woocommerce' );
/* translators: %1$s: tax item name %2$s: tax class name */
$column_tip = sprintf( esc_html__( '%1$s (%2$s)', 'woocommerce' ), $tax_item['name'], $tax_class_name );
?>
<th class="line_tax tips" data-tip="<?php echo esc_attr( $column_tip ); ?>">
<?php echo esc_attr( $column_label ); ?>
<input type="hidden" class="order-tax-id" name="order_taxes[<?php echo esc_attr( $tax_id ); ?>]" value="<?php echo esc_attr( $tax_item['rate_id'] ); ?>">
<a class="delete-order-tax" href="#" data-rate_id="<?php echo esc_attr( $tax_id ); ?>"></a>
</th>
<?php
endforeach;
endif;
?>
<th class="wc-order-edit-line-item" width="1%">&nbsp;</th>
</tr>
</thead>
<tbody id="order_line_items">
<?php
<?php
foreach ( $line_items as $item_id => $item ) {
do_action( 'woocommerce_before_order_item_' . $item->get_type() . '_html', $item_id, $item, $order );
include( 'html-order-item.php' );
include 'html-order-item.php';
do_action( 'woocommerce_order_item_' . $item->get_type() . '_html', $item_id, $item, $order );
}
do_action( 'woocommerce_admin_order_items_after_line_items', $order->get_id() );
?>
?>
</tbody>
<tbody id="order_shipping_line_items">
<?php
<?php
$shipping_methods = WC()->shipping() ? WC()->shipping->load_shipping_methods() : array();
foreach ( $line_items_shipping as $item_id => $item ) {
include( 'html-order-shipping.php' );
include 'html-order-shipping.php';
}
do_action( 'woocommerce_admin_order_items_after_shipping', $order->get_id() );
?>
?>
</tbody>
<tbody id="order_fee_line_items">
<?php
<?php
foreach ( $line_items_fee as $item_id => $item ) {
include( 'html-order-fee.php' );
include 'html-order-fee.php';
}
do_action( 'woocommerce_admin_order_items_after_fees', $order->get_id() );
?>
?>
</tbody>
<tbody id="order_refunds">
<?php
<?php
if ( $refunds = $order->get_refunds() ) {
foreach ( $refunds as $refund ) {
include( 'html-order-refund.php' );
include 'html-order-refund.php';
}
do_action( 'woocommerce_admin_order_items_after_refunds', $order->get_id() );
}
?>
?>
</tbody>
</table>
</div>
@ -107,33 +107,44 @@ if ( wc_tax_enabled() ) {
</div>
<div class="wc-order-data-row wc-order-totals-items wc-order-items-editable">
<?php
$coupons = $order->get_items( 'coupon' );
if ( $coupons ) : ?>
<div class="wc-used-coupons">
<ul class="wc_coupon_list">
<li><strong><?php esc_html_e( 'Coupon(s)', 'woocommerce' ) ?></strong></li>
<?php foreach ( $coupons as $item_id => $item ) :
$post_id = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM {$wpdb->posts} WHERE post_title = %s AND post_type = 'shop_coupon' AND post_status = 'publish' LIMIT 1;", $item->get_code() ) );
$class = $order->is_editable() ? 'code editable' : 'code';
?>
<li class="<?php echo $class ?>">
<?php if ( $post_id ) : ?>
<a href="<?php echo esc_url( add_query_arg( array( 'post' => $post_id, 'action' => 'edit' ), admin_url( 'post.php' ) ) ) ?>" class="tips" data-tip="<?php echo esc_attr( wc_price( $item->get_discount(), array( 'currency' => $order->get_currency() ) ) ) ?>">
<span><?php echo esc_html( $item->get_code() ) ?></span>
</a>
<?php else : ?>
<span class="tips" data-tip="<?php echo esc_attr( wc_price( $item->get_discount(), array( 'currency' => $order->get_currency() ) ) ) ?>">
<span><?php echo esc_html( $item->get_code() ) ?></span>
</span>
<?php endif; ?>
<?php if ( $order->is_editable() ) : ?>
<a class="remove-coupon" href="javascript:void(0)" aria-label="Remove" data-code="<?php echo esc_attr( $item->get_code() ) ?>"></a>
<?php endif; ?>
</li>
<?php endforeach; ?>
</ul>
</div>
<?php endif; ?>
$coupons = $order->get_items( 'coupon' );
if ( $coupons ) :
?>
<div class="wc-used-coupons">
<ul class="wc_coupon_list">
<li><strong><?php esc_html_e( 'Coupon(s)', 'woocommerce' ); ?></strong></li>
<?php
foreach ( $coupons as $item_id => $item ) :
$post_id = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM {$wpdb->posts} WHERE post_title = %s AND post_type = 'shop_coupon' AND post_status = 'publish' LIMIT 1;", $item->get_code() ) );
$class = $order->is_editable() ? 'code editable' : 'code';
?>
<li class="<?php echo $class; ?>">
<?php if ( $post_id ) : ?>
<?php
$post_url = add_query_arg(
array(
'post' => $post_id,
'action' => 'edit',
),
admin_url( 'post.php' )
);
?>
<a href="<?php echo esc_url( $post_url ); ?>" class="tips" data-tip="<?php echo esc_attr( wc_price( $item->get_discount(), array( 'currency' => $order->get_currency() ) ) ); ?>">
<span><?php echo esc_html( $item->get_code() ); ?></span>
</a>
<?php else : ?>
<span class="tips" data-tip="<?php echo esc_attr( wc_price( $item->get_discount(), array( 'currency' => $order->get_currency() ) ) ); ?>">
<span><?php echo esc_html( $item->get_code() ); ?></span>
</span>
<?php endif; ?>
<?php if ( $order->is_editable() ) : ?>
<a class="remove-coupon" href="javascript:void(0)" aria-label="Remove" data-code="<?php echo esc_attr( $item->get_code() ); ?>"></a>
<?php endif; ?>
</li>
<?php endforeach; ?>
</ul>
</div>
<?php endif; ?>
<table class="wc-order-totals">
<?php if ( 0 < $order->get_total_discount() ) : ?>
<tr>
@ -159,7 +170,8 @@ if ( wc_tax_enabled() ) {
} else {
echo wc_price( $order->get_shipping_total(), array( 'currency' => $order->get_currency() ) );
}
?></td>
?>
</td>
</tr>
<?php endif; ?>
@ -346,8 +358,8 @@ if ( wc_tax_enabled() ) {
<?php
$rates = $wpdb->get_results( "SELECT * FROM {$wpdb->prefix}woocommerce_tax_rates ORDER BY tax_rate_name LIMIT 100" );
foreach ( $rates as $rate ) {
echo '
foreach ( $rates as $rate ) {
echo '
<tr>
<td><input type="radio" id="add_order_tax_' . absint( $rate->tax_rate_id ) . '" name="add_order_tax" value="' . absint( $rate->tax_rate_id ) . '" /></td>
<td><label for="add_order_tax_' . absint( $rate->tax_rate_id ) . '">' . WC_Tax::get_rate_label( $rate ) . '</label></td>
@ -356,7 +368,7 @@ if ( wc_tax_enabled() ) {
<td>' . WC_Tax::get_rate_percent( $rate ) . '</td>
</tr>
';
}
}
?>
</table>
<?php if ( absint( $wpdb->get_var( "SELECT COUNT(tax_rate_id) FROM {$wpdb->prefix}woocommerce_tax_rates;" ) ) > 100 ) : ?>

View File

@ -13,27 +13,27 @@ $who_refunded = new WP_User( $refund->get_refunded_by() );
<td class="name">
<?php
if ( $who_refunded->exists() ) {
printf(
/* translators: 1: refund id 2: refund date 3: username */
esc_html__( 'Refund #%1$s - %2$s by %3$s', 'woocommerce' ),
$refund->get_id(),
wc_format_datetime( $refund->get_date_created(), get_option( 'date_format' ) . ', ' . get_option( 'time_format' ) ),
sprintf(
'<abbr class="refund_by" title="%1$s">%2$s</abbr>',
/* translators: 1: ID who refunded */
sprintf( esc_attr__( 'ID: %d', 'woocommerce' ), absint( $who_refunded->ID ) ),
esc_html( $who_refunded->display_name )
)
);
} else {
printf(
/* translators: 1: refund id 2: refund date */
esc_html__( 'Refund #%1$s - %2$s', 'woocommerce' ),
$refund->get_id(),
wc_format_datetime( $refund->get_date_created(), get_option( 'date_format' ) . ', ' . get_option( 'time_format' ) )
);
}
if ( $who_refunded->exists() ) {
printf(
/* translators: 1: refund id 2: refund date 3: username */
esc_html__( 'Refund #%1$s - %2$s by %3$s', 'woocommerce' ),
$refund->get_id(),
wc_format_datetime( $refund->get_date_created(), get_option( 'date_format' ) . ', ' . get_option( 'time_format' ) ),
sprintf(
'<abbr class="refund_by" title="%1$s">%2$s</abbr>',
/* translators: 1: ID who refunded */
sprintf( esc_attr__( 'ID: %d', 'woocommerce' ), absint( $who_refunded->ID ) ),
esc_html( $who_refunded->display_name )
)
);
} else {
printf(
/* translators: 1: refund id 2: refund date */
esc_html__( 'Refund #%1$s - %2$s', 'woocommerce' ),
$refund->get_id(),
wc_format_datetime( $refund->get_date_created(), get_option( 'date_format' ) . ', ' . get_option( 'time_format' ) )
);
}
?>
<?php if ( $refund->get_reason() ) : ?>
<p class="description"><?php echo esc_html( $refund->get_reason() ); ?></p>
@ -52,7 +52,10 @@ $who_refunded = new WP_User( $refund->get_refunded_by() );
</div>
</td>
<?php if ( wc_tax_enabled() ) : $total_taxes = count( $order_taxes ); ?>
<?php
if ( wc_tax_enabled() ) :
$total_taxes = count( $order_taxes );
?>
<?php for ( $i = 0; $i < $total_taxes; $i++ ) : ?>
<td class="line_tax" width="1%"></td>
<?php endfor; ?>

View File

@ -23,30 +23,30 @@ if ( ! defined( 'ABSPATH' ) ) {
<optgroup label="<?php esc_attr_e( 'Shipping method', 'woocommerce' ); ?>">
<option value=""><?php esc_html_e( 'N/A', 'woocommerce' ); ?></option>
<?php
$found_method = false;
$found_method = false;
foreach ( $shipping_methods as $method ) {
$current_method = ( 0 === strpos( $item->get_method_id(), $method->id ) ) ? $item->get_method_id() : $method->id;
foreach ( $shipping_methods as $method ) {
$current_method = ( 0 === strpos( $item->get_method_id(), $method->id ) ) ? $item->get_method_id() : $method->id;
echo '<option value="' . esc_attr( $current_method ) . '" ' . selected( $item->get_method_id() === $current_method, true, false ) . '>' . esc_html( $method->get_method_title() ) . '</option>';
echo '<option value="' . esc_attr( $current_method ) . '" ' . selected( $item->get_method_id() === $current_method, true, false ) . '>' . esc_html( $method->get_method_title() ) . '</option>';
if ( $item->get_method_id() === $current_method ) {
$found_method = true;
}
if ( $item->get_method_id() === $current_method ) {
$found_method = true;
}
}
if ( ! $found_method && $item->get_method_id() ) {
echo '<option value="' . esc_attr( $item->get_method_id() ) . '" selected="selected">' . esc_html__( 'Other', 'woocommerce' ) . '</option>';
} else {
echo '<option value="other">' . esc_html__( 'Other', 'woocommerce' ) . '</option>';
}
if ( ! $found_method && $item->get_method_id() ) {
echo '<option value="' . esc_attr( $item->get_method_id() ) . '" selected="selected">' . esc_html__( 'Other', 'woocommerce' ) . '</option>';
} else {
echo '<option value="other">' . esc_html__( 'Other', 'woocommerce' ) . '</option>';
}
?>
</optgroup>
</select>
</div>
<?php do_action( 'woocommerce_before_order_itemmeta', $item_id, $item, null ); ?>
<?php include( 'html-order-item-meta.php' ); ?>
<?php require 'html-order-item-meta.php'; ?>
<?php do_action( 'woocommerce_after_order_itemmeta', $item_id, $item, null ); ?>
</td>
@ -58,11 +58,11 @@ if ( ! defined( 'ABSPATH' ) ) {
<td class="line_cost" width="1%">
<div class="view">
<?php
echo wc_price( $item->get_total(), array( 'currency' => $order->get_currency() ) );
$refunded = $order->get_total_refunded_for_item( $item_id, 'shipping' );
if ( $refunded ) {
echo '<small class="refunded">-' . wc_price( $refunded, array( 'currency' => $order->get_currency() ) ) . '</small>';
}
echo wc_price( $item->get_total(), array( 'currency' => $order->get_currency() ) );
$refunded = $order->get_total_refunded_for_item( $item_id, 'shipping' );
if ( $refunded ) {
echo '<small class="refunded">-' . wc_price( $refunded, array( 'currency' => $order->get_currency() ) ) . '</small>';
}
?>
</div>
<div class="edit" style="display: none;">
@ -74,31 +74,31 @@ if ( ! defined( 'ABSPATH' ) ) {
</td>
<?php
if ( ( $tax_data = $item->get_taxes() ) && wc_tax_enabled() ) {
foreach ( $order_taxes as $tax_item ) {
$tax_item_id = $tax_item->get_rate_id();
$tax_item_total = isset( $tax_data['total'][ $tax_item_id ] ) ? $tax_data['total'][ $tax_item_id ] : '';
?>
<td class="line_tax" width="1%">
<div class="view">
<?php
echo ( '' !== $tax_item_total ) ? wc_price( wc_round_tax_total( $tax_item_total ), array( 'currency' => $order->get_currency() ) ) : '&ndash;';
$refunded = $order->get_tax_refunded_for_item( $item_id, $tax_item_id, 'shipping' );
if ( $refunded ) {
echo '<small class="refunded">-' . wc_price( $refunded, array( 'currency' => $order->get_currency() ) ) . '</small>';
}
?>
</div>
<div class="edit" style="display: none;">
<input type="text" name="shipping_taxes[<?php echo absint( $item_id ); ?>][<?php echo esc_attr( $tax_item_id ); ?>]" placeholder="<?php echo esc_attr( wc_format_localized_price( 0 ) ); ?>" value="<?php echo ( isset( $tax_item_total ) ) ? esc_attr( wc_format_localized_price( $tax_item_total ) ) : ''; ?>" class="line_tax wc_input_price" />
</div>
<div class="refund" style="display: none;">
<input type="text" name="refund_line_tax[<?php echo absint( $item_id ); ?>][<?php echo esc_attr( $tax_item_id ); ?>]" placeholder="<?php echo esc_attr( wc_format_localized_price( 0 ) ); ?>" class="refund_line_tax wc_input_price" data-tax_id="<?php echo esc_attr( $tax_item_id ); ?>" />
</div>
</td>
<?php
}
if ( ( $tax_data = $item->get_taxes() ) && wc_tax_enabled() ) {
foreach ( $order_taxes as $tax_item ) {
$tax_item_id = $tax_item->get_rate_id();
$tax_item_total = isset( $tax_data['total'][ $tax_item_id ] ) ? $tax_data['total'][ $tax_item_id ] : '';
?>
<td class="line_tax" width="1%">
<div class="view">
<?php
echo ( '' !== $tax_item_total ) ? wc_price( wc_round_tax_total( $tax_item_total ), array( 'currency' => $order->get_currency() ) ) : '&ndash;';
$refunded = $order->get_tax_refunded_for_item( $item_id, $tax_item_id, 'shipping' );
if ( $refunded ) {
echo '<small class="refunded">-' . wc_price( $refunded, array( 'currency' => $order->get_currency() ) ) . '</small>';
}
?>
</div>
<div class="edit" style="display: none;">
<input type="text" name="shipping_taxes[<?php echo absint( $item_id ); ?>][<?php echo esc_attr( $tax_item_id ); ?>]" placeholder="<?php echo esc_attr( wc_format_localized_price( 0 ) ); ?>" value="<?php echo ( isset( $tax_item_total ) ) ? esc_attr( wc_format_localized_price( $tax_item_total ) ) : ''; ?>" class="line_tax wc_input_price" />
</div>
<div class="refund" style="display: none;">
<input type="text" name="refund_line_tax[<?php echo absint( $item_id ); ?>][<?php echo esc_attr( $tax_item_id ); ?>]" placeholder="<?php echo esc_attr( wc_format_localized_price( 0 ) ); ?>" class="refund_line_tax wc_input_price" data-tax_id="<?php echo esc_attr( $tax_item_id ); ?>" />
</div>
</td>
<?php
}
}
?>
<td class="wc-order-edit-line-item">
<?php if ( $order->is_editable() ) : ?>

View File

@ -39,7 +39,7 @@ if ( ! defined( 'ABSPATH' ) ) {
?>
<select multiple="multiple" data-placeholder="<?php esc_attr_e( 'Select terms', 'woocommerce' ); ?>" class="multiselect attribute_values wc-enhanced-select" name="attribute_values[<?php echo esc_attr( $i ); ?>][]">
<?php
$args = array(
$args = array(
'orderby' => 'name',
'hide_empty' => 0,
);
@ -62,7 +62,9 @@ if ( ! defined( 'ABSPATH' ) ) {
do_action( 'woocommerce_product_option_terms', $attribute_taxonomy, $i );
} else {
/* translators: %s: WC_DELIMITER */
?><textarea name="attribute_values[<?php echo esc_attr( $i ); ?>]" cols="5" rows="5" placeholder="<?php printf( esc_attr__( 'Enter some text, or some attributes by "%s" separating values.', 'woocommerce' ), WC_DELIMITER ); ?>"><?php echo esc_textarea( wc_implode_text_attributes( $attribute->get_options() ) ); ?></textarea><?php
?>
<textarea name="attribute_values[<?php echo esc_attr( $i ); ?>]" cols="5" rows="5" placeholder="<?php printf( esc_attr__( 'Enter some text, or some attributes by "%s" separating values.', 'woocommerce' ), WC_DELIMITER ); ?>"><?php echo esc_textarea( wc_implode_text_attributes( $attribute->get_options() ) ); ?></textarea>
<?php
}
?>
</td>

View File

@ -7,41 +7,47 @@ if ( ! defined( 'ABSPATH' ) ) {
<div class="options_group hide_if_external hide_if_grouped">
<?php
woocommerce_wp_textarea_input( array(
'id' => '_purchase_note',
'value' => $product_object->get_purchase_note( 'edit' ),
'label' => __( 'Purchase note', 'woocommerce' ),
'desc_tip' => true,
'description' => __( 'Enter an optional note to send the customer after purchase.', 'woocommerce' ),
) );
woocommerce_wp_textarea_input(
array(
'id' => '_purchase_note',
'value' => $product_object->get_purchase_note( 'edit' ),
'label' => __( 'Purchase note', 'woocommerce' ),
'desc_tip' => true,
'description' => __( 'Enter an optional note to send the customer after purchase.', 'woocommerce' ),
)
);
?>
</div>
<div class="options_group">
<?php
woocommerce_wp_text_input( array(
'id' => 'menu_order',
'value' => $product_object->get_menu_order( 'edit' ),
'label' => __( 'Menu order', 'woocommerce' ),
'desc_tip' => true,
'description' => __( 'Custom ordering position.', 'woocommerce' ),
'type' => 'number',
'custom_attributes' => array(
'step' => '1',
),
) );
woocommerce_wp_text_input(
array(
'id' => 'menu_order',
'value' => $product_object->get_menu_order( 'edit' ),
'label' => __( 'Menu order', 'woocommerce' ),
'desc_tip' => true,
'description' => __( 'Custom ordering position.', 'woocommerce' ),
'type' => 'number',
'custom_attributes' => array(
'step' => '1',
),
)
);
?>
</div>
<?php if ( post_type_supports( 'product', 'comments' ) ) : ?>
<div class="options_group reviews">
<?php
woocommerce_wp_checkbox( array(
'id' => 'comment_status',
'value' => $product_object->get_reviews_allowed( 'edit' ) ? 'open' : 'closed',
'label' => __( 'Enable reviews', 'woocommerce' ),
'cbvalue' => 'open',
) );
woocommerce_wp_checkbox(
array(
'id' => 'comment_status',
'value' => $product_object->get_reviews_allowed( 'edit' ) ? 'open' : 'closed',
'label' => __( 'Enable reviews', 'woocommerce' ),
'cbvalue' => 'open',
)
);
do_action( 'woocommerce_product_options_reviews' );
?>
</div>

View File

@ -11,39 +11,39 @@ if ( ! defined( 'ABSPATH' ) ) {
<select name="attribute_taxonomy" class="attribute_taxonomy">
<option value=""><?php esc_html_e( 'Custom product attribute', 'woocommerce' ); ?></option>
<?php
global $wc_product_attributes;
global $wc_product_attributes;
// Array of defined attribute taxonomies
$attribute_taxonomies = wc_get_attribute_taxonomies();
// Array of defined attribute taxonomies.
$attribute_taxonomies = wc_get_attribute_taxonomies();
if ( ! empty( $attribute_taxonomies ) ) {
foreach ( $attribute_taxonomies as $tax ) {
$attribute_taxonomy_name = wc_attribute_taxonomy_name( $tax->attribute_name );
$label = $tax->attribute_label ? $tax->attribute_label : $tax->attribute_name;
echo '<option value="' . esc_attr( $attribute_taxonomy_name ) . '">' . esc_html( $label ) . '</option>';
}
if ( ! empty( $attribute_taxonomies ) ) {
foreach ( $attribute_taxonomies as $tax ) {
$attribute_taxonomy_name = wc_attribute_taxonomy_name( $tax->attribute_name );
$label = $tax->attribute_label ? $tax->attribute_label : $tax->attribute_name;
echo '<option value="' . esc_attr( $attribute_taxonomy_name ) . '">' . esc_html( $label ) . '</option>';
}
}
?>
</select>
<button type="button" class="button add_attribute"><?php esc_html_e( 'Add', 'woocommerce' ); ?></button>
</div>
<div class="product_attributes wc-metaboxes">
<?php
// Product attributes - taxonomies and custom, ordered, with visibility and variation attributes set
$attributes = $product_object->get_attributes( 'edit' );
$i = -1;
// Product attributes - taxonomies and custom, ordered, with visibility and variation attributes set.
$attributes = $product_object->get_attributes( 'edit' );
$i = -1;
foreach ( $attributes as $attribute ) {
$i++;
$metabox_class = array();
foreach ( $attributes as $attribute ) {
$i++;
$metabox_class = array();
if ( $attribute->is_taxonomy() ) {
$metabox_class[] = 'taxonomy';
$metabox_class[] = $attribute->get_name();
}
include( 'html-product-attribute.php' );
if ( $attribute->is_taxonomy() ) {
$metabox_class[] = 'taxonomy';
$metabox_class[] = $attribute->get_name();
}
include 'html-product-attribute.php';
}
?>
</div>
<div class="toolbar">

View File

@ -7,52 +7,60 @@ if ( ! defined( 'ABSPATH' ) ) {
<div class="options_group show_if_external">
<?php
woocommerce_wp_text_input( array(
woocommerce_wp_text_input(
array(
'id' => '_product_url',
'value' => is_callable( array( $product_object, 'get_product_url' ) ) ? $product_object->get_product_url( 'edit' ) : '',
'label' => __( 'Product URL', 'woocommerce' ),
'placeholder' => 'http://',
'description' => __( 'Enter the external URL to the product.', 'woocommerce' ),
) );
)
);
woocommerce_wp_text_input( array(
woocommerce_wp_text_input(
array(
'id' => '_button_text',
'value' => is_callable( array( $product_object, 'get_button_text' ) ) ? $product_object->get_button_text( 'edit' ) : '',
'label' => __( 'Button text', 'woocommerce' ),
'placeholder' => _x( 'Buy product', 'placeholder', 'woocommerce' ),
'description' => __( 'This text will be shown on the button linking to the external product.', 'woocommerce' ),
) );
)
);
?>
</div>
<div class="options_group pricing show_if_simple show_if_external hidden">
<?php
woocommerce_wp_text_input( array(
woocommerce_wp_text_input(
array(
'id' => '_regular_price',
'value' => $product_object->get_regular_price( 'edit' ),
'label' => __( 'Regular price', 'woocommerce' ) . ' (' . get_woocommerce_currency_symbol() . ')',
'data_type' => 'price',
) );
)
);
woocommerce_wp_text_input( array(
woocommerce_wp_text_input(
array(
'id' => '_sale_price',
'value' => $product_object->get_sale_price( 'edit' ),
'data_type' => 'price',
'label' => __( 'Sale price', 'woocommerce' ) . ' (' . get_woocommerce_currency_symbol() . ')',
'description' => '<a href="#" class="sale_schedule">' . __( 'Schedule', 'woocommerce' ) . '</a>',
) );
)
);
$sale_price_dates_from = $product_object->get_date_on_sale_from( 'edit' ) && ( $date = $product_object->get_date_on_sale_from( 'edit' )->getOffsetTimestamp() ) ? date_i18n( 'Y-m-d', $date ) : '';
$sale_price_dates_to = $product_object->get_date_on_sale_to( 'edit' ) && ( $date = $product_object->get_date_on_sale_to( 'edit' )->getOffsetTimestamp() ) ? date_i18n( 'Y-m-d', $date ) : '';
$sale_price_dates_from = $product_object->get_date_on_sale_from( 'edit' ) && ( $date = $product_object->get_date_on_sale_from( 'edit' )->getOffsetTimestamp() ) ? date_i18n( 'Y-m-d', $date ) : '';
$sale_price_dates_to = $product_object->get_date_on_sale_to( 'edit' ) && ( $date = $product_object->get_date_on_sale_to( 'edit' )->getOffsetTimestamp() ) ? date_i18n( 'Y-m-d', $date ) : '';
echo '<p class="form-field sale_price_dates_fields">
<label for="_sale_price_dates_from">' . esc_html__( 'Sale price dates', 'woocommerce' ) . '</label>
<input type="text" class="short" name="_sale_price_dates_from" id="_sale_price_dates_from" value="' . esc_attr( $sale_price_dates_from ) . '" placeholder="' . esc_html( _x( 'From&hellip;', 'placeholder', 'woocommerce' ) ) . ' YYYY-MM-DD" maxlength="10" pattern="' . esc_attr( apply_filters( 'woocommerce_date_input_html_pattern', '[0-9]{4}-(0[1-9]|1[012])-(0[1-9]|1[0-9]|2[0-9]|3[01])' ) ) . '" />
<input type="text" class="short" name="_sale_price_dates_to" id="_sale_price_dates_to" value="' . esc_attr( $sale_price_dates_to ) . '" placeholder="' . esc_html( _x( 'To&hellip;', 'placeholder', 'woocommerce' ) ) . ' YYYY-MM-DD" maxlength="10" pattern="' . esc_attr( apply_filters( 'woocommerce_date_input_html_pattern', '[0-9]{4}-(0[1-9]|1[012])-(0[1-9]|1[0-9]|2[0-9]|3[01])' ) ) . '" />
<a href="#" class="description cancel_sale_schedule">' . esc_html__( 'Cancel', 'woocommerce' ) . '</a>' . wc_help_tip( __( 'The sale will end at the beginning of the set date.', 'woocommerce' ) ) . '
</p>';
echo '<p class="form-field sale_price_dates_fields">
<label for="_sale_price_dates_from">' . esc_html__( 'Sale price dates', 'woocommerce' ) . '</label>
<input type="text" class="short" name="_sale_price_dates_from" id="_sale_price_dates_from" value="' . esc_attr( $sale_price_dates_from ) . '" placeholder="' . esc_html( _x( 'From&hellip;', 'placeholder', 'woocommerce' ) ) . ' YYYY-MM-DD" maxlength="10" pattern="' . esc_attr( apply_filters( 'woocommerce_date_input_html_pattern', '[0-9]{4}-(0[1-9]|1[012])-(0[1-9]|1[0-9]|2[0-9]|3[01])' ) ) . '" />
<input type="text" class="short" name="_sale_price_dates_to" id="_sale_price_dates_to" value="' . esc_attr( $sale_price_dates_to ) . '" placeholder="' . esc_html( _x( 'To&hellip;', 'placeholder', 'woocommerce' ) ) . ' YYYY-MM-DD" maxlength="10" pattern="' . esc_attr( apply_filters( 'woocommerce_date_input_html_pattern', '[0-9]{4}-(0[1-9]|1[012])-(0[1-9]|1[0-9]|2[0-9]|3[01])' ) ) . '" />
<a href="#" class="description cancel_sale_schedule">' . esc_html__( 'Cancel', 'woocommerce' ) . '</a>' . wc_help_tip( __( 'The sale will end at the beginning of the set date.', 'woocommerce' ) ) . '
</p>';
do_action( 'woocommerce_product_options_pricing' );
do_action( 'woocommerce_product_options_pricing' );
?>
</div>
@ -73,7 +81,7 @@ if ( ! defined( 'ABSPATH' ) ) {
$downloadable_files = $product_object->get_downloads( 'edit' );
if ( $downloadable_files ) {
foreach ( $downloadable_files as $key => $file ) {
include( 'html-product-download.php' );
include 'html-product-download.php';
}
}
?>
@ -81,23 +89,26 @@ if ( ! defined( 'ABSPATH' ) ) {
<tfoot>
<tr>
<th colspan="5">
<a href="#" class="button insert" data-row="<?php
<a href="#" class="button insert" data-row="
<?php
$key = '';
$file = array(
'file' => '',
'name' => '',
);
ob_start();
include( 'html-product-download.php' );
require 'html-product-download.php';
echo esc_attr( ob_get_clean() );
?>"><?php esc_html_e( 'Add File', 'woocommerce' ); ?></a>
?>
"><?php esc_html_e( 'Add File', 'woocommerce' ); ?></a>
</th>
</tr>
</tfoot>
</table>
</div>
<?php
woocommerce_wp_text_input( array(
woocommerce_wp_text_input(
array(
'id' => '_download_limit',
'value' => -1 === $product_object->get_download_limit( 'edit' ) ? '' : $product_object->get_download_limit( 'edit' ),
'label' => __( 'Download limit', 'woocommerce' ),
@ -105,12 +116,14 @@ if ( ! defined( 'ABSPATH' ) ) {
'description' => __( 'Leave blank for unlimited re-downloads.', 'woocommerce' ),
'type' => 'number',
'custom_attributes' => array(
'step' => '1',
'min' => '0',
'step' => '1',
'min' => '0',
),
) );
)
);
woocommerce_wp_text_input( array(
woocommerce_wp_text_input(
array(
'id' => '_download_expiry',
'value' => -1 === $product_object->get_download_expiry( 'edit' ) ? '' : $product_object->get_download_expiry( 'edit' ),
'label' => __( 'Download expiry', 'woocommerce' ),
@ -118,41 +131,46 @@ if ( ! defined( 'ABSPATH' ) ) {
'description' => __( 'Enter the number of days before a download link expires, or leave blank.', 'woocommerce' ),
'type' => 'number',
'custom_attributes' => array(
'step' => '1',
'min' => '0',
'step' => '1',
'min' => '0',
),
) );
)
);
do_action( 'woocommerce_product_options_downloads' );
do_action( 'woocommerce_product_options_downloads' );
?>
</div>
<?php if ( wc_tax_enabled() ) : ?>
<div class="options_group show_if_simple show_if_external show_if_variable">
<?php
woocommerce_wp_select( array(
'id' => '_tax_status',
'value' => $product_object->get_tax_status( 'edit' ),
'label' => __( 'Tax status', 'woocommerce' ),
'options' => array(
'taxable' => __( 'Taxable', 'woocommerce' ),
'shipping' => __( 'Shipping only', 'woocommerce' ),
'none' => _x( 'None', 'Tax status', 'woocommerce' ),
woocommerce_wp_select(
array(
'id' => '_tax_status',
'value' => $product_object->get_tax_status( 'edit' ),
'label' => __( 'Tax status', 'woocommerce' ),
'options' => array(
'taxable' => __( 'Taxable', 'woocommerce' ),
'shipping' => __( 'Shipping only', 'woocommerce' ),
'none' => _x( 'None', 'Tax status', 'woocommerce' ),
),
'desc_tip' => 'true',
'description' => __( 'Define whether or not the entire product is taxable, or just the cost of shipping it.', 'woocommerce' ),
) );
'desc_tip' => 'true',
'description' => __( 'Define whether or not the entire product is taxable, or just the cost of shipping it.', 'woocommerce' ),
)
);
woocommerce_wp_select( array(
woocommerce_wp_select(
array(
'id' => '_tax_class',
'value' => $product_object->get_tax_class( 'edit' ),
'label' => __( 'Tax class', 'woocommerce' ),
'options' => wc_get_product_tax_class_options(),
'desc_tip' => 'true',
'description' => __( 'Choose a tax class for this product. Tax classes are used to apply different tax rates specific to certain types of product.', 'woocommerce' ),
) );
)
);
do_action( 'woocommerce_product_options_tax' );
do_action( 'woocommerce_product_options_tax' );
?>
</div>
<?php endif; ?>

View File

@ -7,33 +7,38 @@ if ( ! defined( 'ABSPATH' ) ) {
<div class="options_group">
<?php
if ( wc_product_sku_enabled() ) {
woocommerce_wp_text_input( array(
if ( wc_product_sku_enabled() ) {
woocommerce_wp_text_input(
array(
'id' => '_sku',
'value' => $product_object->get_sku( 'edit' ),
'label' => '<abbr title="' . esc_attr__( 'Stock Keeping Unit', 'woocommerce' ) . '">' . esc_html__( 'SKU', 'woocommerce' ) . '</abbr>',
'desc_tip' => true,
'description' => __( 'SKU refers to a Stock-keeping unit, a unique identifier for each distinct product and service that can be purchased.', 'woocommerce' ),
) );
}
)
);
}
do_action( 'woocommerce_product_options_sku' );
do_action( 'woocommerce_product_options_sku' );
if ( 'yes' === get_option( 'woocommerce_manage_stock' ) ) {
if ( 'yes' === get_option( 'woocommerce_manage_stock' ) ) {
woocommerce_wp_checkbox( array(
woocommerce_wp_checkbox(
array(
'id' => '_manage_stock',
'value' => $product_object->get_manage_stock( 'edit' ) ? 'yes' : 'no',
'wrapper_class' => 'show_if_simple show_if_variable',
'label' => __( 'Manage stock?', 'woocommerce' ),
'description' => __( 'Enable stock management at product level', 'woocommerce' ),
) );
)
);
do_action( 'woocommerce_product_options_stock' );
do_action( 'woocommerce_product_options_stock' );
echo '<div class="stock_fields show_if_simple show_if_variable">';
echo '<div class="stock_fields show_if_simple show_if_variable">';
woocommerce_wp_text_input( array(
woocommerce_wp_text_input(
array(
'id' => '_stock',
'value' => wc_stock_amount( $product_object->get_stock_quantity( 'edit' ) ),
'label' => __( 'Stock quantity', 'woocommerce' ),
@ -41,52 +46,59 @@ if ( ! defined( 'ABSPATH' ) ) {
'description' => __( 'Stock quantity. If this is a variable product this value will be used to control stock for all variations, unless you define stock at variation level.', 'woocommerce' ),
'type' => 'number',
'custom_attributes' => array(
'step' => 'any',
'step' => 'any',
),
'data_type' => 'stock',
) );
)
);
echo '<input type="hidden" name="_original_stock" value="' . esc_attr( wc_stock_amount( $product_object->get_stock_quantity( 'edit' ) ) ) . '" />';
echo '<input type="hidden" name="_original_stock" value="' . esc_attr( wc_stock_amount( $product_object->get_stock_quantity( 'edit' ) ) ) . '" />';
woocommerce_wp_select( array(
woocommerce_wp_select(
array(
'id' => '_backorders',
'value' => $product_object->get_backorders( 'edit' ),
'label' => __( 'Allow backorders?', 'woocommerce' ),
'options' => wc_get_product_backorder_options(),
'desc_tip' => true,
'description' => __( 'If managing stock, this controls whether or not backorders are allowed. If enabled, stock quantity can go below 0.', 'woocommerce' ),
) );
)
);
do_action( 'woocommerce_product_options_stock_fields' );
do_action( 'woocommerce_product_options_stock_fields' );
echo '</div>';
}
echo '</div>';
}
woocommerce_wp_select( array(
'id' => '_stock_status',
'value' => $product_object->get_stock_status( 'edit' ),
'wrapper_class' => 'stock_status_field hide_if_variable hide_if_external',
'label' => __( 'Stock status', 'woocommerce' ),
'options' => wc_get_product_stock_status_options(),
'desc_tip' => true,
'description' => __( 'Controls whether or not the product is listed as "in stock" or "out of stock" on the frontend.', 'woocommerce' ),
) );
woocommerce_wp_select(
array(
'id' => '_stock_status',
'value' => $product_object->get_stock_status( 'edit' ),
'wrapper_class' => 'stock_status_field hide_if_variable hide_if_external',
'label' => __( 'Stock status', 'woocommerce' ),
'options' => wc_get_product_stock_status_options(),
'desc_tip' => true,
'description' => __( 'Controls whether or not the product is listed as "in stock" or "out of stock" on the frontend.', 'woocommerce' ),
)
);
do_action( 'woocommerce_product_options_stock_status' );
do_action( 'woocommerce_product_options_stock_status' );
?>
</div>
<div class="options_group show_if_simple show_if_variable">
<?php
woocommerce_wp_checkbox( array(
woocommerce_wp_checkbox(
array(
'id' => '_sold_individually',
'value' => $product_object->get_sold_individually( 'edit' ) ? 'yes' : 'no',
'wrapper_class' => 'show_if_simple show_if_variable',
'label' => __( 'Sold individually', 'woocommerce' ),
'description' => __( 'Enable this to only allow one of this item to be bought in a single order', 'woocommerce' ),
) );
)
);
do_action( 'woocommerce_product_options_sold_individually' );
do_action( 'woocommerce_product_options_sold_individually' );
?>
</div>

View File

@ -16,7 +16,8 @@ if ( ! defined( 'ABSPATH' ) ) {
</select>
</label>
<?php foreach ( self::get_product_type_options() as $key => $option ) :
<?php
foreach ( self::get_product_type_options() as $key => $option ) :
if ( metadata_exists( 'post', $post->ID, '_' . $key ) ) {
$selected_value = is_callable( array( $product_object, "is_$key" ) ) ? $product_object->{"is_$key"}() : 'yes' === get_post_meta( $post->ID, '_' . $key, true );
} else {
@ -32,7 +33,7 @@ if ( ! defined( 'ABSPATH' ) ) {
<ul class="product_data_tabs wc-tabs">
<?php foreach ( self::get_product_data_tabs() as $key => $tab ) : ?>
<li class="<?php echo esc_attr( $key ); ?>_options <?php echo esc_attr( $key ); ?>_tab <?php echo esc_attr( isset( $tab['class'] ) ? implode( ' ' , (array) $tab['class'] ) : '' ); ?>">
<li class="<?php echo esc_attr( $key ); ?>_options <?php echo esc_attr( $key ); ?>_tab <?php echo esc_attr( isset( $tab['class'] ) ? implode( ' ', (array) $tab['class'] ) : '' ); ?>">
<a href="#<?php echo esc_attr( $tab['target'] ); ?>"><span><?php echo esc_html( $tab['label'] ); ?></span></a>
</li>
<?php endforeach; ?>

View File

@ -6,8 +6,9 @@ if ( ! defined( 'ABSPATH' ) ) {
<div id="shipping_product_data" class="panel woocommerce_options_panel hidden">
<div class="options_group">
<?php
if ( wc_product_weight_enabled() ) {
woocommerce_wp_text_input( array(
if ( wc_product_weight_enabled() ) {
woocommerce_wp_text_input(
array(
'id' => '_weight',
'value' => $product_object->get_weight( 'edit' ),
'label' => __( 'Weight', 'woocommerce' ) . ' (' . get_option( 'woocommerce_weight_unit' ) . ')',
@ -16,44 +17,49 @@ if ( ! defined( 'ABSPATH' ) ) {
'description' => __( 'Weight in decimal form', 'woocommerce' ),
'type' => 'text',
'data_type' => 'decimal',
) );
}
)
);
}
if ( wc_product_dimensions_enabled() ) {
?><p class="form-field dimensions_field">
if ( wc_product_dimensions_enabled() ) {
?>
<p class="form-field dimensions_field">
<?php /* translators: WooCommerce dimension unit*/ ?>
<label for="product_length"><?php printf( __( 'Dimensions (%s)', 'woocommerce' ), get_option( 'woocommerce_dimension_unit' ) ); ?></label>
<span class="wrap">
<input id="product_length" placeholder="<?php esc_attr_e( 'Length', 'woocommerce' ); ?>" class="input-text wc_input_decimal" size="6" type="text" name="_length" value="<?php echo esc_attr( wc_format_localized_decimal( $product_object->get_length( 'edit' ) ) ); ?>" />
<input placeholder="<?php esc_attr_e( 'Width', 'woocommerce' ); ?>" class="input-text wc_input_decimal" size="6" type="text" name="_width" value="<?php echo esc_attr( wc_format_localized_decimal( $product_object->get_width( 'edit' ) ) ); ?>" />
<input placeholder="<?php esc_attr_e( 'Height', 'woocommerce' ); ?>" class="input-text wc_input_decimal last" size="6" type="text" name="_height" value="<?php echo esc_attr( wc_format_localized_decimal( $product_object->get_height( 'edit' ) ) ); ?>" />
</span>
<?php echo wc_help_tip( __( 'LxWxH in decimal form', 'woocommerce' ) ); ?>
</p><?php
}
<label for="product_length"><?php printf( __( 'Dimensions (%s)', 'woocommerce' ), get_option( 'woocommerce_dimension_unit' ) ); ?></label>
<span class="wrap">
<input id="product_length" placeholder="<?php esc_attr_e( 'Length', 'woocommerce' ); ?>" class="input-text wc_input_decimal" size="6" type="text" name="_length" value="<?php echo esc_attr( wc_format_localized_decimal( $product_object->get_length( 'edit' ) ) ); ?>" />
<input placeholder="<?php esc_attr_e( 'Width', 'woocommerce' ); ?>" class="input-text wc_input_decimal" size="6" type="text" name="_width" value="<?php echo esc_attr( wc_format_localized_decimal( $product_object->get_width( 'edit' ) ) ); ?>" />
<input placeholder="<?php esc_attr_e( 'Height', 'woocommerce' ); ?>" class="input-text wc_input_decimal last" size="6" type="text" name="_height" value="<?php echo esc_attr( wc_format_localized_decimal( $product_object->get_height( 'edit' ) ) ); ?>" />
</span>
<?php echo wc_help_tip( __( 'LxWxH in decimal form', 'woocommerce' ) ); ?>
</p>
<?php
}
do_action( 'woocommerce_product_options_dimensions' );
do_action( 'woocommerce_product_options_dimensions' );
?>
</div>
<div class="options_group">
<?php
$args = array(
'taxonomy' => 'product_shipping_class',
'hide_empty' => 0,
'show_option_none' => __( 'No shipping class', 'woocommerce' ),
'name' => 'product_shipping_class',
'id' => 'product_shipping_class',
'selected' => $product_object->get_shipping_class_id( 'edit' ),
'class' => 'select short',
);
?><p class="form-field dimensions_field">
<label for="product_shipping_class"><?php esc_html_e( 'Shipping class', 'woocommerce' ); ?></label>
<?php wp_dropdown_categories( $args ); ?>
<?php echo wc_help_tip( __( 'Shipping classes are used by certain shipping methods to group similar products.', 'woocommerce' ) ); ?>
</p><?php
$args = array(
'taxonomy' => 'product_shipping_class',
'hide_empty' => 0,
'show_option_none' => __( 'No shipping class', 'woocommerce' ),
'name' => 'product_shipping_class',
'id' => 'product_shipping_class',
'selected' => $product_object->get_shipping_class_id( 'edit' ),
'class' => 'select short',
);
?>
<p class="form-field dimensions_field">
<label for="product_shipping_class"><?php esc_html_e( 'Shipping class', 'woocommerce' ); ?></label>
<?php wp_dropdown_categories( $args ); ?>
<?php echo wc_help_tip( __( 'Shipping classes are used by certain shipping methods to group similar products.', 'woocommerce' ) ); ?>
</p>
<?php
do_action( 'woocommerce_product_options_shipping' );
do_action( 'woocommerce_product_options_shipping' );
?>
</div>
</div>

View File

@ -18,31 +18,33 @@ if ( ! defined( 'ABSPATH' ) ) {
<div class="tips sort" data-tip="<?php esc_attr_e( 'Drag and drop, or click to set admin variation order', 'woocommerce' ); ?>"></div>
<strong>#<?php echo esc_html( $variation_id ); ?> </strong>
<?php
$attribute_values = $variation_object->get_attributes( 'edit' );
$attribute_values = $variation_object->get_attributes( 'edit' );
foreach ( $product_object->get_attributes( 'edit' ) as $attribute ) {
if ( ! $attribute->get_variation() ) {
continue;
}
$selected_value = isset( $attribute_values[ sanitize_title( $attribute->get_name() ) ] ) ? $attribute_values[ sanitize_title( $attribute->get_name() ) ] : '';
?>
<select name="attribute_<?php echo sanitize_title( $attribute->get_name() ) . "[{$loop}]"; ?>">
<option value=""><?php
/* translators: %s: attribute label */
printf( esc_html__( 'Any %s&hellip;', 'woocommerce' ), wc_attribute_label( $attribute->get_name() ) );
?></option>
<?php if ( $attribute->is_taxonomy() ) : ?>
<?php foreach ( $attribute->get_terms() as $option ) : ?>
<option <?php selected( $selected_value, $option->slug ); ?> value="<?php echo esc_attr( $option->slug ); ?>"><?php echo esc_html( apply_filters( 'woocommerce_variation_option_name', $option->name ) ); ?></option>
<?php endforeach; ?>
<?php else : ?>
<?php foreach ( $attribute->get_options() as $option ) : ?>
<option <?php selected( $selected_value, $option ); ?> value="<?php echo esc_attr( $option ); ?>"><?php echo esc_html( apply_filters( 'woocommerce_variation_option_name', $option ) ); ?></option>
<?php endforeach; ?>
<?php endif; ?>
</select>
<?php
foreach ( $product_object->get_attributes( 'edit' ) as $attribute ) {
if ( ! $attribute->get_variation() ) {
continue;
}
$selected_value = isset( $attribute_values[ sanitize_title( $attribute->get_name() ) ] ) ? $attribute_values[ sanitize_title( $attribute->get_name() ) ] : '';
?>
<select name="attribute_<?php echo sanitize_title( $attribute->get_name() ) . "[{$loop}]"; ?>">
<option value="">
<?php
/* translators: %s: attribute label */
printf( esc_html__( 'Any %s&hellip;', 'woocommerce' ), wc_attribute_label( $attribute->get_name() ) );
?>
</option>
<?php if ( $attribute->is_taxonomy() ) : ?>
<?php foreach ( $attribute->get_terms() as $option ) : ?>
<option <?php selected( $selected_value, $option->slug ); ?> value="<?php echo esc_attr( $option->slug ); ?>"><?php echo esc_html( apply_filters( 'woocommerce_variation_option_name', $option->name ) ); ?></option>
<?php endforeach; ?>
<?php else : ?>
<?php foreach ( $attribute->get_options() as $option ) : ?>
<option <?php selected( $selected_value, $option ); ?> value="<?php echo esc_attr( $option ); ?>"><?php echo esc_html( apply_filters( 'woocommerce_variation_option_name', $option ) ); ?></option>
<?php endforeach; ?>
<?php endif; ?>
</select>
<?php
}
?>
<input type="hidden" name="variable_post_id[<?php echo esc_attr( $loop ); ?>]" value="<?php echo esc_attr( $variation_id ); ?>" />
<input type="hidden" class="variation_menu_order" name="variation_menu_order[<?php echo esc_attr( $loop ); ?>]" value="<?php echo esc_attr( $variation_object->get_menu_order( 'edit' ) ); ?>" />
@ -55,8 +57,9 @@ if ( ! defined( 'ABSPATH' ) ) {
</a>
</p>
<?php
if ( wc_product_sku_enabled() ) {
woocommerce_wp_text_input( array(
if ( wc_product_sku_enabled() ) {
woocommerce_wp_text_input(
array(
'id' => "variable_sku{$loop}",
'name' => "variable_sku[{$loop}]",
'value' => $variation_object->get_sku( 'edit' ),
@ -65,8 +68,9 @@ if ( ! defined( 'ABSPATH' ) ) {
'desc_tip' => true,
'description' => __( 'SKU refers to a Stock-keeping unit, a unique identifier for each distinct product and service that can be purchased.', 'woocommerce' ),
'wrapper_class' => 'form-row form-row-last',
) );
}
)
);
}
?>
<p class="form-row form-row-full options">
<label>
@ -94,13 +98,14 @@ if ( ! defined( 'ABSPATH' ) ) {
<div class="variable_pricing">
<?php
$label = sprintf(
/* translators: %s: currency symbol */
__( 'Regular price (%s)', 'woocommerce' ),
get_woocommerce_currency_symbol()
);
$label = sprintf(
/* translators: %s: currency symbol */
__( 'Regular price (%s)', 'woocommerce' ),
get_woocommerce_currency_symbol()
);
woocommerce_wp_text_input( array(
woocommerce_wp_text_input(
array(
'id' => "variable_regular_price_{$loop}",
'name' => "variable_regular_price[{$loop}]",
'value' => wc_format_localized_price( $variation_object->get_regular_price( 'edit' ) ),
@ -108,54 +113,58 @@ if ( ! defined( 'ABSPATH' ) ) {
'data_type' => 'price',
'wrapper_class' => 'form-row form-row-first',
'placeholder' => __( 'Variation price (required)', 'woocommerce' ),
) );
)
);
$label = sprintf(
/* translators: %s: currency symbol */
__( 'Sale price (%s)', 'woocommerce' ),
get_woocommerce_currency_symbol()
);
$label = sprintf(
/* translators: %s: currency symbol */
__( 'Sale price (%s)', 'woocommerce' ),
get_woocommerce_currency_symbol()
);
woocommerce_wp_text_input( array(
woocommerce_wp_text_input(
array(
'id' => "variable_sale_price{$loop}",
'name' => "variable_sale_price[{$loop}]",
'value' => wc_format_localized_price( $variation_object->get_sale_price( 'edit' ) ),
'data_type' => 'price',
'label' => $label . ' <a href="#" class="sale_schedule">' . esc_html__( 'Schedule', 'woocommerce' ) . '</a><a href="#" class="cancel_sale_schedule hidden">' . esc_html__( 'Cancel schedule', 'woocommerce' ) . '</a>',
'wrapper_class' => 'form-row form-row-last',
) );
)
);
$sale_price_dates_from = $variation_object->get_date_on_sale_from( 'edit' ) && ( $date = $variation_object->get_date_on_sale_from( 'edit' )->getOffsetTimestamp() ) ? date_i18n( 'Y-m-d', $date ) : '';
$sale_price_dates_to = $variation_object->get_date_on_sale_to( 'edit' ) && ( $date = $variation_object->get_date_on_sale_to( 'edit' )->getOffsetTimestamp() ) ? date_i18n( 'Y-m-d', $date ) : '';
$sale_price_dates_from = $variation_object->get_date_on_sale_from( 'edit' ) && ( $date = $variation_object->get_date_on_sale_from( 'edit' )->getOffsetTimestamp() ) ? date_i18n( 'Y-m-d', $date ) : '';
$sale_price_dates_to = $variation_object->get_date_on_sale_to( 'edit' ) && ( $date = $variation_object->get_date_on_sale_to( 'edit' )->getOffsetTimestamp() ) ? date_i18n( 'Y-m-d', $date ) : '';
echo '<div class="form-field sale_price_dates_fields hidden">
<p class="form-row form-row-first">
<label>' . __( 'Sale start date', 'woocommerce' ) . '</label>
<input type="text" class="sale_price_dates_from" name="variable_sale_price_dates_from[' . $loop . ']" value="' . esc_attr( $sale_price_dates_from ) . '" placeholder="' . _x( 'From&hellip;', 'placeholder', 'woocommerce' ) . ' YYYY-MM-DD" maxlength="10" pattern="' . esc_attr( apply_filters( 'woocommerce_date_input_html_pattern', '[0-9]{4}-(0[1-9]|1[012])-(0[1-9]|1[0-9]|2[0-9]|3[01])' ) ) . '" />
</p>
<p class="form-row form-row-last">
<label>' . __( 'Sale end date', 'woocommerce' ) . '</label>
<input type="text" class="sale_price_dates_to" name="variable_sale_price_dates_to[' . esc_attr( $loop ) . ']" value="' . esc_attr( $sale_price_dates_to ) . '" placeholder="' . esc_html_x( 'To&hellip;', 'placeholder', 'woocommerce' ) . ' YYYY-MM-DD" maxlength="10" pattern="' . esc_attr( apply_filters( 'woocommerce_date_input_html_pattern', '[0-9]{4}-(0[1-9]|1[012])-(0[1-9]|1[0-9]|2[0-9]|3[01])' ) ) . '" />
</p>
</div>';
echo '<div class="form-field sale_price_dates_fields hidden">
<p class="form-row form-row-first">
<label>' . __( 'Sale start date', 'woocommerce' ) . '</label>
<input type="text" class="sale_price_dates_from" name="variable_sale_price_dates_from[' . $loop . ']" value="' . esc_attr( $sale_price_dates_from ) . '" placeholder="' . _x( 'From&hellip;', 'placeholder', 'woocommerce' ) . ' YYYY-MM-DD" maxlength="10" pattern="' . esc_attr( apply_filters( 'woocommerce_date_input_html_pattern', '[0-9]{4}-(0[1-9]|1[012])-(0[1-9]|1[0-9]|2[0-9]|3[01])' ) ) . '" />
</p>
<p class="form-row form-row-last">
<label>' . __( 'Sale end date', 'woocommerce' ) . '</label>
<input type="text" class="sale_price_dates_to" name="variable_sale_price_dates_to[' . esc_attr( $loop ) . ']" value="' . esc_attr( $sale_price_dates_to ) . '" placeholder="' . esc_html_x( 'To&hellip;', 'placeholder', 'woocommerce' ) . ' YYYY-MM-DD" maxlength="10" pattern="' . esc_attr( apply_filters( 'woocommerce_date_input_html_pattern', '[0-9]{4}-(0[1-9]|1[012])-(0[1-9]|1[0-9]|2[0-9]|3[01])' ) ) . '" />
</p>
</div>';
/**
* woocommerce_variation_options_pricing action.
*
* @since 2.5.0
*
* @param int $loop
* @param array $variation_data
* @param WP_Post $variation
*/
do_action( 'woocommerce_variation_options_pricing', $loop, $variation_data, $variation );
/**
* woocommerce_variation_options_pricing action.
*
* @since 2.5.0
*
* @param int $loop
* @param array $variation_data
* @param WP_Post $variation
*/
do_action( 'woocommerce_variation_options_pricing', $loop, $variation_data, $variation );
?>
</div>
<?php if ( 'yes' === get_option( 'woocommerce_manage_stock' ) ) : ?>
<div class="show_if_variation_manage_stock" style="display: none;">
<?php
woocommerce_wp_text_input( array(
woocommerce_wp_text_input(
array(
'id' => "variable_stock{$loop}",
'name' => "variable_stock[{$loop}]",
'value' => wc_stock_amount( $variation_object->get_stock_quantity( 'edit' ) ),
@ -164,15 +173,17 @@ if ( ! defined( 'ABSPATH' ) ) {
'description' => __( "Enter a quantity to enable stock management at variation level, or leave blank to use the parent product's options.", 'woocommerce' ),
'type' => 'number',
'custom_attributes' => array(
'step' => 'any',
'step' => 'any',
),
'data_type' => 'stock',
'wrapper_class' => 'form-row form-row-first',
) );
)
);
echo '<input type="hidden" name="variable_original_stock[' . esc_attr( $loop ) . ']" value="' . esc_attr( wc_stock_amount( $variation_object->get_stock_quantity( 'edit' ) ) ) . '" />';
echo '<input type="hidden" name="variable_original_stock[' . esc_attr( $loop ) . ']" value="' . esc_attr( wc_stock_amount( $variation_object->get_stock_quantity( 'edit' ) ) ) . '" />';
woocommerce_wp_select( array(
woocommerce_wp_select(
array(
'id' => "variable_backorders{$loop}",
'name' => "variable_backorders[{$loop}]",
'value' => $variation_object->get_backorders( 'edit' ),
@ -181,25 +192,27 @@ if ( ! defined( 'ABSPATH' ) ) {
'desc_tip' => true,
'description' => __( 'If managing stock, this controls whether or not backorders are allowed. If enabled, stock quantity can go below 0.', 'woocommerce' ),
'wrapper_class' => 'form-row form-row-last',
) );
)
);
/**
* woocommerce_variation_options_inventory action.
*
* @since 2.5.0
*
* @param int $loop
* @param array $variation_data
* @param WP_Post $variation
*/
do_action( 'woocommerce_variation_options_inventory', $loop, $variation_data, $variation );
/**
* woocommerce_variation_options_inventory action.
*
* @since 2.5.0
*
* @param int $loop
* @param array $variation_data
* @param WP_Post $variation
*/
do_action( 'woocommerce_variation_options_inventory', $loop, $variation_data, $variation );
?>
</div>
<?php endif; ?>
<div>
<?php
woocommerce_wp_select( array(
woocommerce_wp_select(
array(
'id' => "variable_stock_status{$loop}",
'name' => "variable_stock_status[{$loop}]",
'value' => $variation_object->get_stock_status( 'edit' ),
@ -208,16 +221,18 @@ if ( ! defined( 'ABSPATH' ) ) {
'desc_tip' => true,
'description' => __( 'Controls whether or not the product is listed as "in stock" or "out of stock" on the frontend.', 'woocommerce' ),
'wrapper_class' => 'form-row form-row-full hide_if_variation_manage_stock',
) );
)
);
if ( wc_product_weight_enabled() ) {
$label = sprintf(
/* translators: %s: weight unit */
__( 'Weight (%s)', 'woocommerce' ),
esc_html( get_option( 'woocommerce_weight_unit' ) )
);
if ( wc_product_weight_enabled() ) {
$label = sprintf(
/* translators: %s: weight unit */
__( 'Weight (%s)', 'woocommerce' ),
esc_html( get_option( 'woocommerce_weight_unit' ) )
);
woocommerce_wp_text_input( array(
woocommerce_wp_text_input(
array(
'id' => "variable_weight{$loop}",
'name' => "variable_weight[{$loop}]",
'value' => wc_format_localized_decimal( $variation_object->get_weight( 'edit' ) ),
@ -228,68 +243,80 @@ if ( ! defined( 'ABSPATH' ) ) {
'type' => 'text',
'data_type' => 'decimal',
'wrapper_class' => 'form-row form-row-first hide_if_variation_virtual',
) );
}
)
);
}
if ( wc_product_dimensions_enabled() ) {
$parent_length = wc_format_localized_decimal( $product_object->get_length() );
$parent_width = wc_format_localized_decimal( $product_object->get_width() );
$parent_height = wc_format_localized_decimal( $product_object->get_height() );
if ( wc_product_dimensions_enabled() ) {
$parent_length = wc_format_localized_decimal( $product_object->get_length() );
$parent_width = wc_format_localized_decimal( $product_object->get_width() );
$parent_height = wc_format_localized_decimal( $product_object->get_height() );
?><p class="form-field form-row dimensions_field hide_if_variation_virtual form-row-last">
<label for="product_length"><?php
printf(
/* translators: %s: dimension unit */
esc_html__( 'Dimensions (L&times;W&times;H) (%s)', 'woocommerce' ),
get_option( 'woocommerce_dimension_unit' )
);
?></label>
<?php echo wc_help_tip( __( 'Length x width x height in decimal form', 'woocommerce' ) ); ?>
<span class="wrap">
<input id="product_length" placeholder="<?php echo $parent_length ? esc_attr( $parent_length ) : esc_attr__( 'Length', 'woocommerce' ); ?>" class="input-text wc_input_decimal" size="6" type="text" name="variable_length[<?php echo esc_attr( $loop ); ?>]" value="<?php echo esc_attr( wc_format_localized_decimal( $variation_object->get_length( 'edit' ) ) ); ?>" />
<input placeholder="<?php echo $parent_width ? esc_attr( $parent_width ) : esc_attr__( 'Width', 'woocommerce' ); ?>" class="input-text wc_input_decimal" size="6" type="text" name="variable_width[<?php echo esc_attr( $loop ); ?>]" value="<?php echo esc_attr( wc_format_localized_decimal( $variation_object->get_width( 'edit' ) ) ); ?>" />
<input placeholder="<?php echo $parent_height ? esc_attr( $parent_height ) : esc_attr__( 'Height', 'woocommerce' ); ?>" class="input-text wc_input_decimal last" size="6" type="text" name="variable_height[<?php echo esc_attr( $loop ); ?>]" value="<?php echo esc_attr( wc_format_localized_decimal( $variation_object->get_height( 'edit' ) ) ); ?>" />
</span>
</p><?php
}
?>
<p class="form-field form-row dimensions_field hide_if_variation_virtual form-row-last">
<label for="product_length">
<?php
printf(
/* translators: %s: dimension unit */
esc_html__( 'Dimensions (L&times;W&times;H) (%s)', 'woocommerce' ),
get_option( 'woocommerce_dimension_unit' )
);
?>
</label>
<?php echo wc_help_tip( __( 'Length x width x height in decimal form', 'woocommerce' ) ); ?>
<span class="wrap">
<input id="product_length" placeholder="<?php echo $parent_length ? esc_attr( $parent_length ) : esc_attr__( 'Length', 'woocommerce' ); ?>" class="input-text wc_input_decimal" size="6" type="text" name="variable_length[<?php echo esc_attr( $loop ); ?>]" value="<?php echo esc_attr( wc_format_localized_decimal( $variation_object->get_length( 'edit' ) ) ); ?>" />
<input placeholder="<?php echo $parent_width ? esc_attr( $parent_width ) : esc_attr__( 'Width', 'woocommerce' ); ?>" class="input-text wc_input_decimal" size="6" type="text" name="variable_width[<?php echo esc_attr( $loop ); ?>]" value="<?php echo esc_attr( wc_format_localized_decimal( $variation_object->get_width( 'edit' ) ) ); ?>" />
<input placeholder="<?php echo $parent_height ? esc_attr( $parent_height ) : esc_attr__( 'Height', 'woocommerce' ); ?>" class="input-text wc_input_decimal last" size="6" type="text" name="variable_height[<?php echo esc_attr( $loop ); ?>]" value="<?php echo esc_attr( wc_format_localized_decimal( $variation_object->get_height( 'edit' ) ) ); ?>" />
</span>
</p>
<?php
}
/**
* woocommerce_variation_options_dimensions action.
*
* @since 2.5.0
*
* @param int $loop
* @param array $variation_data
* @param WP_Post $variation
*/
do_action( 'woocommerce_variation_options_dimensions', $loop, $variation_data, $variation );
/**
* woocommerce_variation_options_dimensions action.
*
* @since 2.5.0
*
* @param int $loop
* @param array $variation_data
* @param WP_Post $variation
*/
do_action( 'woocommerce_variation_options_dimensions', $loop, $variation_data, $variation );
?>
</div>
<div>
<p class="form-row hide_if_variation_virtual form-row-full"><label><?php esc_html_e( 'Shipping class', 'woocommerce' ); ?></label> <?php
wp_dropdown_categories( array(
'taxonomy' => 'product_shipping_class',
'hide_empty' => 0,
'show_option_none' => __( 'Same as parent', 'woocommerce' ),
'name' => 'variable_shipping_class[' . $loop . ']',
'id' => '',
'selected' => $variation_object->get_shipping_class_id( 'edit' ),
) );
?></p>
<p class="form-row hide_if_variation_virtual form-row-full">
<label><?php esc_html_e( 'Shipping class', 'woocommerce' ); ?></label>
<?php
wp_dropdown_categories(
array(
'taxonomy' => 'product_shipping_class',
'hide_empty' => 0,
'show_option_none' => __( 'Same as parent', 'woocommerce' ),
'name' => 'variable_shipping_class[' . $loop . ']',
'id' => '',
'selected' => $variation_object->get_shipping_class_id( 'edit' ),
)
);
?>
</p>
<?php
if ( wc_tax_enabled() ) {
woocommerce_wp_select( array(
'id' => "variable_tax_class{$loop}",
'name' => "variable_tax_class[{$loop}]",
'value' => $variation_object->get_tax_class( 'edit' ),
'label' => __( 'Tax class', 'woocommerce' ),
'options' => array_merge( array( 'parent' => __( 'Same as parent', 'woocommerce' ) ), wc_get_product_tax_class_options() ),
'desc_tip' => 'true',
'description' => __( 'Choose a tax class for this product. Tax classes are used to apply different tax rates specific to certain types of product.', 'woocommerce' ),
'wrapper_class' => 'form-row form-row-full',
) );
woocommerce_wp_select(
array(
'id' => "variable_tax_class{$loop}",
'name' => "variable_tax_class[{$loop}]",
'value' => $variation_object->get_tax_class( 'edit' ),
'label' => __( 'Tax class', 'woocommerce' ),
'options' => array_merge( array( 'parent' => __( 'Same as parent', 'woocommerce' ) ), wc_get_product_tax_class_options() ),
'desc_tip' => 'true',
'description' => __( 'Choose a tax class for this product. Tax classes are used to apply different tax rates specific to certain types of product.', 'woocommerce' ),
'wrapper_class' => 'form-row form-row-full',
)
);
/**
* woocommerce_variation_options_tax action.
@ -306,7 +333,8 @@ if ( ! defined( 'ABSPATH' ) ) {
</div>
<div>
<?php
woocommerce_wp_textarea_input( array(
woocommerce_wp_textarea_input(
array(
'id' => "variable_description{$loop}",
'name' => "variable_description[{$loop}]",
'value' => $variation_object->get_description( 'edit' ),
@ -314,7 +342,8 @@ if ( ! defined( 'ABSPATH' ) ) {
'desc_tip' => true,
'description' => __( 'Enter an optional description for this variation.', 'woocommerce' ),
'wrapper_class' => 'form-row form-row-full',
) );
)
);
?>
</div>
<div class="show_if_variation_downloadable" style="display: none;">
@ -332,7 +361,7 @@ if ( ! defined( 'ABSPATH' ) ) {
<?php
if ( $downloads = $variation_object->get_downloads( 'edit' ) ) {
foreach ( $downloads as $key => $file ) {
include( 'html-product-variation-download.php' );
include 'html-product-variation-download.php';
}
}
?>
@ -340,16 +369,18 @@ if ( ! defined( 'ABSPATH' ) ) {
<tfoot>
<div>
<th colspan="4">
<a href="#" class="button insert" data-row="<?php
$key = '';
$file = array(
'file' => '',
'name' => '',
);
ob_start();
include( 'html-product-variation-download.php' );
echo esc_attr( ob_get_clean() );
?>"><?php esc_html_e( 'Add file', 'woocommerce' ); ?></a>
<a href="#" class="button insert" data-row="
<?php
$key = '';
$file = array(
'file' => '',
'name' => '',
);
ob_start();
require 'html-product-variation-download.php';
echo esc_attr( ob_get_clean() );
?>
"><?php esc_html_e( 'Add file', 'woocommerce' ); ?></a>
</th>
</div>
</tfoot>
@ -358,7 +389,8 @@ if ( ! defined( 'ABSPATH' ) ) {
</div>
<div class="show_if_variation_downloadable" style="display: none;">
<?php
woocommerce_wp_text_input( array(
woocommerce_wp_text_input(
array(
'id' => "variable_download_limit{$loop}",
'name' => "variable_download_limit[{$loop}]",
'value' => $variation_object->get_download_limit( 'edit' ) < 0 ? '' : $variation_object->get_download_limit( 'edit' ),
@ -368,13 +400,15 @@ if ( ! defined( 'ABSPATH' ) ) {
'type' => 'number',
'desc_tip' => true,
'custom_attributes' => array(
'step' => '1',
'min' => '0',
'step' => '1',
'min' => '0',
),
'wrapper_class' => 'form-row form-row-first',
) );
)
);
woocommerce_wp_text_input( array(
woocommerce_wp_text_input(
array(
'id' => "variable_download_expiry{$loop}",
'name' => "variable_download_expiry[{$loop}]",
'value' => $variation_object->get_download_expiry( 'edit' ) < 0 ? '' : $variation_object->get_download_expiry( 'edit' ),
@ -384,22 +418,23 @@ if ( ! defined( 'ABSPATH' ) ) {
'type' => 'number',
'desc_tip' => true,
'custom_attributes' => array(
'step' => '1',
'min' => '0',
'step' => '1',
'min' => '0',
),
'wrapper_class' => 'form-row form-row-last',
) );
)
);
/**
* woocommerce_variation_options_download action.
*
* @since 2.5.0
*
* @param int $loop
* @param array $variation_data
* @param WP_Post $variation
*/
do_action( 'woocommerce_variation_options_download', $loop, $variation_data, $variation );
/**
* woocommerce_variation_options_download action.
*
* @since 2.5.0
*
* @param int $loop
* @param array $variation_data
* @param WP_Post $variation
*/
do_action( 'woocommerce_variation_options_download', $loop, $variation_data, $variation );
?>
</div>
<?php do_action( 'woocommerce_product_after_variable_attributes', $loop, $variation_data, $variation ); ?>

View File

@ -18,30 +18,35 @@ class WC_Plugin_Updates {
/**
* This is the header used by extensions to show requirements.
*
* @var string
*/
const VERSION_REQUIRED_HEADER = 'WC requires at least';
/**
* This is the header used by extensions to show testing.
*
* @var string
*/
const VERSION_TESTED_HEADER = 'WC tested up to';
/**
* The version for the update to WooCommerce.
*
* @var string
*/
protected $new_version = '';
/**
* Array of plugins lacking testing with the major version.
*
* @var array
*/
protected $major_untested_plugins = array();
/**
* Array of plugins lacking testing with the minor version.
*
* @var array
*/
protected $minor_untested_plugins = array();
@ -116,7 +121,7 @@ class WC_Plugin_Updates {
$message = sprintf( __( "<strong>Heads up!</strong> The versions of the following plugins you're running haven't been tested with the latest version of WooCommerce (%s).", 'woocommerce' ), $new_version );
ob_start();
include( 'views/html-notice-untested-extensions-inline.php' );
include 'views/html-notice-untested-extensions-inline.php';
return ob_get_clean();
}
@ -139,7 +144,7 @@ class WC_Plugin_Updates {
$message = sprintf( __( "<strong>Heads up!</strong> The versions of the following plugins you're running haven't been tested with WooCommerce %s. Please update them or confirm compatibility before updating WooCommerce, or you may experience issues:", 'woocommerce' ), $new_version );
ob_start();
include( 'views/html-notice-untested-extensions-inline.php' );
include 'views/html-notice-untested-extensions-inline.php';
return ob_get_clean();
}
@ -154,7 +159,7 @@ class WC_Plugin_Updates {
$plugins = $this->major_untested_plugins;
ob_start();
include( 'views/html-notice-untested-extensions-modal.php' );
include 'views/html-notice-untested-extensions-modal.php';
return ob_get_clean();
}
@ -214,7 +219,7 @@ class WC_Plugin_Updates {
}
} else {
$plugin[ self::VERSION_TESTED_HEADER ] = __( 'unknown', 'woocommerce' );
$untested[ $file ] = $plugin;
$untested[ $file ] = $plugin;
}
}

View File

@ -13,13 +13,14 @@ if ( ! defined( 'ABSPATH' ) ) {
}
if ( ! class_exists( 'WC_Plugin_Updates' ) ) {
include_once( dirname( __FILE__ ) . '/class-wc-plugin-updates.php' );
include_once dirname( __FILE__ ) . '/class-wc-plugin-updates.php';
}
class WC_Plugins_Screen_Updates extends WC_Plugin_Updates {
/**
* The upgrade notice shown inline.
*
* @var string
*/
protected $upgrade_notice = '';

View File

@ -12,7 +12,7 @@ if ( ! defined( 'ABSPATH' ) ) {
}
if ( ! class_exists( 'WC_Plugin_Updates' ) ) {
include_once( dirname( __FILE__ ) . '/class-wc-plugin-updates.php' );
include_once dirname( __FILE__ ) . '/class-wc-plugin-updates.php';
}
class WC_Updates_Screen_Updates extends WC_Plugin_Updates {

View File

@ -6,8 +6,8 @@ if ( ! defined( 'ABSPATH' ) ) {
exit;
}
?>
<div class="wc_plugin_upgrade_notice extensions_warning <?php echo esc_attr( $upgrade_type ) ?>">
<p><?php echo wp_kses_post( $message ) ?></p>
<div class="wc_plugin_upgrade_notice extensions_warning <?php echo esc_attr( $upgrade_type ); ?>">
<p><?php echo wp_kses_post( $message ); ?></p>
<table class="plugin-details-table" cellspacing="0">
<thead>

View File

@ -10,13 +10,15 @@ if ( ! defined( 'ABSPATH' ) ) {
<div class="wc_untested_extensions_modal--content">
<h1><?php _e( "This is a major update, are you sure you're ready?", 'woocommerce' ); ?></h1>
<div class="wc_plugin_upgrade_notice extensions_warning">
<p><?php
/* translators: %s: version number */
printf(
__( 'The following active plugin(s) have not declared compatibility with WooCommerce %s yet and should be updated and examined further before you proceed:', 'woocommerce' ),
esc_html( $new_version )
);
?></p>
<p>
<?php
/* translators: %s: version number */
printf(
__( 'The following active plugin(s) have not declared compatibility with WooCommerce %s yet and should be updated and examined further before you proceed:', 'woocommerce' ),
esc_html( $new_version )
);
?>
</p>
<div class="plugin-details-table-container">
<table class="plugin-details-table" cellspacing="0">
@ -39,7 +41,7 @@ if ( ! defined( 'ABSPATH' ) ) {
<p><?php esc_html_e( 'As this is a major update, we strongly recommend creating a backup of your site before updating.', 'woocommerce' ); ?> <a href="https://woocommerce.com/2017/05/create-use-backups-woocommerce/" target="_blank"><?php _e( 'Learn more', 'woocommerce' ); ?></a></p>
<?php if ( current_user_can( 'update_plugins' ) ): ?>
<?php if ( current_user_can( 'update_plugins' ) ) : ?>
<div class="actions">
<a href="#" class="button button-secondary cancel"><?php esc_html_e( 'Cancel', 'woocommerce' ); ?></a>
<a class="button button-primary accept" href="#"><?php esc_html_e( 'Update now', 'woocommerce' ); ?></a>

View File

@ -90,8 +90,8 @@ class WC_Admin_Report {
'order_status' => array( 'completed', 'processing', 'on-hold' ),
'parent_order_status' => false,
);
$args = apply_filters( 'woocommerce_reports_get_order_report_data_args', $args );
$args = wp_parse_args( $args, $default_args );
$args = apply_filters( 'woocommerce_reports_get_order_report_data_args', $args );
$args = wp_parse_args( $args, $default_args );
extract( $args );
@ -113,22 +113,22 @@ class WC_Admin_Report {
}
switch ( $value['type'] ) {
case 'meta' :
case 'meta':
$get_key = "meta_{$key}.meta_value";
break;
case 'parent_meta' :
case 'parent_meta':
$get_key = "parent_meta_{$key}.meta_value";
break;
case 'post_data' :
case 'post_data':
$get_key = "posts.{$key}";
break;
case 'order_item_meta' :
case 'order_item_meta':
$get_key = "order_item_meta_{$key}.meta_value";
break;
case 'order_item' :
case 'order_item':
$get_key = "order_items.{$key}";
break;
default :
default:
continue;
}
@ -141,7 +141,7 @@ class WC_Admin_Report {
$select[] = "{$get} as {$value['name']}";
}
$query['select'] = "SELECT " . implode( ',', $select );
$query['select'] = 'SELECT ' . implode( ',', $select );
$query['from'] = "FROM {$wpdb->posts} AS posts";
// Joins
@ -153,25 +153,25 @@ class WC_Admin_Report {
$key = sanitize_key( $raw_key );
switch ( $type ) {
case 'meta' :
case 'meta':
$joins[ "meta_{$key}" ] = "{$join_type} JOIN {$wpdb->postmeta} AS meta_{$key} ON ( posts.ID = meta_{$key}.post_id AND meta_{$key}.meta_key = '{$raw_key}' )";
break;
case 'parent_meta' :
case 'parent_meta':
$joins[ "parent_meta_{$key}" ] = "{$join_type} JOIN {$wpdb->postmeta} AS parent_meta_{$key} ON (posts.post_parent = parent_meta_{$key}.post_id) AND (parent_meta_{$key}.meta_key = '{$raw_key}')";
break;
case 'order_item_meta' :
$joins["order_items"] = "{$join_type} JOIN {$wpdb->prefix}woocommerce_order_items AS order_items ON (posts.ID = order_items.order_id)";
case 'order_item_meta':
$joins['order_items'] = "{$join_type} JOIN {$wpdb->prefix}woocommerce_order_items AS order_items ON (posts.ID = order_items.order_id)";
if ( ! empty( $value['order_item_type'] ) ) {
$joins["order_items"] .= " AND (order_items.order_item_type = '{$value['order_item_type']}')";
$joins['order_items'] .= " AND (order_items.order_item_type = '{$value['order_item_type']}')";
}
$joins[ "order_item_meta_{$key}" ] = "{$join_type} JOIN {$wpdb->prefix}woocommerce_order_itemmeta AS order_item_meta_{$key} ON " .
$joins[ "order_item_meta_{$key}" ] = "{$join_type} JOIN {$wpdb->prefix}woocommerce_order_itemmeta AS order_item_meta_{$key} ON " .
"(order_items.order_item_id = order_item_meta_{$key}.order_item_id) " .
" AND (order_item_meta_{$key}.meta_key = '{$raw_key}')";
break;
case 'order_item' :
$joins["order_items"] = "{$join_type} JOIN {$wpdb->prefix}woocommerce_order_items AS order_items ON posts.ID = order_items.order_id";
case 'order_item':
$joins['order_items'] = "{$join_type} JOIN {$wpdb->prefix}woocommerce_order_items AS order_items ON posts.ID = order_items.order_id";
break;
}
}
@ -187,7 +187,7 @@ class WC_Admin_Report {
if ( 'order_item_meta' === $type ) {
$joins["order_items"] = "{$join_type} JOIN {$wpdb->prefix}woocommerce_order_items AS order_items ON posts.ID = order_items.order_id";
$joins['order_items'] = "{$join_type} JOIN {$wpdb->prefix}woocommerce_order_items AS order_items ON posts.ID = order_items.order_id";
$joins[ "order_item_meta_{$key}" ] = "{$join_type} JOIN {$wpdb->prefix}woocommerce_order_itemmeta AS order_item_meta_{$key} ON order_items.order_item_id = order_item_meta_{$key}.order_item_id";
} else {
@ -198,12 +198,12 @@ class WC_Admin_Report {
}
if ( ! empty( $parent_order_status ) ) {
$joins["parent"] = "LEFT JOIN {$wpdb->posts} AS parent ON posts.post_parent = parent.ID";
$joins['parent'] = "LEFT JOIN {$wpdb->posts} AS parent ON posts.post_parent = parent.ID";
}
$query['join'] = implode( ' ', $joins );
$query['where'] = "
$query['where'] = "
WHERE posts.post_type IN ( '" . implode( "','", $order_types ) . "' )
";
@ -232,7 +232,7 @@ class WC_Admin_Report {
$relation = isset( $where_meta['relation'] ) ? $where_meta['relation'] : 'AND';
$query['where'] .= " AND (";
$query['where'] .= ' AND (';
foreach ( $where_meta as $index => $value ) {
@ -282,7 +282,7 @@ class WC_Admin_Report {
}
}
$query['where'] .= ")";
$query['where'] .= ')';
}
if ( ! empty( $where ) ) {
@ -346,10 +346,10 @@ class WC_Admin_Report {
/**
* Put data with post_date's into an array of times.
*
* @param array $data array of your data
* @param array $data array of your data
* @param string $date_key key for the 'date' field. e.g. 'post_date'
* @param string $data_key key for the data you are charting
* @param int $interval
* @param int $interval
* @param string $start_date
* @param string $group_by
* @return array
@ -388,13 +388,13 @@ class WC_Admin_Report {
foreach ( $data as $d ) {
switch ( $group_by ) {
case 'day' :
case 'day':
$time = strtotime( date( 'Ymd', strtotime( $d->$date_key ) ) ) . '000';
break;
case 'month' :
default :
break;
case 'month':
default:
$time = strtotime( date( 'Ym', strtotime( $d->$date_key ) ) . '01' ) . '000';
break;
break;
}
if ( ! isset( $prepared_data[ $time ] ) ) {
@ -414,8 +414,8 @@ class WC_Admin_Report {
/**
* Prepares a sparkline to show sales in the last X days.
*
* @param int $id ID of the product to show. Blank to get all orders.
* @param int $days Days of stats to get.
* @param int $id ID of the product to show. Blank to get all orders.
* @param int $days Days of stats to get.
* @param string $type Type of sparkline to get. Ignored if ID is not set.
* @return string
*/
@ -424,68 +424,72 @@ class WC_Admin_Report {
if ( $id ) {
$meta_key = ( 'sales' === $type ) ? '_line_total' : '_qty';
$data = $this->get_order_report_data( array(
'data' => array(
'_product_id' => array(
'type' => 'order_item_meta',
'order_item_type' => 'line_item',
'function' => '',
'name' => 'product_id',
$data = $this->get_order_report_data(
array(
'data' => array(
'_product_id' => array(
'type' => 'order_item_meta',
'order_item_type' => 'line_item',
'function' => '',
'name' => 'product_id',
),
$meta_key => array(
'type' => 'order_item_meta',
'order_item_type' => 'line_item',
'function' => 'SUM',
'name' => 'sparkline_value',
),
'post_date' => array(
'type' => 'post_data',
'function' => '',
'name' => 'post_date',
),
),
$meta_key => array(
'type' => 'order_item_meta',
'order_item_type' => 'line_item',
'function' => 'SUM',
'name' => 'sparkline_value',
'where' => array(
array(
'key' => 'post_date',
'value' => date( 'Y-m-d', strtotime( 'midnight -' . ( $days - 1 ) . ' days', current_time( 'timestamp' ) ) ),
'operator' => '>',
),
array(
'key' => 'order_item_meta__product_id.meta_value',
'value' => $id,
'operator' => '=',
),
),
'post_date' => array(
'type' => 'post_data',
'function' => '',
'name' => 'post_date',
),
),
'where' => array(
array(
'key' => 'post_date',
'value' => date( 'Y-m-d', strtotime( 'midnight -' . ( $days - 1 ) . ' days', current_time( 'timestamp' ) ) ),
'operator' => '>',
),
array(
'key' => 'order_item_meta__product_id.meta_value',
'value' => $id,
'operator' => '=',
),
),
'group_by' => 'YEAR(posts.post_date), MONTH(posts.post_date), DAY(posts.post_date)',
'query_type' => 'get_results',
'filter_range' => false,
) );
'group_by' => 'YEAR(posts.post_date), MONTH(posts.post_date), DAY(posts.post_date)',
'query_type' => 'get_results',
'filter_range' => false,
)
);
} else {
$data = $this->get_order_report_data( array(
'data' => array(
'_order_total' => array(
'type' => 'meta',
'function' => 'SUM',
'name' => 'sparkline_value',
$data = $this->get_order_report_data(
array(
'data' => array(
'_order_total' => array(
'type' => 'meta',
'function' => 'SUM',
'name' => 'sparkline_value',
),
'post_date' => array(
'type' => 'post_data',
'function' => '',
'name' => 'post_date',
),
),
'post_date' => array(
'type' => 'post_data',
'function' => '',
'name' => 'post_date',
'where' => array(
array(
'key' => 'post_date',
'value' => date( 'Y-m-d', strtotime( 'midnight -' . ( $days - 1 ) . ' days', current_time( 'timestamp' ) ) ),
'operator' => '>',
),
),
),
'where' => array(
array(
'key' => 'post_date',
'value' => date( 'Y-m-d', strtotime( 'midnight -' . ( $days - 1 ) . ' days', current_time( 'timestamp' ) ) ),
'operator' => '>',
),
),
'group_by' => 'YEAR(posts.post_date), MONTH(posts.post_date), DAY(posts.post_date)',
'query_type' => 'get_results',
'filter_range' => false,
) );
'group_by' => 'YEAR(posts.post_date), MONTH(posts.post_date), DAY(posts.post_date)',
'query_type' => 'get_results',
'filter_range' => false,
)
);
}
$total = 0;
@ -515,8 +519,7 @@ class WC_Admin_Report {
switch ( $current_range ) {
case 'custom' :
case 'custom':
$this->start_date = max( strtotime( '-20 years' ), strtotime( sanitize_text_field( $_GET['start_date'] ) ) );
if ( empty( $_GET['end_date'] ) ) {
@ -528,7 +531,7 @@ class WC_Admin_Report {
$interval = 0;
$min_date = $this->start_date;
while ( ( $min_date = strtotime( "+1 MONTH", $min_date ) ) <= $this->end_date ) {
while ( ( $min_date = strtotime( '+1 MONTH', $min_date ) ) <= $this->end_date ) {
$interval ++;
}
@ -538,54 +541,54 @@ class WC_Admin_Report {
} else {
$this->chart_groupby = 'day';
}
break;
break;
case 'year' :
case 'year':
$this->start_date = strtotime( date( 'Y-01-01', current_time( 'timestamp' ) ) );
$this->end_date = strtotime( 'midnight', current_time( 'timestamp' ) );
$this->chart_groupby = 'month';
break;
break;
case 'last_month' :
case 'last_month':
$first_day_current_month = strtotime( date( 'Y-m-01', current_time( 'timestamp' ) ) );
$this->start_date = strtotime( date( 'Y-m-01', strtotime( '-1 DAY', $first_day_current_month ) ) );
$this->end_date = strtotime( date( 'Y-m-t', strtotime( '-1 DAY', $first_day_current_month ) ) );
$this->chart_groupby = 'day';
break;
break;
case 'month' :
case 'month':
$this->start_date = strtotime( date( 'Y-m-01', current_time( 'timestamp' ) ) );
$this->end_date = strtotime( 'midnight', current_time( 'timestamp' ) );
$this->chart_groupby = 'day';
break;
break;
case '7day' :
case '7day':
$this->start_date = strtotime( '-6 days', strtotime( 'midnight', current_time( 'timestamp' ) ) );
$this->end_date = strtotime( 'midnight', current_time( 'timestamp' ) );
$this->chart_groupby = 'day';
break;
break;
}
// Group by
switch ( $this->chart_groupby ) {
case 'day' :
case 'day':
$this->group_by_query = 'YEAR(posts.post_date), MONTH(posts.post_date), DAY(posts.post_date)';
$this->chart_interval = absint( ceil( max( 0, ( $this->end_date - $this->start_date ) / ( 60 * 60 * 24 ) ) ) );
$this->barwidth = 60 * 60 * 24 * 1000;
break;
break;
case 'month' :
case 'month':
$this->group_by_query = 'YEAR(posts.post_date), MONTH(posts.post_date)';
$this->chart_interval = 0;
$min_date = strtotime( date( 'Y-m-01', $this->start_date ) );
while ( ( $min_date = strtotime( "+1 MONTH", $min_date ) ) <= $this->end_date ) {
while ( ( $min_date = strtotime( '+1 MONTH', $min_date ) ) <= $this->end_date ) {
$this->chart_interval ++;
}
$this->barwidth = 60 * 60 * 24 * 7 * 4 * 1000;
break;
break;
}
}

View File

@ -53,7 +53,7 @@ class WC_Report_Coupon_Usage extends WC_Admin_Report {
$legend = array();
$total_discount_query = array(
'data' => array(
'data' => array(
'discount_amount' => array(
'type' => 'order_item_meta',
'order_item_type' => 'coupon',
@ -61,7 +61,7 @@ class WC_Report_Coupon_Usage extends WC_Admin_Report {
'name' => 'discount_amount',
),
),
'where' => array(
'where' => array(
array(
'key' => 'order_item_type',
'value' => 'coupon',
@ -74,7 +74,7 @@ class WC_Report_Coupon_Usage extends WC_Admin_Report {
);
$total_coupons_query = array(
'data' => array(
'data' => array(
'order_item_id' => array(
'type' => 'order_item',
'order_item_type' => 'coupon',
@ -82,7 +82,7 @@ class WC_Report_Coupon_Usage extends WC_Admin_Report {
'name' => 'order_coupon_count',
),
),
'where' => array(
'where' => array(
array(
'key' => 'order_item_type',
'value' => 'coupon',
@ -111,15 +111,15 @@ class WC_Report_Coupon_Usage extends WC_Admin_Report {
$legend[] = array(
/* translators: %s: discount amount */
'title' => sprintf( __( '%s discounts in total', 'woocommerce' ), '<strong>' . wc_price( $total_discount ) . '</strong>' ),
'color' => $this->chart_colours['discount_amount'],
'title' => sprintf( __( '%s discounts in total', 'woocommerce' ), '<strong>' . wc_price( $total_discount ) . '</strong>' ),
'color' => $this->chart_colours['discount_amount'],
'highlight_series' => 1,
);
$legend[] = array(
/* translators: %s: coupons amount */
'title' => sprintf( __( '%s coupons used in total', 'woocommerce' ), '<strong>' . $total_coupons . '</strong>' ),
'color' => $this->chart_colours['coupon_count'],
'title' => sprintf( __( '%s coupons used in total', 'woocommerce' ), '<strong>' . $total_coupons . '</strong>' ),
'color' => $this->chart_colours['coupon_count'],
'highlight_series' => 0,
);
@ -132,10 +132,10 @@ class WC_Report_Coupon_Usage extends WC_Admin_Report {
public function output_report() {
$ranges = array(
'year' => __( 'Year', 'woocommerce' ),
'last_month' => __( 'Last month', 'woocommerce' ),
'month' => __( 'This month', 'woocommerce' ),
'7day' => __( 'Last 7 days', 'woocommerce' ),
'year' => __( 'Year', 'woocommerce' ),
'last_month' => __( 'Last month', 'woocommerce' ),
'month' => __( 'This month', 'woocommerce' ),
'7day' => __( 'Last 7 days', 'woocommerce' ),
);
$this->chart_colours = array(
@ -152,7 +152,7 @@ class WC_Report_Coupon_Usage extends WC_Admin_Report {
$this->check_current_range_nonce( $current_range );
$this->calculate_current_range( $current_range );
include( WC()->plugin_path() . '/includes/admin/views/html-report-by-date.php' );
include WC()->plugin_path() . '/includes/admin/views/html-report-by-date.php';
}
/**
@ -181,26 +181,28 @@ class WC_Report_Coupon_Usage extends WC_Admin_Report {
<form method="GET">
<div>
<?php
$used_coupons = $this->get_order_report_data( array(
'data' => array(
'order_item_name' => array(
'type' => 'order_item',
'order_item_type' => 'coupon',
'function' => '',
'distinct' => true,
'name' => 'order_item_name',
$used_coupons = $this->get_order_report_data(
array(
'data' => array(
'order_item_name' => array(
'type' => 'order_item',
'order_item_type' => 'coupon',
'function' => '',
'distinct' => true,
'name' => 'order_item_name',
),
),
),
'where' => array(
array(
'key' => 'order_item_type',
'value' => 'coupon',
'operator' => '=',
'where' => array(
array(
'key' => 'order_item_type',
'value' => 'coupon',
'operator' => '=',
),
),
),
'query_type' => 'get_col',
'filter_range' => false,
) );
'query_type' => 'get_col',
'filter_range' => false,
)
);
if ( ! empty( $used_coupons ) && is_array( $used_coupons ) ) :
?>
@ -231,35 +233,37 @@ class WC_Report_Coupon_Usage extends WC_Admin_Report {
<div class="section">
<table cellspacing="0">
<?php
$most_popular = $this->get_order_report_data( array(
'data' => array(
'order_item_name' => array(
'type' => 'order_item',
'order_item_type' => 'coupon',
'function' => '',
'name' => 'coupon_code',
$most_popular = $this->get_order_report_data(
array(
'data' => array(
'order_item_name' => array(
'type' => 'order_item',
'order_item_type' => 'coupon',
'function' => '',
'name' => 'coupon_code',
),
'order_item_id' => array(
'type' => 'order_item',
'order_item_type' => 'coupon',
'function' => 'COUNT',
'name' => 'coupon_count',
),
),
'order_item_id' => array(
'type' => 'order_item',
'order_item_type' => 'coupon',
'function' => 'COUNT',
'name' => 'coupon_count',
'where' => array(
array(
'type' => 'order_item',
'key' => 'order_item_type',
'value' => 'coupon',
'operator' => '=',
),
),
),
'where' => array(
array(
'type' => 'order_item',
'key' => 'order_item_type',
'value' => 'coupon',
'operator' => '=',
),
),
'order_by' => 'coupon_count DESC',
'group_by' => 'order_item_name',
'limit' => 12,
'query_type' => 'get_results',
'filter_range' => true,
) );
'order_by' => 'coupon_count DESC',
'group_by' => 'order_item_name',
'limit' => 12,
'query_type' => 'get_results',
'filter_range' => true,
)
);
if ( ! empty( $most_popular ) && is_array( $most_popular ) ) {
foreach ( $most_popular as $coupon ) {
@ -278,35 +282,37 @@ class WC_Report_Coupon_Usage extends WC_Admin_Report {
<div class="section">
<table cellspacing="0">
<?php
$most_discount = $this->get_order_report_data( array(
'data' => array(
'order_item_name' => array(
'type' => 'order_item',
'order_item_type' => 'coupon',
'function' => '',
'name' => 'coupon_code',
$most_discount = $this->get_order_report_data(
array(
'data' => array(
'order_item_name' => array(
'type' => 'order_item',
'order_item_type' => 'coupon',
'function' => '',
'name' => 'coupon_code',
),
'discount_amount' => array(
'type' => 'order_item_meta',
'order_item_type' => 'coupon',
'function' => 'SUM',
'name' => 'discount_amount',
),
),
'discount_amount' => array(
'type' => 'order_item_meta',
'order_item_type' => 'coupon',
'function' => 'SUM',
'name' => 'discount_amount',
'where' => array(
array(
'type' => 'order_item',
'key' => 'order_item_type',
'value' => 'coupon',
'operator' => '=',
),
),
),
'where' => array(
array(
'type' => 'order_item',
'key' => 'order_item_type',
'value' => 'coupon',
'operator' => '=',
),
),
'order_by' => 'discount_amount DESC',
'group_by' => 'order_item_name',
'limit' => 12,
'query_type' => 'get_results',
'filter_range' => true,
) );
'order_by' => 'discount_amount DESC',
'group_by' => 'order_item_name',
'limit' => 12,
'query_type' => 'get_results',
'filter_range' => true,
)
);
if ( ! empty( $most_discount ) && is_array( $most_discount ) ) {
foreach ( $most_discount as $coupon ) {
@ -374,20 +380,20 @@ class WC_Report_Coupon_Usage extends WC_Admin_Report {
// Get orders and dates in range - we want the SUM of order totals, COUNT of order items, COUNT of orders, and the date.
$order_coupon_counts_query = array(
'data' => array(
'data' => array(
'order_item_name' => array(
'type' => 'order_item',
'order_item_type' => 'coupon',
'function' => 'COUNT',
'name' => 'order_coupon_count',
),
'post_date' => array(
'post_date' => array(
'type' => 'post_data',
'function' => '',
'name' => 'post_date',
),
),
'where' => array(
'where' => array(
array(
'key' => 'order_item_type',
'value' => 'coupon',
@ -402,20 +408,20 @@ class WC_Report_Coupon_Usage extends WC_Admin_Report {
);
$order_discount_amounts_query = array(
'data' => array(
'data' => array(
'discount_amount' => array(
'type' => 'order_item_meta',
'order_item_type' => 'coupon',
'function' => 'SUM',
'name' => 'discount_amount',
),
'post_date' => array(
'post_date' => array(
'type' => 'post_data',
'function' => '',
'name' => 'post_date',
),
),
'where' => array(
'where' => array(
array(
'key' => 'order_item_type',
'value' => 'coupon',
@ -445,14 +451,16 @@ class WC_Report_Coupon_Usage extends WC_Admin_Report {
$order_discount_amounts = $this->get_order_report_data( $order_discount_amounts_query );
// Prepare data for report.
$order_coupon_counts = $this->prepare_chart_data( $order_coupon_counts, 'post_date', 'order_coupon_count' , $this->chart_interval, $this->start_date, $this->chart_groupby );
$order_coupon_counts = $this->prepare_chart_data( $order_coupon_counts, 'post_date', 'order_coupon_count', $this->chart_interval, $this->start_date, $this->chart_groupby );
$order_discount_amounts = $this->prepare_chart_data( $order_discount_amounts, 'post_date', 'discount_amount', $this->chart_interval, $this->start_date, $this->chart_groupby );
// Encode in json format.
$chart_data = json_encode( array(
'order_coupon_counts' => array_values( $order_coupon_counts ),
'order_discount_amounts' => array_values( $order_discount_amounts ),
) );
$chart_data = json_encode(
array(
'order_coupon_counts' => array_values( $order_coupon_counts ),
'order_discount_amounts' => array_values( $order_discount_amounts ),
)
);
?>
<div class="chart-container">
<div class="chart-placeholder main"></div>
@ -466,7 +474,7 @@ class WC_Report_Coupon_Usage extends WC_Admin_Report {
var drawGraph = function( highlight ) {
var series = [
{
label: "<?php echo esc_js( __( 'Number of coupons used', 'woocommerce' ) ) ?>",
label: "<?php echo esc_js( __( 'Number of coupons used', 'woocommerce' ) ); ?>",
data: order_data.order_coupon_counts,
color: '<?php echo esc_js( $this->chart_colours['coupon_count'] ); ?>',
bars: { fillColor: '<?php echo esc_js( $this->chart_colours['coupon_count'] ); ?>', fill: true, show: true, lineWidth: 0, barWidth: <?php echo esc_js( $this->barwidth ); ?> * 0.5, align: 'center' },
@ -474,7 +482,7 @@ class WC_Report_Coupon_Usage extends WC_Admin_Report {
hoverable: false
},
{
label: "<?php echo esc_js( __( 'Discount amount', 'woocommerce' ) ) ?>",
label: "<?php echo esc_js( __( 'Discount amount', 'woocommerce' ) ); ?>",
data: order_data.order_discount_amounts,
yaxis: 2,
color: '<?php echo esc_js( $this->chart_colours['discount_amount'] ); ?>',
@ -517,7 +525,7 @@ class WC_Report_Coupon_Usage extends WC_Admin_Report {
tickColor: 'transparent',
mode: "time",
timeformat: "<?php echo ( 'day' === $this->chart_groupby ) ? '%d %b' : '%b'; ?>",
monthNames: <?php echo json_encode( array_values( $wp_locale->month_abbrev ) ) ?>,
monthNames: <?php echo json_encode( array_values( $wp_locale->month_abbrev ) ); ?>,
tickLength: 1,
minTickSize: [1, "<?php echo esc_js( $this->chart_groupby ); ?>"],
font: {

View File

@ -5,7 +5,7 @@ if ( ! defined( 'ABSPATH' ) ) {
}
if ( ! class_exists( 'WP_List_Table' ) ) {
require_once( ABSPATH . 'wp-admin/includes/class-wp-list-table.php' );
require_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php';
}
/**
@ -23,11 +23,13 @@ class WC_Report_Customer_List extends WP_List_Table {
*/
public function __construct() {
parent::__construct( array(
'singular' => 'customer',
'plural' => 'customers',
'ajax' => false,
) );
parent::__construct(
array(
'singular' => 'customer',
'plural' => 'customers',
'ajax' => false,
)
);
}
/**
@ -74,24 +76,23 @@ class WC_Report_Customer_List extends WP_List_Table {
* Get column value.
*
* @param WP_User $user
* @param string $column_name
* @param string $column_name
* @return string
*/
public function column_default( $user, $column_name ) {
switch ( $column_name ) {
case 'customer_name' :
case 'customer_name':
if ( $user->last_name && $user->first_name ) {
return $user->last_name . ', ' . $user->first_name;
} else {
return '-';
}
case 'username' :
case 'username':
return $user->user_login;
case 'location' :
case 'location':
$state_code = get_user_meta( $user->ID, 'billing_state', true );
$country_code = get_user_meta( $user->ID, 'billing_country', true );
@ -112,22 +113,23 @@ class WC_Report_Customer_List extends WP_List_Table {
return '-';
}
case 'email' :
case 'email':
return '<a href="mailto:' . $user->user_email . '">' . $user->user_email . '</a>';
case 'spent' :
case 'spent':
return wc_price( wc_get_customer_total_spent( $user->ID ) );
case 'orders' :
case 'orders':
return wc_get_customer_order_count( $user->ID );
case 'last_order' :
$orders = wc_get_orders( array(
'limit' => 1,
'status' => array_map( 'wc_get_order_status_name', wc_get_is_paid_statuses() ),
'customer' => $user->ID,
) );
case 'last_order':
$orders = wc_get_orders(
array(
'limit' => 1,
'status' => array_map( 'wc_get_order_status_name', wc_get_is_paid_statuses() ),
'customer' => $user->ID,
)
);
if ( ! empty( $orders ) ) {
$order = $orders[0];
@ -136,57 +138,60 @@ class WC_Report_Customer_List extends WP_List_Table {
return '-';
}
break;
break;
case 'wc_actions' :
case 'wc_actions':
ob_start();
?><p>
<?php
do_action( 'woocommerce_admin_user_actions_start', $user );
do_action( 'woocommerce_admin_user_actions_start', $user );
$actions = array();
$actions = array();
$actions['refresh'] = array(
'url' => wp_nonce_url( add_query_arg( 'refresh', $user->ID ), 'refresh' ),
'name' => __( 'Refresh stats', 'woocommerce' ),
'action' => "refresh",
$actions['refresh'] = array(
'url' => wp_nonce_url( add_query_arg( 'refresh', $user->ID ), 'refresh' ),
'name' => __( 'Refresh stats', 'woocommerce' ),
'action' => 'refresh',
);
$actions['edit'] = array(
'url' => admin_url( 'user-edit.php?user_id=' . $user->ID ),
'name' => __( 'Edit', 'woocommerce' ),
'action' => 'edit',
);
$actions['view'] = array(
'url' => admin_url( 'edit.php?post_type=shop_order&_customer_user=' . $user->ID ),
'name' => __( 'View orders', 'woocommerce' ),
'action' => 'view',
);
$orders = wc_get_orders(
array(
'limit' => 1,
'status' => array_map( 'wc_get_order_status_name', wc_get_is_paid_statuses() ),
'customer' => array( array( 0, $user->user_email ) ),
)
);
if ( $orders ) {
$actions['link'] = array(
'url' => wp_nonce_url( add_query_arg( 'link_orders', $user->ID ), 'link_orders' ),
'name' => __( 'Link previous orders', 'woocommerce' ),
'action' => 'link',
);
}
$actions['edit'] = array(
'url' => admin_url( 'user-edit.php?user_id=' . $user->ID ),
'name' => __( 'Edit', 'woocommerce' ),
'action' => "edit",
);
$actions = apply_filters( 'woocommerce_admin_user_actions', $actions, $user );
$actions['view'] = array(
'url' => admin_url( 'edit.php?post_type=shop_order&_customer_user=' . $user->ID ),
'name' => __( 'View orders', 'woocommerce' ),
'action' => "view",
);
foreach ( $actions as $action ) {
printf( '<a class="button tips %s" href="%s" data-tip="%s">%s</a>', esc_attr( $action['action'] ), esc_url( $action['url'] ), esc_attr( $action['name'] ), esc_attr( $action['name'] ) );
}
$orders = wc_get_orders( array(
'limit' => 1,
'status' => array_map( 'wc_get_order_status_name', wc_get_is_paid_statuses() ),
'customer' => array( array( 0, $user->user_email ) ),
) );
if ( $orders ) {
$actions['link'] = array(
'url' => wp_nonce_url( add_query_arg( 'link_orders', $user->ID ), 'link_orders' ),
'name' => __( 'Link previous orders', 'woocommerce' ),
'action' => "link",
);
}
$actions = apply_filters( 'woocommerce_admin_user_actions', $actions, $user );
foreach ( $actions as $action ) {
printf( '<a class="button tips %s" href="%s" data-tip="%s">%s</a>', esc_attr( $action['action'] ), esc_url( $action['url'] ), esc_attr( $action['name'] ), esc_attr( $action['name'] ) );
}
do_action( 'woocommerce_admin_user_actions_end', $user );
do_action( 'woocommerce_admin_user_actions_end', $user );
?>
</p><?php
</p>
<?php
$user_actions = ob_get_contents();
ob_end_clean();
@ -203,14 +208,14 @@ class WC_Report_Customer_List extends WP_List_Table {
*/
public function get_columns() {
$columns = array(
'customer_name' => __( 'Name (Last, First)', 'woocommerce' ),
'username' => __( 'Username', 'woocommerce' ),
'email' => __( 'Email', 'woocommerce' ),
'location' => __( 'Location', 'woocommerce' ),
'orders' => __( 'Orders', 'woocommerce' ),
'spent' => __( 'Money spent', 'woocommerce' ),
'last_order' => __( 'Last order', 'woocommerce' ),
'wc_actions' => __( 'Actions', 'woocommerce' ),
'customer_name' => __( 'Name (Last, First)', 'woocommerce' ),
'username' => __( 'Username', 'woocommerce' ),
'email' => __( 'Email', 'woocommerce' ),
'location' => __( 'Location', 'woocommerce' ),
'orders' => __( 'Orders', 'woocommerce' ),
'spent' => __( 'Money spent', 'woocommerce' ),
'last_order' => __( 'Last order', 'woocommerce' ),
'wc_actions' => __( 'Actions', 'woocommerce' ),
);
return $columns;
@ -228,14 +233,14 @@ class WC_Report_Customer_List extends WP_List_Table {
$s = ! empty( $_REQUEST['s'] ) ? stripslashes( $_REQUEST['s'] ) : '';
$query->query_from .= " LEFT JOIN {$wpdb->usermeta} as meta2 ON ({$wpdb->users}.ID = meta2.user_id) ";
$query->query_where .= " AND meta2.meta_key = 'last_name' ";
$query->query_orderby = " ORDER BY meta2.meta_value, user_login ASC ";
$query->query_from .= " LEFT JOIN {$wpdb->usermeta} as meta2 ON ({$wpdb->users}.ID = meta2.user_id) ";
$query->query_where .= " AND meta2.meta_key = 'last_name' ";
$query->query_orderby = ' ORDER BY meta2.meta_value, user_login ASC ';
if ( $s ) {
$query->query_from .= " LEFT JOIN {$wpdb->usermeta} as meta3 ON ({$wpdb->users}.ID = meta3.user_id)";
$query->query_where .= " AND ( user_login LIKE '%" . esc_sql( str_replace( '*', '', $s ) ) . "%' OR user_nicename LIKE '%" . esc_sql( str_replace( '*', '', $s ) ) . "%' OR meta3.meta_value LIKE '%" . esc_sql( str_replace( '*', '', $s ) ) . "%' ) ";
$query->query_orderby = " GROUP BY ID " . $query->query_orderby;
$query->query_from .= " LEFT JOIN {$wpdb->usermeta} as meta3 ON ({$wpdb->users}.ID = meta3.user_id)";
$query->query_where .= " AND ( user_login LIKE '%" . esc_sql( str_replace( '*', '', $s ) ) . "%' OR user_nicename LIKE '%" . esc_sql( str_replace( '*', '', $s ) ) . "%' OR meta3.meta_value LIKE '%" . esc_sql( str_replace( '*', '', $s ) ) . "%' ) ";
$query->query_orderby = ' GROUP BY ID ' . $query->query_orderby;
}
return $query;
@ -272,11 +277,13 @@ class WC_Report_Customer_List extends WP_List_Table {
)
);
$query = new WP_User_Query( array(
'exclude' => array_merge( $admin_users->get_results(), $manager_users->get_results() ),
'number' => $per_page,
'offset' => ( $current_page - 1 ) * $per_page,
) );
$query = new WP_User_Query(
array(
'exclude' => array_merge( $admin_users->get_results(), $manager_users->get_results() ),
'number' => $per_page,
'offset' => ( $current_page - 1 ) * $per_page,
)
);
$this->items = $query->get_results();
@ -285,10 +292,12 @@ class WC_Report_Customer_List extends WP_List_Table {
/**
* Pagination.
*/
$this->set_pagination_args( array(
'total_items' => $query->total_users,
'per_page' => $per_page,
'total_pages' => ceil( $query->total_users / $per_page ),
) );
$this->set_pagination_args(
array(
'total_items' => $query->total_users,
'per_page' => $per_page,
'total_pages' => ceil( $query->total_users / $per_page ),
)
);
}
}

View File

@ -34,12 +34,12 @@ class WC_Report_Customers extends WC_Admin_Report {
* @return array
*/
public function get_chart_legend() {
$legend = array();
$legend = array();
$legend[] = array(
/* translators: %s: signups amount */
'title' => sprintf( __( '%s signups in this period', 'woocommerce' ), '<strong>' . sizeof( $this->customers ) . '</strong>' ),
'color' => $this->chart_colours['signups'],
'title' => sprintf( __( '%s signups in this period', 'woocommerce' ), '<strong>' . sizeof( $this->customers ) . '</strong>' ),
'color' => $this->chart_colours['signups'],
'highlight_series' => 2,
);
@ -67,41 +67,45 @@ class WC_Report_Customers extends WC_Admin_Report {
*/
public function customers_vs_guests() {
$customer_order_totals = $this->get_order_report_data( array(
'data' => array(
'ID' => array(
'type' => 'post_data',
'function' => 'COUNT',
'name' => 'total_orders',
$customer_order_totals = $this->get_order_report_data(
array(
'data' => array(
'ID' => array(
'type' => 'post_data',
'function' => 'COUNT',
'name' => 'total_orders',
),
),
),
'where_meta' => array(
array(
'meta_key' => '_customer_user',
'meta_value' => '0',
'operator' => '>',
'where_meta' => array(
array(
'meta_key' => '_customer_user',
'meta_value' => '0',
'operator' => '>',
),
),
),
'filter_range' => true,
) );
'filter_range' => true,
)
);
$guest_order_totals = $this->get_order_report_data( array(
'data' => array(
'ID' => array(
'type' => 'post_data',
'function' => 'COUNT',
'name' => 'total_orders',
$guest_order_totals = $this->get_order_report_data(
array(
'data' => array(
'ID' => array(
'type' => 'post_data',
'function' => 'COUNT',
'name' => 'total_orders',
),
),
),
'where_meta' => array(
array(
'meta_key' => '_customer_user',
'meta_value' => '0',
'operator' => '=',
'where_meta' => array(
array(
'meta_key' => '_customer_user',
'meta_value' => '0',
'operator' => '=',
),
),
),
'filter_range' => true,
) );
'filter_range' => true,
)
);
?>
<div class="chart-container">
<div class="chart-placeholder customers_vs_guests pie-chart" style="height:200px"></div>
@ -112,17 +116,17 @@ class WC_Report_Customers extends WC_Admin_Report {
</div>
<script type="text/javascript">
jQuery(function(){
jQuery.plot(
jQuery.plot(
jQuery('.chart-placeholder.customers_vs_guests'),
[
{
label: '<?php _e( 'Customer orders', 'woocommerce' ); ?>',
data: "<?php echo $customer_order_totals->total_orders ?>",
data: "<?php echo $customer_order_totals->total_orders; ?>",
color: '<?php echo $this->chart_colours['customers']; ?>'
},
{
label: '<?php _e( 'Guest orders', 'woocommerce' ); ?>',
data: "<?php echo $guest_order_totals->total_orders ?>",
data: "<?php echo $guest_order_totals->total_orders; ?>",
color: '<?php echo $this->chart_colours['guests']; ?>'
}
],
@ -160,10 +164,10 @@ class WC_Report_Customers extends WC_Admin_Report {
public function output_report() {
$ranges = array(
'year' => __( 'Year', 'woocommerce' ),
'last_month' => __( 'Last month', 'woocommerce' ),
'month' => __( 'This month', 'woocommerce' ),
'7day' => __( 'Last 7 days', 'woocommerce' ),
'year' => __( 'Year', 'woocommerce' ),
'last_month' => __( 'Last month', 'woocommerce' ),
'month' => __( 'This month', 'woocommerce' ),
'7day' => __( 'Last 7 days', 'woocommerce' ),
);
$this->chart_colours = array(
@ -210,7 +214,7 @@ class WC_Report_Customers extends WC_Admin_Report {
}
}
include( WC()->plugin_path() . '/includes/admin/views/html-report-by-date.php' );
include WC()->plugin_path() . '/includes/admin/views/html-report-by-date.php';
}
/**
@ -239,68 +243,74 @@ class WC_Report_Customers extends WC_Admin_Report {
public function get_main_chart() {
global $wp_locale;
$customer_orders = $this->get_order_report_data( array(
'data' => array(
'ID' => array(
'type' => 'post_data',
'function' => 'COUNT',
'name' => 'total_orders',
$customer_orders = $this->get_order_report_data(
array(
'data' => array(
'ID' => array(
'type' => 'post_data',
'function' => 'COUNT',
'name' => 'total_orders',
),
'post_date' => array(
'type' => 'post_data',
'function' => '',
'name' => 'post_date',
),
),
'post_date' => array(
'type' => 'post_data',
'function' => '',
'name' => 'post_date',
'where_meta' => array(
array(
'meta_key' => '_customer_user',
'meta_value' => '0',
'operator' => '>',
),
),
),
'where_meta' => array(
array(
'meta_key' => '_customer_user',
'meta_value' => '0',
'operator' => '>',
),
),
'group_by' => $this->group_by_query,
'order_by' => 'post_date ASC',
'query_type' => 'get_results',
'filter_range' => true,
) );
'group_by' => $this->group_by_query,
'order_by' => 'post_date ASC',
'query_type' => 'get_results',
'filter_range' => true,
)
);
$guest_orders = $this->get_order_report_data( array(
'data' => array(
'ID' => array(
'type' => 'post_data',
'function' => 'COUNT',
'name' => 'total_orders',
$guest_orders = $this->get_order_report_data(
array(
'data' => array(
'ID' => array(
'type' => 'post_data',
'function' => 'COUNT',
'name' => 'total_orders',
),
'post_date' => array(
'type' => 'post_data',
'function' => '',
'name' => 'post_date',
),
),
'post_date' => array(
'type' => 'post_data',
'function' => '',
'name' => 'post_date',
'where_meta' => array(
array(
'meta_key' => '_customer_user',
'meta_value' => '0',
'operator' => '=',
),
),
),
'where_meta' => array(
array(
'meta_key' => '_customer_user',
'meta_value' => '0',
'operator' => '=',
),
),
'group_by' => $this->group_by_query,
'order_by' => 'post_date ASC',
'query_type' => 'get_results',
'filter_range' => true,
) );
'group_by' => $this->group_by_query,
'order_by' => 'post_date ASC',
'query_type' => 'get_results',
'filter_range' => true,
)
);
$signups = $this->prepare_chart_data( $this->customers, 'user_registered', '', $this->chart_interval, $this->start_date, $this->chart_groupby );
$customer_orders = $this->prepare_chart_data( $customer_orders, 'post_date', 'total_orders', $this->chart_interval, $this->start_date, $this->chart_groupby );
$guest_orders = $this->prepare_chart_data( $guest_orders, 'post_date', 'total_orders', $this->chart_interval, $this->start_date, $this->chart_groupby );
// Encode in json format
$chart_data = json_encode( array(
'signups' => array_values( $signups ),
'customer_orders' => array_values( $customer_orders ),
'guest_orders' => array_values( $guest_orders ),
) );
$chart_data = json_encode(
array(
'signups' => array_values( $signups ),
'customer_orders' => array_values( $customer_orders ),
'guest_orders' => array_values( $guest_orders ),
)
);
?>
<div class="chart-container">
<div class="chart-placeholder main"></div>
@ -314,7 +324,7 @@ class WC_Report_Customers extends WC_Admin_Report {
var drawGraph = function( highlight ) {
var series = [
{
label: "<?php echo esc_js( __( 'Customer orders', 'woocommerce' ) ) ?>",
label: "<?php echo esc_js( __( 'Customer orders', 'woocommerce' ) ); ?>",
data: chart_data.customer_orders,
color: '<?php echo $this->chart_colours['customers']; ?>',
bars: { fillColor: '<?php echo $this->chart_colours['customers']; ?>', fill: true, show: true, lineWidth: 0, barWidth: <?php echo $this->barwidth; ?> * 0.5, align: 'center' },
@ -324,7 +334,7 @@ class WC_Report_Customers extends WC_Admin_Report {
stack: true,
},
{
label: "<?php echo esc_js( __( 'Guest orders', 'woocommerce' ) ) ?>",
label: "<?php echo esc_js( __( 'Guest orders', 'woocommerce' ) ); ?>",
data: chart_data.guest_orders,
color: '<?php echo $this->chart_colours['guests']; ?>',
bars: { fillColor: '<?php echo $this->chart_colours['guests']; ?>', fill: true, show: true, lineWidth: 0, barWidth: <?php echo $this->barwidth; ?> * 0.5, align: 'center' },
@ -334,7 +344,7 @@ class WC_Report_Customers extends WC_Admin_Report {
stack: true,
},
{
label: "<?php echo esc_js( __( 'Signups', 'woocommerce' ) ) ?>",
label: "<?php echo esc_js( __( 'Signups', 'woocommerce' ) ); ?>",
data: chart_data.signups,
color: '<?php echo $this->chart_colours['signups']; ?>',
points: { show: true, radius: 5, lineWidth: 3, fillColor: '#fff', fill: true },
@ -378,7 +388,7 @@ class WC_Report_Customers extends WC_Admin_Report {
tickColor: 'transparent',
mode: "time",
timeformat: "<?php echo ( 'day' === $this->chart_groupby ) ? '%d %b' : '%b'; ?>",
monthNames: <?php echo json_encode( array_values( $wp_locale->month_abbrev ) ) ?>,
monthNames: <?php echo json_encode( array_values( $wp_locale->month_abbrev ) ); ?>,
tickLength: 1,
minTickSize: [1, "<?php echo $this->chart_groupby; ?>"],
tickSize: [1, "<?php echo $this->chart_groupby; ?>"],

View File

@ -13,7 +13,7 @@ if ( ! defined( 'ABSPATH' ) ) {
}
if ( ! class_exists( 'WP_List_Table' ) ) {
require_once( ABSPATH . 'wp-admin/includes/class-wp-list-table.php' );
require_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php';
}
/**
@ -33,11 +33,13 @@ class WC_Report_Downloads extends WP_List_Table {
*/
public function __construct() {
parent::__construct( array(
'singular' => 'download',
'plural' => 'downloads',
'ajax' => false,
) );
parent::__construct(
array(
'singular' => 'download',
'plural' => 'downloads',
'ajax' => false,
)
);
}
/**
@ -63,12 +65,12 @@ class WC_Report_Downloads extends WP_List_Table {
$permission_id = absint( $_GET['permission_id'] ); // WPCS: input var ok.
// Load the permission, order, etc. so we can render more information.
$permission = null;
$product = null;
$permission = null;
$product = null;
try {
$permission = new WC_Customer_Download( $permission_id );
$product = wc_get_product( $permission->product_id );
$permission = new WC_Customer_Download( $permission_id );
$product = wc_get_product( $permission->product_id );
} catch ( Exception $e ) {
wp_die( sprintf( esc_html__( 'Permission #%d not found.', 'woocommerce' ), esc_html( $permission_id ) ) );
}
@ -92,23 +94,23 @@ class WC_Report_Downloads extends WP_List_Table {
continue;
}
switch ( $key ) {
case 'order_id' :
case 'order_id':
$order = wc_get_order( $value );
if ( $order ) {
if ( $order ) {
$display_value = _x( '#', 'hash before order number', 'woocommerce' ) . $order->get_order_number();
} else {
break 2;
}
break;
case 'product_id' :
case 'product_id':
$product = wc_get_product( $value );
if ( $product ) {
if ( $product ) {
$display_value = $product->get_formatted_name();
} else {
break 2;
}
break;
default :
default:
$display_value = $value;
break;
}
@ -137,18 +139,18 @@ class WC_Report_Downloads extends WP_List_Table {
$permission = null;
$product = null;
try {
$permission = new WC_Customer_Download( $item->permission_id );
$product = wc_get_product( $permission->product_id );
$permission = new WC_Customer_Download( $item->permission_id );
$product = wc_get_product( $permission->product_id );
} catch ( Exception $e ) {
// Ok to continue rendering other information even if permission and/or product is not found.
return;
}
switch ( $column_name ) {
case 'timestamp' :
case 'timestamp':
echo esc_html( $item->timestamp );
break;
case 'product' :
case 'product':
if ( ! empty( $product ) ) {
edit_post_link( esc_html( $product->get_formatted_name() ), '', '', $product->get_id(), 'view-link' );
@ -157,19 +159,19 @@ class WC_Report_Downloads extends WP_List_Table {
echo '</div>';
}
break;
case 'file' :
case 'file':
if ( ! empty( $permission ) && ! empty( $product ) ) {
// File information.
$file = $product->get_file( $permission->get_download_id() );
echo esc_html( $file->get_name() . ' - ' . basename( $file->get_file() ) );
echo esc_html( $file->get_name() . ' - ' . basename( $file->get_file() ) );
echo '<div class="row-actions">';
echo '<a href="' . esc_url( add_query_arg( 'download_id', $permission->get_download_id() ) ) . '">' . esc_html__( 'Filter by file', 'woocommerce' ) . '</a>';
echo '</div>';
}
break;
case 'order' :
case 'order':
if ( ! empty( $permission ) && ( $order = wc_get_order( $permission->order_id ) ) ) {
edit_post_link( esc_html( _x( '#', 'hash before order number', 'woocommerce' ) . $order->get_order_number() ), '', '', $permission->order_id, 'view-link' );
@ -178,7 +180,7 @@ class WC_Report_Downloads extends WP_List_Table {
echo '</div>';
}
break;
case 'user' :
case 'user':
if ( $item->user_id > 0 ) {
$user = get_user_by( 'id', $item->user_id );
@ -192,7 +194,7 @@ class WC_Report_Downloads extends WP_List_Table {
esc_html_e( 'Guest', 'woocommerce' );
}
break;
case 'user_ip_address' :
case 'user_ip_address':
echo esc_html( $item->user_ip_address );
echo '<div class="row-actions">';
@ -228,18 +230,20 @@ class WC_Report_Downloads extends WP_List_Table {
$this->_column_headers = array( $this->get_columns(), array(), $this->get_sortable_columns() );
$current_page = absint( $this->get_pagenum() );
// Allow filtering per_page value, but ensure it's at least 1.
$per_page = max( 1, apply_filters( 'woocommerce_admin_downloads_report_downloads_per_page', 20 ) );
$per_page = max( 1, apply_filters( 'woocommerce_admin_downloads_report_downloads_per_page', 20 ) );
$this->get_items( $current_page, $per_page );
/**
* Pagination.
*/
$this->set_pagination_args( array(
'total_items' => $this->max_items,
'per_page' => $per_page,
'total_pages' => ceil( $this->max_items / $per_page ),
) );
$this->set_pagination_args(
array(
'total_items' => $this->max_items,
'per_page' => $per_page,
'total_pages' => ceil( $this->max_items / $per_page ),
)
);
}
/**
@ -255,12 +259,12 @@ class WC_Report_Downloads extends WP_List_Table {
* @return object
*/
protected function get_filter_vars() {
$product_id = ! empty( $_GET['product_id'] ) ? absint( wp_unslash( $_GET['product_id'] ) ) : null; // WPCS: input var ok.
$download_id = ! empty( $_GET['download_id'] ) ? wc_clean( wp_unslash( $_GET['download_id'] ) ) : null; // WPCS: input var ok.
$permission_id = ! empty( $_GET['permission_id'] ) ? absint( wp_unslash( $_GET['permission_id'] ) ) : null; // WPCS: input var ok.
$order_id = ! empty( $_GET['order_id'] ) ? absint( wp_unslash( $_GET['order_id'] ) ) : null; // WPCS: input var ok.
$user_id = ! empty( $_GET['user_id'] ) ? absint( wp_unslash( $_GET['user_id'] ) ) : null; // WPCS: input var ok.
$user_ip_address = ! empty( $_GET['user_ip_address'] ) ? wc_clean( wp_unslash( $_GET['user_ip_address'] ) ): null; // WPCS: input var ok.
$product_id = ! empty( $_GET['product_id'] ) ? absint( wp_unslash( $_GET['product_id'] ) ) : null; // WPCS: input var ok.
$download_id = ! empty( $_GET['download_id'] ) ? wc_clean( wp_unslash( $_GET['download_id'] ) ) : null; // WPCS: input var ok.
$permission_id = ! empty( $_GET['permission_id'] ) ? absint( wp_unslash( $_GET['permission_id'] ) ) : null; // WPCS: input var ok.
$order_id = ! empty( $_GET['order_id'] ) ? absint( wp_unslash( $_GET['order_id'] ) ) : null; // WPCS: input var ok.
$user_id = ! empty( $_GET['user_id'] ) ? absint( wp_unslash( $_GET['user_id'] ) ) : null; // WPCS: input var ok.
$user_ip_address = ! empty( $_GET['user_ip_address'] ) ? wc_clean( wp_unslash( $_GET['user_ip_address'] ) ) : null; // WPCS: input var ok.
return (object) array(
'product_id' => $product_id,

View File

@ -5,7 +5,7 @@ if ( ! defined( 'ABSPATH' ) ) {
}
if ( ! class_exists( 'WC_Report_Stock' ) ) {
require_once( dirname( __FILE__ ) . '/class-wc-report-stock.php' );
require_once dirname( __FILE__ ) . '/class-wc-report-stock.php';
}
/**
@ -41,7 +41,8 @@ class WC_Report_Low_In_Stock extends WC_Report_Stock {
$stock = absint( max( get_option( 'woocommerce_notify_low_stock_amount' ), 1 ) );
$nostock = absint( max( get_option( 'woocommerce_notify_no_stock_amount' ), 0 ) );
$query_from = apply_filters( 'woocommerce_report_low_in_stock_query_from', "FROM {$wpdb->posts} as posts
$query_from = apply_filters(
'woocommerce_report_low_in_stock_query_from', "FROM {$wpdb->posts} as posts
INNER JOIN {$wpdb->postmeta} AS postmeta ON posts.ID = postmeta.post_id
INNER JOIN {$wpdb->postmeta} AS postmeta2 ON posts.ID = postmeta2.post_id
WHERE 1=1
@ -50,7 +51,8 @@ class WC_Report_Low_In_Stock extends WC_Report_Stock {
AND postmeta2.meta_key = '_manage_stock' AND postmeta2.meta_value = 'yes'
AND postmeta.meta_key = '_stock' AND CAST(postmeta.meta_value AS SIGNED) <= '{$stock}'
AND postmeta.meta_key = '_stock' AND CAST(postmeta.meta_value AS SIGNED) > '{$nostock}'
" );
"
);
$this->items = $wpdb->get_results( $wpdb->prepare( "SELECT posts.ID as id, posts.post_parent as parent {$query_from} GROUP BY posts.ID ORDER BY posts.post_title DESC LIMIT %d, %d;", ( $current_page - 1 ) * $per_page, $per_page ) );
$this->max_items = $wpdb->get_var( "SELECT COUNT( DISTINCT posts.ID ) {$query_from};" );

View File

@ -5,7 +5,7 @@ if ( ! defined( 'ABSPATH' ) ) {
}
if ( ! class_exists( 'WC_Report_Stock' ) ) {
require_once( dirname( __FILE__ ) . '/class-wc-report-stock.php' );
require_once dirname( __FILE__ ) . '/class-wc-report-stock.php';
}
/**

View File

@ -5,7 +5,7 @@ if ( ! defined( 'ABSPATH' ) ) {
}
if ( ! class_exists( 'WC_Report_Stock' ) ) {
require_once( dirname( __FILE__ ) . '/class-wc-report-stock.php' );
require_once dirname( __FILE__ ) . '/class-wc-report-stock.php';
}
/**
@ -40,7 +40,8 @@ class WC_Report_Out_Of_Stock extends WC_Report_Stock {
// Get products using a query - this is too advanced for get_posts :(
$stock = absint( max( get_option( 'woocommerce_notify_no_stock_amount' ), 0 ) );
$query_from = apply_filters( 'woocommerce_report_out_of_stock_query_from', "FROM {$wpdb->posts} as posts
$query_from = apply_filters(
'woocommerce_report_out_of_stock_query_from', "FROM {$wpdb->posts} as posts
INNER JOIN {$wpdb->postmeta} AS postmeta ON posts.ID = postmeta.post_id
INNER JOIN {$wpdb->postmeta} AS postmeta2 ON posts.ID = postmeta2.post_id
WHERE 1=1
@ -48,7 +49,8 @@ class WC_Report_Out_Of_Stock extends WC_Report_Stock {
AND posts.post_status = 'publish'
AND postmeta2.meta_key = '_manage_stock' AND postmeta2.meta_value = 'yes'
AND postmeta.meta_key = '_stock' AND CAST(postmeta.meta_value AS SIGNED) <= '{$stock}'
" );
"
);
$this->items = $wpdb->get_results( $wpdb->prepare( "SELECT posts.ID as id, posts.post_parent as parent {$query_from} GROUP BY posts.ID ORDER BY posts.post_title DESC LIMIT %d, %d;", ( $current_page - 1 ) * $per_page, $per_page ) );
$this->max_items = $wpdb->get_var( "SELECT COUNT( DISTINCT posts.ID ) {$query_from};" );

View File

@ -24,21 +24,21 @@ class WC_Report_Sales_By_Category extends WC_Admin_Report {
*
* @var array
*/
public $chart_colours = array();
public $chart_colours = array();
/**
* Categories ids.
*
* @var array
*/
public $show_categories = array();
public $show_categories = array();
/**
* Item sales.
*
* @var array
*/
private $item_sales = array();
private $item_sales = array();
/**
* Item sales and times.
@ -116,10 +116,10 @@ class WC_Report_Sales_By_Category extends WC_Admin_Report {
public function output_report() {
$ranges = array(
'year' => __( 'Year', 'woocommerce' ),
'last_month' => __( 'Last month', 'woocommerce' ),
'month' => __( 'This month', 'woocommerce' ),
'7day' => __( 'Last 7 days', 'woocommerce' ),
'year' => __( 'Year', 'woocommerce' ),
'last_month' => __( 'Last month', 'woocommerce' ),
'month' => __( 'This month', 'woocommerce' ),
'7day' => __( 'Last 7 days', 'woocommerce' ),
);
$this->chart_colours = array( '#3498db', '#34495e', '#1abc9c', '#2ecc71', '#f1c40f', '#e67e22', '#e74c3c', '#2980b9', '#8e44ad', '#2c3e50', '#16a085', '#27ae60', '#f39c12', '#d35400', '#c0392b' );
@ -135,30 +135,32 @@ class WC_Report_Sales_By_Category extends WC_Admin_Report {
// Get item sales data.
if ( ! empty( $this->show_categories ) ) {
$order_items = $this->get_order_report_data( array(
'data' => array(
'_product_id' => array(
'type' => 'order_item_meta',
'order_item_type' => 'line_item',
'function' => '',
'name' => 'product_id',
$order_items = $this->get_order_report_data(
array(
'data' => array(
'_product_id' => array(
'type' => 'order_item_meta',
'order_item_type' => 'line_item',
'function' => '',
'name' => 'product_id',
),
'_line_total' => array(
'type' => 'order_item_meta',
'order_item_type' => 'line_item',
'function' => 'SUM',
'name' => 'order_item_amount',
),
'post_date' => array(
'type' => 'post_data',
'function' => '',
'name' => 'post_date',
),
),
'_line_total' => array(
'type' => 'order_item_meta',
'order_item_type' => 'line_item',
'function' => 'SUM',
'name' => 'order_item_amount',
),
'post_date' => array(
'type' => 'post_data',
'function' => '',
'name' => 'post_date',
),
),
'group_by' => 'ID, product_id, post_date',
'query_type' => 'get_results',
'filter_range' => true,
) );
'group_by' => 'ID, product_id, post_date',
'query_type' => 'get_results',
'filter_range' => true,
)
);
$this->item_sales = array();
$this->item_sales_and_times = array();
@ -168,13 +170,13 @@ class WC_Report_Sales_By_Category extends WC_Admin_Report {
foreach ( $order_items as $order_item ) {
switch ( $this->chart_groupby ) {
case 'day' :
case 'day':
$time = strtotime( date( 'Ymd', strtotime( $order_item->post_date ) ) ) * 1000;
break;
case 'month' :
default :
break;
case 'month':
default:
$time = strtotime( date( 'Ym', strtotime( $order_item->post_date ) ) . '01' ) * 1000;
break;
break;
}
$this->item_sales_and_times[ $time ][ $order_item->product_id ] = isset( $this->item_sales_and_times[ $time ][ $order_item->product_id ] ) ? $this->item_sales_and_times[ $time ][ $order_item->product_id ] + $order_item->order_item_amount : $order_item->order_item_amount;
@ -184,7 +186,7 @@ class WC_Report_Sales_By_Category extends WC_Admin_Report {
}
}
include( WC()->plugin_path() . '/includes/admin/views/html-report-by-date.php' );
include WC()->plugin_path() . '/includes/admin/views/html-report-by-date.php';
}
/**
@ -213,14 +215,14 @@ class WC_Report_Sales_By_Category extends WC_Admin_Report {
<div>
<select multiple="multiple" data-placeholder="<?php esc_attr_e( 'Select categories&hellip;', 'woocommerce' ); ?>" class="wc-enhanced-select" id="show_categories" name="show_categories[]" style="width: 205px;">
<?php
$r = array();
$r['pad_counts'] = 1;
$r['hierarchical'] = 1;
$r['hide_empty'] = 1;
$r['value'] = 'id';
$r['selected'] = $this->show_categories;
$r = array();
$r['pad_counts'] = 1;
$r['hierarchical'] = 1;
$r['hide_empty'] = 1;
$r['value'] = 'id';
$r['selected'] = $this->show_categories;
include_once( WC()->plugin_path() . '/includes/walkers/class-product-cat-dropdown-walker.php' );
include_once WC()->plugin_path() . '/includes/walkers/class-product-cat-dropdown-walker.php';
echo wc_walk_category_dropdown_tree( $categories, 0, $r ); // @codingStandardsIgnoreLine
?>
@ -304,13 +306,13 @@ class WC_Report_Sales_By_Category extends WC_Admin_Report {
$interval_total = 0;
switch ( $this->chart_groupby ) {
case 'day' :
case 'day':
$time = strtotime( date( 'Ymd', strtotime( "+{$i} DAY", $this->start_date ) ) ) * 1000;
break;
case 'month' :
default :
break;
case 'month':
default:
$time = strtotime( date( 'Ym', strtotime( "+{$i} MONTH", $this->start_date ) ) . '01' ) * 1000;
break;
break;
}
foreach ( $product_ids as $id ) {
@ -324,7 +326,7 @@ class WC_Report_Sales_By_Category extends WC_Admin_Report {
}
$chart_data[ $category->term_id ]['category'] = $category->name;
$chart_data[ $category->term_id ]['data'] = $category_chart_data;
$chart_data[ $category->term_id ]['data'] = $category_chart_data;
$index++;
}
@ -350,22 +352,22 @@ class WC_Report_Sales_By_Category extends WC_Admin_Report {
$series[ $key ][0] = $series_data[0] + $offset;
}
echo '{
label: "' . esc_js( $data['category'] ) . '",
data: jQuery.parseJSON( "' . json_encode( $series ) . '" ),
color: "' . $color . '",
bars: {
fillColor: "' . $color . '",
fill: true,
show: true,
lineWidth: 1,
align: "center",
barWidth: ' . $width * 0.75 . ',
stack: false
},
' . $this->get_currency_tooltip() . ',
enable_tooltip: true,
prepend_label: true
},';
label: "' . esc_js( $data['category'] ) . '",
data: jQuery.parseJSON( "' . json_encode( $series ) . '" ),
color: "' . $color . '",
bars: {
fillColor: "' . $color . '",
fill: true,
show: true,
lineWidth: 1,
align: "center",
barWidth: ' . $width * 0.75 . ',
stack: false
},
' . $this->get_currency_tooltip() . ',
enable_tooltip: true,
prepend_label: true
},';
$index++;
}
?>

View File

@ -30,6 +30,7 @@ class WC_Report_Sales_By_Date extends WC_Admin_Report {
/**
* Get report data.
*
* @return stdClass
*/
public function get_report_data() {
@ -43,324 +44,342 @@ class WC_Report_Sales_By_Date extends WC_Admin_Report {
* Get all data needed for this report and store in the class.
*/
private function query_report_data() {
$this->report_data = new stdClass;
$this->report_data = new stdClass();
$this->report_data->order_counts = (array) $this->get_order_report_data( array(
'data' => array(
'ID' => array(
'type' => 'post_data',
'function' => 'COUNT',
'name' => 'count',
'distinct' => true,
$this->report_data->order_counts = (array) $this->get_order_report_data(
array(
'data' => array(
'ID' => array(
'type' => 'post_data',
'function' => 'COUNT',
'name' => 'count',
'distinct' => true,
),
'post_date' => array(
'type' => 'post_data',
'function' => '',
'name' => 'post_date',
),
),
'post_date' => array(
'type' => 'post_data',
'function' => '',
'name' => 'post_date',
),
),
'group_by' => $this->group_by_query,
'order_by' => 'post_date ASC',
'query_type' => 'get_results',
'filter_range' => true,
'order_types' => wc_get_order_types( 'order-count' ),
'order_status' => array( 'completed', 'processing', 'on-hold', 'refunded' ),
) );
'group_by' => $this->group_by_query,
'order_by' => 'post_date ASC',
'query_type' => 'get_results',
'filter_range' => true,
'order_types' => wc_get_order_types( 'order-count' ),
'order_status' => array( 'completed', 'processing', 'on-hold', 'refunded' ),
)
);
$this->report_data->coupons = (array) $this->get_order_report_data( array(
'data' => array(
'order_item_name' => array(
'type' => 'order_item',
'function' => '',
'name' => 'order_item_name',
$this->report_data->coupons = (array) $this->get_order_report_data(
array(
'data' => array(
'order_item_name' => array(
'type' => 'order_item',
'function' => '',
'name' => 'order_item_name',
),
'discount_amount' => array(
'type' => 'order_item_meta',
'order_item_type' => 'coupon',
'function' => 'SUM',
'name' => 'discount_amount',
),
'post_date' => array(
'type' => 'post_data',
'function' => '',
'name' => 'post_date',
),
),
'discount_amount' => array(
'type' => 'order_item_meta',
'order_item_type' => 'coupon',
'function' => 'SUM',
'name' => 'discount_amount',
'where' => array(
array(
'key' => 'order_items.order_item_type',
'value' => 'coupon',
'operator' => '=',
),
),
'post_date' => array(
'type' => 'post_data',
'function' => '',
'name' => 'post_date',
),
),
'where' => array(
array(
'key' => 'order_items.order_item_type',
'value' => 'coupon',
'operator' => '=',
),
),
'group_by' => $this->group_by_query . ', order_item_name',
'order_by' => 'post_date ASC',
'query_type' => 'get_results',
'filter_range' => true,
'order_types' => wc_get_order_types( 'order-count' ),
'order_status' => array( 'completed', 'processing', 'on-hold', 'refunded' ),
) );
'group_by' => $this->group_by_query . ', order_item_name',
'order_by' => 'post_date ASC',
'query_type' => 'get_results',
'filter_range' => true,
'order_types' => wc_get_order_types( 'order-count' ),
'order_status' => array( 'completed', 'processing', 'on-hold', 'refunded' ),
)
);
// All items from orders - even those refunded
$this->report_data->order_items = (array) $this->get_order_report_data( array(
'data' => array(
'_qty' => array(
'type' => 'order_item_meta',
'order_item_type' => 'line_item',
'function' => 'SUM',
'name' => 'order_item_count',
$this->report_data->order_items = (array) $this->get_order_report_data(
array(
'data' => array(
'_qty' => array(
'type' => 'order_item_meta',
'order_item_type' => 'line_item',
'function' => 'SUM',
'name' => 'order_item_count',
),
'post_date' => array(
'type' => 'post_data',
'function' => '',
'name' => 'post_date',
),
),
'post_date' => array(
'type' => 'post_data',
'function' => '',
'name' => 'post_date',
'where' => array(
array(
'key' => 'order_items.order_item_type',
'value' => 'line_item',
'operator' => '=',
),
),
),
'where' => array(
array(
'key' => 'order_items.order_item_type',
'value' => 'line_item',
'operator' => '=',
),
),
'group_by' => $this->group_by_query,
'order_by' => 'post_date ASC',
'query_type' => 'get_results',
'filter_range' => true,
'order_types' => wc_get_order_types( 'order-count' ),
'order_status' => array( 'completed', 'processing', 'on-hold', 'refunded' ),
) );
'group_by' => $this->group_by_query,
'order_by' => 'post_date ASC',
'query_type' => 'get_results',
'filter_range' => true,
'order_types' => wc_get_order_types( 'order-count' ),
'order_status' => array( 'completed', 'processing', 'on-hold', 'refunded' ),
)
);
/**
* Get total of fully refunded items.
*/
$this->report_data->refunded_order_items = absint( $this->get_order_report_data( array(
'data' => array(
'_qty' => array(
'type' => 'order_item_meta',
'order_item_type' => 'line_item',
'function' => 'SUM',
'name' => 'order_item_count',
),
),
'where' => array(
$this->report_data->refunded_order_items = absint(
$this->get_order_report_data(
array(
'key' => 'order_items.order_item_type',
'value' => 'line_item',
'operator' => '=',
),
),
'query_type' => 'get_var',
'filter_range' => true,
'order_types' => wc_get_order_types( 'order-count' ),
'order_status' => array( 'refunded' ),
) ) );
'data' => array(
'_qty' => array(
'type' => 'order_item_meta',
'order_item_type' => 'line_item',
'function' => 'SUM',
'name' => 'order_item_count',
),
),
'where' => array(
array(
'key' => 'order_items.order_item_type',
'value' => 'line_item',
'operator' => '=',
),
),
'query_type' => 'get_var',
'filter_range' => true,
'order_types' => wc_get_order_types( 'order-count' ),
'order_status' => array( 'refunded' ),
)
)
);
/**
* Order totals by date. Charts should show GROSS amounts to avoid going -ve.
*/
$this->report_data->orders = (array) $this->get_order_report_data( array(
'data' => array(
'_order_total' => array(
'type' => 'meta',
'function' => 'SUM',
'name' => 'total_sales',
$this->report_data->orders = (array) $this->get_order_report_data(
array(
'data' => array(
'_order_total' => array(
'type' => 'meta',
'function' => 'SUM',
'name' => 'total_sales',
),
'_order_shipping' => array(
'type' => 'meta',
'function' => 'SUM',
'name' => 'total_shipping',
),
'_order_tax' => array(
'type' => 'meta',
'function' => 'SUM',
'name' => 'total_tax',
),
'_order_shipping_tax' => array(
'type' => 'meta',
'function' => 'SUM',
'name' => 'total_shipping_tax',
),
'post_date' => array(
'type' => 'post_data',
'function' => '',
'name' => 'post_date',
),
),
'_order_shipping' => array(
'type' => 'meta',
'function' => 'SUM',
'name' => 'total_shipping',
),
'_order_tax' => array(
'type' => 'meta',
'function' => 'SUM',
'name' => 'total_tax',
),
'_order_shipping_tax' => array(
'type' => 'meta',
'function' => 'SUM',
'name' => 'total_shipping_tax',
),
'post_date' => array(
'type' => 'post_data',
'function' => '',
'name' => 'post_date',
),
),
'group_by' => $this->group_by_query,
'order_by' => 'post_date ASC',
'query_type' => 'get_results',
'filter_range' => true,
'order_types' => wc_get_order_types( 'sales-reports' ),
'order_status' => array( 'completed', 'processing', 'on-hold', 'refunded' ),
) );
'group_by' => $this->group_by_query,
'order_by' => 'post_date ASC',
'query_type' => 'get_results',
'filter_range' => true,
'order_types' => wc_get_order_types( 'sales-reports' ),
'order_status' => array( 'completed', 'processing', 'on-hold', 'refunded' ),
)
);
/**
* If an order is 100% refunded we should look at the parent's totals, but the refunds dates.
* We also need to ensure each parent order's values are only counted/summed once.
*/
$this->report_data->full_refunds = (array) $this->get_order_report_data( array(
'data' => array(
'_order_total' => array(
'type' => 'parent_meta',
'function' => '',
'name' => 'total_refund',
$this->report_data->full_refunds = (array) $this->get_order_report_data(
array(
'data' => array(
'_order_total' => array(
'type' => 'parent_meta',
'function' => '',
'name' => 'total_refund',
),
'_order_shipping' => array(
'type' => 'parent_meta',
'function' => '',
'name' => 'total_shipping',
),
'_order_tax' => array(
'type' => 'parent_meta',
'function' => '',
'name' => 'total_tax',
),
'_order_shipping_tax' => array(
'type' => 'parent_meta',
'function' => '',
'name' => 'total_shipping_tax',
),
'post_date' => array(
'type' => 'post_data',
'function' => '',
'name' => 'post_date',
),
),
'_order_shipping' => array(
'type' => 'parent_meta',
'function' => '',
'name' => 'total_shipping',
),
'_order_tax' => array(
'type' => 'parent_meta',
'function' => '',
'name' => 'total_tax',
),
'_order_shipping_tax' => array(
'type' => 'parent_meta',
'function' => '',
'name' => 'total_shipping_tax',
),
'post_date' => array(
'type' => 'post_data',
'function' => '',
'name' => 'post_date',
),
),
'group_by' => 'posts.post_parent',
'query_type' => 'get_results',
'filter_range' => true,
'order_status' => false,
'parent_order_status' => array( 'refunded' ),
) );
'group_by' => 'posts.post_parent',
'query_type' => 'get_results',
'filter_range' => true,
'order_status' => false,
'parent_order_status' => array( 'refunded' ),
)
);
/**
* Partial refunds. This includes line items, shipping and taxes. Not grouped by date.
*/
$this->report_data->partial_refunds = (array) $this->get_order_report_data( array(
'data' => array(
'ID' => array(
'type' => 'post_data',
'function' => '',
'name' => 'refund_id',
$this->report_data->partial_refunds = (array) $this->get_order_report_data(
array(
'data' => array(
'ID' => array(
'type' => 'post_data',
'function' => '',
'name' => 'refund_id',
),
'_refund_amount' => array(
'type' => 'meta',
'function' => '',
'name' => 'total_refund',
),
'post_date' => array(
'type' => 'post_data',
'function' => '',
'name' => 'post_date',
),
'order_item_type' => array(
'type' => 'order_item',
'function' => '',
'name' => 'item_type',
'join_type' => 'LEFT',
),
'_order_total' => array(
'type' => 'meta',
'function' => '',
'name' => 'total_sales',
),
'_order_shipping' => array(
'type' => 'meta',
'function' => '',
'name' => 'total_shipping',
'join_type' => 'LEFT',
),
'_order_tax' => array(
'type' => 'meta',
'function' => '',
'name' => 'total_tax',
'join_type' => 'LEFT',
),
'_order_shipping_tax' => array(
'type' => 'meta',
'function' => '',
'name' => 'total_shipping_tax',
'join_type' => 'LEFT',
),
'_qty' => array(
'type' => 'order_item_meta',
'function' => 'SUM',
'name' => 'order_item_count',
'join_type' => 'LEFT',
),
),
'_refund_amount' => array(
'type' => 'meta',
'function' => '',
'name' => 'total_refund',
),
'post_date' => array(
'type' => 'post_data',
'function' => '',
'name' => 'post_date',
),
'order_item_type' => array(
'type' => 'order_item',
'function' => '',
'name' => 'item_type',
'join_type' => 'LEFT',
),
'_order_total' => array(
'type' => 'meta',
'function' => '',
'name' => 'total_sales',
),
'_order_shipping' => array(
'type' => 'meta',
'function' => '',
'name' => 'total_shipping',
'join_type' => 'LEFT',
),
'_order_tax' => array(
'type' => 'meta',
'function' => '',
'name' => 'total_tax',
'join_type' => 'LEFT',
),
'_order_shipping_tax' => array(
'type' => 'meta',
'function' => '',
'name' => 'total_shipping_tax',
'join_type' => 'LEFT',
),
'_qty' => array(
'type' => 'order_item_meta',
'function' => 'SUM',
'name' => 'order_item_count',
'join_type' => 'LEFT',
),
),
'group_by' => 'refund_id',
'order_by' => 'post_date ASC',
'query_type' => 'get_results',
'filter_range' => true,
'order_status' => false,
'parent_order_status' => array( 'completed', 'processing', 'on-hold' ),
) );
'group_by' => 'refund_id',
'order_by' => 'post_date ASC',
'query_type' => 'get_results',
'filter_range' => true,
'order_status' => false,
'parent_order_status' => array( 'completed', 'processing', 'on-hold' ),
)
);
/**
* Refund lines - all partial refunds on all order types so we can plot full AND partial refunds on the chart.
*/
$this->report_data->refund_lines = (array) $this->get_order_report_data( array(
'data' => array(
'ID' => array(
'type' => 'post_data',
'function' => '',
'name' => 'refund_id',
$this->report_data->refund_lines = (array) $this->get_order_report_data(
array(
'data' => array(
'ID' => array(
'type' => 'post_data',
'function' => '',
'name' => 'refund_id',
),
'_refund_amount' => array(
'type' => 'meta',
'function' => '',
'name' => 'total_refund',
),
'post_date' => array(
'type' => 'post_data',
'function' => '',
'name' => 'post_date',
),
'order_item_type' => array(
'type' => 'order_item',
'function' => '',
'name' => 'item_type',
'join_type' => 'LEFT',
),
'_order_total' => array(
'type' => 'meta',
'function' => '',
'name' => 'total_sales',
),
'_order_shipping' => array(
'type' => 'meta',
'function' => '',
'name' => 'total_shipping',
'join_type' => 'LEFT',
),
'_order_tax' => array(
'type' => 'meta',
'function' => '',
'name' => 'total_tax',
'join_type' => 'LEFT',
),
'_order_shipping_tax' => array(
'type' => 'meta',
'function' => '',
'name' => 'total_shipping_tax',
'join_type' => 'LEFT',
),
'_qty' => array(
'type' => 'order_item_meta',
'function' => 'SUM',
'name' => 'order_item_count',
'join_type' => 'LEFT',
),
),
'_refund_amount' => array(
'type' => 'meta',
'function' => '',
'name' => 'total_refund',
),
'post_date' => array(
'type' => 'post_data',
'function' => '',
'name' => 'post_date',
),
'order_item_type' => array(
'type' => 'order_item',
'function' => '',
'name' => 'item_type',
'join_type' => 'LEFT',
),
'_order_total' => array(
'type' => 'meta',
'function' => '',
'name' => 'total_sales',
),
'_order_shipping' => array(
'type' => 'meta',
'function' => '',
'name' => 'total_shipping',
'join_type' => 'LEFT',
),
'_order_tax' => array(
'type' => 'meta',
'function' => '',
'name' => 'total_tax',
'join_type' => 'LEFT',
),
'_order_shipping_tax' => array(
'type' => 'meta',
'function' => '',
'name' => 'total_shipping_tax',
'join_type' => 'LEFT',
),
'_qty' => array(
'type' => 'order_item_meta',
'function' => 'SUM',
'name' => 'order_item_count',
'join_type' => 'LEFT',
),
),
'group_by' => 'refund_id',
'order_by' => 'post_date ASC',
'query_type' => 'get_results',
'filter_range' => true,
'order_status' => false,
'parent_order_status' => array( 'completed', 'processing', 'on-hold', 'refunded' ),
) );
'group_by' => 'refund_id',
'order_by' => 'post_date ASC',
'query_type' => 'get_results',
'filter_range' => true,
'order_status' => false,
'parent_order_status' => array( 'completed', 'processing', 'on-hold', 'refunded' ),
)
);
/**
* Total up refunds. Note: when an order is fully refunded, a refund line will be added.
@ -380,7 +399,7 @@ class WC_Report_Sales_By_Date extends WC_Admin_Report {
// Only applies to parial.
if ( isset( $value->order_item_count ) ) {
$this->report_data->refunded_order_items += floatval( $value->order_item_count < 0 ? $value->order_item_count * -1 : $value->order_item_count );
$this->report_data->refunded_order_items += floatval( $value->order_item_count < 0 ? $value->order_item_count * -1 : $value->order_item_count );
}
}
@ -402,7 +421,7 @@ class WC_Report_Sales_By_Date extends WC_Admin_Report {
$this->report_data->total_refunded_orders = absint( count( $this->report_data->full_refunds ) );
// Total orders in this period, even if refunded.
$this->report_data->total_orders = absint( array_sum( wp_list_pluck( $this->report_data->order_counts, 'count' ) ) );
$this->report_data->total_orders = absint( array_sum( wp_list_pluck( $this->report_data->order_counts, 'count' ) ) );
// Item items ordered in this period, even if refunded.
$this->report_data->total_items = absint( array_sum( wp_list_pluck( $this->report_data->order_items, 'order_item_count' ) ) );
@ -413,6 +432,7 @@ class WC_Report_Sales_By_Date extends WC_Admin_Report {
/**
* Get the legend for the main chart sidebar.
*
* @return array
*/
public function get_chart_legend() {
@ -420,7 +440,7 @@ class WC_Report_Sales_By_Date extends WC_Admin_Report {
$data = $this->get_report_data();
switch ( $this->chart_groupby ) {
case 'day' :
case 'day':
/* translators: %s: average total sales */
$average_total_sales_title = sprintf(
__( '%s average gross daily sales', 'woocommerce' ),
@ -431,9 +451,9 @@ class WC_Report_Sales_By_Date extends WC_Admin_Report {
__( '%s average net daily sales', 'woocommerce' ),
'<strong>' . wc_price( $data->average_sales ) . '</strong>'
);
break;
case 'month' :
default :
break;
case 'month':
default:
/* translators: %s: average total sales */
$average_total_sales_title = sprintf(
__( '%s average gross monthly sales', 'woocommerce' ),
@ -444,12 +464,12 @@ class WC_Report_Sales_By_Date extends WC_Admin_Report {
__( '%s average net monthly sales', 'woocommerce' ),
'<strong>' . wc_price( $data->average_sales ) . '</strong>'
);
break;
break;
}
$legend[] = array(
/* translators: %s: total sales */
'title' => sprintf(
'title' => sprintf(
__( '%s gross sales in this period', 'woocommerce' ),
'<strong>' . wc_price( $data->total_sales ) . '</strong>'
),
@ -459,15 +479,15 @@ class WC_Report_Sales_By_Date extends WC_Admin_Report {
);
if ( $data->average_total_sales > 0 ) {
$legend[] = array(
'title' => $average_total_sales_title,
'color' => $this->chart_colours['average'],
'title' => $average_total_sales_title,
'color' => $this->chart_colours['average'],
'highlight_series' => 2,
);
}
$legend[] = array(
/* translators: %s: net sales */
'title' => sprintf(
'title' => sprintf(
__( '%s net sales in this period', 'woocommerce' ),
'<strong>' . wc_price( $data->net_sales ) . '</strong>'
),
@ -477,58 +497,58 @@ class WC_Report_Sales_By_Date extends WC_Admin_Report {
);
if ( $data->average_sales > 0 ) {
$legend[] = array(
'title' => $average_sales_title,
'color' => $this->chart_colours['net_average'],
'title' => $average_sales_title,
'color' => $this->chart_colours['net_average'],
'highlight_series' => 3,
);
}
$legend[] = array(
/* translators: %s: total orders */
'title' => sprintf(
'title' => sprintf(
__( '%s orders placed', 'woocommerce' ),
'<strong>' . $data->total_orders . '</strong>'
),
'color' => $this->chart_colours['order_count'],
'color' => $this->chart_colours['order_count'],
'highlight_series' => 1,
);
$legend[] = array(
/* translators: %s: total items */
'title' => sprintf(
'title' => sprintf(
__( '%s items purchased', 'woocommerce' ),
'<strong>' . $data->total_items . '</strong>'
),
'color' => $this->chart_colours['item_count'],
'color' => $this->chart_colours['item_count'],
'highlight_series' => 0,
);
$legend[] = array(
/* translators: 1: total refunds 2: total refunded orders 3: refunded items */
'title' => sprintf(
'title' => sprintf(
_n( '%1$s refunded %2$d order (%3$d item)', '%1$s refunded %2$d orders (%3$d items)', $this->report_data->total_refunded_orders, 'woocommerce' ),
'<strong>' . wc_price( $data->total_refunds ) . '</strong>',
$this->report_data->total_refunded_orders,
$this->report_data->refunded_order_items
),
'color' => $this->chart_colours['refund_amount'],
'color' => $this->chart_colours['refund_amount'],
'highlight_series' => 8,
);
$legend[] = array(
/* translators: %s: total shipping */
'title' => sprintf(
'title' => sprintf(
__( '%s charged for shipping', 'woocommerce' ),
'<strong>' . wc_price( $data->total_shipping ) . '</strong>'
),
'color' => $this->chart_colours['shipping_amount'],
'color' => $this->chart_colours['shipping_amount'],
'highlight_series' => 5,
);
$legend[] = array(
/* translators: %s: total coupons */
'title' => sprintf(
'title' => sprintf(
__( '%s worth of coupons used', 'woocommerce' ),
'<strong>' . wc_price( $data->total_coupons ) . '</strong>'
),
'color' => $this->chart_colours['coupon_amount'],
'color' => $this->chart_colours['coupon_amount'],
'highlight_series' => 4,
);
@ -540,10 +560,10 @@ class WC_Report_Sales_By_Date extends WC_Admin_Report {
*/
public function output_report() {
$ranges = array(
'year' => __( 'Year', 'woocommerce' ),
'last_month' => __( 'Last month', 'woocommerce' ),
'month' => __( 'This month', 'woocommerce' ),
'7day' => __( 'Last 7 days', 'woocommerce' ),
'year' => __( 'Year', 'woocommerce' ),
'last_month' => __( 'Last month', 'woocommerce' ),
'month' => __( 'This month', 'woocommerce' ),
'7day' => __( 'Last 7 days', 'woocommerce' ),
);
$this->chart_colours = array(
@ -567,7 +587,7 @@ class WC_Report_Sales_By_Date extends WC_Admin_Report {
$this->check_current_range_nonce( $current_range );
$this->calculate_current_range( $current_range );
include( WC()->plugin_path() . '/includes/admin/views/html-report-by-date.php' );
include WC()->plugin_path() . '/includes/admin/views/html-report-by-date.php';
}
/**
@ -626,10 +646,10 @@ class WC_Report_Sales_By_Date extends WC_Admin_Report {
);
foreach ( $data['order_amounts'] as $order_amount_key => $order_amount_value ) {
$data['gross_order_amounts'][ $order_amount_key ] = $order_amount_value;
$data['gross_order_amounts'][ $order_amount_key ] = $order_amount_value;
$data['gross_order_amounts'][ $order_amount_key ][1] -= $data['refund_amounts'][ $order_amount_key ][1];
$data['net_order_amounts'][ $order_amount_key ] = $order_amount_value;
$data['net_order_amounts'][ $order_amount_key ] = $order_amount_value;
// subtract the sum of the values from net order amounts
$data['net_order_amounts'][ $order_amount_key ][1] -=
$data['refund_amounts'][ $order_amount_key ][1] +
@ -642,16 +662,18 @@ class WC_Report_Sales_By_Date extends WC_Admin_Report {
$data = apply_filters( 'woocommerce_admin_report_chart_data', $data );
// Encode in json format
$chart_data = json_encode( array(
'order_counts' => array_values( $data['order_counts'] ),
'order_item_counts' => array_values( $data['order_item_counts'] ),
'order_amounts' => array_map( array( $this, 'round_chart_totals' ), array_values( $data['order_amounts'] ) ),
'gross_order_amounts' => array_map( array( $this, 'round_chart_totals' ), array_values( $data['gross_order_amounts'] ) ),
'net_order_amounts' => array_map( array( $this, 'round_chart_totals' ), array_values( $data['net_order_amounts'] ) ),
'shipping_amounts' => array_map( array( $this, 'round_chart_totals' ), array_values( $data['shipping_amounts'] ) ),
'coupon_amounts' => array_map( array( $this, 'round_chart_totals' ), array_values( $data['coupon_amounts'] ) ),
'refund_amounts' => array_map( array( $this, 'round_chart_totals' ), array_values( $data['refund_amounts'] ) ),
) );
$chart_data = json_encode(
array(
'order_counts' => array_values( $data['order_counts'] ),
'order_item_counts' => array_values( $data['order_item_counts'] ),
'order_amounts' => array_map( array( $this, 'round_chart_totals' ), array_values( $data['order_amounts'] ) ),
'gross_order_amounts' => array_map( array( $this, 'round_chart_totals' ), array_values( $data['gross_order_amounts'] ) ),
'net_order_amounts' => array_map( array( $this, 'round_chart_totals' ), array_values( $data['net_order_amounts'] ) ),
'shipping_amounts' => array_map( array( $this, 'round_chart_totals' ), array_values( $data['shipping_amounts'] ) ),
'coupon_amounts' => array_map( array( $this, 'round_chart_totals' ), array_values( $data['coupon_amounts'] ) ),
'refund_amounts' => array_map( array( $this, 'round_chart_totals' ), array_values( $data['refund_amounts'] ) ),
)
);
?>
<div class="chart-container">
<div class="chart-placeholder main"></div>
@ -665,7 +687,7 @@ class WC_Report_Sales_By_Date extends WC_Admin_Report {
var drawGraph = function( highlight ) {
var series = [
{
label: "<?php echo esc_js( __( 'Number of items sold', 'woocommerce' ) ) ?>",
label: "<?php echo esc_js( __( 'Number of items sold', 'woocommerce' ) ); ?>",
data: order_data.order_item_counts,
color: '<?php echo $this->chart_colours['item_count']; ?>',
bars: { fillColor: '<?php echo $this->chart_colours['item_count']; ?>', fill: true, show: true, lineWidth: 0, barWidth: <?php echo $this->barwidth; ?> * 0.5, align: 'center' },
@ -673,7 +695,7 @@ class WC_Report_Sales_By_Date extends WC_Admin_Report {
hoverable: false
},
{
label: "<?php echo esc_js( __( 'Number of orders', 'woocommerce' ) ) ?>",
label: "<?php echo esc_js( __( 'Number of orders', 'woocommerce' ) ); ?>",
data: order_data.order_counts,
color: '<?php echo $this->chart_colours['order_count']; ?>',
bars: { fillColor: '<?php echo $this->chart_colours['order_count']; ?>', fill: true, show: true, lineWidth: 0, barWidth: <?php echo $this->barwidth; ?> * 0.5, align: 'center' },
@ -681,7 +703,7 @@ class WC_Report_Sales_By_Date extends WC_Admin_Report {
hoverable: false
},
{
label: "<?php echo esc_js( __( 'Average gross sales amount', 'woocommerce' ) ) ?>",
label: "<?php echo esc_js( __( 'Average gross sales amount', 'woocommerce' ) ); ?>",
data: [ [ <?php echo min( array_keys( $data['order_amounts'] ) ); ?>, <?php echo $this->report_data->average_total_sales; ?> ], [ <?php echo max( array_keys( $data['order_amounts'] ) ); ?>, <?php echo $this->report_data->average_total_sales; ?> ] ],
yaxis: 2,
color: '<?php echo $this->chart_colours['average']; ?>',
@ -691,7 +713,7 @@ class WC_Report_Sales_By_Date extends WC_Admin_Report {
hoverable: false
},
{
label: "<?php echo esc_js( __( 'Average net sales amount', 'woocommerce' ) ) ?>",
label: "<?php echo esc_js( __( 'Average net sales amount', 'woocommerce' ) ); ?>",
data: [ [ <?php echo min( array_keys( $data['order_amounts'] ) ); ?>, <?php echo $this->report_data->average_sales; ?> ], [ <?php echo max( array_keys( $data['order_amounts'] ) ); ?>, <?php echo $this->report_data->average_sales; ?> ] ],
yaxis: 2,
color: '<?php echo $this->chart_colours['net_average']; ?>',
@ -701,7 +723,7 @@ class WC_Report_Sales_By_Date extends WC_Admin_Report {
hoverable: false
},
{
label: "<?php echo esc_js( __( 'Coupon amount', 'woocommerce' ) ) ?>",
label: "<?php echo esc_js( __( 'Coupon amount', 'woocommerce' ) ); ?>",
data: order_data.coupon_amounts,
yaxis: 2,
color: '<?php echo $this->chart_colours['coupon_amount']; ?>',
@ -711,7 +733,7 @@ class WC_Report_Sales_By_Date extends WC_Admin_Report {
<?php echo $this->get_currency_tooltip(); ?>
},
{
label: "<?php echo esc_js( __( 'Shipping amount', 'woocommerce' ) ) ?>",
label: "<?php echo esc_js( __( 'Shipping amount', 'woocommerce' ) ); ?>",
data: order_data.shipping_amounts,
yaxis: 2,
color: '<?php echo $this->chart_colours['shipping_amount']; ?>',
@ -721,7 +743,7 @@ class WC_Report_Sales_By_Date extends WC_Admin_Report {
prepend_tooltip: "<?php echo get_woocommerce_currency_symbol(); ?>"
},
{
label: "<?php echo esc_js( __( 'Gross sales amount', 'woocommerce' ) ) ?>",
label: "<?php echo esc_js( __( 'Gross sales amount', 'woocommerce' ) ); ?>",
data: order_data.gross_order_amounts,
yaxis: 2,
color: '<?php echo $this->chart_colours['sales_amount']; ?>',
@ -731,7 +753,7 @@ class WC_Report_Sales_By_Date extends WC_Admin_Report {
<?php echo $this->get_currency_tooltip(); ?>
},
{
label: "<?php echo esc_js( __( 'Net sales amount', 'woocommerce' ) ) ?>",
label: "<?php echo esc_js( __( 'Net sales amount', 'woocommerce' ) ); ?>",
data: order_data.net_order_amounts,
yaxis: 2,
color: '<?php echo $this->chart_colours['net_sales_amount']; ?>',
@ -741,7 +763,7 @@ class WC_Report_Sales_By_Date extends WC_Admin_Report {
<?php echo $this->get_currency_tooltip(); ?>
},
{
label: "<?php echo esc_js( __( 'Refund amount', 'woocommerce' ) ) ?>",
label: "<?php echo esc_js( __( 'Refund amount', 'woocommerce' ) ); ?>",
data: order_data.refund_amounts,
yaxis: 2,
color: '<?php echo $this->chart_colours['refund_amount']; ?>',
@ -785,7 +807,7 @@ class WC_Report_Sales_By_Date extends WC_Admin_Report {
tickColor: 'transparent',
mode: "time",
timeformat: "<?php echo ( 'day' === $this->chart_groupby ) ? '%d %b' : '%b'; ?>",
monthNames: <?php echo json_encode( array_values( $wp_locale->month_abbrev ) ) ?>,
monthNames: <?php echo json_encode( array_values( $wp_locale->month_abbrev ) ); ?>,
tickLength: 1,
minTickSize: [1, "<?php echo $this->chart_groupby; ?>"],
font: {

View File

@ -24,14 +24,14 @@ class WC_Report_Sales_By_Product extends WC_Admin_Report {
*
* @var array
*/
public $chart_colours = array();
public $chart_colours = array();
/**
* Product ids.
*
* @var array
*/
public $product_ids = array();
public $product_ids = array();
/**
* Product ids with titles.
@ -62,63 +62,69 @@ class WC_Report_Sales_By_Product extends WC_Admin_Report {
return array();
}
$legend = array();
$legend = array();
$total_sales = $this->get_order_report_data( array(
'data' => array(
'_line_total' => array(
'type' => 'order_item_meta',
'order_item_type' => 'line_item',
'function' => 'SUM',
'name' => 'order_item_amount',
$total_sales = $this->get_order_report_data(
array(
'data' => array(
'_line_total' => array(
'type' => 'order_item_meta',
'order_item_type' => 'line_item',
'function' => 'SUM',
'name' => 'order_item_amount',
),
),
),
'where_meta' => array(
'relation' => 'OR',
array(
'type' => 'order_item_meta',
'meta_key' => array( '_product_id', '_variation_id' ),
'meta_value' => $this->product_ids,
'operator' => 'IN',
)
),
'query_type' => 'get_var',
'filter_range' => true,
) );
'where_meta' => array(
'relation' => 'OR',
array(
'type' => 'order_item_meta',
'meta_key' => array( '_product_id', '_variation_id' ),
'meta_value' => $this->product_ids,
'operator' => 'IN',
),
),
'query_type' => 'get_var',
'filter_range' => true,
)
);
$total_items = absint( $this->get_order_report_data( array(
'data' => array(
'_qty' => array(
'type' => 'order_item_meta',
'order_item_type' => 'line_item',
'function' => 'SUM',
'name' => 'order_item_count',
),
),
'where_meta' => array(
'relation' => 'OR',
$total_items = absint(
$this->get_order_report_data(
array(
'type' => 'order_item_meta',
'meta_key' => array( '_product_id', '_variation_id' ),
'meta_value' => $this->product_ids,
'operator' => 'IN',
'data' => array(
'_qty' => array(
'type' => 'order_item_meta',
'order_item_type' => 'line_item',
'function' => 'SUM',
'name' => 'order_item_count',
),
),
'where_meta' => array(
'relation' => 'OR',
array(
'type' => 'order_item_meta',
'meta_key' => array( '_product_id', '_variation_id' ),
'meta_value' => $this->product_ids,
'operator' => 'IN',
),
),
'query_type' => 'get_var',
'filter_range' => true,
)
),
'query_type' => 'get_var',
'filter_range' => true,
) ) );
)
);
$legend[] = array(
/* translators: %s: total items sold */
'title' => sprintf( __( '%s sales for the selected items', 'woocommerce' ), '<strong>' . wc_price( $total_sales ) . '</strong>' ),
'color' => $this->chart_colours['sales_amount'],
'title' => sprintf( __( '%s sales for the selected items', 'woocommerce' ), '<strong>' . wc_price( $total_sales ) . '</strong>' ),
'color' => $this->chart_colours['sales_amount'],
'highlight_series' => 1,
);
$legend[] = array(
/* translators: %s: total items purchased */
'title' => sprintf( __( '%s purchases for the selected items', 'woocommerce' ), '<strong>' . ( $total_items ) . '</strong>' ),
'color' => $this->chart_colours['item_count'],
'title' => sprintf( __( '%s purchases for the selected items', 'woocommerce' ), '<strong>' . ( $total_items ) . '</strong>' ),
'color' => $this->chart_colours['item_count'],
'highlight_series' => 0,
);
@ -131,10 +137,10 @@ class WC_Report_Sales_By_Product extends WC_Admin_Report {
public function output_report() {
$ranges = array(
'year' => __( 'Year', 'woocommerce' ),
'last_month' => __( 'Last month', 'woocommerce' ),
'month' => __( 'This month', 'woocommerce' ),
'7day' => __( 'Last 7 days', 'woocommerce' ),
'year' => __( 'Year', 'woocommerce' ),
'last_month' => __( 'Last month', 'woocommerce' ),
'month' => __( 'This month', 'woocommerce' ),
'7day' => __( 'Last 7 days', 'woocommerce' ),
);
$this->chart_colours = array(
@ -151,7 +157,7 @@ class WC_Report_Sales_By_Product extends WC_Admin_Report {
$this->check_current_range_nonce( $current_range );
$this->calculate_current_range( $current_range );
include( WC()->plugin_path() . '/includes/admin/views/html-report-by-date.php' );
include WC()->plugin_path() . '/includes/admin/views/html-report-by-date.php';
}
/**
@ -227,27 +233,29 @@ class WC_Report_Sales_By_Product extends WC_Admin_Report {
<div class="section">
<table cellspacing="0">
<?php
$top_sellers = $this->get_order_report_data( array(
'data' => array(
'_product_id' => array(
'type' => 'order_item_meta',
'order_item_type' => 'line_item',
'function' => '',
'name' => 'product_id',
$top_sellers = $this->get_order_report_data(
array(
'data' => array(
'_product_id' => array(
'type' => 'order_item_meta',
'order_item_type' => 'line_item',
'function' => '',
'name' => 'product_id',
),
'_qty' => array(
'type' => 'order_item_meta',
'order_item_type' => 'line_item',
'function' => 'SUM',
'name' => 'order_item_qty',
),
),
'_qty' => array(
'type' => 'order_item_meta',
'order_item_type' => 'line_item',
'function' => 'SUM',
'name' => 'order_item_qty',
),
),
'order_by' => 'order_item_qty DESC',
'group_by' => 'product_id',
'limit' => 12,
'query_type' => 'get_results',
'filter_range' => true,
) );
'order_by' => 'order_item_qty DESC',
'group_by' => 'product_id',
'limit' => 12,
'query_type' => 'get_results',
'filter_range' => true,
)
);
if ( $top_sellers ) {
// @codingStandardsIgnoreStart
@ -269,35 +277,37 @@ class WC_Report_Sales_By_Product extends WC_Admin_Report {
<div class="section">
<table cellspacing="0">
<?php
$top_freebies = $this->get_order_report_data( array(
'data' => array(
'_product_id' => array(
'type' => 'order_item_meta',
'order_item_type' => 'line_item',
'function' => '',
'name' => 'product_id',
$top_freebies = $this->get_order_report_data(
array(
'data' => array(
'_product_id' => array(
'type' => 'order_item_meta',
'order_item_type' => 'line_item',
'function' => '',
'name' => 'product_id',
),
'_qty' => array(
'type' => 'order_item_meta',
'order_item_type' => 'line_item',
'function' => 'SUM',
'name' => 'order_item_qty',
),
),
'_qty' => array(
'type' => 'order_item_meta',
'order_item_type' => 'line_item',
'function' => 'SUM',
'name' => 'order_item_qty',
'where_meta' => array(
array(
'type' => 'order_item_meta',
'meta_key' => '_line_subtotal',
'meta_value' => '0',
'operator' => '=',
),
),
),
'where_meta' => array(
array(
'type' => 'order_item_meta',
'meta_key' => '_line_subtotal',
'meta_value' => '0',
'operator' => '=',
),
),
'order_by' => 'order_item_qty DESC',
'group_by' => 'product_id',
'limit' => 12,
'query_type' => 'get_results',
'filter_range' => true,
) );
'order_by' => 'order_item_qty DESC',
'group_by' => 'product_id',
'limit' => 12,
'query_type' => 'get_results',
'filter_range' => true,
)
);
if ( $top_freebies ) {
// @codingStandardsIgnoreStart
@ -319,27 +329,29 @@ class WC_Report_Sales_By_Product extends WC_Admin_Report {
<div class="section">
<table cellspacing="0">
<?php
$top_earners = $this->get_order_report_data( array(
'data' => array(
'_product_id' => array(
'type' => 'order_item_meta',
'order_item_type' => 'line_item',
'function' => '',
'name' => 'product_id',
$top_earners = $this->get_order_report_data(
array(
'data' => array(
'_product_id' => array(
'type' => 'order_item_meta',
'order_item_type' => 'line_item',
'function' => '',
'name' => 'product_id',
),
'_line_total' => array(
'type' => 'order_item_meta',
'order_item_type' => 'line_item',
'function' => 'SUM',
'name' => 'order_item_total',
),
),
'_line_total' => array(
'type' => 'order_item_meta',
'order_item_type' => 'line_item',
'function' => 'SUM',
'name' => 'order_item_total',
),
),
'order_by' => 'order_item_total DESC',
'group_by' => 'product_id',
'limit' => 12,
'query_type' => 'get_results',
'filter_range' => true,
) );
'order_by' => 'order_item_total DESC',
'group_by' => 'product_id',
'limit' => 12,
'query_type' => 'get_results',
'filter_range' => true,
)
);
if ( $top_earners ) {
// @codingStandardsIgnoreStart
@ -413,85 +425,91 @@ class WC_Report_Sales_By_Product extends WC_Admin_Report {
<?php
} else {
// Get orders and dates in range - we want the SUM of order totals, COUNT of order items, COUNT of orders, and the date.
$order_item_counts = $this->get_order_report_data( array(
'data' => array(
'_qty' => array(
'type' => 'order_item_meta',
'order_item_type' => 'line_item',
'function' => 'SUM',
'name' => 'order_item_count',
$order_item_counts = $this->get_order_report_data(
array(
'data' => array(
'_qty' => array(
'type' => 'order_item_meta',
'order_item_type' => 'line_item',
'function' => 'SUM',
'name' => 'order_item_count',
),
'post_date' => array(
'type' => 'post_data',
'function' => '',
'name' => 'post_date',
),
'_product_id' => array(
'type' => 'order_item_meta',
'order_item_type' => 'line_item',
'function' => '',
'name' => 'product_id',
),
),
'post_date' => array(
'type' => 'post_data',
'function' => '',
'name' => 'post_date',
'where_meta' => array(
'relation' => 'OR',
array(
'type' => 'order_item_meta',
'meta_key' => array( '_product_id', '_variation_id' ),
'meta_value' => $this->product_ids,
'operator' => 'IN',
),
),
'_product_id' => array(
'type' => 'order_item_meta',
'order_item_type' => 'line_item',
'function' => '',
'name' => 'product_id',
),
),
'where_meta' => array(
'relation' => 'OR',
array(
'type' => 'order_item_meta',
'meta_key' => array( '_product_id', '_variation_id' ),
'meta_value' => $this->product_ids,
'operator' => 'IN',
),
),
'group_by' => 'product_id,' . $this->group_by_query,
'order_by' => 'post_date ASC',
'query_type' => 'get_results',
'filter_range' => true,
) );
'group_by' => 'product_id,' . $this->group_by_query,
'order_by' => 'post_date ASC',
'query_type' => 'get_results',
'filter_range' => true,
)
);
$order_item_amounts = $this->get_order_report_data( array(
'data' => array(
'_line_total' => array(
'type' => 'order_item_meta',
'order_item_type' => 'line_item',
'function' => 'SUM',
'name' => 'order_item_amount',
$order_item_amounts = $this->get_order_report_data(
array(
'data' => array(
'_line_total' => array(
'type' => 'order_item_meta',
'order_item_type' => 'line_item',
'function' => 'SUM',
'name' => 'order_item_amount',
),
'post_date' => array(
'type' => 'post_data',
'function' => '',
'name' => 'post_date',
),
'_product_id' => array(
'type' => 'order_item_meta',
'order_item_type' => 'line_item',
'function' => '',
'name' => 'product_id',
),
),
'post_date' => array(
'type' => 'post_data',
'function' => '',
'name' => 'post_date',
'where_meta' => array(
'relation' => 'OR',
array(
'type' => 'order_item_meta',
'meta_key' => array( '_product_id', '_variation_id' ),
'meta_value' => $this->product_ids,
'operator' => 'IN',
),
),
'_product_id' => array(
'type' => 'order_item_meta',
'order_item_type' => 'line_item',
'function' => '',
'name' => 'product_id',
),
),
'where_meta' => array(
'relation' => 'OR',
array(
'type' => 'order_item_meta',
'meta_key' => array( '_product_id', '_variation_id' ),
'meta_value' => $this->product_ids,
'operator' => 'IN',
),
),
'group_by' => 'product_id, ' . $this->group_by_query,
'order_by' => 'post_date ASC',
'query_type' => 'get_results',
'filter_range' => true,
) );
'group_by' => 'product_id, ' . $this->group_by_query,
'order_by' => 'post_date ASC',
'query_type' => 'get_results',
'filter_range' => true,
)
);
// Prepare data for report.
$order_item_counts = $this->prepare_chart_data( $order_item_counts, 'post_date', 'order_item_count', $this->chart_interval, $this->start_date, $this->chart_groupby );
$order_item_amounts = $this->prepare_chart_data( $order_item_amounts, 'post_date', 'order_item_amount', $this->chart_interval, $this->start_date, $this->chart_groupby );
// Encode in json format.
$chart_data = json_encode( array(
'order_item_counts' => array_values( $order_item_counts ),
'order_item_amounts' => array_values( $order_item_amounts ),
) );
$chart_data = json_encode(
array(
'order_item_counts' => array_values( $order_item_counts ),
'order_item_amounts' => array_values( $order_item_amounts ),
)
);
?>
<div class="chart-container">
<div class="chart-placeholder main"></div>

View File

@ -5,7 +5,7 @@ if ( ! defined( 'ABSPATH' ) ) {
}
if ( ! class_exists( 'WP_List_Table' ) ) {
require_once( ABSPATH . 'wp-admin/includes/class-wp-list-table.php' );
require_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php';
}
/**
@ -30,11 +30,13 @@ class WC_Report_Stock extends WP_List_Table {
*/
public function __construct() {
parent::__construct( array(
'singular' => 'stock',
'plural' => 'stock',
'ajax' => false,
) );
parent::__construct(
array(
'singular' => 'stock',
'plural' => 'stock',
'ajax' => false,
)
);
}
/**
@ -70,7 +72,7 @@ class WC_Report_Stock extends WP_List_Table {
/**
* Get column value.
*
* @param mixed $item
* @param mixed $item
* @param string $column_name
*/
public function column_default( $item, $column_name ) {
@ -86,7 +88,7 @@ class WC_Report_Stock extends WP_List_Table {
switch ( $column_name ) {
case 'product' :
case 'product':
if ( $sku = $product->get_sku() ) {
echo esc_html( $sku ) . ' - ';
}
@ -97,17 +99,17 @@ class WC_Report_Stock extends WP_List_Table {
if ( $product->is_type( 'variation' ) ) {
echo '<div class="description">' . wp_kses_post( wc_get_formatted_variation( $product, true ) ) . '</div>';
}
break;
break;
case 'parent' :
case 'parent':
if ( $item->parent ) {
echo esc_html( get_the_title( $item->parent ) );
} else {
echo '-';
}
break;
break;
case 'stock_status' :
case 'stock_status':
if ( $product->is_on_backorder() ) {
$stock_html = '<mark class="onbackorder">' . __( 'On backorder', 'woocommerce' ) . '</mark>';
} elseif ( $product->is_in_stock() ) {
@ -116,46 +118,47 @@ class WC_Report_Stock extends WP_List_Table {
$stock_html = '<mark class="outofstock">' . __( 'Out of stock', 'woocommerce' ) . '</mark>';
}
echo apply_filters( 'woocommerce_admin_stock_html', $stock_html, $product );
break;
break;
case 'stock_level' :
case 'stock_level':
echo esc_html( $product->get_stock_quantity() );
break;
break;
case 'wc_actions' :
case 'wc_actions':
?><p>
<?php
$actions = array();
$action_id = $product->is_type( 'variation' ) ? $item->parent : $item->id;
$actions = array();
$action_id = $product->is_type( 'variation' ) ? $item->parent : $item->id;
$actions['edit'] = array(
'url' => admin_url( 'post.php?post=' . $action_id . '&action=edit' ),
'name' => __( 'Edit', 'woocommerce' ),
'action' => "edit",
$actions['edit'] = array(
'url' => admin_url( 'post.php?post=' . $action_id . '&action=edit' ),
'name' => __( 'Edit', 'woocommerce' ),
'action' => 'edit',
);
if ( $product->is_visible() ) {
$actions['view'] = array(
'url' => get_permalink( $action_id ),
'name' => __( 'View', 'woocommerce' ),
'action' => 'view',
);
}
if ( $product->is_visible() ) {
$actions['view'] = array(
'url' => get_permalink( $action_id ),
'name' => __( 'View', 'woocommerce' ),
'action' => "view",
);
}
$actions = apply_filters( 'woocommerce_admin_stock_report_product_actions', $actions, $product );
$actions = apply_filters( 'woocommerce_admin_stock_report_product_actions', $actions, $product );
foreach ( $actions as $action ) {
printf(
'<a class="button tips %1$s" href="%2$s" data-tip="%3$s">%4$s</a>',
esc_attr( $action['action'] ),
esc_url( $action['url'] ),
sprintf( esc_attr__( '%s product', 'woocommerce' ), $action['name'] ),
esc_html( $action['name'] )
);
}
foreach ( $actions as $action ) {
printf(
'<a class="button tips %1$s" href="%2$s" data-tip="%3$s">%4$s</a>',
esc_attr( $action['action'] ),
esc_url( $action['url'] ),
sprintf( esc_attr__( '%s product', 'woocommerce' ), $action['name'] ),
esc_html( $action['name'] )
);
}
?>
</p><?php
break;
</p>
<?php
break;
}
}
@ -191,10 +194,12 @@ class WC_Report_Stock extends WP_List_Table {
/**
* Pagination.
*/
$this->set_pagination_args( array(
'total_items' => $this->max_items,
'per_page' => $per_page,
'total_pages' => ceil( $this->max_items / $per_page ),
) );
$this->set_pagination_args(
array(
'total_items' => $this->max_items,
'per_page' => $per_page,
'total_pages' => ceil( $this->max_items / $per_page ),
)
);
}
}

View File

@ -16,6 +16,7 @@ class WC_Report_Taxes_By_Code extends WC_Admin_Report {
/**
* Get the legend for the main chart sidebar.
*
* @return array
*/
public function get_chart_legend() {
@ -46,9 +47,9 @@ class WC_Report_Taxes_By_Code extends WC_Admin_Report {
public function output_report() {
$ranges = array(
'year' => __( 'Year', 'woocommerce' ),
'last_month' => __( 'Last month', 'woocommerce' ),
'month' => __( 'This month', 'woocommerce' ),
'year' => __( 'Year', 'woocommerce' ),
'last_month' => __( 'Last month', 'woocommerce' ),
'month' => __( 'This month', 'woocommerce' ),
);
$current_range = ! empty( $_GET['range'] ) ? sanitize_text_field( $_GET['range'] ) : 'last_month';
@ -62,7 +63,7 @@ class WC_Report_Taxes_By_Code extends WC_Admin_Report {
$hide_sidebar = true;
include( WC()->plugin_path() . '/includes/admin/views/html-report-by-date.php' );
include WC()->plugin_path() . '/includes/admin/views/html-report-by-date.php';
}
/**
@ -72,12 +73,12 @@ class WC_Report_Taxes_By_Code extends WC_Admin_Report {
global $wpdb;
$query_data = array(
'order_item_name' => array(
'order_item_name' => array(
'type' => 'order_item',
'function' => '',
'name' => 'tax_rate',
),
'tax_amount' => array(
'tax_amount' => array(
'type' => 'order_item_meta',
'order_item_type' => 'tax',
'function' => '',
@ -89,13 +90,13 @@ class WC_Report_Taxes_By_Code extends WC_Admin_Report {
'function' => '',
'name' => 'shipping_tax_amount',
),
'rate_id' => array(
'rate_id' => array(
'type' => 'order_item_meta',
'order_item_type' => 'tax',
'function' => '',
'name' => 'rate_id',
),
'ID' => array(
'ID' => array(
'type' => 'post_data',
'function' => '',
'name' => 'post_id',
@ -115,29 +116,35 @@ class WC_Report_Taxes_By_Code extends WC_Admin_Report {
),
);
$tax_rows_orders = $this->get_order_report_data( array(
'data' => $query_data,
'where' => $query_where,
'order_by' => 'posts.post_date ASC',
'query_type' => 'get_results',
'filter_range' => true,
'order_types' => array_merge( wc_get_order_types( 'sales-reports' ), array( 'shop_order_refund' ) ),
'order_status' => array( 'completed', 'processing', 'on-hold' ),
'parent_order_status' => array( 'completed', 'processing', 'on-hold' ), // Partial refunds inside refunded orders should be ignored
) );
$tax_rows_orders = $this->get_order_report_data(
array(
'data' => $query_data,
'where' => $query_where,
'order_by' => 'posts.post_date ASC',
'query_type' => 'get_results',
'filter_range' => true,
'order_types' => array_merge( wc_get_order_types( 'sales-reports' ), array( 'shop_order_refund' ) ),
'order_status' => array( 'completed', 'processing', 'on-hold' ),
'parent_order_status' => array( 'completed', 'processing', 'on-hold' ), // Partial refunds inside refunded orders should be ignored
)
);
// Merge
$tax_rows = array();
foreach ( $tax_rows_orders as $tax_row ) {
$key = $tax_row->rate_id;
$tax_rows[ $key ] = isset( $tax_rows[ $key ] ) ? $tax_rows[ $key ] : (object) array( 'tax_amount' => 0, 'shipping_tax_amount' => 0, 'total_orders' => 0 );
$tax_rows[ $key ] = isset( $tax_rows[ $key ] ) ? $tax_rows[ $key ] : (object) array(
'tax_amount' => 0,
'shipping_tax_amount' => 0,
'total_orders' => 0,
);
if ( 'shop_order_refund' !== get_post_type( $tax_row->post_id ) ) {
$tax_rows[ $key ]->total_orders += 1;
$tax_rows[ $key ]->total_orders += 1;
}
$tax_rows[ $key ]->tax_rate = $tax_row->tax_rate;
$tax_rows[ $key ]->tax_rate = $tax_row->tax_rate;
$tax_rows[ $key ]->tax_amount += wc_round_tax_total( $tax_row->tax_amount );
$tax_rows[ $key ]->shipping_tax_amount += wc_round_tax_total( $tax_row->shipping_tax_amount );
}

View File

@ -16,6 +16,7 @@ class WC_Report_Taxes_By_Date extends WC_Admin_Report {
/**
* Get the legend for the main chart sidebar.
*
* @return array
*/
public function get_chart_legend() {
@ -46,9 +47,9 @@ class WC_Report_Taxes_By_Date extends WC_Admin_Report {
public function output_report() {
$ranges = array(
'year' => __( 'Year', 'woocommerce' ),
'last_month' => __( 'Last month', 'woocommerce' ),
'month' => __( 'This month', 'woocommerce' ),
'year' => __( 'Year', 'woocommerce' ),
'last_month' => __( 'Last month', 'woocommerce' ),
'month' => __( 'This month', 'woocommerce' ),
);
$current_range = ! empty( $_GET['range'] ) ? sanitize_text_field( $_GET['range'] ) : 'last_month';
@ -62,7 +63,7 @@ class WC_Report_Taxes_By_Date extends WC_Admin_Report {
$hide_sidebar = true;
include( WC()->plugin_path() . '/includes/admin/views/html-report-by-date.php' );
include WC()->plugin_path() . '/includes/admin/views/html-report-by-date.php';
}
/**
@ -70,89 +71,95 @@ class WC_Report_Taxes_By_Date extends WC_Admin_Report {
*/
public function get_main_chart() {
$query_data = array(
'_order_tax' => array(
'type' => 'meta',
'function' => 'SUM',
'name' => 'tax_amount',
'_order_tax' => array(
'type' => 'meta',
'function' => 'SUM',
'name' => 'tax_amount',
),
'_order_shipping_tax' => array(
'type' => 'meta',
'function' => 'SUM',
'name' => 'shipping_tax_amount',
'type' => 'meta',
'function' => 'SUM',
'name' => 'shipping_tax_amount',
),
'_order_total' => array(
'_order_total' => array(
'type' => 'meta',
'function' => 'SUM',
'name' => 'total_sales',
),
'_order_shipping' => array(
'_order_shipping' => array(
'type' => 'meta',
'function' => 'SUM',
'name' => 'total_shipping',
),
'ID' => array(
'ID' => array(
'type' => 'post_data',
'function' => 'COUNT',
'name' => 'total_orders',
'distinct' => true,
),
'post_date' => array(
'post_date' => array(
'type' => 'post_data',
'function' => '',
'name' => 'post_date',
),
);
$tax_rows_orders = $this->get_order_report_data( array(
'data' => $query_data,
'group_by' => $this->group_by_query,
'order_by' => 'post_date ASC',
'query_type' => 'get_results',
'filter_range' => true,
'order_types' => wc_get_order_types( 'sales-reports' ),
'order_status' => array( 'completed', 'processing', 'on-hold', 'refunded' ),
) );
$tax_rows_orders = $this->get_order_report_data(
array(
'data' => $query_data,
'group_by' => $this->group_by_query,
'order_by' => 'post_date ASC',
'query_type' => 'get_results',
'filter_range' => true,
'order_types' => wc_get_order_types( 'sales-reports' ),
'order_status' => array( 'completed', 'processing', 'on-hold', 'refunded' ),
)
);
$tax_rows_full_refunds = $this->get_order_report_data( array(
'data' => array(
'ID' => array(
'type' => 'post_data',
'distinct' => true,
'function' => '',
'name' => 'ID',
$tax_rows_full_refunds = $this->get_order_report_data(
array(
'data' => array(
'ID' => array(
'type' => 'post_data',
'distinct' => true,
'function' => '',
'name' => 'ID',
),
'post_parent' => array(
'type' => 'post_data',
'function' => '',
'name' => 'post_parent',
),
'post_date' => array(
'type' => 'post_data',
'function' => '',
'name' => 'post_date',
),
),
'post_parent' => array(
'type' => 'post_data',
'function' => '',
'name' => 'post_parent',
),
'post_date' => array(
'type' => 'post_data',
'function' => '',
'name' => 'post_date',
),
),
'query_type' => 'get_results',
'filter_range' => true,
'order_types' => array( 'shop_order_refund' ),
'parent_order_status' => array( 'refunded' ),
) );
'query_type' => 'get_results',
'filter_range' => true,
'order_types' => array( 'shop_order_refund' ),
'parent_order_status' => array( 'refunded' ),
)
);
$tax_rows_partial_refunds = $this->get_order_report_data( array(
'data' => $query_data,
'group_by' => $this->group_by_query,
'order_by' => 'post_date ASC',
'query_type' => 'get_results',
'filter_range' => true,
'order_types' => array( 'shop_order_refund' ),
'parent_order_status' => array( 'completed', 'processing', 'on-hold' ), // Partial refunds inside refunded orders should be ignored.
) );
$tax_rows_partial_refunds = $this->get_order_report_data(
array(
'data' => $query_data,
'group_by' => $this->group_by_query,
'order_by' => 'post_date ASC',
'query_type' => 'get_results',
'filter_range' => true,
'order_types' => array( 'shop_order_refund' ),
'parent_order_status' => array( 'completed', 'processing', 'on-hold' ), // Partial refunds inside refunded orders should be ignored.
)
);
$tax_rows = array();
foreach ( $tax_rows_orders + $tax_rows_partial_refunds as $tax_row ) {
$key = date( ( 'month' === $this->chart_groupby ) ? 'Ym': 'Ymd', strtotime( $tax_row->post_date ) );
$tax_rows[ $key ] = isset( $tax_rows[ $key ] ) ? $tax_rows[ $key ]: (object) array(
$key = date( ( 'month' === $this->chart_groupby ) ? 'Ym' : 'Ymd', strtotime( $tax_row->post_date ) );
$tax_rows[ $key ] = isset( $tax_rows[ $key ] ) ? $tax_rows[ $key ] : (object) array(
'tax_amount' => 0,
'shipping_tax_amount' => 0,
'total_sales' => 0,
@ -162,7 +169,7 @@ class WC_Report_Taxes_By_Date extends WC_Admin_Report {
}
foreach ( $tax_rows_orders as $tax_row ) {
$key = date( ( 'month' === $this->chart_groupby ) ? 'Ym': 'Ymd', strtotime( $tax_row->post_date ) );
$key = date( ( 'month' === $this->chart_groupby ) ? 'Ym' : 'Ymd', strtotime( $tax_row->post_date ) );
$tax_rows[ $key ]->total_orders += $tax_row->total_orders;
$tax_rows[ $key ]->tax_amount += $tax_row->tax_amount;
$tax_rows[ $key ]->shipping_tax_amount += $tax_row->shipping_tax_amount;
@ -171,7 +178,7 @@ class WC_Report_Taxes_By_Date extends WC_Admin_Report {
}
foreach ( $tax_rows_partial_refunds as $tax_row ) {
$key = date( ( 'month' === $this->chart_groupby ) ? 'Ym': 'Ymd', strtotime( $tax_row->post_date ) );
$key = date( ( 'month' === $this->chart_groupby ) ? 'Ym' : 'Ymd', strtotime( $tax_row->post_date ) );
$tax_rows[ $key ]->tax_amount += $tax_row->tax_amount;
$tax_rows[ $key ]->shipping_tax_amount += $tax_row->shipping_tax_amount;
$tax_rows[ $key ]->total_sales += $tax_row->total_sales;
@ -180,7 +187,13 @@ class WC_Report_Taxes_By_Date extends WC_Admin_Report {
foreach ( $tax_rows_full_refunds as $tax_row ) {
$key = date( ( 'month' === $this->chart_groupby ) ? 'Ym' : 'Ymd', strtotime( $tax_row->post_date ) );
$tax_rows[ $key ] = isset( $tax_rows[ $key ] ) ? $tax_rows[ $key ] : (object) array( 'tax_amount' => 0, 'shipping_tax_amount' => 0, 'total_sales' => 0, 'total_shipping' => 0, 'total_orders' => 0 );
$tax_rows[ $key ] = isset( $tax_rows[ $key ] ) ? $tax_rows[ $key ] : (object) array(
'tax_amount' => 0,
'shipping_tax_amount' => 0,
'total_sales' => 0,
'total_shipping' => 0,
'total_orders' => 0,
);
$parent_order = wc_get_order( $tax_row->post_parent );
if ( $parent_order ) {
@ -199,7 +212,7 @@ class WC_Report_Taxes_By_Date extends WC_Admin_Report {
<th class="total_row"><?php _e( 'Total sales', 'woocommerce' ); ?> <?php echo wc_help_tip( __( "This is the sum of the 'Order total' field within your orders.", 'woocommerce' ) ); ?></th>
<th class="total_row"><?php _e( 'Total shipping', 'woocommerce' ); ?> <?php echo wc_help_tip( __( "This is the sum of the 'Shipping total' field within your orders.", 'woocommerce' ) ); ?></th>
<th class="total_row"><?php _e( 'Total tax', 'woocommerce' ); ?> <?php echo wc_help_tip( __( 'This is the total tax for the rate (shipping tax + product tax).', 'woocommerce' ) ); ?></th>
<th class="total_row"><?php _e( 'Net profit', 'woocommerce' ); ?> <?php echo wc_help_tip( __( "Total sales minus shipping and tax.", 'woocommerce' ) ); ?></th>
<th class="total_row"><?php _e( 'Net profit', 'woocommerce' ); ?> <?php echo wc_help_tip( __( 'Total sales minus shipping and tax.', 'woocommerce' ) ); ?></th>
</tr>
</thead>
<?php if ( ! empty( $tax_rows ) ) : ?>

View File

@ -14,178 +14,203 @@ if ( ! defined( 'ABSPATH' ) ) {
if ( ! class_exists( 'WC_Settings_Accounts', false ) ) :
/**
* WC_Settings_Accounts.
*/
class WC_Settings_Accounts extends WC_Settings_Page {
/**
* Constructor.
* WC_Settings_Accounts.
*/
public function __construct() {
$this->id = 'account';
$this->label = __( 'Accounts', 'woocommerce' );
class WC_Settings_Accounts extends WC_Settings_Page {
parent::__construct();
/**
* Constructor.
*/
public function __construct() {
$this->id = 'account';
$this->label = __( 'Accounts', 'woocommerce' );
parent::__construct();
}
/**
* Get settings array.
*
* @return array
*/
public function get_settings() {
$settings = apply_filters(
'woocommerce_' . $this->id . '_settings', array(
array(
'title' => __( 'Account pages', 'woocommerce' ),
'type' => 'title',
'desc' => __( 'These pages need to be set so that WooCommerce knows where to send users to access account related functionality.', 'woocommerce' ),
'id' => 'account_page_options',
),
array(
'title' => __( 'My account page', 'woocommerce' ),
'desc' => sprintf( __( 'Page contents: [%s]', 'woocommerce' ), apply_filters( 'woocommerce_my_account_shortcode_tag', 'woocommerce_my_account' ) ),
'id' => 'woocommerce_myaccount_page_id',
'type' => 'single_select_page',
'default' => '',
'class' => 'wc-enhanced-select-nostd',
'css' => 'min-width:300px;',
'desc_tip' => true,
),
array(
'type' => 'sectionend',
'id' => 'account_page_options',
),
array(
'title' => '',
'type' => 'title',
'id' => 'account_registration_options',
),
array(
'title' => __( 'Customer registration', 'woocommerce' ),
'desc' => __( 'Enable customer registration on the "Checkout" page.', 'woocommerce' ),
'id' => 'woocommerce_enable_signup_and_login_from_checkout',
'default' => 'yes',
'type' => 'checkbox',
'checkboxgroup' => 'start',
'autoload' => false,
),
array(
'desc' => __( 'Enable customer registration on the "My account" page.', 'woocommerce' ),
'id' => 'woocommerce_enable_myaccount_registration',
'default' => 'no',
'type' => 'checkbox',
'checkboxgroup' => 'end',
'autoload' => false,
),
array(
'title' => __( 'Login', 'woocommerce' ),
'desc' => __( 'Display returning customer login reminder on the "Checkout" page.', 'woocommerce' ),
'id' => 'woocommerce_enable_checkout_login_reminder',
'default' => 'yes',
'type' => 'checkbox',
'checkboxgroup' => 'start',
'autoload' => false,
),
array(
'title' => __( 'Account creation', 'woocommerce' ),
'desc' => __( 'Automatically generate username from customer email.', 'woocommerce' ),
'id' => 'woocommerce_registration_generate_username',
'default' => 'yes',
'type' => 'checkbox',
'checkboxgroup' => 'start',
'autoload' => false,
),
array(
'desc' => __( 'Automatically generate customer password', 'woocommerce' ),
'id' => 'woocommerce_registration_generate_password',
'default' => 'no',
'type' => 'checkbox',
'checkboxgroup' => 'end',
'autoload' => false,
),
array(
'type' => 'sectionend',
'id' => 'account_registration_options',
),
array(
'title' => __( 'My account endpoints', 'woocommerce' ),
'type' => 'title',
'desc' => __( 'Endpoints are appended to your page URLs to handle specific actions on the accounts pages. They should be unique and can be left blank to disable the endpoint.', 'woocommerce' ),
'id' => 'account_endpoint_options',
),
array(
'title' => __( 'Orders', 'woocommerce' ),
'desc' => __( 'Endpoint for the "My account &rarr; Orders" page.', 'woocommerce' ),
'id' => 'woocommerce_myaccount_orders_endpoint',
'type' => 'text',
'default' => 'orders',
'desc_tip' => true,
),
array(
'title' => __( 'View order', 'woocommerce' ),
'desc' => __( 'Endpoint for the "My account &rarr; View order" page.', 'woocommerce' ),
'id' => 'woocommerce_myaccount_view_order_endpoint',
'type' => 'text',
'default' => 'view-order',
'desc_tip' => true,
),
array(
'title' => __( 'Downloads', 'woocommerce' ),
'desc' => __( 'Endpoint for the "My account &rarr; Downloads" page.', 'woocommerce' ),
'id' => 'woocommerce_myaccount_downloads_endpoint',
'type' => 'text',
'default' => 'downloads',
'desc_tip' => true,
),
array(
'title' => __( 'Edit account', 'woocommerce' ),
'desc' => __( 'Endpoint for the "My account &rarr; Edit account" page.', 'woocommerce' ),
'id' => 'woocommerce_myaccount_edit_account_endpoint',
'type' => 'text',
'default' => 'edit-account',
'desc_tip' => true,
),
array(
'title' => __( 'Addresses', 'woocommerce' ),
'desc' => __( 'Endpoint for the "My account &rarr; Addresses" page.', 'woocommerce' ),
'id' => 'woocommerce_myaccount_edit_address_endpoint',
'type' => 'text',
'default' => 'edit-address',
'desc_tip' => true,
),
array(
'title' => __( 'Payment methods', 'woocommerce' ),
'desc' => __( 'Endpoint for the "My account &rarr; Payment methods" page.', 'woocommerce' ),
'id' => 'woocommerce_myaccount_payment_methods_endpoint',
'type' => 'text',
'default' => 'payment-methods',
'desc_tip' => true,
),
array(
'title' => __( 'Lost password', 'woocommerce' ),
'desc' => __( 'Endpoint for the "My account &rarr; Lost password" page.', 'woocommerce' ),
'id' => 'woocommerce_myaccount_lost_password_endpoint',
'type' => 'text',
'default' => 'lost-password',
'desc_tip' => true,
),
array(
'title' => __( 'Logout', 'woocommerce' ),
'desc' => __( 'Endpoint for the triggering logout. You can add this to your menus via a custom link: yoursite.com/?customer-logout=true', 'woocommerce' ),
'id' => 'woocommerce_logout_endpoint',
'type' => 'text',
'default' => 'customer-logout',
'desc_tip' => true,
),
array(
'type' => 'sectionend',
'id' => 'account_endpoint_options',
),
)
);
return apply_filters( 'woocommerce_get_settings_' . $this->id, $settings );
}
}
/**
* Get settings array.
*
* @return array
*/
public function get_settings() {
$settings = apply_filters( 'woocommerce_' . $this->id . '_settings', array(
array( 'title' => __( 'Account pages', 'woocommerce' ), 'type' => 'title', 'desc' => __( 'These pages need to be set so that WooCommerce knows where to send users to access account related functionality.', 'woocommerce' ), 'id' => 'account_page_options' ),
array(
'title' => __( 'My account page', 'woocommerce' ),
'desc' => sprintf( __( 'Page contents: [%s]', 'woocommerce' ), apply_filters( 'woocommerce_my_account_shortcode_tag', 'woocommerce_my_account' ) ),
'id' => 'woocommerce_myaccount_page_id',
'type' => 'single_select_page',
'default' => '',
'class' => 'wc-enhanced-select-nostd',
'css' => 'min-width:300px;',
'desc_tip' => true,
),
array( 'type' => 'sectionend', 'id' => 'account_page_options' ),
array( 'title' => '', 'type' => 'title', 'id' => 'account_registration_options' ),
array(
'title' => __( 'Customer registration', 'woocommerce' ),
'desc' => __( 'Enable customer registration on the "Checkout" page.', 'woocommerce' ),
'id' => 'woocommerce_enable_signup_and_login_from_checkout',
'default' => 'yes',
'type' => 'checkbox',
'checkboxgroup' => 'start',
'autoload' => false,
),
array(
'desc' => __( 'Enable customer registration on the "My account" page.', 'woocommerce' ),
'id' => 'woocommerce_enable_myaccount_registration',
'default' => 'no',
'type' => 'checkbox',
'checkboxgroup' => 'end',
'autoload' => false,
),
array(
'title' => __( 'Login', 'woocommerce' ),
'desc' => __( 'Display returning customer login reminder on the "Checkout" page.', 'woocommerce' ),
'id' => 'woocommerce_enable_checkout_login_reminder',
'default' => 'yes',
'type' => 'checkbox',
'checkboxgroup' => 'start',
'autoload' => false,
),
array(
'title' => __( 'Account creation', 'woocommerce' ),
'desc' => __( 'Automatically generate username from customer email.', 'woocommerce' ),
'id' => 'woocommerce_registration_generate_username',
'default' => 'yes',
'type' => 'checkbox',
'checkboxgroup' => 'start',
'autoload' => false,
),
array(
'desc' => __( 'Automatically generate customer password', 'woocommerce' ),
'id' => 'woocommerce_registration_generate_password',
'default' => 'no',
'type' => 'checkbox',
'checkboxgroup' => 'end',
'autoload' => false,
),
array( 'type' => 'sectionend', 'id' => 'account_registration_options' ),
array( 'title' => __( 'My account endpoints', 'woocommerce' ), 'type' => 'title', 'desc' => __( 'Endpoints are appended to your page URLs to handle specific actions on the accounts pages. They should be unique and can be left blank to disable the endpoint.', 'woocommerce' ), 'id' => 'account_endpoint_options' ),
array(
'title' => __( 'Orders', 'woocommerce' ),
'desc' => __( 'Endpoint for the "My account &rarr; Orders" page.', 'woocommerce' ),
'id' => 'woocommerce_myaccount_orders_endpoint',
'type' => 'text',
'default' => 'orders',
'desc_tip' => true,
),
array(
'title' => __( 'View order', 'woocommerce' ),
'desc' => __( 'Endpoint for the "My account &rarr; View order" page.', 'woocommerce' ),
'id' => 'woocommerce_myaccount_view_order_endpoint',
'type' => 'text',
'default' => 'view-order',
'desc_tip' => true,
),
array(
'title' => __( 'Downloads', 'woocommerce' ),
'desc' => __( 'Endpoint for the "My account &rarr; Downloads" page.', 'woocommerce' ),
'id' => 'woocommerce_myaccount_downloads_endpoint',
'type' => 'text',
'default' => 'downloads',
'desc_tip' => true,
),
array(
'title' => __( 'Edit account', 'woocommerce' ),
'desc' => __( 'Endpoint for the "My account &rarr; Edit account" page.', 'woocommerce' ),
'id' => 'woocommerce_myaccount_edit_account_endpoint',
'type' => 'text',
'default' => 'edit-account',
'desc_tip' => true,
),
array(
'title' => __( 'Addresses', 'woocommerce' ),
'desc' => __( 'Endpoint for the "My account &rarr; Addresses" page.', 'woocommerce' ),
'id' => 'woocommerce_myaccount_edit_address_endpoint',
'type' => 'text',
'default' => 'edit-address',
'desc_tip' => true,
),
array(
'title' => __( 'Payment methods', 'woocommerce' ),
'desc' => __( 'Endpoint for the "My account &rarr; Payment methods" page.', 'woocommerce' ),
'id' => 'woocommerce_myaccount_payment_methods_endpoint',
'type' => 'text',
'default' => 'payment-methods',
'desc_tip' => true,
),
array(
'title' => __( 'Lost password', 'woocommerce' ),
'desc' => __( 'Endpoint for the "My account &rarr; Lost password" page.', 'woocommerce' ),
'id' => 'woocommerce_myaccount_lost_password_endpoint',
'type' => 'text',
'default' => 'lost-password',
'desc_tip' => true,
),
array(
'title' => __( 'Logout', 'woocommerce' ),
'desc' => __( 'Endpoint for the triggering logout. You can add this to your menus via a custom link: yoursite.com/?customer-logout=true', 'woocommerce' ),
'id' => 'woocommerce_logout_endpoint',
'type' => 'text',
'default' => 'customer-logout',
'desc_tip' => true,
),
array( 'type' => 'sectionend', 'id' => 'account_endpoint_options' ),
) );
return apply_filters( 'woocommerce_get_settings_' . $this->id, $settings );
}
}
endif;
return new WC_Settings_Accounts();

View File

@ -14,371 +14,380 @@ if ( ! defined( 'ABSPATH' ) ) {
if ( ! class_exists( 'WC_Settings_Payment_Gateways', false ) ) :
/**
* WC_Settings_Payment_Gateways.
*/
class WC_Settings_Payment_Gateways extends WC_Settings_Page {
/**
* Constructor.
* WC_Settings_Payment_Gateways.
*/
public function __construct() {
$this->id = 'checkout';
$this->label = _x( 'Checkout', 'Settings tab label', 'woocommerce' );
class WC_Settings_Payment_Gateways extends WC_Settings_Page {
add_action( 'woocommerce_admin_field_payment_gateways', array( $this, 'payment_gateways_setting' ) );
parent::__construct();
}
/**
* Constructor.
*/
public function __construct() {
$this->id = 'checkout';
$this->label = _x( 'Checkout', 'Settings tab label', 'woocommerce' );
/**
* Get sections.
*
* @return array
*/
public function get_sections() {
$sections = array(
'' => __( 'Checkout options', 'woocommerce' ),
);
if ( ! defined( 'WC_INSTALLING' ) ) {
$payment_gateways = WC()->payment_gateways->payment_gateways();
foreach ( $payment_gateways as $gateway ) {
$title = empty( $gateway->method_title ) ? ucfirst( $gateway->id ) : $gateway->method_title;
$sections[ strtolower( $gateway->id ) ] = esc_html( $title );
}
add_action( 'woocommerce_admin_field_payment_gateways', array( $this, 'payment_gateways_setting' ) );
parent::__construct();
}
return apply_filters( 'woocommerce_get_sections_' . $this->id, $sections );
}
/**
* Get sections.
*
* @return array
*/
public function get_sections() {
$sections = array(
'' => __( 'Checkout options', 'woocommerce' ),
);
/**
* Get settings array.
*
* @param string $current_section
*
* @return array
*/
public function get_settings( $current_section = '' ) {
$settings = array();
if ( ! defined( 'WC_INSTALLING' ) ) {
$payment_gateways = WC()->payment_gateways->payment_gateways();
if ( '' === $current_section ) {
$settings = apply_filters( 'woocommerce_payment_gateways_settings', array(
array(
'title' => __( 'Checkout process', 'woocommerce' ),
'type' => 'title',
'id' => 'checkout_process_options',
),
array(
'title' => __( 'Coupons', 'woocommerce' ),
'desc' => __( 'Enable the use of coupons', 'woocommerce' ),
'id' => 'woocommerce_enable_coupons',
'default' => 'yes',
'type' => 'checkbox',
'checkboxgroup' => 'start',
'desc_tip' => __( 'Coupons can be applied from the cart and checkout pages.', 'woocommerce' ),
),
array(
'desc' => __( 'Calculate coupon discounts sequentially', 'woocommerce' ),
'id' => 'woocommerce_calc_discounts_sequentially',
'default' => 'no',
'type' => 'checkbox',
'desc_tip' => __( 'When applying multiple coupons, apply the first coupon to the full price and the second coupon to the discounted price and so on.', 'woocommerce' ),
'checkboxgroup' => 'end',
'autoload' => false,
),
array(
'title' => __( 'Checkout process', 'woocommerce' ),
'desc' => __( 'Enable guest checkout', 'woocommerce' ),
'desc_tip' => __( 'Allows customers to checkout without creating an account.', 'woocommerce' ),
'id' => 'woocommerce_enable_guest_checkout',
'default' => 'yes',
'type' => 'checkbox',
'checkboxgroup' => 'start',
'autoload' => false,
),
array(
'desc' => __( 'Force secure checkout', 'woocommerce' ),
'id' => 'woocommerce_force_ssl_checkout',
'default' => 'no',
'type' => 'checkbox',
'checkboxgroup' => '',
'show_if_checked' => 'option',
'desc_tip' => sprintf( __( 'Force SSL (HTTPS) on the checkout pages (<a href="%s" target="_blank">an SSL Certificate is required</a>).', 'woocommerce' ), 'https://docs.woocommerce.com/document/ssl-and-https/#section-3' ),
),
'unforce_ssl_checkout' => array(
'desc' => __( 'Force HTTP when leaving the checkout', 'woocommerce' ),
'id' => 'woocommerce_unforce_ssl_checkout',
'default' => 'no',
'type' => 'checkbox',
'checkboxgroup' => 'end',
'show_if_checked' => 'yes',
),
array(
'type' => 'sectionend',
'id' => 'checkout_process_options',
),
array(
'title' => __( 'Checkout pages', 'woocommerce' ),
'desc' => __( 'These pages need to be set so that WooCommerce knows where to send users to checkout.', 'woocommerce' ),
'type' => 'title',
'id' => 'checkout_page_options',
),
array(
'title' => __( 'Cart page', 'woocommerce' ),
'desc' => sprintf( __( 'Page contents: [%s]', 'woocommerce' ), apply_filters( 'woocommerce_cart_shortcode_tag', 'woocommerce_cart' ) ),
'id' => 'woocommerce_cart_page_id',
'type' => 'single_select_page',
'default' => '',
'class' => 'wc-enhanced-select-nostd',
'css' => 'min-width:300px;',
'desc_tip' => true,
),
array(
'title' => __( 'Checkout page', 'woocommerce' ),
'desc' => sprintf( __( 'Page contents: [%s]', 'woocommerce' ), apply_filters( 'woocommerce_checkout_shortcode_tag', 'woocommerce_checkout' ) ),
'id' => 'woocommerce_checkout_page_id',
'type' => 'single_select_page',
'default' => '',
'class' => 'wc-enhanced-select-nostd',
'css' => 'min-width:300px;',
'desc_tip' => true,
),
array(
'title' => __( 'Terms and conditions', 'woocommerce' ),
'desc' => __( 'If you define a "Terms" page the customer will be asked if they accept them when checking out.', 'woocommerce' ),
'id' => 'woocommerce_terms_page_id',
'default' => '',
'class' => 'wc-enhanced-select-nostd',
'css' => 'min-width:300px;',
'type' => 'single_select_page',
'args' => array( 'exclude' => wc_get_page_id( 'checkout' ) ),
'desc_tip' => true,
'autoload' => false,
),
array(
'type' => 'sectionend',
'id' => 'checkout_page_options',
),
array( 'title' => __( 'Checkout endpoints', 'woocommerce' ), 'type' => 'title', 'desc' => __( 'Endpoints are appended to your page URLs to handle specific actions during the checkout process. They should be unique.', 'woocommerce' ), 'id' => 'account_endpoint_options' ),
array(
'title' => __( 'Pay', 'woocommerce' ),
'desc' => __( 'Endpoint for the "Checkout &rarr; Pay" page.', 'woocommerce' ),
'id' => 'woocommerce_checkout_pay_endpoint',
'type' => 'text',
'default' => 'order-pay',
'desc_tip' => true,
),
array(
'title' => __( 'Order received', 'woocommerce' ),
'desc' => __( 'Endpoint for the "Checkout &rarr; Order received" page.', 'woocommerce' ),
'id' => 'woocommerce_checkout_order_received_endpoint',
'type' => 'text',
'default' => 'order-received',
'desc_tip' => true,
),
array(
'title' => __( 'Add payment method', 'woocommerce' ),
'desc' => __( 'Endpoint for the "Checkout &rarr; Add payment method" page.', 'woocommerce' ),
'id' => 'woocommerce_myaccount_add_payment_method_endpoint',
'type' => 'text',
'default' => 'add-payment-method',
'desc_tip' => true,
),
array(
'title' => __( 'Delete payment method', 'woocommerce' ),
'desc' => __( 'Endpoint for the delete payment method page.', 'woocommerce' ),
'id' => 'woocommerce_myaccount_delete_payment_method_endpoint',
'type' => 'text',
'default' => 'delete-payment-method',
'desc_tip' => true,
),
array(
'title' => __( 'Set default payment method', 'woocommerce' ),
'desc' => __( 'Endpoint for the setting a default payment method page.', 'woocommerce' ),
'id' => 'woocommerce_myaccount_set_default_payment_method_endpoint',
'type' => 'text',
'default' => 'set-default-payment-method',
'desc_tip' => true,
),
array(
'type' => 'sectionend',
'id' => 'checkout_endpoint_options',
),
array(
'title' => __( 'Payment gateways', 'woocommerce' ),
'desc' => __( 'Installed gateways are listed below. Drag and drop gateways to control their display order on the frontend.', 'woocommerce' ),
'type' => 'title',
'id' => 'payment_gateways_options',
),
array(
'type' => 'payment_gateways',
),
array(
'type' => 'sectionend',
'id' => 'payment_gateways_options',
),
) );
if ( wc_site_is_https() ) {
unset( $settings['unforce_ssl_checkout'] );
}
}
return apply_filters( 'woocommerce_get_settings_' . $this->id, $settings, $current_section );
}
/**
* Output the settings.
*/
public function output() {
global $current_section;
// Load shipping methods so we can show any global options they may have.
$payment_gateways = WC()->payment_gateways->payment_gateways();
if ( $current_section ) {
foreach ( $payment_gateways as $gateway ) {
if ( in_array( $current_section, array( $gateway->id, sanitize_title( get_class( $gateway ) ) ) ) ) {
$gateway->admin_options();
break;
foreach ( $payment_gateways as $gateway ) {
$title = empty( $gateway->method_title ) ? ucfirst( $gateway->id ) : $gateway->method_title;
$sections[ strtolower( $gateway->id ) ] = esc_html( $title );
}
}
} else {
$settings = $this->get_settings();
WC_Admin_Settings::output_fields( $settings );
return apply_filters( 'woocommerce_get_sections_' . $this->id, $sections );
}
}
/**
* Output payment gateway settings.
*/
public function payment_gateways_setting() {
?>
<tr valign="top">
<th scope="row" class="titledesc"><?php _e( 'Gateway display order', 'woocommerce' ) ?></th>
/**
* Get settings array.
*
* @param string $current_section
*
* @return array
*/
public function get_settings( $current_section = '' ) {
$settings = array();
if ( '' === $current_section ) {
$settings = apply_filters(
'woocommerce_payment_gateways_settings', array(
array(
'title' => __( 'Checkout process', 'woocommerce' ),
'type' => 'title',
'id' => 'checkout_process_options',
),
array(
'title' => __( 'Coupons', 'woocommerce' ),
'desc' => __( 'Enable the use of coupons', 'woocommerce' ),
'id' => 'woocommerce_enable_coupons',
'default' => 'yes',
'type' => 'checkbox',
'checkboxgroup' => 'start',
'desc_tip' => __( 'Coupons can be applied from the cart and checkout pages.', 'woocommerce' ),
),
array(
'desc' => __( 'Calculate coupon discounts sequentially', 'woocommerce' ),
'id' => 'woocommerce_calc_discounts_sequentially',
'default' => 'no',
'type' => 'checkbox',
'desc_tip' => __( 'When applying multiple coupons, apply the first coupon to the full price and the second coupon to the discounted price and so on.', 'woocommerce' ),
'checkboxgroup' => 'end',
'autoload' => false,
),
array(
'title' => __( 'Checkout process', 'woocommerce' ),
'desc' => __( 'Enable guest checkout', 'woocommerce' ),
'desc_tip' => __( 'Allows customers to checkout without creating an account.', 'woocommerce' ),
'id' => 'woocommerce_enable_guest_checkout',
'default' => 'yes',
'type' => 'checkbox',
'checkboxgroup' => 'start',
'autoload' => false,
),
array(
'desc' => __( 'Force secure checkout', 'woocommerce' ),
'id' => 'woocommerce_force_ssl_checkout',
'default' => 'no',
'type' => 'checkbox',
'checkboxgroup' => '',
'show_if_checked' => 'option',
'desc_tip' => sprintf( __( 'Force SSL (HTTPS) on the checkout pages (<a href="%s" target="_blank">an SSL Certificate is required</a>).', 'woocommerce' ), 'https://docs.woocommerce.com/document/ssl-and-https/#section-3' ),
),
'unforce_ssl_checkout' => array(
'desc' => __( 'Force HTTP when leaving the checkout', 'woocommerce' ),
'id' => 'woocommerce_unforce_ssl_checkout',
'default' => 'no',
'type' => 'checkbox',
'checkboxgroup' => 'end',
'show_if_checked' => 'yes',
),
array(
'type' => 'sectionend',
'id' => 'checkout_process_options',
),
array(
'title' => __( 'Checkout pages', 'woocommerce' ),
'desc' => __( 'These pages need to be set so that WooCommerce knows where to send users to checkout.', 'woocommerce' ),
'type' => 'title',
'id' => 'checkout_page_options',
),
array(
'title' => __( 'Cart page', 'woocommerce' ),
'desc' => sprintf( __( 'Page contents: [%s]', 'woocommerce' ), apply_filters( 'woocommerce_cart_shortcode_tag', 'woocommerce_cart' ) ),
'id' => 'woocommerce_cart_page_id',
'type' => 'single_select_page',
'default' => '',
'class' => 'wc-enhanced-select-nostd',
'css' => 'min-width:300px;',
'desc_tip' => true,
),
array(
'title' => __( 'Checkout page', 'woocommerce' ),
'desc' => sprintf( __( 'Page contents: [%s]', 'woocommerce' ), apply_filters( 'woocommerce_checkout_shortcode_tag', 'woocommerce_checkout' ) ),
'id' => 'woocommerce_checkout_page_id',
'type' => 'single_select_page',
'default' => '',
'class' => 'wc-enhanced-select-nostd',
'css' => 'min-width:300px;',
'desc_tip' => true,
),
array(
'title' => __( 'Terms and conditions', 'woocommerce' ),
'desc' => __( 'If you define a "Terms" page the customer will be asked if they accept them when checking out.', 'woocommerce' ),
'id' => 'woocommerce_terms_page_id',
'default' => '',
'class' => 'wc-enhanced-select-nostd',
'css' => 'min-width:300px;',
'type' => 'single_select_page',
'args' => array( 'exclude' => wc_get_page_id( 'checkout' ) ),
'desc_tip' => true,
'autoload' => false,
),
array(
'type' => 'sectionend',
'id' => 'checkout_page_options',
),
array(
'title' => __( 'Checkout endpoints', 'woocommerce' ),
'type' => 'title',
'desc' => __( 'Endpoints are appended to your page URLs to handle specific actions during the checkout process. They should be unique.', 'woocommerce' ),
'id' => 'account_endpoint_options',
),
array(
'title' => __( 'Pay', 'woocommerce' ),
'desc' => __( 'Endpoint for the "Checkout &rarr; Pay" page.', 'woocommerce' ),
'id' => 'woocommerce_checkout_pay_endpoint',
'type' => 'text',
'default' => 'order-pay',
'desc_tip' => true,
),
array(
'title' => __( 'Order received', 'woocommerce' ),
'desc' => __( 'Endpoint for the "Checkout &rarr; Order received" page.', 'woocommerce' ),
'id' => 'woocommerce_checkout_order_received_endpoint',
'type' => 'text',
'default' => 'order-received',
'desc_tip' => true,
),
array(
'title' => __( 'Add payment method', 'woocommerce' ),
'desc' => __( 'Endpoint for the "Checkout &rarr; Add payment method" page.', 'woocommerce' ),
'id' => 'woocommerce_myaccount_add_payment_method_endpoint',
'type' => 'text',
'default' => 'add-payment-method',
'desc_tip' => true,
),
array(
'title' => __( 'Delete payment method', 'woocommerce' ),
'desc' => __( 'Endpoint for the delete payment method page.', 'woocommerce' ),
'id' => 'woocommerce_myaccount_delete_payment_method_endpoint',
'type' => 'text',
'default' => 'delete-payment-method',
'desc_tip' => true,
),
array(
'title' => __( 'Set default payment method', 'woocommerce' ),
'desc' => __( 'Endpoint for the setting a default payment method page.', 'woocommerce' ),
'id' => 'woocommerce_myaccount_set_default_payment_method_endpoint',
'type' => 'text',
'default' => 'set-default-payment-method',
'desc_tip' => true,
),
array(
'type' => 'sectionend',
'id' => 'checkout_endpoint_options',
),
array(
'title' => __( 'Payment gateways', 'woocommerce' ),
'desc' => __( 'Installed gateways are listed below. Drag and drop gateways to control their display order on the frontend.', 'woocommerce' ),
'type' => 'title',
'id' => 'payment_gateways_options',
),
array(
'type' => 'payment_gateways',
),
array(
'type' => 'sectionend',
'id' => 'payment_gateways_options',
),
)
);
if ( wc_site_is_https() ) {
unset( $settings['unforce_ssl_checkout'] );
}
}
return apply_filters( 'woocommerce_get_settings_' . $this->id, $settings, $current_section );
}
/**
* Output the settings.
*/
public function output() {
global $current_section;
// Load shipping methods so we can show any global options they may have.
$payment_gateways = WC()->payment_gateways->payment_gateways();
if ( $current_section ) {
foreach ( $payment_gateways as $gateway ) {
if ( in_array( $current_section, array( $gateway->id, sanitize_title( get_class( $gateway ) ) ) ) ) {
$gateway->admin_options();
break;
}
}
} else {
$settings = $this->get_settings();
WC_Admin_Settings::output_fields( $settings );
}
}
/**
* Output payment gateway settings.
*/
public function payment_gateways_setting() {
?>
<tr valign="top">
<th scope="row" class="titledesc"><?php _e( 'Gateway display order', 'woocommerce' ); ?></th>
<td class="forminp">
<table class="wc_gateways widefat" cellspacing="0">
<thead>
<tr>
<?php
$columns = apply_filters( 'woocommerce_payment_gateways_setting_columns', array(
'sort' => '',
'name' => __( 'Gateway', 'woocommerce' ),
'id' => __( 'Gateway ID', 'woocommerce' ),
'status' => __( 'Enabled', 'woocommerce' ),
) );
foreach ( $columns as $key => $column ) {
echo '<th class="' . esc_attr( $key ) . '">' . esc_html( $column ) . '</th>';
}
?>
</tr>
</thead>
<tbody>
<?php
foreach ( WC()->payment_gateways->payment_gateways() as $gateway ) {
echo '<tr>';
$columns = apply_filters(
'woocommerce_payment_gateways_setting_columns', array(
'sort' => '',
'name' => __( 'Gateway', 'woocommerce' ),
'id' => __( 'Gateway ID', 'woocommerce' ),
'status' => __( 'Enabled', 'woocommerce' ),
)
);
foreach ( $columns as $key => $column ) {
echo '<th class="' . esc_attr( $key ) . '">' . esc_html( $column ) . '</th>';
}
?>
</tr>
</thead>
<tbody>
<?php
foreach ( WC()->payment_gateways->payment_gateways() as $gateway ) {
switch ( $key ) {
echo '<tr>';
case 'sort' :
echo '<td width="1%" class="sort">
foreach ( $columns as $key => $column ) {
switch ( $key ) {
case 'sort':
echo '<td width="1%" class="sort">
<input type="hidden" name="gateway_order[]" value="' . esc_attr( $gateway->id ) . '" />
</td>';
break;
break;
case 'name' :
$method_title = $gateway->get_title() ? $gateway->get_title() : __( '(no title)', 'woocommerce' );
echo '<td class="name">
case 'name':
$method_title = $gateway->get_title() ? $gateway->get_title() : __( '(no title)', 'woocommerce' );
echo '<td class="name">
<a href="' . admin_url( 'admin.php?page=wc-settings&tab=checkout&section=' . strtolower( $gateway->id ) ) . '">' . esc_html( $method_title ) . '</a>
</td>';
break;
break;
case 'id' :
echo '<td class="id">' . esc_html( $gateway->id ) . '</td>';
break;
case 'id':
echo '<td class="id">' . esc_html( $gateway->id ) . '</td>';
break;
case 'status' :
echo '<td class="status">';
echo ( 'yes' === $gateway->enabled ) ? '<span class="status-enabled tips" data-tip="' . esc_attr__( 'Yes', 'woocommerce' ) . '">' . esc_html__( 'Yes', 'woocommerce' ) . '</span>' : '-';
echo '</td>';
break;
case 'status':
echo '<td class="status">';
echo ( 'yes' === $gateway->enabled ) ? '<span class="status-enabled tips" data-tip="' . esc_attr__( 'Yes', 'woocommerce' ) . '">' . esc_html__( 'Yes', 'woocommerce' ) . '</span>' : '-';
echo '</td>';
break;
default :
do_action( 'woocommerce_payment_gateways_setting_column_' . $key, $gateway );
break;
default:
do_action( 'woocommerce_payment_gateways_setting_column_' . $key, $gateway );
break;
}
}
echo '</tr>';
}
?>
</tbody>
</table>
</td>
</tr>
<?php
}
echo '</tr>';
}
?>
</tbody>
</table>
</td>
</tr>
<?php
}
/**
* Save settings.
*/
public function save() {
global $current_section;
/**
* Save settings.
*/
public function save() {
global $current_section;
$wc_payment_gateways = WC_Payment_Gateways::instance();
$wc_payment_gateways = WC_Payment_Gateways::instance();
if ( ! $current_section ) {
// Prevent the T&Cs and checkout page from being set to the same page.
if ( isset( $_POST['woocommerce_terms_page_id'], $_POST['woocommerce_checkout_page_id'] ) && $_POST['woocommerce_terms_page_id'] === $_POST['woocommerce_checkout_page_id'] ) {
$_POST['woocommerce_terms_page_id'] = '';
}
if ( ! $current_section ) {
// Prevent the T&Cs and checkout page from being set to the same page.
if ( isset( $_POST['woocommerce_terms_page_id'], $_POST['woocommerce_checkout_page_id'] ) && $_POST['woocommerce_terms_page_id'] === $_POST['woocommerce_checkout_page_id'] ) {
$_POST['woocommerce_terms_page_id'] = '';
}
WC_Admin_Settings::save_fields( $this->get_settings() );
$wc_payment_gateways->process_admin_options();
WC_Admin_Settings::save_fields( $this->get_settings() );
$wc_payment_gateways->process_admin_options();
} else {
foreach ( $wc_payment_gateways->payment_gateways() as $gateway ) {
if ( in_array( $current_section, array( $gateway->id, sanitize_title( get_class( $gateway ) ) ) ) ) {
do_action( 'woocommerce_update_options_payment_gateways_' . $gateway->id );
$wc_payment_gateways->init();
} else {
foreach ( $wc_payment_gateways->payment_gateways() as $gateway ) {
if ( in_array( $current_section, array( $gateway->id, sanitize_title( get_class( $gateway ) ) ) ) ) {
do_action( 'woocommerce_update_options_payment_gateways_' . $gateway->id );
$wc_payment_gateways->init();
}
}
}
}
if ( $current_section ) {
do_action( 'woocommerce_update_options_' . $this->id . '_' . $current_section );
if ( $current_section ) {
do_action( 'woocommerce_update_options_' . $this->id . '_' . $current_section );
}
}
}
}
endif;

View File

@ -14,293 +14,325 @@ if ( ! defined( 'ABSPATH' ) ) {
if ( ! class_exists( 'WC_Settings_Emails', false ) ) :
/**
* WC_Settings_Emails.
*/
class WC_Settings_Emails extends WC_Settings_Page {
/**
* Constructor.
* WC_Settings_Emails.
*/
public function __construct() {
$this->id = 'email';
$this->label = __( 'Emails', 'woocommerce' );
class WC_Settings_Emails extends WC_Settings_Page {
add_action( 'woocommerce_admin_field_email_notification', array( $this, 'email_notification_setting' ) );
parent::__construct();
}
/**
* Constructor.
*/
public function __construct() {
$this->id = 'email';
$this->label = __( 'Emails', 'woocommerce' );
/**
* Get sections.
*
* @return array
*/
public function get_sections() {
$sections = array(
'' => __( 'Email options', 'woocommerce' ),
);
return apply_filters( 'woocommerce_get_sections_' . $this->id, $sections );
}
/**
* Get settings array.
*
* @return array
*/
public function get_settings() {
$settings = apply_filters( 'woocommerce_email_settings', array(
array( 'title' => __( 'Email notifications', 'woocommerce' ), 'desc' => __( 'Email notifications sent from WooCommerce are listed below. Click on an email to configure it.', 'woocommerce' ), 'type' => 'title', 'id' => 'email_notification_settings' ),
array( 'type' => 'email_notification' ),
array( 'type' => 'sectionend', 'id' => 'email_notification_settings' ),
array( 'type' => 'sectionend', 'id' => 'email_recipient_options' ),
array( 'title' => __( 'Email sender options', 'woocommerce' ), 'type' => 'title', 'desc' => '', 'id' => 'email_options' ),
array(
'title' => __( '"From" name', 'woocommerce' ),
'desc' => __( 'How the sender name appears in outgoing WooCommerce emails.', 'woocommerce' ),
'id' => 'woocommerce_email_from_name',
'type' => 'text',
'css' => 'min-width:300px;',
'default' => esc_attr( get_bloginfo( 'name', 'display' ) ),
'autoload' => false,
'desc_tip' => true,
),
array(
'title' => __( '"From" address', 'woocommerce' ),
'desc' => __( 'How the sender email appears in outgoing WooCommerce emails.', 'woocommerce' ),
'id' => 'woocommerce_email_from_address',
'type' => 'email',
'custom_attributes' => array(
'multiple' => 'multiple',
),
'css' => 'min-width:300px;',
'default' => get_option( 'admin_email' ),
'autoload' => false,
'desc_tip' => true,
),
array( 'type' => 'sectionend', 'id' => 'email_options' ),
array( 'title' => __( 'Email template', 'woocommerce' ), 'type' => 'title', 'desc' => sprintf( __( 'This section lets you customize the WooCommerce emails. <a href="%s" target="_blank">Click here to preview your email template</a>.', 'woocommerce' ), wp_nonce_url( admin_url( '?preview_woocommerce_mail=true' ), 'preview-mail' ) ), 'id' => 'email_template_options' ),
array(
'title' => __( 'Header image', 'woocommerce' ),
'desc' => __( 'URL to an image you want to show in the email header. Upload images using the media uploader (Admin > Media).', 'woocommerce' ),
'id' => 'woocommerce_email_header_image',
'type' => 'text',
'css' => 'min-width:300px;',
'placeholder' => __( 'N/A', 'woocommerce' ),
'default' => '',
'autoload' => false,
'desc_tip' => true,
),
array(
'title' => __( 'Footer text', 'woocommerce' ),
'desc' => __( 'The text to appear in the footer of WooCommerce emails.', 'woocommerce' )
. ' ' . sprintf( __( 'Available placeholders: %s', 'woocommerce' ), '{site_title}' ),
'id' => 'woocommerce_email_footer_text',
'css' => 'width:300px; height: 75px;',
'placeholder' => __( 'N/A', 'woocommerce' ),
'type' => 'textarea',
'default' => '{site_title}',
'autoload' => false,
'desc_tip' => true,
),
array(
'title' => __( 'Base color', 'woocommerce' ),
/* translators: %s: default color */
'desc' => sprintf( __( 'The base color for WooCommerce email templates. Default %s.', 'woocommerce' ), '<code>#96588a</code>' ),
'id' => 'woocommerce_email_base_color',
'type' => 'color',
'css' => 'width:6em;',
'default' => '#96588a',
'autoload' => false,
'desc_tip' => true,
),
array(
'title' => __( 'Background color', 'woocommerce' ),
/* translators: %s: default color */
'desc' => sprintf( __( 'The background color for WooCommerce email templates. Default %s.', 'woocommerce' ), '<code>#f7f7f7</code>' ),
'id' => 'woocommerce_email_background_color',
'type' => 'color',
'css' => 'width:6em;',
'default' => '#f7f7f7',
'autoload' => false,
'desc_tip' => true,
),
array(
'title' => __( 'Body background color', 'woocommerce' ),
/* translators: %s: default color */
'desc' => sprintf( __( 'The main body background color. Default %s.', 'woocommerce' ), '<code>#ffffff</code>' ),
'id' => 'woocommerce_email_body_background_color',
'type' => 'color',
'css' => 'width:6em;',
'default' => '#ffffff',
'autoload' => false,
'desc_tip' => true,
),
array(
'title' => __( 'Body text color', 'woocommerce' ),
/* translators: %s: default color */
'desc' => sprintf( __( 'The main body text color. Default %s.', 'woocommerce' ), '<code>#3c3c3c</code>' ),
'id' => 'woocommerce_email_text_color',
'type' => 'color',
'css' => 'width:6em;',
'default' => '#3c3c3c',
'autoload' => false,
'desc_tip' => true,
),
array( 'type' => 'sectionend', 'id' => 'email_template_options' ),
) );
return apply_filters( 'woocommerce_get_settings_' . $this->id, $settings );
}
/**
* Output the settings.
*/
public function output() {
global $current_section;
// Define emails that can be customised here
$mailer = WC()->mailer();
$email_templates = $mailer->get_emails();
if ( $current_section ) {
foreach ( $email_templates as $email_key => $email ) {
if ( strtolower( $email_key ) == $current_section ) {
$email->admin_options();
break;
}
}
} else {
$settings = $this->get_settings();
WC_Admin_Settings::output_fields( $settings );
add_action( 'woocommerce_admin_field_email_notification', array( $this, 'email_notification_setting' ) );
parent::__construct();
}
}
/**
* Save settings.
*/
public function save() {
global $current_section;
/**
* Get sections.
*
* @return array
*/
public function get_sections() {
$sections = array(
'' => __( 'Email options', 'woocommerce' ),
);
return apply_filters( 'woocommerce_get_sections_' . $this->id, $sections );
}
if ( ! $current_section ) {
WC_Admin_Settings::save_fields( $this->get_settings() );
/**
* Get settings array.
*
* @return array
*/
public function get_settings() {
$settings = apply_filters(
'woocommerce_email_settings', array(
} else {
$wc_emails = WC_Emails::instance();
array(
'title' => __( 'Email notifications', 'woocommerce' ),
'desc' => __( 'Email notifications sent from WooCommerce are listed below. Click on an email to configure it.', 'woocommerce' ),
'type' => 'title',
'id' => 'email_notification_settings',
),
if ( in_array( $current_section, array_map( 'sanitize_title', array_keys( $wc_emails->get_emails() ) ) ) ) {
foreach ( $wc_emails->get_emails() as $email_id => $email ) {
if ( sanitize_title( $email_id ) === $current_section ) {
do_action( 'woocommerce_update_options_' . $this->id . '_' . $email->id );
array( 'type' => 'email_notification' ),
array(
'type' => 'sectionend',
'id' => 'email_notification_settings',
),
array(
'type' => 'sectionend',
'id' => 'email_recipient_options',
),
array(
'title' => __( 'Email sender options', 'woocommerce' ),
'type' => 'title',
'desc' => '',
'id' => 'email_options',
),
array(
'title' => __( '"From" name', 'woocommerce' ),
'desc' => __( 'How the sender name appears in outgoing WooCommerce emails.', 'woocommerce' ),
'id' => 'woocommerce_email_from_name',
'type' => 'text',
'css' => 'min-width:300px;',
'default' => esc_attr( get_bloginfo( 'name', 'display' ) ),
'autoload' => false,
'desc_tip' => true,
),
array(
'title' => __( '"From" address', 'woocommerce' ),
'desc' => __( 'How the sender email appears in outgoing WooCommerce emails.', 'woocommerce' ),
'id' => 'woocommerce_email_from_address',
'type' => 'email',
'custom_attributes' => array(
'multiple' => 'multiple',
),
'css' => 'min-width:300px;',
'default' => get_option( 'admin_email' ),
'autoload' => false,
'desc_tip' => true,
),
array(
'type' => 'sectionend',
'id' => 'email_options',
),
array(
'title' => __( 'Email template', 'woocommerce' ),
'type' => 'title',
'desc' => sprintf( __( 'This section lets you customize the WooCommerce emails. <a href="%s" target="_blank">Click here to preview your email template</a>.', 'woocommerce' ), wp_nonce_url( admin_url( '?preview_woocommerce_mail=true' ), 'preview-mail' ) ),
'id' => 'email_template_options',
),
array(
'title' => __( 'Header image', 'woocommerce' ),
'desc' => __( 'URL to an image you want to show in the email header. Upload images using the media uploader (Admin > Media).', 'woocommerce' ),
'id' => 'woocommerce_email_header_image',
'type' => 'text',
'css' => 'min-width:300px;',
'placeholder' => __( 'N/A', 'woocommerce' ),
'default' => '',
'autoload' => false,
'desc_tip' => true,
),
array(
'title' => __( 'Footer text', 'woocommerce' ),
'desc' => __( 'The text to appear in the footer of WooCommerce emails.', 'woocommerce' )
. ' ' . sprintf( __( 'Available placeholders: %s', 'woocommerce' ), '{site_title}' ),
'id' => 'woocommerce_email_footer_text',
'css' => 'width:300px; height: 75px;',
'placeholder' => __( 'N/A', 'woocommerce' ),
'type' => 'textarea',
'default' => '{site_title}',
'autoload' => false,
'desc_tip' => true,
),
array(
'title' => __( 'Base color', 'woocommerce' ),
/* translators: %s: default color */
'desc' => sprintf( __( 'The base color for WooCommerce email templates. Default %s.', 'woocommerce' ), '<code>#96588a</code>' ),
'id' => 'woocommerce_email_base_color',
'type' => 'color',
'css' => 'width:6em;',
'default' => '#96588a',
'autoload' => false,
'desc_tip' => true,
),
array(
'title' => __( 'Background color', 'woocommerce' ),
/* translators: %s: default color */
'desc' => sprintf( __( 'The background color for WooCommerce email templates. Default %s.', 'woocommerce' ), '<code>#f7f7f7</code>' ),
'id' => 'woocommerce_email_background_color',
'type' => 'color',
'css' => 'width:6em;',
'default' => '#f7f7f7',
'autoload' => false,
'desc_tip' => true,
),
array(
'title' => __( 'Body background color', 'woocommerce' ),
/* translators: %s: default color */
'desc' => sprintf( __( 'The main body background color. Default %s.', 'woocommerce' ), '<code>#ffffff</code>' ),
'id' => 'woocommerce_email_body_background_color',
'type' => 'color',
'css' => 'width:6em;',
'default' => '#ffffff',
'autoload' => false,
'desc_tip' => true,
),
array(
'title' => __( 'Body text color', 'woocommerce' ),
/* translators: %s: default color */
'desc' => sprintf( __( 'The main body text color. Default %s.', 'woocommerce' ), '<code>#3c3c3c</code>' ),
'id' => 'woocommerce_email_text_color',
'type' => 'color',
'css' => 'width:6em;',
'default' => '#3c3c3c',
'autoload' => false,
'desc_tip' => true,
),
array(
'type' => 'sectionend',
'id' => 'email_template_options',
),
)
);
return apply_filters( 'woocommerce_get_settings_' . $this->id, $settings );
}
/**
* Output the settings.
*/
public function output() {
global $current_section;
// Define emails that can be customised here.
$mailer = WC()->mailer();
$email_templates = $mailer->get_emails();
if ( $current_section ) {
foreach ( $email_templates as $email_key => $email ) {
if ( strtolower( $email_key ) == $current_section ) {
$email->admin_options();
break;
}
}
} else {
do_action( 'woocommerce_update_options_' . $this->id . '_' . $current_section );
$settings = $this->get_settings();
WC_Admin_Settings::output_fields( $settings );
}
}
}
/**
* Output email notification settings.
*/
public function email_notification_setting() {
// Define emails that can be customised here
$mailer = WC()->mailer();
$email_templates = $mailer->get_emails();
?>
<tr valign="top">
<td class="wc_emails_wrapper" colspan="2">
/**
* Save settings.
*/
public function save() {
global $current_section;
if ( ! $current_section ) {
WC_Admin_Settings::save_fields( $this->get_settings() );
} else {
$wc_emails = WC_Emails::instance();
if ( in_array( $current_section, array_map( 'sanitize_title', array_keys( $wc_emails->get_emails() ) ) ) ) {
foreach ( $wc_emails->get_emails() as $email_id => $email ) {
if ( sanitize_title( $email_id ) === $current_section ) {
do_action( 'woocommerce_update_options_' . $this->id . '_' . $email->id );
}
}
} else {
do_action( 'woocommerce_update_options_' . $this->id . '_' . $current_section );
}
}
}
/**
* Output email notification settings.
*/
public function email_notification_setting() {
// Define emails that can be customised here.
$mailer = WC()->mailer();
$email_templates = $mailer->get_emails();
?>
<tr valign="top">
<td class="wc_emails_wrapper" colspan="2">
<table class="wc_emails widefat" cellspacing="0">
<thead>
<tr>
<?php
$columns = apply_filters( 'woocommerce_email_setting_columns', array(
$columns = apply_filters(
'woocommerce_email_setting_columns', array(
'status' => '',
'name' => __( 'Email', 'woocommerce' ),
'email_type' => __( 'Content type', 'woocommerce' ),
'recipient' => __( 'Recipient(s)', 'woocommerce' ),
'actions' => '',
) );
foreach ( $columns as $key => $column ) {
echo '<th class="wc-email-settings-table-' . esc_attr( $key ) . '">' . esc_html( $column ) . '</th>';
}
?>
</tr>
</thead>
<tbody>
<?php
foreach ( $email_templates as $email_key => $email ) {
echo '<tr>';
)
);
foreach ( $columns as $key => $column ) {
echo '<th class="wc-email-settings-table-' . esc_attr( $key ) . '">' . esc_html( $column ) . '</th>';
}
?>
</tr>
</thead>
<tbody>
<?php
foreach ( $email_templates as $email_key => $email ) {
echo '<tr>';
switch ( $key ) {
case 'name' :
echo '<td class="wc-email-settings-table-' . esc_attr( $key ) . '">
foreach ( $columns as $key => $column ) {
switch ( $key ) {
case 'name':
echo '<td class="wc-email-settings-table-' . esc_attr( $key ) . '">
<a href="' . admin_url( 'admin.php?page=wc-settings&tab=email&section=' . strtolower( $email_key ) ) . '">' . $email->get_title() . '</a>
' . wc_help_tip( $email->get_description() ) . '
</td>';
break;
case 'recipient' :
echo '<td class="wc-email-settings-table-' . esc_attr( $key ) . '">
break;
case 'recipient':
echo '<td class="wc-email-settings-table-' . esc_attr( $key ) . '">
' . esc_html( $email->is_customer_email() ? __( 'Customer', 'woocommerce' ) : $email->get_recipient() ) . '
</td>';
break;
case 'status' :
echo '<td class="wc-email-settings-table-' . esc_attr( $key ) . '">';
break;
case 'status':
echo '<td class="wc-email-settings-table-' . esc_attr( $key ) . '">';
if ( $email->is_manual() ) {
echo '<span class="status-manual tips" data-tip="' . esc_attr__( 'Manually sent', 'woocommerce' ) . '">' . esc_html__( 'Manual', 'woocommerce' ) . '</span>';
} elseif ( $email->is_enabled() ) {
echo '<span class="status-enabled tips" data-tip="' . esc_attr__( 'Enabled', 'woocommerce' ) . '">' . esc_html__( 'Yes', 'woocommerce' ) . '</span>';
} else {
echo '<span class="status-disabled tips" data-tip="' . esc_attr__( 'Disabled', 'woocommerce' ) . '">-</span>';
}
if ( $email->is_manual() ) {
echo '<span class="status-manual tips" data-tip="' . esc_attr__( 'Manually sent', 'woocommerce' ) . '">' . esc_html__( 'Manual', 'woocommerce' ) . '</span>';
} elseif ( $email->is_enabled() ) {
echo '<span class="status-enabled tips" data-tip="' . esc_attr__( 'Enabled', 'woocommerce' ) . '">' . esc_html__( 'Yes', 'woocommerce' ) . '</span>';
} else {
echo '<span class="status-disabled tips" data-tip="' . esc_attr__( 'Disabled', 'woocommerce' ) . '">-</span>';
}
echo '</td>';
break;
case 'email_type' :
echo '<td class="wc-email-settings-table-' . esc_attr( $key ) . '">
echo '</td>';
break;
case 'email_type':
echo '<td class="wc-email-settings-table-' . esc_attr( $key ) . '">
' . esc_html( $email->get_content_type() ) . '
</td>';
break;
case 'actions' :
echo '<td class="wc-email-settings-table-' . esc_attr( $key ) . '">
break;
case 'actions':
echo '<td class="wc-email-settings-table-' . esc_attr( $key ) . '">
<a class="button alignright tips" data-tip="' . esc_attr__( 'Configure', 'woocommerce' ) . '" href="' . admin_url( 'admin.php?page=wc-settings&tab=email&section=' . strtolower( $email_key ) ) . '">' . esc_html__( 'Configure', 'woocommerce' ) . '</a>
</td>';
break;
default :
do_action( 'woocommerce_email_setting_column_' . $key, $email );
break;
break;
default:
do_action( 'woocommerce_email_setting_column_' . $key, $email );
break;
}
}
}
echo '</tr>';
}
?>
</tbody>
</table>
</td>
</tr>
<?php
echo '</tr>';
}
?>
</tbody>
</table>
</td>
</tr>
<?php
}
}
}
endif;

View File

@ -14,314 +14,345 @@ if ( ! defined( 'ABSPATH' ) ) {
if ( ! class_exists( 'WC_Settings_General', false ) ) :
/**
* WC_Admin_Settings_General.
*/
class WC_Settings_General extends WC_Settings_Page {
/**
* Constructor.
* WC_Admin_Settings_General.
*/
public function __construct() {
$this->id = 'general';
$this->label = __( 'General', 'woocommerce' );
class WC_Settings_General extends WC_Settings_Page {
parent::__construct();
}
/**
* Constructor.
*/
public function __construct() {
$this->id = 'general';
$this->label = __( 'General', 'woocommerce' );
/**
* Get settings array.
*
* @return array
*/
public function get_settings() {
$currency_code_options = get_woocommerce_currencies();
foreach ( $currency_code_options as $code => $name ) {
$currency_code_options[ $code ] = $name . ' (' . get_woocommerce_currency_symbol( $code ) . ')';
parent::__construct();
}
$settings = apply_filters( 'woocommerce_general_settings', array(
/**
* Get settings array.
*
* @return array
*/
public function get_settings() {
array(
'title' => __( 'Store Address', 'woocommerce' ),
'type' => 'title',
'desc' => __( 'This is where your business is located. Tax rates and shipping rates will use this address.', 'woocommerce' ),
'id' => 'store_address',
),
$currency_code_options = get_woocommerce_currencies();
array(
'title' => __( 'Address line 1', 'woocommerce' ),
'desc' => __( 'The street address for your business location.', 'woocommerce' ),
'id' => 'woocommerce_store_address',
'default' => '',
'type' => 'text',
'desc_tip' => true,
),
foreach ( $currency_code_options as $code => $name ) {
$currency_code_options[ $code ] = $name . ' (' . get_woocommerce_currency_symbol( $code ) . ')';
}
array(
'title' => __( 'Address line 2', 'woocommerce' ),
'desc' => __( 'An additional, optional address line for your business location.', 'woocommerce' ),
'id' => 'woocommerce_store_address_2',
'default' => '',
'type' => 'text',
'desc_tip' => true,
),
$settings = apply_filters(
'woocommerce_general_settings', array(
array(
'title' => __( 'City', 'woocommerce' ),
'desc' => __( 'The city in which your business is located.', 'woocommerce' ),
'id' => 'woocommerce_store_city',
'default' => '',
'type' => 'text',
'desc_tip' => true,
),
array(
'title' => __( 'Store Address', 'woocommerce' ),
'type' => 'title',
'desc' => __( 'This is where your business is located. Tax rates and shipping rates will use this address.', 'woocommerce' ),
'id' => 'store_address',
),
array(
'title' => __( 'Country / State', 'woocommerce' ),
'desc' => __( 'The country and state or province, if any, in which your business is located.', 'woocommerce' ),
'id' => 'woocommerce_default_country',
'default' => 'GB',
'type' => 'single_select_country',
'desc_tip' => true,
),
array(
'title' => __( 'Address line 1', 'woocommerce' ),
'desc' => __( 'The street address for your business location.', 'woocommerce' ),
'id' => 'woocommerce_store_address',
'default' => '',
'type' => 'text',
'desc_tip' => true,
),
array(
'title' => __( 'Postcode / ZIP', 'woocommerce' ),
'desc' => __( 'The postal code, if any, in which your business is located.', 'woocommerce' ),
'id' => 'woocommerce_store_postcode',
'css' => 'min-width:50px;',
'default' => '',
'type' => 'text',
'desc_tip' => true,
),
array(
'title' => __( 'Address line 2', 'woocommerce' ),
'desc' => __( 'An additional, optional address line for your business location.', 'woocommerce' ),
'id' => 'woocommerce_store_address_2',
'default' => '',
'type' => 'text',
'desc_tip' => true,
),
array( 'type' => 'sectionend', 'id' => 'store_address' ),
array(
'title' => __( 'City', 'woocommerce' ),
'desc' => __( 'The city in which your business is located.', 'woocommerce' ),
'id' => 'woocommerce_store_city',
'default' => '',
'type' => 'text',
'desc_tip' => true,
),
array( 'title' => __( 'General options', 'woocommerce' ), 'type' => 'title', 'desc' => '', 'id' => 'general_options' ),
array(
'title' => __( 'Country / State', 'woocommerce' ),
'desc' => __( 'The country and state or province, if any, in which your business is located.', 'woocommerce' ),
'id' => 'woocommerce_default_country',
'default' => 'GB',
'type' => 'single_select_country',
'desc_tip' => true,
),
array(
'title' => __( 'Selling location(s)', 'woocommerce' ),
'desc' => __( 'This option lets you limit which countries you are willing to sell to.', 'woocommerce' ),
'id' => 'woocommerce_allowed_countries',
'default' => 'all',
'type' => 'select',
'class' => 'wc-enhanced-select',
'css' => 'min-width: 350px;',
'desc_tip' => true,
'options' => array(
'all' => __( 'Sell to all countries', 'woocommerce' ),
'all_except' => __( 'Sell to all countries, except for&hellip;', 'woocommerce' ),
'specific' => __( 'Sell to specific countries', 'woocommerce' ),
),
),
array(
'title' => __( 'Postcode / ZIP', 'woocommerce' ),
'desc' => __( 'The postal code, if any, in which your business is located.', 'woocommerce' ),
'id' => 'woocommerce_store_postcode',
'css' => 'min-width:50px;',
'default' => '',
'type' => 'text',
'desc_tip' => true,
),
array(
'title' => __( 'Sell to all countries, except for&hellip;', 'woocommerce' ),
'desc' => '',
'id' => 'woocommerce_all_except_countries',
'css' => 'min-width: 350px;',
'default' => '',
'type' => 'multi_select_countries',
),
array(
'type' => 'sectionend',
'id' => 'store_address',
),
array(
'title' => __( 'Sell to specific countries', 'woocommerce' ),
'desc' => '',
'id' => 'woocommerce_specific_allowed_countries',
'css' => 'min-width: 350px;',
'default' => '',
'type' => 'multi_select_countries',
),
array(
'title' => __( 'General options', 'woocommerce' ),
'type' => 'title',
'desc' => '',
'id' => 'general_options',
),
array(
'title' => __( 'Shipping location(s)', 'woocommerce' ),
'desc' => __( 'Choose which countries you want to ship to, or choose to ship to all locations you sell to.', 'woocommerce' ),
'id' => 'woocommerce_ship_to_countries',
'default' => '',
'type' => 'select',
'class' => 'wc-enhanced-select',
'desc_tip' => true,
'options' => array(
'' => __( 'Ship to all countries you sell to', 'woocommerce' ),
'all' => __( 'Ship to all countries', 'woocommerce' ),
'specific' => __( 'Ship to specific countries only', 'woocommerce' ),
'disabled' => __( 'Disable shipping &amp; shipping calculations', 'woocommerce' ),
),
),
array(
'title' => __( 'Selling location(s)', 'woocommerce' ),
'desc' => __( 'This option lets you limit which countries you are willing to sell to.', 'woocommerce' ),
'id' => 'woocommerce_allowed_countries',
'default' => 'all',
'type' => 'select',
'class' => 'wc-enhanced-select',
'css' => 'min-width: 350px;',
'desc_tip' => true,
'options' => array(
'all' => __( 'Sell to all countries', 'woocommerce' ),
'all_except' => __( 'Sell to all countries, except for&hellip;', 'woocommerce' ),
'specific' => __( 'Sell to specific countries', 'woocommerce' ),
),
),
array(
'title' => __( 'Ship to specific countries', 'woocommerce' ),
'desc' => '',
'id' => 'woocommerce_specific_ship_to_countries',
'css' => '',
'default' => '',
'type' => 'multi_select_countries',
),
array(
'title' => __( 'Sell to all countries, except for&hellip;', 'woocommerce' ),
'desc' => '',
'id' => 'woocommerce_all_except_countries',
'css' => 'min-width: 350px;',
'default' => '',
'type' => 'multi_select_countries',
),
array(
'title' => __( 'Default customer location', 'woocommerce' ),
'id' => 'woocommerce_default_customer_address',
'desc_tip' => __( 'This option determines a customers default location. The MaxMind GeoLite Database will be periodically downloaded to your wp-content directory if using geolocation.', 'woocommerce' ),
'default' => 'geolocation',
'type' => 'select',
'class' => 'wc-enhanced-select',
'options' => array(
'' => __( 'No location by default', 'woocommerce' ),
'base' => __( 'Shop base address', 'woocommerce' ),
'geolocation' => __( 'Geolocate', 'woocommerce' ),
'geolocation_ajax' => __( 'Geolocate (with page caching support)', 'woocommerce' ),
),
),
array(
'title' => __( 'Sell to specific countries', 'woocommerce' ),
'desc' => '',
'id' => 'woocommerce_specific_allowed_countries',
'css' => 'min-width: 350px;',
'default' => '',
'type' => 'multi_select_countries',
),
array(
'title' => __( 'Enable taxes', 'woocommerce' ),
'desc' => __( 'Enable taxes and tax calculations', 'woocommerce' ),
'id' => 'woocommerce_calc_taxes',
'default' => 'no',
'type' => 'checkbox',
),
array(
'title' => __( 'Shipping location(s)', 'woocommerce' ),
'desc' => __( 'Choose which countries you want to ship to, or choose to ship to all locations you sell to.', 'woocommerce' ),
'id' => 'woocommerce_ship_to_countries',
'default' => '',
'type' => 'select',
'class' => 'wc-enhanced-select',
'desc_tip' => true,
'options' => array(
'' => __( 'Ship to all countries you sell to', 'woocommerce' ),
'all' => __( 'Ship to all countries', 'woocommerce' ),
'specific' => __( 'Ship to specific countries only', 'woocommerce' ),
'disabled' => __( 'Disable shipping &amp; shipping calculations', 'woocommerce' ),
),
),
array( 'type' => 'sectionend', 'id' => 'general_options' ),
array(
'title' => __( 'Ship to specific countries', 'woocommerce' ),
'desc' => '',
'id' => 'woocommerce_specific_ship_to_countries',
'css' => '',
'default' => '',
'type' => 'multi_select_countries',
),
array( 'title' => __( 'Currency options', 'woocommerce' ), 'type' => 'title', 'desc' => __( 'The following options affect how prices are displayed on the frontend.', 'woocommerce' ), 'id' => 'pricing_options' ),
array(
'title' => __( 'Default customer location', 'woocommerce' ),
'id' => 'woocommerce_default_customer_address',
'desc_tip' => __( 'This option determines a customers default location. The MaxMind GeoLite Database will be periodically downloaded to your wp-content directory if using geolocation.', 'woocommerce' ),
'default' => 'geolocation',
'type' => 'select',
'class' => 'wc-enhanced-select',
'options' => array(
'' => __( 'No location by default', 'woocommerce' ),
'base' => __( 'Shop base address', 'woocommerce' ),
'geolocation' => __( 'Geolocate', 'woocommerce' ),
'geolocation_ajax' => __( 'Geolocate (with page caching support)', 'woocommerce' ),
),
),
array(
'title' => __( 'Currency', 'woocommerce' ),
'desc' => __( 'This controls what currency prices are listed at in the catalog and which currency gateways will take payments in.', 'woocommerce' ),
'id' => 'woocommerce_currency',
'default' => 'GBP',
'type' => 'select',
'class' => 'wc-enhanced-select',
'desc_tip' => true,
'options' => $currency_code_options,
),
array(
'title' => __( 'Enable taxes', 'woocommerce' ),
'desc' => __( 'Enable taxes and tax calculations', 'woocommerce' ),
'id' => 'woocommerce_calc_taxes',
'default' => 'no',
'type' => 'checkbox',
),
array(
'title' => __( 'Currency position', 'woocommerce' ),
'desc' => __( 'This controls the position of the currency symbol.', 'woocommerce' ),
'id' => 'woocommerce_currency_pos',
'class' => 'wc-enhanced-select',
'default' => 'left',
'type' => 'select',
'options' => array(
'left' => __( 'Left', 'woocommerce' ),
'right' => __( 'Right', 'woocommerce' ),
'left_space' => __( 'Left with space', 'woocommerce' ),
'right_space' => __( 'Right with space', 'woocommerce' ),
),
'desc_tip' => true,
),
array(
'type' => 'sectionend',
'id' => 'general_options',
),
array(
'title' => __( 'Thousand separator', 'woocommerce' ),
'desc' => __( 'This sets the thousand separator of displayed prices.', 'woocommerce' ),
'id' => 'woocommerce_price_thousand_sep',
'css' => 'width:50px;',
'default' => ',',
'type' => 'text',
'desc_tip' => true,
),
array(
'title' => __( 'Currency options', 'woocommerce' ),
'type' => 'title',
'desc' => __( 'The following options affect how prices are displayed on the frontend.', 'woocommerce' ),
'id' => 'pricing_options',
),
array(
'title' => __( 'Decimal separator', 'woocommerce' ),
'desc' => __( 'This sets the decimal separator of displayed prices.', 'woocommerce' ),
'id' => 'woocommerce_price_decimal_sep',
'css' => 'width:50px;',
'default' => '.',
'type' => 'text',
'desc_tip' => true,
),
array(
'title' => __( 'Currency', 'woocommerce' ),
'desc' => __( 'This controls what currency prices are listed at in the catalog and which currency gateways will take payments in.', 'woocommerce' ),
'id' => 'woocommerce_currency',
'default' => 'GBP',
'type' => 'select',
'class' => 'wc-enhanced-select',
'desc_tip' => true,
'options' => $currency_code_options,
),
array(
'title' => __( 'Number of decimals', 'woocommerce' ),
'desc' => __( 'This sets the number of decimal points shown in displayed prices.', 'woocommerce' ),
'id' => 'woocommerce_price_num_decimals',
'css' => 'width:50px;',
'default' => '2',
'desc_tip' => true,
'type' => 'number',
'custom_attributes' => array(
'min' => 0,
'step' => 1,
),
),
array(
'title' => __( 'Currency position', 'woocommerce' ),
'desc' => __( 'This controls the position of the currency symbol.', 'woocommerce' ),
'id' => 'woocommerce_currency_pos',
'class' => 'wc-enhanced-select',
'default' => 'left',
'type' => 'select',
'options' => array(
'left' => __( 'Left', 'woocommerce' ),
'right' => __( 'Right', 'woocommerce' ),
'left_space' => __( 'Left with space', 'woocommerce' ),
'right_space' => __( 'Right with space', 'woocommerce' ),
),
'desc_tip' => true,
),
array( 'type' => 'sectionend', 'id' => 'pricing_options' ),
array(
'title' => __( 'Thousand separator', 'woocommerce' ),
'desc' => __( 'This sets the thousand separator of displayed prices.', 'woocommerce' ),
'id' => 'woocommerce_price_thousand_sep',
'css' => 'width:50px;',
'default' => ',',
'type' => 'text',
'desc_tip' => true,
),
) );
array(
'title' => __( 'Decimal separator', 'woocommerce' ),
'desc' => __( 'This sets the decimal separator of displayed prices.', 'woocommerce' ),
'id' => 'woocommerce_price_decimal_sep',
'css' => 'width:50px;',
'default' => '.',
'type' => 'text',
'desc_tip' => true,
),
return apply_filters( 'woocommerce_get_settings_' . $this->id, $settings );
}
array(
'title' => __( 'Number of decimals', 'woocommerce' ),
'desc' => __( 'This sets the number of decimal points shown in displayed prices.', 'woocommerce' ),
'id' => 'woocommerce_price_num_decimals',
'css' => 'width:50px;',
'default' => '2',
'desc_tip' => true,
'type' => 'number',
'custom_attributes' => array(
'min' => 0,
'step' => 1,
),
),
/**
* Output a color picker input box.
*
* @param mixed $name
* @param string $id
* @param mixed $value
* @param string $desc (default: '')
*/
public function color_picker( $name, $id, $value, $desc = '' ) {
echo '<div class="color_box">' . wc_help_tip( $desc ) . '
<input name="' . esc_attr( $id ) . '" id="' . esc_attr( $id ) . '" type="text" value="' . esc_attr( $value ) . '" class="colorpick" /> <div id="colorPickerDiv_' . esc_attr( $id ) . '" class="colorpickdiv"></div>
</div>';
}
array(
'type' => 'sectionend',
'id' => 'pricing_options',
),
/**
* Show a notice showing where the store notice setting has moved.
*
* @since 3.3.1
* @todo remove in next major release.
*/
private function store_notice_setting_moved_notice() {
if ( get_user_meta( get_current_user_id(), 'dismissed_store_notice_setting_moved_notice', true ) ) {
return;
)
);
return apply_filters( 'woocommerce_get_settings_' . $this->id, $settings );
}
?>
<div id="message" class="updated woocommerce-message inline">
<a class="woocommerce-message-close notice-dismiss" style="top:0;" href="<?php echo esc_url( wp_nonce_url( add_query_arg( 'wc-hide-notice', 'store_notice_setting_moved' ), 'woocommerce_hide_notices_nonce', '_wc_notice_nonce' ) ); ?>"><?php esc_html_e( 'Dismiss', 'woocommerce' ); ?></a>
<p><?php
/* translators: %s: URL to customizer. */
echo wp_kses( sprintf( __( 'Looking for the store notice setting? It can now be found <a href="%s">in the Customizer</a>.', 'woocommerce' ), esc_url( add_query_arg( array(
'autofocus' => array(
'panel' => 'woocommerce',
),
'url' => wc_get_page_permalink( 'shop' ),
), admin_url( 'customize.php' ) ) ) ), array(
'a' => array(
'href' => array(),
'title' => array(),
),
) );
?></p>
</div>
<?php
/**
* Output a color picker input box.
*
* @param mixed $name
* @param string $id
* @param mixed $value
* @param string $desc (default: '')
*/
public function color_picker( $name, $id, $value, $desc = '' ) {
echo '<div class="color_box">' . wc_help_tip( $desc ) . '
<input name="' . esc_attr( $id ) . '" id="' . esc_attr( $id ) . '" type="text" value="' . esc_attr( $value ) . '" class="colorpick" /> <div id="colorPickerDiv_' . esc_attr( $id ) . '" class="colorpickdiv"></div>
</div>';
}
/**
* Show a notice showing where the store notice setting has moved.
*
* @since 3.3.1
* @todo remove in next major release.
*/
private function store_notice_setting_moved_notice() {
if ( get_user_meta( get_current_user_id(), 'dismissed_store_notice_setting_moved_notice', true ) ) {
return;
}
?>
<div id="message" class="updated woocommerce-message inline">
<a class="woocommerce-message-close notice-dismiss" style="top:0;" href="<?php echo esc_url( wp_nonce_url( add_query_arg( 'wc-hide-notice', 'store_notice_setting_moved' ), 'woocommerce_hide_notices_nonce', '_wc_notice_nonce' ) ); ?>"><?php esc_html_e( 'Dismiss', 'woocommerce' ); ?></a>
<p>
<?php
/* translators: %s: URL to customizer. */
echo wp_kses(
sprintf(
__( 'Looking for the store notice setting? It can now be found <a href="%s">in the Customizer</a>.', 'woocommerce' ), esc_url(
add_query_arg(
array(
'autofocus' => array(
'panel' => 'woocommerce',
),
'url' => wc_get_page_permalink( 'shop' ),
), admin_url( 'customize.php' )
)
)
), array(
'a' => array(
'href' => array(),
'title' => array(),
),
)
);
?>
</p>
</div>
<?php
}
/**
* Output the settings.
*/
public function output() {
$settings = $this->get_settings();
$this->store_notice_setting_moved_notice();
WC_Admin_Settings::output_fields( $settings );
}
/**
* Save settings.
*/
public function save() {
$settings = $this->get_settings();
WC_Admin_Settings::save_fields( $settings );
}
}
/**
* Output the settings.
*/
public function output() {
$settings = $this->get_settings();
$this->store_notice_setting_moved_notice();
WC_Admin_Settings::output_fields( $settings );
}
/**
* Save settings.
*/
public function save() {
$settings = $this->get_settings();
WC_Admin_Settings::save_fields( $settings );
}
}
endif;
return new WC_Settings_General();

View File

@ -14,64 +14,64 @@ if ( ! defined( 'ABSPATH' ) ) {
if ( ! class_exists( 'WC_Settings_Integrations', false ) ) :
/**
* WC_Settings_Integrations.
*/
class WC_Settings_Integrations extends WC_Settings_Page {
/**
* Constructor.
* WC_Settings_Integrations.
*/
public function __construct() {
$this->id = 'integration';
$this->label = __( 'Integration', 'woocommerce' );
class WC_Settings_Integrations extends WC_Settings_Page {
if ( isset( WC()->integrations ) && WC()->integrations->get_integrations() ) {
parent::__construct();
}
}
/**
* Constructor.
*/
public function __construct() {
$this->id = 'integration';
$this->label = __( 'Integration', 'woocommerce' );
/**
* Get sections.
*
* @return array
*/
public function get_sections() {
global $current_section;
$sections = array();
if ( ! defined( 'WC_INSTALLING' ) ) {
$integrations = WC()->integrations->get_integrations();
if ( ! $current_section && ! empty( $integrations ) ) {
$current_section = current( $integrations )->id;
if ( isset( WC()->integrations ) && WC()->integrations->get_integrations() ) {
parent::__construct();
}
}
if ( sizeof( $integrations ) > 1 ) {
foreach ( $integrations as $integration ) {
$title = empty( $integration->method_title ) ? ucfirst( $integration->id ) : $integration->method_title;
$sections[ strtolower( $integration->id ) ] = esc_html( $title );
/**
* Get sections.
*
* @return array
*/
public function get_sections() {
global $current_section;
$sections = array();
if ( ! defined( 'WC_INSTALLING' ) ) {
$integrations = WC()->integrations->get_integrations();
if ( ! $current_section && ! empty( $integrations ) ) {
$current_section = current( $integrations )->id;
}
if ( sizeof( $integrations ) > 1 ) {
foreach ( $integrations as $integration ) {
$title = empty( $integration->method_title ) ? ucfirst( $integration->id ) : $integration->method_title;
$sections[ strtolower( $integration->id ) ] = esc_html( $title );
}
}
}
return apply_filters( 'woocommerce_get_sections_' . $this->id, $sections );
}
return apply_filters( 'woocommerce_get_sections_' . $this->id, $sections );
}
/**
* Output the settings.
*/
public function output() {
global $current_section;
/**
* Output the settings.
*/
public function output() {
global $current_section;
$integrations = WC()->integrations->get_integrations();
$integrations = WC()->integrations->get_integrations();
if ( isset( $integrations[ $current_section ] ) ) {
$integrations[ $current_section ]->admin_options();
if ( isset( $integrations[ $current_section ] ) ) {
$integrations[ $current_section ]->admin_options();
}
}
}
}
endif;

View File

@ -14,129 +14,131 @@ if ( ! defined( 'ABSPATH' ) ) {
if ( ! class_exists( 'WC_Settings_Page', false ) ) :
/**
* WC_Settings_Page.
*/
abstract class WC_Settings_Page {
/**
* Setting page id.
*
* @var string
* WC_Settings_Page.
*/
protected $id = '';
abstract class WC_Settings_Page {
/**
* Setting page label.
*
* @var string
*/
protected $label = '';
/**
* Setting page id.
*
* @var string
*/
protected $id = '';
/**
* Constructor.
*/
public function __construct() {
add_filter( 'woocommerce_settings_tabs_array', array( $this, 'add_settings_page' ), 20 );
add_action( 'woocommerce_sections_' . $this->id, array( $this, 'output_sections' ) );
add_action( 'woocommerce_settings_' . $this->id, array( $this, 'output' ) );
add_action( 'woocommerce_settings_save_' . $this->id, array( $this, 'save' ) );
}
/**
* Setting page label.
*
* @var string
*/
protected $label = '';
/**
* Get settings page ID.
* @since 3.0.0
* @return string
*/
public function get_id() {
return $this->id;
}
/**
* Get settings page label.
* @since 3.0.0
* @return string
*/
public function get_label() {
return $this->label;
}
/**
* Add this page to settings.
*
* @param array $pages
*
* @return mixed
*/
public function add_settings_page( $pages ) {
$pages[ $this->id ] = $this->label;
return $pages;
}
/**
* Get settings array.
*
* @return array
*/
public function get_settings() {
return apply_filters( 'woocommerce_get_settings_' . $this->id, array() );
}
/**
* Get sections.
*
* @return array
*/
public function get_sections() {
return apply_filters( 'woocommerce_get_sections_' . $this->id, array() );
}
/**
* Output sections.
*/
public function output_sections() {
global $current_section;
$sections = $this->get_sections();
if ( empty( $sections ) || 1 === sizeof( $sections ) ) {
return;
/**
* Constructor.
*/
public function __construct() {
add_filter( 'woocommerce_settings_tabs_array', array( $this, 'add_settings_page' ), 20 );
add_action( 'woocommerce_sections_' . $this->id, array( $this, 'output_sections' ) );
add_action( 'woocommerce_settings_' . $this->id, array( $this, 'output' ) );
add_action( 'woocommerce_settings_save_' . $this->id, array( $this, 'save' ) );
}
echo '<ul class="subsubsub">';
$array_keys = array_keys( $sections );
foreach ( $sections as $id => $label ) {
echo '<li><a href="' . admin_url( 'admin.php?page=wc-settings&tab=' . $this->id . '&section=' . sanitize_title( $id ) ) . '" class="' . ( $current_section == $id ? 'current' : '' ) . '">' . $label . '</a> ' . ( end( $array_keys ) == $id ? '' : '|' ) . ' </li>';
/**
* Get settings page ID.
*
* @since 3.0.0
* @return string
*/
public function get_id() {
return $this->id;
}
echo '</ul><br class="clear" />';
}
/**
* Get settings page label.
*
* @since 3.0.0
* @return string
*/
public function get_label() {
return $this->label;
}
/**
* Output the settings.
*/
public function output() {
$settings = $this->get_settings();
/**
* Add this page to settings.
*
* @param array $pages
*
* @return mixed
*/
public function add_settings_page( $pages ) {
$pages[ $this->id ] = $this->label;
WC_Admin_Settings::output_fields( $settings );
}
return $pages;
}
/**
* Save settings.
*/
public function save() {
global $current_section;
/**
* Get settings array.
*
* @return array
*/
public function get_settings() {
return apply_filters( 'woocommerce_get_settings_' . $this->id, array() );
}
$settings = $this->get_settings();
WC_Admin_Settings::save_fields( $settings );
/**
* Get sections.
*
* @return array
*/
public function get_sections() {
return apply_filters( 'woocommerce_get_sections_' . $this->id, array() );
}
if ( $current_section ) {
do_action( 'woocommerce_update_options_' . $this->id . '_' . $current_section );
/**
* Output sections.
*/
public function output_sections() {
global $current_section;
$sections = $this->get_sections();
if ( empty( $sections ) || 1 === sizeof( $sections ) ) {
return;
}
echo '<ul class="subsubsub">';
$array_keys = array_keys( $sections );
foreach ( $sections as $id => $label ) {
echo '<li><a href="' . admin_url( 'admin.php?page=wc-settings&tab=' . $this->id . '&section=' . sanitize_title( $id ) ) . '" class="' . ( $current_section == $id ? 'current' : '' ) . '">' . $label . '</a> ' . ( end( $array_keys ) == $id ? '' : '|' ) . ' </li>';
}
echo '</ul><br class="clear" />';
}
/**
* Output the settings.
*/
public function output() {
$settings = $this->get_settings();
WC_Admin_Settings::output_fields( $settings );
}
/**
* Save settings.
*/
public function save() {
global $current_section;
$settings = $this->get_settings();
WC_Admin_Settings::save_fields( $settings );
if ( $current_section ) {
do_action( 'woocommerce_update_options_' . $this->id . '_' . $current_section );
}
}
}
}
endif;

View File

@ -38,9 +38,9 @@ class WC_Settings_Products extends WC_Settings_Page {
*/
public function get_sections() {
$sections = array(
'' => __( 'General', 'woocommerce' ),
'inventory' => __( 'Inventory', 'woocommerce' ),
'downloadable' => __( 'Downloadable products', 'woocommerce' ),
'' => __( 'General', 'woocommerce' ),
'inventory' => __( 'Inventory', 'woocommerce' ),
'downloadable' => __( 'Downloadable products', 'woocommerce' ),
);
return apply_filters( 'woocommerce_get_sections_' . $this->id, $sections );
@ -73,20 +73,30 @@ class WC_Settings_Products extends WC_Settings_Page {
<div id="message" class="updated woocommerce-message inline">
<a class="woocommerce-message-close notice-dismiss" style="top:0;" href="<?php echo esc_url( wp_nonce_url( add_query_arg( 'wc-hide-notice', 'product_display_settings_moved' ), 'woocommerce_hide_notices_nonce', '_wc_notice_nonce' ) ); ?>"><?php esc_html_e( 'Dismiss', 'woocommerce' ); ?></a>
<p><?php
/* translators: %s: URL to customizer. */
echo wp_kses( sprintf( __( 'Looking for the product display options? They can now be found in the Customizer. <a href="%s">Go see them in action here.</a>', 'woocommerce' ), esc_url( add_query_arg( array(
'autofocus' => array(
'panel' => 'woocommerce',
),
'url' => wc_get_page_permalink( 'shop' ),
), admin_url( 'customize.php' ) ) ) ), array(
'a' => array(
'href' => array(),
'title' => array(),
),
) );
?></p>
<p>
<?php
/* translators: %s: URL to customizer. */
echo wp_kses(
sprintf(
__( 'Looking for the product display options? They can now be found in the Customizer. <a href="%s">Go see them in action here.</a>', 'woocommerce' ), esc_url(
add_query_arg(
array(
'autofocus' => array(
'panel' => 'woocommerce',
),
'url' => wc_get_page_permalink( 'shop' ),
), admin_url( 'customize.php' )
)
)
), array(
'a' => array(
'href' => array(),
'title' => array(),
),
)
);
?>
</p>
</div>
<?php
}
@ -113,339 +123,347 @@ class WC_Settings_Products extends WC_Settings_Page {
*/
public function get_settings( $current_section = '' ) {
if ( 'inventory' === $current_section ) {
$settings = apply_filters( 'woocommerce_inventory_settings', array(
$settings = apply_filters(
'woocommerce_inventory_settings', array(
array(
'title' => __( 'Inventory', 'woocommerce' ),
'type' => 'title',
'desc' => '',
'id' => 'product_inventory_options',
),
array(
'title' => __( 'Manage stock', 'woocommerce' ),
'desc' => __( 'Enable stock management', 'woocommerce' ),
'id' => 'woocommerce_manage_stock',
'default' => 'yes',
'type' => 'checkbox',
),
array(
'title' => __( 'Hold stock (minutes)', 'woocommerce' ),
'desc' => __( 'Hold stock (for unpaid orders) for x minutes. When this limit is reached, the pending order will be cancelled. Leave blank to disable.', 'woocommerce' ),
'id' => 'woocommerce_hold_stock_minutes',
'type' => 'number',
'custom_attributes' => array(
'min' => 0,
'step' => 1,
array(
'title' => __( 'Inventory', 'woocommerce' ),
'type' => 'title',
'desc' => '',
'id' => 'product_inventory_options',
),
'css' => 'width: 80px;',
'default' => '60',
'autoload' => false,
'class' => 'manage_stock_field',
),
array(
'title' => __( 'Notifications', 'woocommerce' ),
'desc' => __( 'Enable low stock notifications', 'woocommerce' ),
'id' => 'woocommerce_notify_low_stock',
'default' => 'yes',
'type' => 'checkbox',
'checkboxgroup' => 'start',
'autoload' => false,
'class' => 'manage_stock_field',
),
array(
'desc' => __( 'Enable out of stock notifications', 'woocommerce' ),
'id' => 'woocommerce_notify_no_stock',
'default' => 'yes',
'type' => 'checkbox',
'checkboxgroup' => 'end',
'autoload' => false,
'class' => 'manage_stock_field',
),
array(
'title' => __( 'Notification recipient(s)', 'woocommerce' ),
'desc' => __( 'Enter recipients (comma separated) that will receive this notification.', 'woocommerce' ),
'id' => 'woocommerce_stock_email_recipient',
'type' => 'text',
'default' => get_option( 'admin_email' ),
'css' => 'width: 250px;',
'autoload' => false,
'desc_tip' => true,
'class' => 'manage_stock_field',
),
array(
'title' => __( 'Low stock threshold', 'woocommerce' ),
'desc' => __( 'When product stock reaches this amount you will be notified via email.', 'woocommerce' ),
'id' => 'woocommerce_notify_low_stock_amount',
'css' => 'width:50px;',
'type' => 'number',
'custom_attributes' => array(
'min' => 0,
'step' => 1,
array(
'title' => __( 'Manage stock', 'woocommerce' ),
'desc' => __( 'Enable stock management', 'woocommerce' ),
'id' => 'woocommerce_manage_stock',
'default' => 'yes',
'type' => 'checkbox',
),
'default' => '2',
'autoload' => false,
'desc_tip' => true,
'class' => 'manage_stock_field',
),
array(
'title' => __( 'Out of stock threshold', 'woocommerce' ),
'desc' => __( 'When product stock reaches this amount the stock status will change to "out of stock" and you will be notified via email. This setting does not affect existing "in stock" products.', 'woocommerce' ),
'id' => 'woocommerce_notify_no_stock_amount',
'css' => 'width:50px;',
'type' => 'number',
'custom_attributes' => array(
'min' => 0,
'step' => 1,
array(
'title' => __( 'Hold stock (minutes)', 'woocommerce' ),
'desc' => __( 'Hold stock (for unpaid orders) for x minutes. When this limit is reached, the pending order will be cancelled. Leave blank to disable.', 'woocommerce' ),
'id' => 'woocommerce_hold_stock_minutes',
'type' => 'number',
'custom_attributes' => array(
'min' => 0,
'step' => 1,
),
'css' => 'width: 80px;',
'default' => '60',
'autoload' => false,
'class' => 'manage_stock_field',
),
'default' => '0',
'desc_tip' => true,
'class' => 'manage_stock_field',
),
array(
'title' => __( 'Out of stock visibility', 'woocommerce' ),
'desc' => __( 'Hide out of stock items from the catalog', 'woocommerce' ),
'id' => 'woocommerce_hide_out_of_stock_items',
'default' => 'no',
'type' => 'checkbox',
),
array(
'title' => __( 'Stock display format', 'woocommerce' ),
'desc' => __( 'This controls how stock quantities are displayed on the frontend.', 'woocommerce' ),
'id' => 'woocommerce_stock_format',
'css' => 'min-width:150px;',
'class' => 'wc-enhanced-select',
'default' => '',
'type' => 'select',
'options' => array(
'' => __( 'Always show quantity remaining in stock e.g. "12 in stock"', 'woocommerce' ),
'low_amount' => __( 'Only show quantity remaining in stock when low e.g. "Only 2 left in stock"', 'woocommerce' ),
'no_amount' => __( 'Never show quantity remaining in stock', 'woocommerce' ),
array(
'title' => __( 'Notifications', 'woocommerce' ),
'desc' => __( 'Enable low stock notifications', 'woocommerce' ),
'id' => 'woocommerce_notify_low_stock',
'default' => 'yes',
'type' => 'checkbox',
'checkboxgroup' => 'start',
'autoload' => false,
'class' => 'manage_stock_field',
),
'desc_tip' => true,
),
array(
'type' => 'sectionend',
'id' => 'product_inventory_options',
),
array(
'desc' => __( 'Enable out of stock notifications', 'woocommerce' ),
'id' => 'woocommerce_notify_no_stock',
'default' => 'yes',
'type' => 'checkbox',
'checkboxgroup' => 'end',
'autoload' => false,
'class' => 'manage_stock_field',
),
));
array(
'title' => __( 'Notification recipient(s)', 'woocommerce' ),
'desc' => __( 'Enter recipients (comma separated) that will receive this notification.', 'woocommerce' ),
'id' => 'woocommerce_stock_email_recipient',
'type' => 'text',
'default' => get_option( 'admin_email' ),
'css' => 'width: 250px;',
'autoload' => false,
'desc_tip' => true,
'class' => 'manage_stock_field',
),
array(
'title' => __( 'Low stock threshold', 'woocommerce' ),
'desc' => __( 'When product stock reaches this amount you will be notified via email.', 'woocommerce' ),
'id' => 'woocommerce_notify_low_stock_amount',
'css' => 'width:50px;',
'type' => 'number',
'custom_attributes' => array(
'min' => 0,
'step' => 1,
),
'default' => '2',
'autoload' => false,
'desc_tip' => true,
'class' => 'manage_stock_field',
),
array(
'title' => __( 'Out of stock threshold', 'woocommerce' ),
'desc' => __( 'When product stock reaches this amount the stock status will change to "out of stock" and you will be notified via email. This setting does not affect existing "in stock" products.', 'woocommerce' ),
'id' => 'woocommerce_notify_no_stock_amount',
'css' => 'width:50px;',
'type' => 'number',
'custom_attributes' => array(
'min' => 0,
'step' => 1,
),
'default' => '0',
'desc_tip' => true,
'class' => 'manage_stock_field',
),
array(
'title' => __( 'Out of stock visibility', 'woocommerce' ),
'desc' => __( 'Hide out of stock items from the catalog', 'woocommerce' ),
'id' => 'woocommerce_hide_out_of_stock_items',
'default' => 'no',
'type' => 'checkbox',
),
array(
'title' => __( 'Stock display format', 'woocommerce' ),
'desc' => __( 'This controls how stock quantities are displayed on the frontend.', 'woocommerce' ),
'id' => 'woocommerce_stock_format',
'css' => 'min-width:150px;',
'class' => 'wc-enhanced-select',
'default' => '',
'type' => 'select',
'options' => array(
'' => __( 'Always show quantity remaining in stock e.g. "12 in stock"', 'woocommerce' ),
'low_amount' => __( 'Only show quantity remaining in stock when low e.g. "Only 2 left in stock"', 'woocommerce' ),
'no_amount' => __( 'Never show quantity remaining in stock', 'woocommerce' ),
),
'desc_tip' => true,
),
array(
'type' => 'sectionend',
'id' => 'product_inventory_options',
),
)
);
} elseif ( 'downloadable' === $current_section ) {
$settings = apply_filters( 'woocommerce_downloadable_products_settings', array(
array(
'title' => __( 'Downloadable products', 'woocommerce' ),
'type' => 'title',
'id' => 'digital_download_options',
),
array(
'title' => __( 'File download method', 'woocommerce' ),
'desc' => sprintf(
/* translators: 1: X-Accel-Redirect 2: X-Sendfile 3: mod_xsendfile */
__( 'Forcing downloads will keep URLs hidden, but some servers may serve large files unreliably. If supported, %1$s / %2$s can be used to serve downloads instead (server requires %3$s).', 'woocommerce' ),
'<code>X-Accel-Redirect</code>',
'<code>X-Sendfile</code>',
'<code>mod_xsendfile</code>'
$settings = apply_filters(
'woocommerce_downloadable_products_settings', array(
array(
'title' => __( 'Downloadable products', 'woocommerce' ),
'type' => 'title',
'id' => 'digital_download_options',
),
'id' => 'woocommerce_file_download_method',
'type' => 'select',
'class' => 'wc-enhanced-select',
'css' => 'min-width:300px;',
'default' => 'force',
'desc_tip' => true,
'options' => array(
'force' => __( 'Force downloads', 'woocommerce' ),
'xsendfile' => __( 'X-Accel-Redirect/X-Sendfile', 'woocommerce' ),
'redirect' => __( 'Redirect only', 'woocommerce' ),
array(
'title' => __( 'File download method', 'woocommerce' ),
'desc' => sprintf(
/* translators: 1: X-Accel-Redirect 2: X-Sendfile 3: mod_xsendfile */
__( 'Forcing downloads will keep URLs hidden, but some servers may serve large files unreliably. If supported, %1$s / %2$s can be used to serve downloads instead (server requires %3$s).', 'woocommerce' ),
'<code>X-Accel-Redirect</code>',
'<code>X-Sendfile</code>',
'<code>mod_xsendfile</code>'
),
'id' => 'woocommerce_file_download_method',
'type' => 'select',
'class' => 'wc-enhanced-select',
'css' => 'min-width:300px;',
'default' => 'force',
'desc_tip' => true,
'options' => array(
'force' => __( 'Force downloads', 'woocommerce' ),
'xsendfile' => __( 'X-Accel-Redirect/X-Sendfile', 'woocommerce' ),
'redirect' => __( 'Redirect only', 'woocommerce' ),
),
'autoload' => false,
),
'autoload' => false,
),
array(
'title' => __( 'Access restriction', 'woocommerce' ),
'desc' => __( 'Downloads require login', 'woocommerce' ),
'id' => 'woocommerce_downloads_require_login',
'type' => 'checkbox',
'default' => 'no',
'desc_tip' => __( 'This setting does not apply to guest purchases.', 'woocommerce' ),
'checkboxgroup' => 'start',
'autoload' => false,
),
array(
'title' => __( 'Access restriction', 'woocommerce' ),
'desc' => __( 'Downloads require login', 'woocommerce' ),
'id' => 'woocommerce_downloads_require_login',
'type' => 'checkbox',
'default' => 'no',
'desc_tip' => __( 'This setting does not apply to guest purchases.', 'woocommerce' ),
'checkboxgroup' => 'start',
'autoload' => false,
),
array(
'desc' => __( 'Grant access to downloadable products after payment', 'woocommerce' ),
'id' => 'woocommerce_downloads_grant_access_after_payment',
'type' => 'checkbox',
'default' => 'yes',
'desc_tip' => __( 'Enable this option to grant access to downloads when orders are "processing", rather than "completed".', 'woocommerce' ),
'checkboxgroup' => 'end',
'autoload' => false,
),
array(
'desc' => __( 'Grant access to downloadable products after payment', 'woocommerce' ),
'id' => 'woocommerce_downloads_grant_access_after_payment',
'type' => 'checkbox',
'default' => 'yes',
'desc_tip' => __( 'Enable this option to grant access to downloads when orders are "processing", rather than "completed".', 'woocommerce' ),
'checkboxgroup' => 'end',
'autoload' => false,
),
array(
'type' => 'sectionend',
'id' => 'digital_download_options',
),
array(
'type' => 'sectionend',
'id' => 'digital_download_options',
),
));
)
);
} else {
$settings = apply_filters( 'woocommerce_product_settings', apply_filters( 'woocommerce_products_general_settings', array(
array(
'title' => __( 'Shop pages', 'woocommerce' ),
'type' => 'title',
'desc' => '',
'id' => 'catalog_options',
),
array(
'title' => __( 'Shop page', 'woocommerce' ),
'desc' => '<br/>' . sprintf( __( 'The base page can also be used in your <a href="%s">product permalinks</a>.', 'woocommerce' ), admin_url( 'options-permalink.php' ) ),
'id' => 'woocommerce_shop_page_id',
'type' => 'single_select_page',
'default' => '',
'class' => 'wc-enhanced-select-nostd',
'css' => 'min-width:300px;',
'desc_tip' => __( 'This sets the base page of your shop - this is where your product archive will be.', 'woocommerce' ),
),
array(
'title' => __( 'Add to cart behaviour', 'woocommerce' ),
'desc' => __( 'Redirect to the cart page after successful addition', 'woocommerce' ),
'id' => 'woocommerce_cart_redirect_after_add',
'default' => 'no',
'type' => 'checkbox',
'checkboxgroup' => 'start',
),
array(
'desc' => __( 'Enable AJAX add to cart buttons on archives', 'woocommerce' ),
'id' => 'woocommerce_enable_ajax_add_to_cart',
'default' => 'yes',
'type' => 'checkbox',
'checkboxgroup' => 'end',
),
array(
'type' => 'sectionend',
'id' => 'catalog_options',
),
$settings = apply_filters(
'woocommerce_product_settings', apply_filters(
'woocommerce_products_general_settings', array(
array(
'title' => __( 'Shop pages', 'woocommerce' ),
'type' => 'title',
'desc' => '',
'id' => 'catalog_options',
),
array(
'title' => __( 'Shop page', 'woocommerce' ),
'desc' => '<br/>' . sprintf( __( 'The base page can also be used in your <a href="%s">product permalinks</a>.', 'woocommerce' ), admin_url( 'options-permalink.php' ) ),
'id' => 'woocommerce_shop_page_id',
'type' => 'single_select_page',
'default' => '',
'class' => 'wc-enhanced-select-nostd',
'css' => 'min-width:300px;',
'desc_tip' => __( 'This sets the base page of your shop - this is where your product archive will be.', 'woocommerce' ),
),
array(
'title' => __( 'Add to cart behaviour', 'woocommerce' ),
'desc' => __( 'Redirect to the cart page after successful addition', 'woocommerce' ),
'id' => 'woocommerce_cart_redirect_after_add',
'default' => 'no',
'type' => 'checkbox',
'checkboxgroup' => 'start',
),
array(
'desc' => __( 'Enable AJAX add to cart buttons on archives', 'woocommerce' ),
'id' => 'woocommerce_enable_ajax_add_to_cart',
'default' => 'yes',
'type' => 'checkbox',
'checkboxgroup' => 'end',
),
array(
'type' => 'sectionend',
'id' => 'catalog_options',
),
array(
'title' => __( 'Measurements', 'woocommerce' ),
'type' => 'title',
'id' => 'product_measurement_options',
),
array(
'title' => __( 'Measurements', 'woocommerce' ),
'type' => 'title',
'id' => 'product_measurement_options',
),
array(
'title' => __( 'Weight unit', 'woocommerce' ),
'desc' => __( 'This controls what unit you will define weights in.', 'woocommerce' ),
'id' => 'woocommerce_weight_unit',
'class' => 'wc-enhanced-select',
'css' => 'min-width:300px;',
'default' => 'kg',
'type' => 'select',
'options' => array(
'kg' => __( 'kg', 'woocommerce' ),
'g' => __( 'g', 'woocommerce' ),
'lbs' => __( 'lbs', 'woocommerce' ),
'oz' => __( 'oz', 'woocommerce' ),
),
'desc_tip' => true,
),
array(
'title' => __( 'Weight unit', 'woocommerce' ),
'desc' => __( 'This controls what unit you will define weights in.', 'woocommerce' ),
'id' => 'woocommerce_weight_unit',
'class' => 'wc-enhanced-select',
'css' => 'min-width:300px;',
'default' => 'kg',
'type' => 'select',
'options' => array(
'kg' => __( 'kg', 'woocommerce' ),
'g' => __( 'g', 'woocommerce' ),
'lbs' => __( 'lbs', 'woocommerce' ),
'oz' => __( 'oz', 'woocommerce' ),
),
'desc_tip' => true,
),
array(
'title' => __( 'Dimensions unit', 'woocommerce' ),
'desc' => __( 'This controls what unit you will define lengths in.', 'woocommerce' ),
'id' => 'woocommerce_dimension_unit',
'class' => 'wc-enhanced-select',
'css' => 'min-width:300px;',
'default' => 'cm',
'type' => 'select',
'options' => array(
'm' => __( 'm', 'woocommerce' ),
'cm' => __( 'cm', 'woocommerce' ),
'mm' => __( 'mm', 'woocommerce' ),
'in' => __( 'in', 'woocommerce' ),
'yd' => __( 'yd', 'woocommerce' ),
),
'desc_tip' => true,
),
array(
'title' => __( 'Dimensions unit', 'woocommerce' ),
'desc' => __( 'This controls what unit you will define lengths in.', 'woocommerce' ),
'id' => 'woocommerce_dimension_unit',
'class' => 'wc-enhanced-select',
'css' => 'min-width:300px;',
'default' => 'cm',
'type' => 'select',
'options' => array(
'm' => __( 'm', 'woocommerce' ),
'cm' => __( 'cm', 'woocommerce' ),
'mm' => __( 'mm', 'woocommerce' ),
'in' => __( 'in', 'woocommerce' ),
'yd' => __( 'yd', 'woocommerce' ),
),
'desc_tip' => true,
),
array(
'type' => 'sectionend',
'id' => 'product_measurement_options',
),
array(
'type' => 'sectionend',
'id' => 'product_measurement_options',
),
array(
'title' => __( 'Reviews', 'woocommerce' ),
'type' => 'title',
'desc' => '',
'id' => 'product_rating_options',
),
array(
'title' => __( 'Reviews', 'woocommerce' ),
'type' => 'title',
'desc' => '',
'id' => 'product_rating_options',
),
array(
'title' => __( 'Enable reviews', 'woocommerce' ),
'desc' => __( 'Enable product reviews', 'woocommerce' ),
'id' => 'woocommerce_enable_reviews',
'default' => 'yes',
'type' => 'checkbox',
'checkboxgroup' => 'start',
'show_if_checked' => 'option',
),
array(
'title' => __( 'Enable reviews', 'woocommerce' ),
'desc' => __( 'Enable product reviews', 'woocommerce' ),
'id' => 'woocommerce_enable_reviews',
'default' => 'yes',
'type' => 'checkbox',
'checkboxgroup' => 'start',
'show_if_checked' => 'option',
),
array(
'desc' => __( 'Show "verified owner" label on customer reviews', 'woocommerce' ),
'id' => 'woocommerce_review_rating_verification_label',
'default' => 'yes',
'type' => 'checkbox',
'checkboxgroup' => '',
'show_if_checked' => 'yes',
'autoload' => false,
),
array(
'desc' => __( 'Show "verified owner" label on customer reviews', 'woocommerce' ),
'id' => 'woocommerce_review_rating_verification_label',
'default' => 'yes',
'type' => 'checkbox',
'checkboxgroup' => '',
'show_if_checked' => 'yes',
'autoload' => false,
),
array(
'desc' => __( 'Reviews can only be left by "verified owners"', 'woocommerce' ),
'id' => 'woocommerce_review_rating_verification_required',
'default' => 'no',
'type' => 'checkbox',
'checkboxgroup' => 'end',
'show_if_checked' => 'yes',
'autoload' => false,
),
array(
'desc' => __( 'Reviews can only be left by "verified owners"', 'woocommerce' ),
'id' => 'woocommerce_review_rating_verification_required',
'default' => 'no',
'type' => 'checkbox',
'checkboxgroup' => 'end',
'show_if_checked' => 'yes',
'autoload' => false,
),
array(
'title' => __( 'Product ratings', 'woocommerce' ),
'desc' => __( 'Enable star rating on reviews', 'woocommerce' ),
'id' => 'woocommerce_enable_review_rating',
'default' => 'yes',
'type' => 'checkbox',
'checkboxgroup' => 'start',
'show_if_checked' => 'option',
),
array(
'title' => __( 'Product ratings', 'woocommerce' ),
'desc' => __( 'Enable star rating on reviews', 'woocommerce' ),
'id' => 'woocommerce_enable_review_rating',
'default' => 'yes',
'type' => 'checkbox',
'checkboxgroup' => 'start',
'show_if_checked' => 'option',
),
array(
'desc' => __( 'Star ratings should be required, not optional', 'woocommerce' ),
'id' => 'woocommerce_review_rating_required',
'default' => 'yes',
'type' => 'checkbox',
'checkboxgroup' => 'end',
'show_if_checked' => 'yes',
'autoload' => false,
),
array(
'desc' => __( 'Star ratings should be required, not optional', 'woocommerce' ),
'id' => 'woocommerce_review_rating_required',
'default' => 'yes',
'type' => 'checkbox',
'checkboxgroup' => 'end',
'show_if_checked' => 'yes',
'autoload' => false,
),
array(
'type' => 'sectionend',
'id' => 'product_rating_options',
),
array(
'type' => 'sectionend',
'id' => 'product_rating_options',
),
) ) );
)
)
);
}
return apply_filters( 'woocommerce_get_settings_' . $this->id, $settings, $current_section );

View File

@ -62,27 +62,29 @@ class WC_Settings_Rest_API extends WC_Settings_Page {
$settings = array();
if ( '' === $current_section ) {
$settings = apply_filters( 'woocommerce_settings_rest_api', array(
array(
'title' => __( 'General options', 'woocommerce' ),
'type' => 'title',
'desc' => '',
'id' => 'general_options',
),
$settings = apply_filters(
'woocommerce_settings_rest_api', array(
array(
'title' => __( 'General options', 'woocommerce' ),
'type' => 'title',
'desc' => '',
'id' => 'general_options',
),
array(
'title' => __( 'Legacy API', 'woocommerce' ),
'desc' => __( 'Enable the legacy REST API', 'woocommerce' ),
'id' => 'woocommerce_api_enabled',
'type' => 'checkbox',
'default' => 'no',
),
array(
'title' => __( 'Legacy API', 'woocommerce' ),
'desc' => __( 'Enable the legacy REST API', 'woocommerce' ),
'id' => 'woocommerce_api_enabled',
'type' => 'checkbox',
'default' => 'no',
),
array(
'type' => 'sectionend',
'id' => 'general_options',
),
) );
array(
'type' => 'sectionend',
'id' => 'general_options',
),
)
);
}
return apply_filters( 'woocommerce_get_settings_' . $this->id, $settings, $current_section );

View File

@ -14,346 +14,365 @@ if ( ! defined( 'ABSPATH' ) ) {
if ( ! class_exists( 'WC_Settings_Shipping', false ) ) :
/**
* WC_Settings_Shipping.
*/
class WC_Settings_Shipping extends WC_Settings_Page {
/**
* Constructor.
* WC_Settings_Shipping.
*/
public function __construct() {
$this->id = 'shipping';
$this->label = __( 'Shipping', 'woocommerce' );
class WC_Settings_Shipping extends WC_Settings_Page {
parent::__construct();
}
/**
* Constructor.
*/
public function __construct() {
$this->id = 'shipping';
$this->label = __( 'Shipping', 'woocommerce' );
/**
* Add this page to settings.
*
* @param array $pages
*
* @return array|mixed
*/
public function add_settings_page( $pages ) {
return wc_shipping_enabled() ? parent::add_settings_page( $pages ) : $pages;
}
parent::__construct();
}
/**
* Get sections.
*
* @return array
*/
public function get_sections() {
$sections = array(
'' => __( 'Shipping zones', 'woocommerce' ),
'options' => __( 'Shipping options', 'woocommerce' ),
'classes' => __( 'Shipping classes', 'woocommerce' ),
);
/**
* Add this page to settings.
*
* @param array $pages
*
* @return array|mixed
*/
public function add_settings_page( $pages ) {
return wc_shipping_enabled() ? parent::add_settings_page( $pages ) : $pages;
}
/**
* Get sections.
*
* @return array
*/
public function get_sections() {
$sections = array(
'' => __( 'Shipping zones', 'woocommerce' ),
'options' => __( 'Shipping options', 'woocommerce' ),
'classes' => __( 'Shipping classes', 'woocommerce' ),
);
if ( ! defined( 'WC_INSTALLING' ) ) {
// Load shipping methods so we can show any global options they may have.
$shipping_methods = WC()->shipping->load_shipping_methods();
foreach ( $shipping_methods as $method ) {
if ( ! $method->has_settings() ) {
continue;
}
$title = empty( $method->method_title ) ? ucfirst( $method->id ) : $method->method_title;
$sections[ strtolower( $method->id ) ] = esc_html( $title );
}
}
return apply_filters( 'woocommerce_get_sections_' . $this->id, $sections );
}
/**
* Get settings array.
*
* @param string $current_section
*
* @return array
*/
public function get_settings( $current_section = '' ) {
$settings = array();
if ( '' === $current_section ) {
$settings = apply_filters(
'woocommerce_shipping_settings', array(
array(
'title' => __( 'Shipping options', 'woocommerce' ),
'type' => 'title',
'id' => 'shipping_options',
),
array(
'title' => __( 'Calculations', 'woocommerce' ),
'desc' => __( 'Enable the shipping calculator on the cart page', 'woocommerce' ),
'id' => 'woocommerce_enable_shipping_calc',
'default' => 'yes',
'type' => 'checkbox',
'checkboxgroup' => 'start',
'autoload' => false,
),
array(
'desc' => __( 'Hide shipping costs until an address is entered', 'woocommerce' ),
'id' => 'woocommerce_shipping_cost_requires_address',
'default' => 'no',
'type' => 'checkbox',
'checkboxgroup' => 'end',
'autoload' => false,
),
array(
'title' => __( 'Shipping destination', 'woocommerce' ),
'desc' => __( 'This controls which shipping address is used by default.', 'woocommerce' ),
'id' => 'woocommerce_ship_to_destination',
'default' => 'billing',
'type' => 'radio',
'options' => array(
'shipping' => __( 'Default to customer shipping address', 'woocommerce' ),
'billing' => __( 'Default to customer billing address', 'woocommerce' ),
'billing_only' => __( 'Force shipping to the customer billing address', 'woocommerce' ),
),
'autoload' => false,
'desc_tip' => true,
'show_if_checked' => 'option',
),
array(
'title' => __( 'Debug mode', 'woocommerce' ),
'desc' => __( 'Enable debug mode', 'woocommerce' ),
'desc_tip' => __( 'Enable shipping debug mode to show matching shipping zones and to bypass shipping rate cache.', 'woocommerce' ),
'id' => 'woocommerce_shipping_debug_mode',
'default' => 'no',
'type' => 'checkbox',
'autoload' => false,
),
array(
'type' => 'sectionend',
'id' => 'shipping_options',
),
)
);
}
return apply_filters( 'woocommerce_get_settings_' . $this->id, $settings, $current_section );
}
/**
* Output the settings.
*/
public function output() {
global $current_section, $hide_save_button;
if ( ! defined( 'WC_INSTALLING' ) ) {
// Load shipping methods so we can show any global options they may have
$shipping_methods = WC()->shipping->load_shipping_methods();
foreach ( $shipping_methods as $method ) {
if ( ! $method->has_settings() ) {
continue;
}
$title = empty( $method->method_title ) ? ucfirst( $method->id ) : $method->method_title;
$sections[ strtolower( $method->id ) ] = esc_html( $title );
}
}
return apply_filters( 'woocommerce_get_sections_' . $this->id, $sections );
}
/**
* Get settings array.
*
* @param string $current_section
*
* @return array
*/
public function get_settings( $current_section = '' ) {
$settings = array();
if ( '' === $current_section ) {
$settings = apply_filters( 'woocommerce_shipping_settings', array(
array( 'title' => __( 'Shipping options', 'woocommerce' ), 'type' => 'title', 'id' => 'shipping_options' ),
array(
'title' => __( 'Calculations', 'woocommerce' ),
'desc' => __( 'Enable the shipping calculator on the cart page', 'woocommerce' ),
'id' => 'woocommerce_enable_shipping_calc',
'default' => 'yes',
'type' => 'checkbox',
'checkboxgroup' => 'start',
'autoload' => false,
),
array(
'desc' => __( 'Hide shipping costs until an address is entered', 'woocommerce' ),
'id' => 'woocommerce_shipping_cost_requires_address',
'default' => 'no',
'type' => 'checkbox',
'checkboxgroup' => 'end',
'autoload' => false,
),
array(
'title' => __( 'Shipping destination', 'woocommerce' ),
'desc' => __( 'This controls which shipping address is used by default.', 'woocommerce' ),
'id' => 'woocommerce_ship_to_destination',
'default' => 'billing',
'type' => 'radio',
'options' => array(
'shipping' => __( 'Default to customer shipping address', 'woocommerce' ),
'billing' => __( 'Default to customer billing address', 'woocommerce' ),
'billing_only' => __( 'Force shipping to the customer billing address', 'woocommerce' ),
),
'autoload' => false,
'desc_tip' => true,
'show_if_checked' => 'option',
),
array(
'title' => __( 'Debug mode', 'woocommerce' ),
'desc' => __( 'Enable debug mode', 'woocommerce' ),
'desc_tip' => __( 'Enable shipping debug mode to show matching shipping zones and to bypass shipping rate cache.', 'woocommerce' ),
'id' => 'woocommerce_shipping_debug_mode',
'default' => 'no',
'type' => 'checkbox',
'autoload' => false,
),
array( 'type' => 'sectionend', 'id' => 'shipping_options' ),
) );
}
return apply_filters( 'woocommerce_get_settings_' . $this->id, $settings, $current_section );
}
/**
* Output the settings.
*/
public function output() {
global $current_section, $hide_save_button;
// Load shipping methods so we can show any global options they may have
$shipping_methods = WC()->shipping->load_shipping_methods();
if ( '' === $current_section ) {
$this->output_zones_screen();
} elseif ( 'options' === $current_section ) {
$settings = $this->get_settings();
WC_Admin_Settings::output_fields( $settings );
} elseif ( 'classes' === $current_section ) {
$hide_save_button = true;
$this->output_shipping_class_screen();
} else {
foreach ( $shipping_methods as $method ) {
if ( in_array( $current_section, array( $method->id, sanitize_title( get_class( $method ) ) ) ) && $method->has_settings() ) {
$method->admin_options();
}
}
}
}
/**
* Save settings.
*/
public function save() {
global $current_section;
switch ( $current_section ) {
case 'options' :
WC_Admin_Settings::save_fields( $this->get_settings() );
break;
case 'classes' :
case '' :
break;
default :
$wc_shipping = WC_Shipping::instance();
foreach ( $wc_shipping->get_shipping_methods() as $method_id => $method ) {
if ( in_array( $current_section, array( $method->id, sanitize_title( get_class( $method ) ) ) ) ) {
do_action( 'woocommerce_update_options_' . $this->id . '_' . $method->id );
if ( '' === $current_section ) {
$this->output_zones_screen();
} elseif ( 'options' === $current_section ) {
$settings = $this->get_settings();
WC_Admin_Settings::output_fields( $settings );
} elseif ( 'classes' === $current_section ) {
$hide_save_button = true;
$this->output_shipping_class_screen();
} else {
foreach ( $shipping_methods as $method ) {
if ( in_array( $current_section, array( $method->id, sanitize_title( get_class( $method ) ) ) ) && $method->has_settings() ) {
$method->admin_options();
}
}
break;
}
}
if ( $current_section ) {
do_action( 'woocommerce_update_options_' . $this->id . '_' . $current_section );
/**
* Save settings.
*/
public function save() {
global $current_section;
switch ( $current_section ) {
case 'options':
WC_Admin_Settings::save_fields( $this->get_settings() );
break;
case 'classes':
case '':
break;
default:
$wc_shipping = WC_Shipping::instance();
foreach ( $wc_shipping->get_shipping_methods() as $method_id => $method ) {
if ( in_array( $current_section, array( $method->id, sanitize_title( get_class( $method ) ) ) ) ) {
do_action( 'woocommerce_update_options_' . $this->id . '_' . $method->id );
}
}
break;
}
if ( $current_section ) {
do_action( 'woocommerce_update_options_' . $this->id . '_' . $current_section );
}
// Increments the transient version to invalidate cache.
WC_Cache_Helper::get_transient_version( 'shipping', true );
}
// Increments the transient version to invalidate cache.
WC_Cache_Helper::get_transient_version( 'shipping', true );
}
/**
* Handles output of the shipping zones page in admin.
*/
protected function output_zones_screen() {
global $hide_save_button;
/**
* Handles output of the shipping zones page in admin.
*/
protected function output_zones_screen() {
global $hide_save_button;
if ( isset( $_REQUEST['zone_id'] ) ) {
$hide_save_button = true;
$this->zone_methods_screen( wc_clean( $_REQUEST['zone_id'] ) );
} elseif ( isset( $_REQUEST['instance_id'] ) ) {
$this->instance_settings_screen( absint( $_REQUEST['instance_id'] ) );
} else {
$hide_save_button = true;
$this->zones_screen();
}
}
/**
* Show method for a zone
* @param int $zone_id
*/
protected function zone_methods_screen( $zone_id ) {
if ( 'new' === $zone_id ) {
$zone = new WC_Shipping_Zone();
} else {
$zone = WC_Shipping_Zones::get_zone( absint( $zone_id ) );
}
if ( ! $zone ) {
wp_die( __( 'Zone does not exist!', 'woocommerce' ) );
}
$allowed_countries = WC()->countries->get_allowed_countries();
$wc_shipping = WC_Shipping ::instance();
$shipping_methods = $wc_shipping->get_shipping_methods();
$continents = WC()->countries->get_continents();
// Prepare locations
$locations = array();
$postcodes = array();
foreach ( $zone->get_zone_locations() as $location ) {
if ( 'postcode' === $location->type ) {
$postcodes[] = $location->code;
if ( isset( $_REQUEST['zone_id'] ) ) {
$hide_save_button = true;
$this->zone_methods_screen( wc_clean( $_REQUEST['zone_id'] ) );
} elseif ( isset( $_REQUEST['instance_id'] ) ) {
$this->instance_settings_screen( absint( $_REQUEST['instance_id'] ) );
} else {
$locations[] = $location->type . ':' . $location->code;
$hide_save_button = true;
$this->zones_screen();
}
}
wp_localize_script( 'wc-shipping-zone-methods', 'shippingZoneMethodsLocalizeScript', array(
'methods' => $zone->get_shipping_methods( false, 'json' ),
'zone_name' => $zone->get_zone_name(),
'zone_id' => $zone->get_id(),
'wc_shipping_zones_nonce' => wp_create_nonce( 'wc_shipping_zones_nonce' ),
'strings' => array(
'unload_confirmation_msg' => __( 'Your changed data will be lost if you leave this page without saving.', 'woocommerce' ),
'save_changes_prompt' => __( 'Do you wish to save your changes first? Your changed data will be discarded if you choose to cancel.', 'woocommerce' ),
'save_failed' => __( 'Your changes were not saved. Please retry.', 'woocommerce' ),
'add_method_failed' => __( 'Shipping method could not be added. Please retry.', 'woocommerce' ),
'yes' => __( 'Yes', 'woocommerce' ),
'no' => __( 'No', 'woocommerce' ),
'default_zone_name' => __( 'Zone', 'woocommerce' ),
),
) );
wp_enqueue_script( 'wc-shipping-zone-methods' );
include_once( dirname( __FILE__ ) . '/views/html-admin-page-shipping-zone-methods.php' );
}
/**
* Show zones
*/
protected function zones_screen() {
$allowed_countries = WC()->countries->get_allowed_countries();
$continents = WC()->countries->get_continents();
$method_count = wc_get_shipping_method_count();
wp_localize_script( 'wc-shipping-zones', 'shippingZonesLocalizeScript', array(
'zones' => WC_Shipping_Zones::get_zones(),
'default_zone' => array(
'zone_id' => 0,
'zone_name' => '',
'zone_order' => null,
),
'wc_shipping_zones_nonce' => wp_create_nonce( 'wc_shipping_zones_nonce' ),
'strings' => array(
'unload_confirmation_msg' => __( 'Your changed data will be lost if you leave this page without saving.', 'woocommerce' ),
'delete_confirmation_msg' => __( 'Are you sure you want to delete this zone? This action cannot be undone.', 'woocommerce' ),
'save_failed' => __( 'Your changes were not saved. Please retry.', 'woocommerce' ),
'no_shipping_methods_offered' => __( 'No shipping methods offered to this zone.', 'woocommerce' ),
),
) );
wp_enqueue_script( 'wc-shipping-zones' );
include_once( dirname( __FILE__ ) . '/views/html-admin-page-shipping-zones.php' );
}
/**
* Show instance settings
* @param int $instance_id
*/
protected function instance_settings_screen( $instance_id ) {
$zone = WC_Shipping_Zones::get_zone_by( 'instance_id', $instance_id );
$shipping_method = WC_Shipping_Zones::get_shipping_method( $instance_id );
if ( ! $shipping_method ) {
wp_die( __( 'Invalid shipping method!', 'woocommerce' ) );
}
if ( ! $zone ) {
wp_die( __( 'Zone does not exist!', 'woocommerce' ) );
}
if ( ! $shipping_method->has_settings() ) {
wp_die( __( 'This shipping method does not have any settings to configure.', 'woocommerce' ) );
}
if ( ! empty( $_POST['save'] ) ) {
if ( empty( $_REQUEST['_wpnonce'] ) || ! wp_verify_nonce( $_REQUEST['_wpnonce'], 'woocommerce-settings' ) ) {
echo '<div class="updated error"><p>' . __( 'Edit failed. Please try again.', 'woocommerce' ) . '</p></div>';
/**
* Show method for a zone
*
* @param int $zone_id
*/
protected function zone_methods_screen( $zone_id ) {
if ( 'new' === $zone_id ) {
$zone = new WC_Shipping_Zone();
} else {
$zone = WC_Shipping_Zones::get_zone( absint( $zone_id ) );
}
$shipping_method->process_admin_options();
$shipping_method->display_errors();
if ( ! $zone ) {
wp_die( __( 'Zone does not exist!', 'woocommerce' ) );
}
$allowed_countries = WC()->countries->get_allowed_countries();
$wc_shipping = WC_Shipping::instance();
$shipping_methods = $wc_shipping->get_shipping_methods();
$continents = WC()->countries->get_continents();
// Prepare locations.
$locations = array();
$postcodes = array();
foreach ( $zone->get_zone_locations() as $location ) {
if ( 'postcode' === $location->type ) {
$postcodes[] = $location->code;
} else {
$locations[] = $location->type . ':' . $location->code;
}
}
wp_localize_script(
'wc-shipping-zone-methods', 'shippingZoneMethodsLocalizeScript', array(
'methods' => $zone->get_shipping_methods( false, 'json' ),
'zone_name' => $zone->get_zone_name(),
'zone_id' => $zone->get_id(),
'wc_shipping_zones_nonce' => wp_create_nonce( 'wc_shipping_zones_nonce' ),
'strings' => array(
'unload_confirmation_msg' => __( 'Your changed data will be lost if you leave this page without saving.', 'woocommerce' ),
'save_changes_prompt' => __( 'Do you wish to save your changes first? Your changed data will be discarded if you choose to cancel.', 'woocommerce' ),
'save_failed' => __( 'Your changes were not saved. Please retry.', 'woocommerce' ),
'add_method_failed' => __( 'Shipping method could not be added. Please retry.', 'woocommerce' ),
'yes' => __( 'Yes', 'woocommerce' ),
'no' => __( 'No', 'woocommerce' ),
'default_zone_name' => __( 'Zone', 'woocommerce' ),
),
)
);
wp_enqueue_script( 'wc-shipping-zone-methods' );
include_once dirname( __FILE__ ) . '/views/html-admin-page-shipping-zone-methods.php';
}
include_once( dirname( __FILE__ ) . '/views/html-admin-page-shipping-zones-instance.php' );
/**
* Show zones
*/
protected function zones_screen() {
$allowed_countries = WC()->countries->get_allowed_countries();
$continents = WC()->countries->get_continents();
$method_count = wc_get_shipping_method_count();
wp_localize_script(
'wc-shipping-zones', 'shippingZonesLocalizeScript', array(
'zones' => WC_Shipping_Zones::get_zones(),
'default_zone' => array(
'zone_id' => 0,
'zone_name' => '',
'zone_order' => null,
),
'wc_shipping_zones_nonce' => wp_create_nonce( 'wc_shipping_zones_nonce' ),
'strings' => array(
'unload_confirmation_msg' => __( 'Your changed data will be lost if you leave this page without saving.', 'woocommerce' ),
'delete_confirmation_msg' => __( 'Are you sure you want to delete this zone? This action cannot be undone.', 'woocommerce' ),
'save_failed' => __( 'Your changes were not saved. Please retry.', 'woocommerce' ),
'no_shipping_methods_offered' => __( 'No shipping methods offered to this zone.', 'woocommerce' ),
),
)
);
wp_enqueue_script( 'wc-shipping-zones' );
include_once dirname( __FILE__ ) . '/views/html-admin-page-shipping-zones.php';
}
/**
* Show instance settings
*
* @param int $instance_id
*/
protected function instance_settings_screen( $instance_id ) {
$zone = WC_Shipping_Zones::get_zone_by( 'instance_id', $instance_id );
$shipping_method = WC_Shipping_Zones::get_shipping_method( $instance_id );
if ( ! $shipping_method ) {
wp_die( __( 'Invalid shipping method!', 'woocommerce' ) );
}
if ( ! $zone ) {
wp_die( __( 'Zone does not exist!', 'woocommerce' ) );
}
if ( ! $shipping_method->has_settings() ) {
wp_die( __( 'This shipping method does not have any settings to configure.', 'woocommerce' ) );
}
if ( ! empty( $_POST['save'] ) ) {
if ( empty( $_REQUEST['_wpnonce'] ) || ! wp_verify_nonce( $_REQUEST['_wpnonce'], 'woocommerce-settings' ) ) {
echo '<div class="updated error"><p>' . __( 'Edit failed. Please try again.', 'woocommerce' ) . '</p></div>';
}
$shipping_method->process_admin_options();
$shipping_method->display_errors();
}
include_once dirname( __FILE__ ) . '/views/html-admin-page-shipping-zones-instance.php';
}
/**
* Handles output of the shipping class settings screen.
*/
protected function output_shipping_class_screen() {
$wc_shipping = WC_Shipping::instance();
wp_localize_script(
'wc-shipping-classes', 'shippingClassesLocalizeScript', array(
'classes' => $wc_shipping->get_shipping_classes(),
'default_shipping_class' => array(
'term_id' => 0,
'name' => '',
'description' => '',
),
'wc_shipping_classes_nonce' => wp_create_nonce( 'wc_shipping_classes_nonce' ),
'strings' => array(
'unload_confirmation_msg' => __( 'Your changed data will be lost if you leave this page without saving.', 'woocommerce' ),
'save_failed' => __( 'Your changes were not saved. Please retry.', 'woocommerce' ),
),
)
);
wp_enqueue_script( 'wc-shipping-classes' );
// Extendable columns to show on the shipping classes screen.
$shipping_class_columns = apply_filters(
'woocommerce_shipping_classes_columns', array(
'wc-shipping-class-name' => __( 'Shipping class', 'woocommerce' ),
'wc-shipping-class-slug' => __( 'Slug', 'woocommerce' ),
'wc-shipping-class-description' => __( 'Description', 'woocommerce' ),
'wc-shipping-class-count' => __( 'Product count', 'woocommerce' ),
)
);
include_once dirname( __FILE__ ) . '/views/html-admin-page-shipping-classes.php';
}
}
/**
* Handles output of the shipping class settings screen.
*/
protected function output_shipping_class_screen() {
$wc_shipping = WC_Shipping::instance();
wp_localize_script( 'wc-shipping-classes', 'shippingClassesLocalizeScript', array(
'classes' => $wc_shipping->get_shipping_classes(),
'default_shipping_class' => array(
'term_id' => 0,
'name' => '',
'description' => '',
),
'wc_shipping_classes_nonce' => wp_create_nonce( 'wc_shipping_classes_nonce' ),
'strings' => array(
'unload_confirmation_msg' => __( 'Your changed data will be lost if you leave this page without saving.', 'woocommerce' ),
'save_failed' => __( 'Your changes were not saved. Please retry.', 'woocommerce' ),
),
) );
wp_enqueue_script( 'wc-shipping-classes' );
// Extendable columns to show on the shipping classes screen.
$shipping_class_columns = apply_filters( 'woocommerce_shipping_classes_columns', array(
'wc-shipping-class-name' => __( 'Shipping class', 'woocommerce' ),
'wc-shipping-class-slug' => __( 'Slug', 'woocommerce' ),
'wc-shipping-class-description' => __( 'Description', 'woocommerce' ),
'wc-shipping-class-count' => __( 'Product count', 'woocommerce' ),
) );
include_once( dirname( __FILE__ ) . '/views/html-admin-page-shipping-classes.php' );
}
}
endif;
return new WC_Settings_Shipping();

View File

@ -82,7 +82,7 @@ class WC_Settings_Tax extends WC_Settings_Page {
$settings = array();
if ( '' === $current_section ) {
$settings = include( 'views/settings-tax.php' );
$settings = include 'views/settings-tax.php';
}
return apply_filters( 'woocommerce_get_settings_' . $this->id, $settings, $current_section );
}
@ -153,54 +153,60 @@ class WC_Settings_Tax extends WC_Settings_Page {
}
}
$base_url = admin_url( add_query_arg( array(
'page' => 'wc-settings',
'tab' => 'tax',
'section' => $current_section,
), 'admin.php' ) );
$base_url = admin_url(
add_query_arg(
array(
'page' => 'wc-settings',
'tab' => 'tax',
'section' => $current_section,
), 'admin.php'
)
);
// Localize and enqueue our js.
wp_localize_script( 'wc-settings-tax', 'htmlSettingsTaxLocalizeScript', array(
'current_class' => $current_class,
'wc_tax_nonce' => wp_create_nonce( 'wc_tax_nonce-class:' . $current_class ),
'base_url' => $base_url,
'rates' => array_values( WC_Tax::get_rates_for_tax_class( $current_class ) ),
'page' => ! empty( $_GET['p'] ) ? absint( $_GET['p'] ) : 1,
'limit' => 100,
'countries' => $countries,
'states' => $states,
'default_rate' => array(
'tax_rate_id' => 0,
'tax_rate_country' => '',
'tax_rate_state' => '',
'tax_rate' => '',
'tax_rate_name' => '',
'tax_rate_priority' => 1,
'tax_rate_compound' => 0,
'tax_rate_shipping' => 1,
'tax_rate_order' => null,
'tax_rate_class' => $current_class,
),
'strings' => array(
'no_rows_selected' => __( 'No row(s) selected', 'woocommerce' ),
'unload_confirmation_msg' => __( 'Your changed data will be lost if you leave this page without saving.', 'woocommerce' ),
'csv_data_cols' => array(
__( 'Country code', 'woocommerce' ),
__( 'State code', 'woocommerce' ),
__( 'Postcode / ZIP', 'woocommerce' ),
__( 'City', 'woocommerce' ),
__( 'Rate %', 'woocommerce' ),
__( 'Tax name', 'woocommerce' ),
__( 'Priority', 'woocommerce' ),
__( 'Compound', 'woocommerce' ),
__( 'Shipping', 'woocommerce' ),
__( 'Tax class', 'woocommerce' ),
wp_localize_script(
'wc-settings-tax', 'htmlSettingsTaxLocalizeScript', array(
'current_class' => $current_class,
'wc_tax_nonce' => wp_create_nonce( 'wc_tax_nonce-class:' . $current_class ),
'base_url' => $base_url,
'rates' => array_values( WC_Tax::get_rates_for_tax_class( $current_class ) ),
'page' => ! empty( $_GET['p'] ) ? absint( $_GET['p'] ) : 1,
'limit' => 100,
'countries' => $countries,
'states' => $states,
'default_rate' => array(
'tax_rate_id' => 0,
'tax_rate_country' => '',
'tax_rate_state' => '',
'tax_rate' => '',
'tax_rate_name' => '',
'tax_rate_priority' => 1,
'tax_rate_compound' => 0,
'tax_rate_shipping' => 1,
'tax_rate_order' => null,
'tax_rate_class' => $current_class,
),
),
) );
'strings' => array(
'no_rows_selected' => __( 'No row(s) selected', 'woocommerce' ),
'unload_confirmation_msg' => __( 'Your changed data will be lost if you leave this page without saving.', 'woocommerce' ),
'csv_data_cols' => array(
__( 'Country code', 'woocommerce' ),
__( 'State code', 'woocommerce' ),
__( 'Postcode / ZIP', 'woocommerce' ),
__( 'City', 'woocommerce' ),
__( 'Rate %', 'woocommerce' ),
__( 'Tax name', 'woocommerce' ),
__( 'Priority', 'woocommerce' ),
__( 'Compound', 'woocommerce' ),
__( 'Shipping', 'woocommerce' ),
__( 'Tax class', 'woocommerce' ),
),
),
)
);
wp_enqueue_script( 'wc-settings-tax' );
include( 'views/html-settings-tax.php' );
include 'views/html-settings-tax.php';
}
/**
@ -232,7 +238,7 @@ class WC_Settings_Tax extends WC_Settings_Page {
* @return array
*/
private function get_posted_tax_rate( $key, $order, $class ) {
$tax_rate = array();
$tax_rate = array();
$tax_rate_keys = array(
'tax_rate_country',
'tax_rate_state',
@ -274,8 +280,8 @@ class WC_Settings_Tax extends WC_Settings_Page {
// Loop posted fields.
foreach ( $posted_countries as $key => $value ) {
$mode = ( 0 === strpos( $key, 'new-' ) ) ? 'insert' : 'update';
$tax_rate = $this->get_posted_tax_rate( $key, $index ++, $current_class );
$mode = ( 0 === strpos( $key, 'new-' ) ) ? 'insert' : 'update';
$tax_rate = $this->get_posted_tax_rate( $key, $index ++, $current_class );
if ( 'insert' === $mode ) {
$tax_rate_id = WC_Tax::_insert_tax_rate( $tax_rate );

View File

@ -46,7 +46,7 @@ if ( ! defined( 'ABSPATH' ) ) {
foreach ( $shipping_class_columns as $class => $heading ) {
echo '<td class="' . esc_attr( $class ) . '">';
switch ( $class ) {
case 'wc-shipping-class-name' :
case 'wc-shipping-class-name':
?>
<div class="view">
{{ data.name }}
@ -61,27 +61,27 @@ if ( ! defined( 'ABSPATH' ) ) {
</div>
</div>
<?php
break;
case 'wc-shipping-class-slug' :
break;
case 'wc-shipping-class-slug':
?>
<div class="view">{{ data.slug }}</div>
<div class="edit"><input type="text" name="slug[{{ data.term_id }}]" data-attribute="slug" value="{{ data.slug }}" placeholder="<?php esc_attr_e( 'Slug', 'woocommerce' ); ?>" /></div>
<?php
break;
case 'wc-shipping-class-description' :
break;
case 'wc-shipping-class-description':
?>
<div class="view">{{ data.description }}</div>
<div class="edit"><input type="text" name="description[{{ data.term_id }}]" data-attribute="description" value="{{ data.description }}" placeholder="<?php esc_attr_e( 'Description for your reference', 'woocommerce' ); ?>" /></div>
<?php
break;
case 'wc-shipping-class-count' :
break;
case 'wc-shipping-class-count':
?>
<a href="<?php echo esc_url( admin_url( 'edit.php?post_type=product&product_shipping_class=' ) ); ?>{{data.slug}}">{{ data.count }}</a>
<?php
break;
default :
break;
default:
do_action( 'woocommerce_shipping_classes_column_' . $class );
break;
break;
}
echo '</td>';
}

View File

@ -127,13 +127,15 @@ if ( ! defined( 'ABSPATH' ) ) {
<div class="wc-backbone-modal-content">
<section class="wc-backbone-modal-main" role="main">
<header class="wc-backbone-modal-header">
<h1><?php
<h1>
<?php
/* translators: %s: shipping method title */
printf(
esc_html__( '%s Settings', 'woocommerce' ),
'{{{ data.method.method_title }}}'
);
?></h1>
?>
</h1>
<button class="modal-close modal-close-link dashicons dashicons-no-alt">
<span class="screen-reader-text"><?php esc_html_e( 'Close modal panel', 'woocommerce' ); ?></span>
</button>

View File

@ -32,18 +32,18 @@ if ( ! defined( 'ABSPATH' ) ) {
<td class="wc-shipping-zone-methods">
<ul>
<?php
$worldwide = new WC_Shipping_Zone( 0 );
$methods = $worldwide->get_shipping_methods();
uasort( $methods, 'wc_shipping_zone_method_order_uasort_comparison' );
$worldwide = new WC_Shipping_Zone( 0 );
$methods = $worldwide->get_shipping_methods();
uasort( $methods, 'wc_shipping_zone_method_order_uasort_comparison' );
if ( ! empty( $methods ) ) {
foreach ( $methods as $method ) {
$class_name = 'yes' === $method->enabled ? 'method_enabled' : 'method_disabled';
echo '<li class="wc-shipping-zone-method ' . esc_attr( $class_name ) . '">' . esc_html( $method->get_title() ) . '</li>';
}
} else {
echo '<li class="wc-shipping-zone-method">' . __( 'No shipping methods offered to this zone.', 'woocommerce' ) . '</li>';
if ( ! empty( $methods ) ) {
foreach ( $methods as $method ) {
$class_name = 'yes' === $method->enabled ? 'method_enabled' : 'method_disabled';
echo '<li class="wc-shipping-zone-method ' . esc_attr( $class_name ) . '">' . esc_html( $method->get_title() ) . '</li>';
}
} else {
echo '<li class="wc-shipping-zone-method">' . __( 'No shipping methods offered to this zone.', 'woocommerce' ) . '</li>';
}
?>
</ul>
</td>
@ -104,12 +104,12 @@ if ( ! defined( 'ABSPATH' ) ) {
<select name="add_method_id">
<?php
foreach ( WC()->shipping->load_shipping_methods() as $method ) {
if ( ! $method->supports( 'shipping-zones' ) ) {
continue;
}
echo '<option data-description="' . esc_attr( wp_kses_post( wpautop( $method->get_method_description() ) ) ) . '" value="' . esc_attr( $method->id ) . '">' . esc_attr( $method->get_method_title() ) . '</li>';
foreach ( WC()->shipping->load_shipping_methods() as $method ) {
if ( ! $method->supports( 'shipping-zones' ) ) {
continue;
}
echo '<option data-description="' . esc_attr( wp_kses_post( wpautop( $method->get_method_description() ) ) ) . '" value="' . esc_attr( $method->id ) . '">' . esc_attr( $method->get_method_title() ) . '</li>';
}
?>
</select>
<input type="hidden" name="zone_id" value="{{{ data.zone_id }}}" />

View File

@ -27,16 +27,16 @@ if ( ! defined( 'ABSPATH' ) ) {
</th>
<td class="forminp">
<?php
$curent_user_id = get_current_user_id();
$user_id = ! empty( $key_data['user_id'] ) ? absint( $key_data['user_id'] ) : $curent_user_id;
$user = get_user_by( 'id', $user_id );
/* translators: 1: user display name 2: user ID 3: user email */
$user_string = sprintf(
esc_html__( '%1$s (#%2$s &ndash; %3$s)', 'woocommerce' ),
$user->display_name,
absint( $user->ID ),
$user->user_email
);
$curent_user_id = get_current_user_id();
$user_id = ! empty( $key_data['user_id'] ) ? absint( $key_data['user_id'] ) : $curent_user_id;
$user = get_user_by( 'id', $user_id );
/* translators: 1: user display name 2: user ID 3: user email */
$user_string = sprintf(
esc_html__( '%1$s (#%2$s &ndash; %3$s)', 'woocommerce' ),
$user->display_name,
absint( $user->ID ),
$user->user_email
);
?>
<select class="wc-customer-search" id="key_user" data-placeholder="<?php esc_attr_e( 'Search for a user&hellip;', 'woocommerce' ); ?>" data-allow_clear="true">
<option value="<?php echo esc_attr( $user_id ); ?>" selected="selected"><?php echo $user_string; ?><option>
@ -51,13 +51,14 @@ if ( ! defined( 'ABSPATH' ) ) {
<td class="forminp">
<select id="key_permissions" class="wc-enhanced-select">
<?php
$permissions = array(
'read' => __( 'Read', 'woocommerce' ),
'write' => __( 'Write', 'woocommerce' ),
'read_write' => __( 'Read/Write', 'woocommerce' ),
);
$permissions = array(
'read' => __( 'Read', 'woocommerce' ),
'write' => __( 'Write', 'woocommerce' ),
'read_write' => __( 'Read/Write', 'woocommerce' ),
);
foreach ( $permissions as $permission_id => $permission_name ) : ?>
foreach ( $permissions as $permission_id => $permission_name ) :
?>
<option value="<?php echo esc_attr( $permission_id ); ?>" <?php selected( $key_data['permissions'], $permission_id, true ); ?>><?php echo esc_html( $permission_name ); ?></option>
<?php endforeach; ?>
</select>
@ -78,16 +79,18 @@ if ( ! defined( 'ABSPATH' ) ) {
<?php _e( 'Last access', 'woocommerce' ); ?>
</th>
<td class="forminp">
<span><?php
if ( ! empty( $key_data['last_access'] ) ) {
/* translators: 1: last access date 2: last access time */
$date = sprintf( __( '%1$s at %2$s', 'woocommerce' ), date_i18n( wc_date_format(), strtotime( $key_data['last_access'] ) ), date_i18n( wc_time_format(), strtotime( $key_data['last_access'] ) ) );
<span>
<?php
if ( ! empty( $key_data['last_access'] ) ) {
/* translators: 1: last access date 2: last access time */
$date = sprintf( __( '%1$s at %2$s', 'woocommerce' ), date_i18n( wc_date_format(), strtotime( $key_data['last_access'] ) ), date_i18n( wc_time_format(), strtotime( $key_data['last_access'] ) ) );
echo apply_filters( 'woocommerce_api_key_last_access_datetime', $date, $key_data['last_access'] );
} else {
_e( 'Unknown', 'woocommerce' );
}
?></span>
echo apply_filters( 'woocommerce_api_key_last_access_datetime', $date, $key_data['last_access'] );
} else {
_e( 'Unknown', 'woocommerce' );
}
?>
</span>
</td>
</tr>
<?php endif ?>
@ -97,16 +100,16 @@ if ( ! defined( 'ABSPATH' ) ) {
<?php do_action( 'woocommerce_admin_key_fields', $key_data ); ?>
<?php
if ( 0 == $key_id ) {
submit_button( __( 'Generate API key', 'woocommerce' ), 'primary', 'update_api_key' );
} else {
?>
<p class="submit">
<?php submit_button( __( 'Save changes', 'woocommerce' ), 'primary', 'update_api_key', false ); ?>
<a style="color: #a00; text-decoration: none; margin-left: 10px;" href="<?php echo esc_url( wp_nonce_url( add_query_arg( array( 'revoke-key' => $key_id ), admin_url( 'admin.php?page=wc-settings&tab=api&section=keys' ) ), 'revoke' ) ); ?>"><?php _e( 'Revoke key', 'woocommerce' ); ?></a>
</p>
<?php
}
if ( 0 == $key_id ) {
submit_button( __( 'Generate API key', 'woocommerce' ), 'primary', 'update_api_key' );
} else {
?>
<p class="submit">
<?php submit_button( __( 'Save changes', 'woocommerce' ), 'primary', 'update_api_key', false ); ?>
<a style="color: #a00; text-decoration: none; margin-left: 10px;" href="<?php echo esc_url( wp_nonce_url( add_query_arg( array( 'revoke-key' => $key_id ), admin_url( 'admin.php?page=wc-settings&tab=api&section=keys' ) ), 'revoke' ) ); ?>"><?php _e( 'Revoke key', 'woocommerce' ); ?></a>
</p>
<?php
}
?>
</div>

Some files were not shown because too many files have changed in this diff Show More