Merge remote-tracking branch 'refs/remotes/woothemes/master'

This commit is contained in:
Reigel Gallarde 2016-01-28 13:28:19 +08:00
commit 66dcacdb73
143 changed files with 2223 additions and 1627 deletions

View File

@ -1,5 +1,84 @@
== Changelog == == Changelog ==
= 2.5.1 - 25/01/2016 =
* Fix - Remove usage of get_currentuserinfo() which is deprecated in WordPress 4.5.
* Fix - Fix responsive product sizes when the columns class is missing.
* Fix - Fix function exists check for woocommerce_template_loop_category_title.
* Fix - check_version on all requests so that the installer runs after remote plugin updates.
* Fix - Only show the "add payment method" button when needed, and check for required fields on the add payment method page.
* Fix - Correctly block UI to prevent attribute issues in backend when adding multiple attributes in quick succession.
* Fix - Show SKU in admin emails.
* Fix - Don't show downloads in admin emails.
* Fix - Fix query/missing variable in validate_user_usage_limit function.
* Fix - Prevent endless loading on checkout when reload_checkout session variable was used.
* Fix - Correctly display html entities in tax screen autocomplete.
* Fix - Do sales reports based on refund line items rather than fully refunded orders to prevent double refunds being reported.
* Fix - Qty button can be hidden for variable products sold individually.
* Fix - Show the taxable country rather than base country in "estimated for" text during checkout.
* Fix - Prevent select2 gaining focus on IOS7 scroll.
* Fix - API - Fix indexes on decimal and thousand values.
* Tweak - Clear cron jobs on uninstall.
* Tweak - Don't disable place order button on checkout if a weak password is used.
* Tweak - Added password strength meter in lost password and edit accout pages.
* Tweak - Pass $args to woocommerce_dropdown_variation_attribute_options_html hook.
= 2.5.0 - 18/01/2016 =
* Feature - New default session handler. Uses custom table to store data rather than the options table for performance and scalability reasons. https://woocommerce.wordpress.com/2015/10/07/new-session-handler-in-2-5/
* Feature - New tax settings UI - faster, enhanced with ajax, searchable.
* Feature - WP CLI Support. https://woocommerce.wordpress.com/2015/10/01/sneak-peek-wp-cli-support-in-woocommerce/
* Feature - Added terms and conditions checkbox to pay page.
* Feature - Password strength indicators.
* Feature - Added 'pay' link to order screen.
* Feature - Added admin order/payment failed notification.
* Fix - Check for existence of global attribute when you get_attributes() for a product.
* Fix - Show order by template on product search.
* Fix - Search variation skus in backend search.
* Tweak - For coupons with category restrictions, respect the category hierarchy.
* Tweak - Added wc_array_cartesian function to generate variations in a logical order.
* Tweak - Revised email settings screens to show emails in a table and avoid a long sub-nav.
* Tweak - Default customer role capabilities.
* Tweak - Expire mini-cart cache after 24 hours.
* Tweak - Improved refund error messages in PayPal standard.
* Tweak - Removed language pack downloader in favour of translate.wordpress.org.
* Tweak - Added onboarding wizard button to the contextual help so it can be accessed again.
* Tweak - When a WordPress user is deleted, turn any orders they have into Guest orders.
* Tweak - When calculating order taxes, respect tax settings and default to base country.
* Tweak - Fade in variation images to avoid flicker during load.
* Tweak - Display 2 averages on report (net and gross).
* Tweak - Improve product search and use WPDB instead of several get_posts queries for performance.
* Tweak - Use SKU for stock order notes.
* Tweak - Added order notes for manual email sends.
* Tweak - Sanitize shipping method labels/titles.
* Tweak - Only display the coupon form on the checkout if a coupon hasn't been applied.
* Tweak - Added billing address column to order screen (off for new users).
* Tweak - Created function to disable author archives for customers.
* Tweak - When updating cart hash, refresh all open tabs.
* Tweak - Use new "question" mark icon font for help tips.
* Tweak - Improved review verification status retrieval.
* Tweak - Improve appearance when only 1 gateway is active.
* Tweak - Aligned terms box left and added required asterisk.
* Tweak - Removed dropdown display mode for cart shipping methods - radios are more flexible.
* Dev - API - Added /products/shipping_classes endpoint.
* Dev - API - Added support to POST, PUT, and DELETE categories and tags.
* Dev - API - Added support to filter products by tag, category, shipping class, and attribute.
* Dev - API - Added tax and tax_class endpoints.
* Dev - Template - New star ratings. The old one was 5 separate buttons. This new one consolidates the 5 options into one element making it leaner visually and more intuitive. Works in IE9+ with a graceful degradation for IE8.
* Dev - Template - Added `data-title` attribute to cart table.
* Dev - Template - Product archive anchors are now hooked into templates rather than hard coded.
* Dev - Template - Added template files for the customer details list in emails. emails/email-customer-details.php
* Dev - Template - Revised single variation cart template. Template files now exist for variations, and the cart button will display (disabled) when no selections are made.
* Dev - Template - Made "my orders" columns fully customizable with filters.
* Dev - Template - Unified email template order details tables to use a single template.
* Dev - Allow wc_clean to support arrays.
* Dev - Added a manual update trigger for checkout.
* Dev - Added woocommerce_is_price_filter_active filter to Query class.
* Dev - Replaced some cart methods with dedicated functions. e.g. wc_ship_to_billing_address_only().
* Localisation - Add Kenyan currency and symbol.
= 2.4.13 - 11/01/2016 =
* Fix - Potential redirect loop when using 'unforce ssl' setting and a https home URL.
* Fix - Escape option names when cleaning up sessions.
= 2.4.12 - 9/12/2015 = = 2.4.12 - 9/12/2015 =
* Fix - 4.4 - Permission error when editing attribute terms. * Fix - 4.4 - Permission error when editing attribute terms.
* Fix - 4.4 - Missing variation images when wp_get_attachment_image_srcset() returns false instead of a string. * Fix - 4.4 - Missing variation images when wp_get_attachment_image_srcset() returns false instead of a string.

View File

@ -235,6 +235,12 @@ module.exports = function( grunt ) {
'css' 'css'
]); ]);
grunt.registerTask( 'js', [
'jshint',
'uglify:admin',
'uglify:frontend'
]);
grunt.registerTask( 'css', [ grunt.registerTask( 'css', [
'sass', 'sass',
'cssmin' 'cssmin'

File diff suppressed because one or more lines are too long

View File

@ -1880,6 +1880,13 @@ a.import_rates {
font-size: 1.2em; font-size: 1.2em;
} }
} }
#rates-pagination {
float: right;
margin-right: .5em;
.tablenav {
margin: 0;
}
}
table.wc_tax_rates, table.wc_tax_rates,
table.wc_input_table { table.wc_input_table {
@ -2943,7 +2950,8 @@ img.help_tip {
input[type="text"], input[type="text"],
input[type="email"], input[type="email"],
input[type="number"] { input[type="number"],
input[type="password"] {
width: 50%; width: 50%;
float: left; float: left;
} }
@ -2960,6 +2968,7 @@ img.help_tip {
input[type="text"].short, input[type="text"].short,
input[type="email"].short, input[type="email"].short,
input[type="number"].short, input[type="number"].short,
input[type="password"].short,
.short { .short {
width: 50%; width: 50%;
} }

File diff suppressed because one or more lines are too long

View File

@ -99,7 +99,7 @@
/** /**
* Products * Products
*/ */
&[class*="columns-"] { &, &[class*="columns-"] {
ul.products { ul.products {
li.product { li.product {
width: 48%; width: 48%;

File diff suppressed because one or more lines are too long

View File

@ -1324,6 +1324,12 @@ p.demo_store {
padding: .25em 0 .25em 22px; padding: .25em 0 .25em 22px;
text-indent: -22px; text-indent: -22px;
list-style: none outside; list-style: none outside;
input {
margin: 3px 0.5ex;
}
label {
display: inline;
}
} }
.amount { .amount {
@ -1908,6 +1914,11 @@ p.demo_store {
} }
} }
.woocommerce-password-hint {
margin: .5em 0 0 0;
display: block;
}
/* added to get around variation image flicker issue */ /* added to get around variation image flicker issue */
.product.has-default-attributes.has-children { .product.has-default-attributes.has-children {
> .images { > .images {

View File

@ -131,12 +131,12 @@ jQuery( function( $ ) {
// Hide/Show all with rules // Hide/Show all with rules
var hide_classes = '.hide_if_downloadable, .hide_if_virtual'; var hide_classes = '.hide_if_downloadable, .hide_if_virtual';
var show_classes = '.show_if_downloadable, .show_if_virtual, .show_if_external'; var show_classes = '.show_if_downloadable, .show_if_virtual';
$.each( woocommerce_admin_meta_boxes.product_types, function( index, value ) { $.each( woocommerce_admin_meta_boxes.product_types, function( index, value ) {
hide_classes = hide_classes + ', .hide_if_' + value; hide_classes = hide_classes + ', .hide_if_' + value;
show_classes = show_classes + ', .show_if_' + value; show_classes = show_classes + ', .show_if_' + value;
} ); });
$( hide_classes ).show(); $( hide_classes ).show();
$( show_classes ).hide(); $( show_classes ).hide();
@ -270,7 +270,8 @@ jQuery( function( $ ) {
$( 'button.add_attribute' ).on( 'click', function() { $( 'button.add_attribute' ).on( 'click', function() {
var size = $( '.product_attributes .woocommerce_attribute' ).size(); var size = $( '.product_attributes .woocommerce_attribute' ).size();
var attribute = $( 'select.attribute_taxonomy' ).val(); var attribute = $( 'select.attribute_taxonomy' ).val();
var $wrapper = $( this ).closest( '#product_attributes' ).find( '.product_attributes' ); var $wrapper = $( this ).closest( '#product_attributes' );
var $attributes = $wrapper.find( '.product_attributes' );
var product_type = $( 'select#product-type' ).val(); var product_type = $( 'select#product-type' ).val();
var data = { var data = {
action: 'woocommerce_add_attribute', action: 'woocommerce_add_attribute',
@ -288,10 +289,10 @@ jQuery( function( $ ) {
}); });
$.post( woocommerce_admin_meta_boxes.ajax_url, data, function( response ) { $.post( woocommerce_admin_meta_boxes.ajax_url, data, function( response ) {
$wrapper.append( response ); $attributes.append( response );
if ( product_type !== 'variable' ) { if ( product_type !== 'variable' ) {
$wrapper.find( '.enable_variation' ).hide(); $attributes.find( '.enable_variation' ).hide();
} }
$( document.body ).trigger( 'wc-enhanced-select-init' ); $( document.body ).trigger( 'wc-enhanced-select-init' );

File diff suppressed because one or more lines are too long

View File

@ -1,8 +1,8 @@
/* global htmlSettingsTaxLocalizeScript, ajaxurl */ /* global htmlSettingsTaxLocalizeScript, ajaxurl */
/** /**
* Used by woocommerce/includes/admin/settings/views/html-settings-tax.php * Used by woocommerce/includes/admin/settings/views/html-settings-tax.php
*/ */
( function( $, data, wp, ajaxurl ) { ( function( $, data, wp, ajaxurl ) {
$( function() { $( function() {
@ -39,7 +39,9 @@
var changes = this.changes || {}; var changes = this.changes || {};
_.each( changedRows, function( row, id ) { _.each( changedRows, function( row, id ) {
changes[ id ] = _.extend( changes[ id ] || { tax_rate_id : id }, row ); changes[ id ] = _.extend( changes[ id ] || {
tax_rate_id : id
}, row );
} ); } );
this.changes = changes; this.changes = changes;
@ -95,6 +97,9 @@
WCTaxTableModelInstance.changes = {}; WCTaxTableModelInstance.changes = {};
WCTaxTableModelInstance.trigger( 'saved:rates' ); WCTaxTableModelInstance.trigger( 'saved:rates' );
// Reload view.
WCTaxTableInstance.render();
} }
self.unblock(); self.unblock();
@ -114,7 +119,7 @@
this.listenTo( this.model, 'change:rates', this.setUnloadConfirmation ); this.listenTo( this.model, 'change:rates', this.setUnloadConfirmation );
this.listenTo( this.model, 'saved:rates', this.clearUnloadConfirmation ); this.listenTo( this.model, 'saved:rates', this.clearUnloadConfirmation );
$tbody.on( 'change', ':input', { view: this }, this.updateModelOnChange ); $tbody.on( 'change autocompletechange', ':input', { view: this }, this.updateModelOnChange );
$tbody.on( 'sortupdate', { view: this }, this.updateModelOnSort ); $tbody.on( 'sortupdate', { view: this }, this.updateModelOnSort );
$search_field.on( 'keyup search', { view: this }, this.onSearchField ); $search_field.on( 'keyup search', { view: this }, this.onSearchField );
$pagination.on( 'click', 'a', { view: this }, this.onPageChange ); $pagination.on( 'click', 'a', { view: this }, this.onPageChange );
@ -173,6 +178,9 @@
current_page: this.page, current_page: this.page,
qty_pages: qty_pages qty_pages: qty_pages
} ) ); } ) );
} else {
$pagination.empty();
view.page = 1;
} }
// Disable sorting if there is a search term filtering the items. // Disable sorting if there is a search term filtering the items.
@ -243,6 +251,8 @@
return parseInt( val, 10 ); return parseInt( val, 10 );
} }
); );
// Move the last page
view.page = view.qty_pages;
} }
rates[ newRow.tax_rate_id ] = newRow; rates[ newRow.tax_rate_id ] = newRow;
@ -258,27 +268,13 @@
model = view.model, model = view.model,
rates = _.indexBy( model.get( 'rates' ), 'tax_rate_id' ), rates = _.indexBy( model.get( 'rates' ), 'tax_rate_id' ),
changes = {}, changes = {},
$current, current_id, current_order, rates_to_reorder, reordered_rates; $current, current_id;
event.preventDefault(); event.preventDefault();
if ( $current = $tbody.children( '.current' ) ) { if ( $current = $tbody.children( '.current' ) ) {
$current.each(function(){ $current.each(function(){
current_id = $( this ).data('id'); current_id = $( this ).data('id');
current_order = parseInt( rates[ current_id ].tax_rate_order, 10 );
rates_to_reorder = _.filter( rates, function( rate ) {
if ( parseInt( rate.tax_rate_order, 10 ) > current_order ) {
return true;
}
return false;
} );
reordered_rates = _.map( rates_to_reorder, function( rate ) {
rate.tax_rate_order--;
changes[ rate.tax_rate_id ] = _.extend( changes[ rate.tax_rate_id ] || {}, { tax_rate_order : rate.tax_rate_order } );
return rate;
} );
delete rates[ current_id ]; delete rates[ current_id ];
@ -368,53 +364,29 @@
model.setRateAttribute( id, attribute, val ); model.setRateAttribute( id, attribute, val );
}, },
updateModelOnSort: function( event, ui ) { updateModelOnSort: function( event ) {
var view = event.data.view, var view = event.data.view,
model = view.model, model = view.model,
$tr = ui.item,
tax_rate_id = $tr.data( 'id' ),
rates = _.indexBy( model.get( 'rates' ), 'tax_rate_id' ), rates = _.indexBy( model.get( 'rates' ), 'tax_rate_id' ),
old_position = rates[ tax_rate_id ].tax_rate_order, changes = {};
new_position = $tr.index() + ( ( view.page - 1 ) * view.per_page ),
which_way = ( new_position > old_position ) ? 'higher' : 'lower',
changes = {},
rates_to_reorder, reordered_rates;
rates_to_reorder = _.filter( rates, function( rate ) { _.each( rates, function( rate ) {
var order = parseInt( rate.tax_rate_order, 10 ), var new_position = 0;
limits = [ old_position, new_position ]; var old_position = parseInt( rate.tax_rate_order, 10 );
if ( parseInt( rate.tax_rate_id, 10 ) === parseInt( tax_rate_id, 10 ) ) { if ( $table.find( 'tr[data-id="' + rate.tax_rate_id + '"]').size() ) {
return true; new_position = parseInt( $table.find( 'tr[data-id="' + rate.tax_rate_id + '"]').index(), 10 ) + parseInt( ( view.page - 1 ) * view.per_page, 10 );
} else if ( order > _.min( limits ) && order < _.max( limits ) ) { } else {
return true; new_position = old_position;
} else if ( 'higher' === which_way && order === _.max( limits ) ) {
return true;
} else if ( 'lower' === which_way && order === _.min( limits ) ) {
return true;
}
return false;
} );
reordered_rates = _.map( rates_to_reorder, function( rate ) {
var order = parseInt( rate.tax_rate_order, 10 );
if ( parseInt( rate.tax_rate_id, 10 ) === parseInt( tax_rate_id, 10 ) ) {
rate.tax_rate_order = new_position;
} else if ( 'higher' === which_way ) {
rate.tax_rate_order = order - 1;
} else if ( 'lower' === which_way ) {
rate.tax_rate_order = order + 1;
} }
changes[ rate.tax_rate_id ] = _.extend( changes[ rate.tax_rate_id ] || {}, { tax_rate_order : rate.tax_rate_order } ); if ( old_position !== new_position ) {
changes[ rate.tax_rate_id ] = _.extend( changes[ rate.tax_rate_id ] || {}, { tax_rate_order : new_position } );
return rate; }
} ); } );
if ( reordered_rates.length ) { if ( _.size( changes ) ) {
model.logChanges( changes ); model.logChanges( changes );
view.render(); // temporary, probably should get yanked.
} }
}, },
sanitizePage: function( page_num ) { sanitizePage: function( page_num ) {
@ -432,8 +404,6 @@
} ), } ),
WCTaxTableInstance = new WCTaxTableViewConstructor({ WCTaxTableInstance = new WCTaxTableViewConstructor({
model: WCTaxTableModelInstance, model: WCTaxTableModelInstance,
// page: data.page, // I'd prefer to have these two specified down here in the instance,
// per_page: data.limit, // but it doesn't seem to recognize them in render if I do. :\
el: '#rates' el: '#rates'
} ); } );

File diff suppressed because one or more lines are too long

View File

@ -53,7 +53,7 @@ jQuery( function ( $ ) {
}) })
.on( 'keyup change', '.wc_input_country_iso[type=text]', function() { .on( 'keyup change', '.wc_input_country_iso[type=text]', function() {
var value = $( this ).val(); var value = $( this ).val();
var regex = new RegExp( '^([A-Z])?([A-Z])$' ); var regex = new RegExp( '^([a-zA-Z])?([a-zA-Z])$' );
if ( ! regex.test( value ) ) { if ( ! regex.test( value ) ) {
$( this ).val( '' ); $( this ).val( '' );
@ -222,4 +222,11 @@ jQuery( function ( $ ) {
// Attribute term table // Attribute term table
$( 'table.attributes-table tbody tr:nth-child(odd)' ).addClass( 'alternate' ); $( 'table.attributes-table tbody tr:nth-child(odd)' ).addClass( 'alternate' );
// Load videos when help button is clicked.
$( '#contextual-help-link' ).on( 'click', function() {
var frame = $( '#tab-panel-woocommerce_101_tab iframe' );
frame.attr( 'src', frame.data( 'src' ) );
});
}); });

File diff suppressed because one or more lines are too long

View File

@ -181,13 +181,23 @@
$form.wc_variations_image_update( variation ); $form.wc_variations_image_update( variation );
// Output correct templates // Output correct templates
var $template_html = '';
if ( ! variation.variation_is_visible ) { if ( ! variation.variation_is_visible ) {
$single_variation.html( unavailable_template ); $template_html = unavailable_template;
// w3 total cache inline minification adds CDATA tags around our HTML (sigh)
$template_html = $template_html.replace( '/*<![CDATA[*/', '' );
$template_html = $template_html.replace( '/*]]>*/', '' );
$single_variation.html( $template_html );
$form.find( 'input[name="variation_id"], input.variation_id' ).val( '' ).change(); $form.find( 'input[name="variation_id"], input.variation_id' ).val( '' ).change();
} else { } else {
$single_variation.html( template( { $template_html = template( {
variation: variation variation: variation
} ) ); } );
// w3 total cache inline minification adds CDATA tags around our HTML (sigh)
$template_html = $template_html.replace( '/*<![CDATA[*/', '' );
$template_html = $template_html.replace( '/*]]>*/', '' );
$single_variation.html( $template_html );
$form.find( 'input[name="variation_id"], input.variation_id' ).val( variation.variation_id ).change(); $form.find( 'input[name="variation_id"], input.variation_id' ).val( variation.variation_id ).change();
} }

File diff suppressed because one or more lines are too long

View File

@ -62,7 +62,6 @@ jQuery( function( $ ) {
var wc_country_select_select2 = function() { var wc_country_select_select2 = function() {
$( 'select.country_select:visible, select.state_select:visible' ).each( function() { $( 'select.country_select:visible, select.state_select:visible' ).each( function() {
var select2_args = $.extend({ var select2_args = $.extend({
placeholder: $( this ).attr( 'placeholder' ),
placeholderOption: 'first', placeholderOption: 'first',
width: '100%' width: '100%'
}, getEnhancedSelectFormatString() ); }, getEnhancedSelectFormatString() );
@ -91,7 +90,7 @@ jQuery( function( $ ) {
input_name = $statebox.attr( 'name' ), input_name = $statebox.attr( 'name' ),
input_id = $statebox.attr( 'id' ), input_id = $statebox.attr( 'id' ),
value = $statebox.val(), value = $statebox.val(),
placeholder = $statebox.attr( 'placeholder' ); placeholder = $statebox.attr( 'placeholder' ) || $statebox.attr( 'data-placeholder' ) || '';
if ( states[ country ] ) { if ( states[ country ] ) {
if ( $.isEmptyObject( states[ country ] ) ) { if ( $.isEmptyObject( states[ country ] ) ) {
@ -116,7 +115,7 @@ jQuery( function( $ ) {
if ( $statebox.is( 'input' ) ) { if ( $statebox.is( 'input' ) ) {
// Change for select // Change for select
$statebox.replaceWith( '<select name="' + input_name + '" id="' + input_id + '" class="state_select" placeholder="' + placeholder + '"></select>' ); $statebox.replaceWith( '<select name="' + input_name + '" id="' + input_id + '" class="state_select" data-placeholder="' + placeholder + '"></select>' );
$statebox = $wrapper.find( '#billing_state, #shipping_state, #calc_shipping_state' ); $statebox = $wrapper.find( '#billing_state, #shipping_state, #calc_shipping_state' );
} }

View File

@ -1 +1 @@
jQuery(function(a){function b(){var a={formatMatches:function(a){return 1===a?wc_country_select_params.i18n_matches_1:wc_country_select_params.i18n_matches_n.replace("%qty%",a)},formatNoMatches:function(){return wc_country_select_params.i18n_no_matches},formatAjaxError:function(){return wc_country_select_params.i18n_ajax_error},formatInputTooShort:function(a,b){var c=b-a.length;return 1===c?wc_country_select_params.i18n_input_too_short_1:wc_country_select_params.i18n_input_too_short_n.replace("%qty%",c)},formatInputTooLong:function(a,b){var c=a.length-b;return 1===c?wc_country_select_params.i18n_input_too_long_1:wc_country_select_params.i18n_input_too_long_n.replace("%qty%",c)},formatSelectionTooBig:function(a){return 1===a?wc_country_select_params.i18n_selection_too_long_1:wc_country_select_params.i18n_selection_too_long_n.replace("%qty%",a)},formatLoadMore:function(){return wc_country_select_params.i18n_load_more},formatSearching:function(){return wc_country_select_params.i18n_searching}};return a}if("undefined"==typeof wc_country_select_params)return!1;if(a().select2){var c=function(){a("select.country_select:visible, select.state_select:visible").each(function(){var c=a.extend({placeholder:a(this).attr("placeholder"),placeholderOption:"first",width:"100%"},b());a(this).select2(c)})};c(),a(document.body).bind("country_to_state_changed",function(){c()})}var d=wc_country_select_params.countries.replace(/&quot;/g,'"'),e=a.parseJSON(d);a(document.body).on("change","select.country_to_state, input.country_to_state",function(){var b=a(this).val(),c=a(this).closest(".form-row").parent(),d=c.find("#billing_state, #shipping_state, #calc_shipping_state"),f=d.parent(),g=d.attr("name"),h=d.attr("id"),i=d.val(),j=d.attr("placeholder");if(e[b])if(a.isEmptyObject(e[b]))d.parent().hide().find(".select2-container").remove(),d.replaceWith('<input type="hidden" class="hidden" name="'+g+'" id="'+h+'" value="" placeholder="'+j+'" />'),a(document.body).trigger("country_to_state_changed",[b,c]);else{var k="",l=e[b];for(var m in l)l.hasOwnProperty(m)&&(k=k+'<option value="'+m+'">'+l[m]+"</option>");d.parent().show(),d.is("input")&&(d.replaceWith('<select name="'+g+'" id="'+h+'" class="state_select" placeholder="'+j+'"></select>'),d=c.find("#billing_state, #shipping_state, #calc_shipping_state")),d.html('<option value="">'+wc_country_select_params.i18n_select_state_text+"</option>"+k),d.val(i).change(),a(document.body).trigger("country_to_state_changed",[b,c])}else d.is("select")?(f.show().find(".select2-container").remove(),d.replaceWith('<input type="text" class="input-text" name="'+g+'" id="'+h+'" placeholder="'+j+'" />'),a(document.body).trigger("country_to_state_changed",[b,c])):d.is(".hidden")&&(f.show().find(".select2-container").remove(),d.replaceWith('<input type="text" class="input-text" name="'+g+'" id="'+h+'" placeholder="'+j+'" />'),a(document.body).trigger("country_to_state_changed",[b,c]));a(document.body).trigger("country_to_state_changing",[b,c])}),a(function(){a(":input.country_to_state").change()})}); jQuery(function(a){function b(){var a={formatMatches:function(a){return 1===a?wc_country_select_params.i18n_matches_1:wc_country_select_params.i18n_matches_n.replace("%qty%",a)},formatNoMatches:function(){return wc_country_select_params.i18n_no_matches},formatAjaxError:function(){return wc_country_select_params.i18n_ajax_error},formatInputTooShort:function(a,b){var c=b-a.length;return 1===c?wc_country_select_params.i18n_input_too_short_1:wc_country_select_params.i18n_input_too_short_n.replace("%qty%",c)},formatInputTooLong:function(a,b){var c=a.length-b;return 1===c?wc_country_select_params.i18n_input_too_long_1:wc_country_select_params.i18n_input_too_long_n.replace("%qty%",c)},formatSelectionTooBig:function(a){return 1===a?wc_country_select_params.i18n_selection_too_long_1:wc_country_select_params.i18n_selection_too_long_n.replace("%qty%",a)},formatLoadMore:function(){return wc_country_select_params.i18n_load_more},formatSearching:function(){return wc_country_select_params.i18n_searching}};return a}if("undefined"==typeof wc_country_select_params)return!1;if(a().select2){var c=function(){a("select.country_select:visible, select.state_select:visible").each(function(){var c=a.extend({placeholderOption:"first",width:"100%"},b());a(this).select2(c)})};c(),a(document.body).bind("country_to_state_changed",function(){c()})}var d=wc_country_select_params.countries.replace(/&quot;/g,'"'),e=a.parseJSON(d);a(document.body).on("change","select.country_to_state, input.country_to_state",function(){var b=a(this).val(),c=a(this).closest(".form-row").parent(),d=c.find("#billing_state, #shipping_state, #calc_shipping_state"),f=d.parent(),g=d.attr("name"),h=d.attr("id"),i=d.val(),j=d.attr("placeholder")||d.attr("data-placeholder")||"";if(e[b])if(a.isEmptyObject(e[b]))d.parent().hide().find(".select2-container").remove(),d.replaceWith('<input type="hidden" class="hidden" name="'+g+'" id="'+h+'" value="" placeholder="'+j+'" />'),a(document.body).trigger("country_to_state_changed",[b,c]);else{var k="",l=e[b];for(var m in l)l.hasOwnProperty(m)&&(k=k+'<option value="'+m+'">'+l[m]+"</option>");d.parent().show(),d.is("input")&&(d.replaceWith('<select name="'+g+'" id="'+h+'" class="state_select" data-placeholder="'+j+'"></select>'),d=c.find("#billing_state, #shipping_state, #calc_shipping_state")),d.html('<option value="">'+wc_country_select_params.i18n_select_state_text+"</option>"+k),d.val(i).change(),a(document.body).trigger("country_to_state_changed",[b,c])}else d.is("select")?(f.show().find(".select2-container").remove(),d.replaceWith('<input type="text" class="input-text" name="'+g+'" id="'+h+'" placeholder="'+j+'" />'),a(document.body).trigger("country_to_state_changed",[b,c])):d.is(".hidden")&&(f.show().find(".select2-container").remove(),d.replaceWith('<input type="text" class="input-text" name="'+g+'" id="'+h+'" placeholder="'+j+'" />'),a(document.body).trigger("country_to_state_changed",[b,c]));a(document.body).trigger("country_to_state_changing",[b,c])}),a(function(){a(":input.country_to_state").change()})});

View File

@ -1,44 +1,65 @@
/* global wp, pwsL10n */ /* global wp, pwsL10n, wc_password_strength_meter_params */
jQuery( function( $ ) { jQuery( function( $ ) {
/** /**
* Password Strength Meter class * Password Strength Meter class.
*/ */
var wc_password_strength_meter = { var wc_password_strength_meter = {
/** /**
* Initialize strength meter actions * Initialize strength meter actions.
*/ */
init: function() { init: function() {
$( document.body ) $( document.body )
.on( 'keyup', 'form.register #reg_password, form.checkout #account_password', this.strengthMeter ) .on( 'keyup', 'form.register #reg_password, form.checkout #account_password, form.edit-account #password_1, form.lost_reset_password #password_1', this.strengthMeter )
.on( 'change', 'form.checkout #createaccount', this.checkoutNeedsRegistration ); .on( 'submit', 'form.register, form.edit-account, form.lost_reset_password', this.onSubmit );
$( 'form.checkout #createaccount' ).change(); $( 'form.checkout #createaccount' ).change();
}, },
/** /**
* Strength Meter * Strength Meter.
*/ */
strengthMeter: function() { strengthMeter: function() {
var wrapper = $( 'form.register, form.checkout' ), var wrapper = $( 'form.register, form.checkout, form.edit-account, form.lost_reset_password' ),
submit = $( 'input[type="submit"]', wrapper ), submit = $( 'input[type="submit"]', wrapper ),
field = $( '#reg_password, #account_password', wrapper ), field = $( '#reg_password, #account_password, #password_1', wrapper ),
strength = 1; strength = 1;
wc_password_strength_meter.includeMeter( wrapper, field ); wc_password_strength_meter.includeMeter( wrapper, field );
strength = wc_password_strength_meter.checkPasswordStrength( field ); strength = wc_password_strength_meter.checkPasswordStrength( field );
// Add class to wrapper
if ( 3 === strength || 4 === strength ) { if ( 3 === strength || 4 === strength ) {
submit.removeAttr( 'disabled' ); wrapper.removeClass( 'has-weak-password' );
} else { } else {
submit.attr( 'disabled', 'disabled' ); wrapper.addClass( 'has-weak-password' );
}
// Stop form if password is weak... But not in checkout form!
if ( 3 === strength || 4 === strength ) {
submit.removeClass( 'disabled' );
} else if ( ! wrapper.hasClass( 'checkout' ) ) {
submit.addClass( 'disabled' );
} }
}, },
/** /**
* Include meter HTML * When the form is submitted, prevent if weak.
*/
onSubmit: function() {
$( '.woocommerce-password-error' ).remove();
if ( $( this ).is( '.has-weak-password' ) ) {
$( this ).prepend( '<div class="woocommerce-error woocommerce-password-error">' + wc_password_strength_meter_params.i18n_password_error + '</div>' );
return false;
} else {
return true;
}
},
/**
* Include meter HTML.
* *
* @param {Object} wrapper * @param {Object} wrapper
* @param {Object} field * @param {Object} field
@ -54,22 +75,26 @@ jQuery( function( $ ) {
}, },
/** /**
* Check password strength * Check password strength.
* *
* @param {Object} field * @param {Object} field
* *
* @return {Int} * @return {Int}
*/ */
checkPasswordStrength: function( field ) { checkPasswordStrength: function( field ) {
var meter = $( '.woocommerce-password-strength' ); var meter = $( '.woocommerce-password-strength' );
var strength = wp.passwordStrength.meter( field.val(), wp.passwordStrength.userInputBlacklist() ); var hint = $( '.woocommerce-password-hint' );
var hint_html = '<small class="woocommerce-password-hint">' + wc_password_strength_meter_params.i18n_password_hint + '</small>';
var strength = wp.passwordStrength.meter( field.val(), wp.passwordStrength.userInputBlacklist() );
// Reset classes // Reset
meter.removeClass( 'short bad good strong' ); meter.removeClass( 'short bad good strong' );
hint.remove();
switch ( strength ) { switch ( strength ) {
case 2 : case 2 :
meter.addClass( 'bad' ).html( pwsL10n.bad ); meter.addClass( 'bad' ).html( pwsL10n.bad );
meter.after( hint_html );
break; break;
case 3 : case 3 :
meter.addClass( 'good' ).html( pwsL10n.good ); meter.addClass( 'good' ).html( pwsL10n.good );
@ -80,25 +105,12 @@ jQuery( function( $ ) {
case 5 : case 5 :
meter.addClass( 'short' ).html( pwsL10n.mismatch ); meter.addClass( 'short' ).html( pwsL10n.mismatch );
break; break;
default : default :
meter.addClass( 'short' ).html( pwsL10n['short'] ); meter.addClass( 'short' ).html( pwsL10n['short'] );
meter.after( hint_html );
} }
return strength; return strength;
},
/**
* Check if user wants register on checkout.
*/
checkoutNeedsRegistration: function() {
var submit = $( 'form.checkout input[type="submit"]' );
if ( $( this ).is( ':checked' ) ) {
submit.attr( 'disabled', 'disabled' );
} else {
submit.removeAttr( 'disabled' );
}
} }
}; };

View File

@ -1 +1 @@
jQuery(function(a){var b={init:function(){a(document.body).on("keyup","form.register #reg_password, form.checkout #account_password",this.strengthMeter).on("change","form.checkout #createaccount",this.checkoutNeedsRegistration),a("form.checkout #createaccount").change()},strengthMeter:function(){var c=a("form.register, form.checkout"),d=a('input[type="submit"]',c),e=a("#reg_password, #account_password",c),f=1;b.includeMeter(c,e),f=b.checkPasswordStrength(e),3===f||4===f?d.removeAttr("disabled"):d.attr("disabled","disabled")},includeMeter:function(a,b){var c=a.find(".woocommerce-password-strength");0===c.length?b.after('<div class="woocommerce-password-strength" aria-live="polite"></div>'):""===b.val()&&c.remove()},checkPasswordStrength:function(b){var c=a(".woocommerce-password-strength"),d=wp.passwordStrength.meter(b.val(),wp.passwordStrength.userInputBlacklist());switch(c.removeClass("short bad good strong"),d){case 2:c.addClass("bad").html(pwsL10n.bad);break;case 3:c.addClass("good").html(pwsL10n.good);break;case 4:c.addClass("strong").html(pwsL10n.strong);break;case 5:c.addClass("short").html(pwsL10n.mismatch);break;default:c.addClass("short").html(pwsL10n["short"])}return d},checkoutNeedsRegistration:function(){var b=a('form.checkout input[type="submit"]');a(this).is(":checked")?b.attr("disabled","disabled"):b.removeAttr("disabled")}};b.init()}); jQuery(function(a){var b={init:function(){a(document.body).on("keyup","form.register #reg_password, form.checkout #account_password, form.edit-account #password_1, form.lost_reset_password #password_1",this.strengthMeter).on("submit","form.register, form.edit-account, form.lost_reset_password",this.onSubmit),a("form.checkout #createaccount").change()},strengthMeter:function(){var c=a("form.register, form.checkout, form.edit-account, form.lost_reset_password"),d=a('input[type="submit"]',c),e=a("#reg_password, #account_password, #password_1",c),f=1;b.includeMeter(c,e),f=b.checkPasswordStrength(e),3===f||4===f?c.removeClass("has-weak-password"):c.addClass("has-weak-password"),3===f||4===f?d.removeClass("disabled"):c.hasClass("checkout")||d.addClass("disabled")},onSubmit:function(){return a(".woocommerce-password-error").remove(),a(this).is(".has-weak-password")?(a(this).prepend('<div class="woocommerce-error woocommerce-password-error">'+wc_password_strength_meter_params.i18n_password_error+"</div>"),!1):!0},includeMeter:function(a,b){var c=a.find(".woocommerce-password-strength");0===c.length?b.after('<div class="woocommerce-password-strength" aria-live="polite"></div>'):""===b.val()&&c.remove()},checkPasswordStrength:function(b){var c=a(".woocommerce-password-strength"),d=a(".woocommerce-password-hint"),e='<small class="woocommerce-password-hint">'+wc_password_strength_meter_params.i18n_password_hint+"</small>",f=wp.passwordStrength.meter(b.val(),wp.passwordStrength.userInputBlacklist());switch(c.removeClass("short bad good strong"),d.remove(),f){case 2:c.addClass("bad").html(pwsL10n.bad),c.after(e);break;case 3:c.addClass("good").html(pwsL10n.good);break;case 4:c.addClass("strong").html(pwsL10n.strong);break;case 5:c.addClass("short").html(pwsL10n.mismatch);break;default:c.addClass("short").html(pwsL10n["short"]),c.after(e)}return f}};b.init()});

View File

@ -2399,22 +2399,41 @@ the specific language governing permissions and limitations under the Apache Lic
} }
})); }));
selection.on("mousedown touchstart", this.bind(function (e) { if(this.supportsTouchEvents) {
// Prevent IE from generating a click event on the body selection.on("mousedown touchstart", this.bind(function (e) {
reinsertElement(selection); // Prevent IE from generating a click event on the body
reinsertElement(selection);
if (!this.container.hasClass("select2-container-active")) { if (!this.container.hasClass("select2-container-active")) {
this.opts.element.trigger($.Event("select2-focus")); this.opts.element.trigger($.Event("select2-focus"));
} }
if (this.opened()) { if (this.opened()) {
this.close(); this.close();
} else if (this.isInterfaceEnabled()) { } else if (this.isInterfaceEnabled()) {
this.open(); this.open();
} }
killEvent(e); killEvent(e);
})); }));
} else {
selection.on("mousedown", this.bind(function (e) {
// Prevent IE from generating a click event on the body
reinsertElement(selection);
if (!this.container.hasClass("select2-container-active")) {
this.opts.element.trigger($.Event("select2-focus"));
}
if (this.opened()) {
this.close();
} else if (this.isInterfaceEnabled()) {
this.open();
}
killEvent(e);
}));
}
dropdown.on("mousedown touchstart", this.bind(function() { dropdown.on("mousedown touchstart", this.bind(function() {
if (this.opts.shouldFocusInput(this)) { if (this.opts.shouldFocusInput(this)) {

File diff suppressed because one or more lines are too long

File diff suppressed because it is too large Load Diff

View File

@ -1948,10 +1948,11 @@ abstract class WC_Abstract_Order {
} }
$defaults = array( $defaults = array(
'show_sku' => false, 'show_sku' => false,
'show_image' => false, 'show_image' => false,
'image_size' => array( 32, 32 ), 'image_size' => array( 32, 32 ),
'plain_text' => false 'plain_text' => false,
'sent_to_admin' => false
); );
$args = wp_parse_args( $args, $defaults ); $args = wp_parse_args( $args, $defaults );
@ -1960,11 +1961,12 @@ abstract class WC_Abstract_Order {
wc_get_template( $template, array( wc_get_template( $template, array(
'order' => $this, 'order' => $this,
'items' => $this->get_items(), 'items' => $this->get_items(),
'show_download_links' => $this->is_download_permitted(), 'show_download_links' => $this->is_download_permitted() && ! $args['sent_to_admin'],
'show_sku' => $args['show_sku'], 'show_sku' => $args['show_sku'],
'show_purchase_note' => $this->is_paid(), 'show_purchase_note' => $this->is_paid() && ! $args['sent_to_admin'],
'show_image' => $args['show_image'], 'show_image' => $args['show_image'],
'image_size' => $args['image_size'], 'image_size' => $args['image_size'],
'sent_to_admin' => $args['sent_to_admin']
) ); ) );
return apply_filters( 'woocommerce_email_order_items_table', ob_get_clean(), $this ); return apply_filters( 'woocommerce_email_order_items_table', ob_get_clean(), $this );

View File

@ -153,7 +153,7 @@ abstract class WC_Payment_Gateway extends WC_Settings_API {
*/ */
public function is_available() { public function is_available() {
$is_available = ( 'yes' === $this->enabled ) ? true : false; $is_available = ( 'yes' === $this->enabled );
if ( WC()->cart && 0 < $this->get_order_total() && 0 < $this->max_amount && $this->max_amount < $this->get_order_total() ) { if ( WC()->cart && 0 < $this->get_order_total() && 0 < $this->max_amount && $this->max_amount < $this->get_order_total() ) {
$is_available = false; $is_available = false;

View File

@ -222,15 +222,17 @@ class WC_Product {
*/ */
public function get_total_stock() { public function get_total_stock() {
if ( empty( $this->total_stock ) ) { if ( empty( $this->total_stock ) ) {
$this->total_stock = max( 0, $this->get_stock_quantity() );
if ( sizeof( $this->get_children() ) > 0 ) { if ( sizeof( $this->get_children() ) > 0 ) {
$this->total_stock = max( 0, $this->get_stock_quantity() );
foreach ( $this->get_children() as $child_id ) { foreach ( $this->get_children() as $child_id ) {
if ( 'yes' === get_post_meta( $child_id, '_manage_stock', true ) ) { if ( 'yes' === get_post_meta( $child_id, '_manage_stock', true ) ) {
$stock = get_post_meta( $child_id, '_stock', true ); $stock = get_post_meta( $child_id, '_stock', true );
$this->total_stock += max( 0, wc_stock_amount( $stock ) ); $this->total_stock += max( 0, wc_stock_amount( $stock ) );
} }
} }
} else {
$this->total_stock = $this->get_stock_quantity();
} }
} }
return wc_stock_amount( $this->total_stock ); return wc_stock_amount( $this->total_stock );
@ -1343,7 +1345,7 @@ class WC_Product {
$attribute = isset( $attributes[ $attr ] ) ? $attributes[ $attr ] : $attributes[ 'pa_' . $attr ]; $attribute = isset( $attributes[ $attr ] ) ? $attributes[ $attr ] : $attributes[ 'pa_' . $attr ];
if ( $attribute['is_taxonomy'] ) { if ( isset( $attribute['is_taxonomy'] ) && $attribute['is_taxonomy'] ) {
return implode( ', ', wc_get_product_terms( $this->id, $attribute['name'], array( 'fields' => 'names' ) ) ); return implode( ', ', wc_get_product_terms( $this->id, $attribute['name'], array( 'fields' => 'names' ) ) );

View File

@ -666,6 +666,7 @@ abstract class WC_Settings_API {
'desc_tip' => false, 'desc_tip' => false,
'description' => '', 'description' => '',
'custom_attributes' => array(), 'custom_attributes' => array(),
'select_buttons' => false,
'options' => array() 'options' => array()
); );
@ -688,6 +689,9 @@ abstract class WC_Settings_API {
<?php endforeach; ?> <?php endforeach; ?>
</select> </select>
<?php echo $this->get_description_html( $data ); ?> <?php echo $this->get_description_html( $data ); ?>
<?php if ( $data['select_buttons'] ) : ?>
<br/><a class="select_all button" href="#"><?php _e( 'Select all', 'woocommerce' ); ?></a> <a class="select_none button" href="#"><?php _e( 'Select none', 'woocommerce' ); ?></a>
<?php endif; ?>
</fieldset> </fieldset>
</td> </td>
</tr> </tr>

View File

@ -86,8 +86,8 @@ abstract class WC_Shipping_Method extends WC_Settings_API {
return; return;
} }
// Handle cost // Total up the cost
$total_cost = is_array( $args['cost'] ) ? array_sum( $args['cost'] ) : $args['cost']; $total_cost = wc_format_decimal( is_array( $args['cost'] ) ? array_sum( $args['cost'] ) : $args['cost'], wc_get_price_decimals() );
$taxes = $args['taxes']; $taxes = $args['taxes'];
// Taxes - if not an array and not set to false, calc tax based on cost and passed calc_tax variable // Taxes - if not an array and not set to false, calc tax based on cost and passed calc_tax variable

View File

@ -77,9 +77,7 @@ class WC_Admin_Assets {
* Enqueue scripts. * Enqueue scripts.
*/ */
public function admin_scripts() { public function admin_scripts() {
global $wp_query, $post, $current_user; global $wp_query, $post;
get_currentuserinfo();
$screen = get_current_screen(); $screen = get_current_screen();
$wc_screen_id = sanitize_title( __( 'WooCommerce', 'woocommerce' ) ); $wc_screen_id = sanitize_title( __( 'WooCommerce', 'woocommerce' ) );

View File

@ -160,7 +160,7 @@ class WC_Admin_Help {
'title' => __( 'WooCommerce 101', 'woocommerce' ), 'title' => __( 'WooCommerce 101', 'woocommerce' ),
'content' => 'content' =>
'<h2><a href="http://docs.woothemes.com/document/woocommerce-101-video-series/?utm_source=WooCommercePlugin&utm_medium=Help&utm_content=Videos&utm_campaign=Onboarding">' . __( 'WooCommerce 101', 'woocommerce' ) . '</a> &ndash; ' . esc_html( $video_map[ $video_key ]['title'] ) . '</h2>' . '<h2><a href="http://docs.woothemes.com/document/woocommerce-101-video-series/?utm_source=WooCommercePlugin&utm_medium=Help&utm_content=Videos&utm_campaign=Onboarding">' . __( 'WooCommerce 101', 'woocommerce' ) . '</a> &ndash; ' . esc_html( $video_map[ $video_key ]['title'] ) . '</h2>' .
'<iframe src="' . esc_url( $video_map[ $video_key ]['url'] ) . '" allowtransparency="true" frameborder="0" scrolling="no" class="wistia_embed" name="wistia_embed" allowfullscreen mozallowfullscreen webkitallowfullscreen oallowfullscreen msallowfullscreen width="480" height="298"></iframe>' '<iframe data-src="' . esc_url( $video_map[ $video_key ]['url'] ) . '" src="" allowtransparency="true" frameborder="0" scrolling="no" class="wistia_embed" name="wistia_embed" allowfullscreen mozallowfullscreen webkitallowfullscreen oallowfullscreen msallowfullscreen width="480" height="298"></iframe>'
) ); ) );
} }

View File

@ -222,7 +222,7 @@ class WC_Admin_Post_Types {
$columns['sku'] = __( 'SKU', 'woocommerce' ); $columns['sku'] = __( 'SKU', 'woocommerce' );
} }
if ( 'yes' == get_option( 'woocommerce_manage_stock' ) ) { if ( 'yes' === get_option( 'woocommerce_manage_stock' ) ) {
$columns['is_in_stock'] = __( 'Stock', 'woocommerce' ); $columns['is_in_stock'] = __( 'Stock', 'woocommerce' );
} }
@ -395,19 +395,18 @@ class WC_Admin_Post_Types {
echo '</a>'; echo '</a>';
break; break;
case 'is_in_stock' : case 'is_in_stock' :
if ( $the_product->is_in_stock() ) { if ( $the_product->is_in_stock() ) {
echo '<mark class="instock">' . __( 'In stock', 'woocommerce' ) . '</mark>'; echo '<mark class="instock">' . __( 'In stock', 'woocommerce' ) . '</mark>';
} else { } else {
echo '<mark class="outofstock">' . __( 'Out of stock', 'woocommerce' ) . '</mark>'; echo '<mark class="outofstock">' . __( 'Out of stock', 'woocommerce' ) . '</mark>';
} }
if ( $the_product->managing_stock() ) { // If the product has children, a single stock level would be misleading as some could be -ve and some +ve, some managed/some unmanaged etc so hide stock level in this case.
echo ' &times; ' . $the_product->get_total_stock(); if ( $the_product->managing_stock() && ! sizeof( $the_product->get_children() ) ) {
echo ' (' . $the_product->get_total_stock() . ')';
} }
break; break;
default : default :
break; break;
} }

View File

@ -286,6 +286,7 @@ class WC_Admin_Setup_Wizard {
$currency = get_option( 'woocommerce_currency', 'GBP' ); $currency = get_option( 'woocommerce_currency', 'GBP' );
$currency_pos = get_option( 'woocommerce_currency_pos', 'left' ); $currency_pos = get_option( 'woocommerce_currency_pos', 'left' );
$decimal_sep = get_option( 'woocommerce_price_decimal_sep', '.' ); $decimal_sep = get_option( 'woocommerce_price_decimal_sep', '.' );
$num_decimals = get_option( 'woocommerce_price_num_decimals', '2' );
$thousand_sep = get_option( 'woocommerce_price_thousand_sep', ',' ); $thousand_sep = get_option( 'woocommerce_price_thousand_sep', ',' );
$dimension_unit = get_option( 'woocommerce_dimension_unit', 'cm' ); $dimension_unit = get_option( 'woocommerce_dimension_unit', 'cm' );
$weight_unit = get_option( 'woocommerce_weight_unit', 'kg' ); $weight_unit = get_option( 'woocommerce_weight_unit', 'kg' );
@ -308,7 +309,7 @@ class WC_Admin_Setup_Wizard {
<option value=""><?php _e( 'Choose a currency&hellip;', 'woocommerce' ); ?></option> <option value=""><?php _e( 'Choose a currency&hellip;', 'woocommerce' ); ?></option>
<?php <?php
foreach ( get_woocommerce_currencies() as $code => $name ) { foreach ( get_woocommerce_currencies() as $code => $name ) {
echo '<option value="' . esc_attr( $code ) . '" ' . checked( $currency, $code, false ) . '>' . esc_html( $name . ' (' . get_woocommerce_currency_symbol( $code ) . ')' ) . '</option>'; echo '<option value="' . esc_attr( $code ) . '" ' . selected( $currency, $code, false ) . '>' . esc_html( $name . ' (' . get_woocommerce_currency_symbol( $code ) . ')' ) . '</option>';
} }
?> ?>
</select> </select>
@ -338,6 +339,12 @@ class WC_Admin_Setup_Wizard {
<input type="text" id="decimal_sep" name="decimal_sep" size="2" value="<?php echo esc_attr( $decimal_sep ) ; ?>" /> <input type="text" id="decimal_sep" name="decimal_sep" size="2" value="<?php echo esc_attr( $decimal_sep ) ; ?>" />
</td> </td>
</tr> </tr>
<tr>
<th scope="row"><label for="num_decimals"><?php _e( 'Number of Decimals', 'woocommerce' ); ?></label></th>
<td>
<input type="text" id="num_decimals" name="num_decimals" size="2" value="<?php echo esc_attr( $num_decimals ) ; ?>" />
</td>
</tr>
<tr> <tr>
<th scope="row"><label for="weight_unit"><?php _e( 'Which unit should be used for product weights?', 'woocommerce' ); ?></label></th> <th scope="row"><label for="weight_unit"><?php _e( 'Which unit should be used for product weights?', 'woocommerce' ); ?></label></th>
<td> <td>
@ -381,6 +388,7 @@ class WC_Admin_Setup_Wizard {
$currency_code = sanitize_text_field( $_POST['currency_code'] ); $currency_code = sanitize_text_field( $_POST['currency_code'] );
$currency_pos = sanitize_text_field( $_POST['currency_pos'] ); $currency_pos = sanitize_text_field( $_POST['currency_pos'] );
$decimal_sep = sanitize_text_field( $_POST['decimal_sep'] ); $decimal_sep = sanitize_text_field( $_POST['decimal_sep'] );
$num_decimals = sanitize_text_field( $_POST['num_decimals'] );
$thousand_sep = sanitize_text_field( $_POST['thousand_sep'] ); $thousand_sep = sanitize_text_field( $_POST['thousand_sep'] );
$weight_unit = sanitize_text_field( $_POST['weight_unit'] ); $weight_unit = sanitize_text_field( $_POST['weight_unit'] );
$dimension_unit = sanitize_text_field( $_POST['dimension_unit'] ); $dimension_unit = sanitize_text_field( $_POST['dimension_unit'] );
@ -389,6 +397,7 @@ class WC_Admin_Setup_Wizard {
update_option( 'woocommerce_currency', $currency_code ); update_option( 'woocommerce_currency', $currency_code );
update_option( 'woocommerce_currency_pos', $currency_pos ); update_option( 'woocommerce_currency_pos', $currency_pos );
update_option( 'woocommerce_price_decimal_sep', $decimal_sep ); update_option( 'woocommerce_price_decimal_sep', $decimal_sep );
update_option( 'woocommerce_price_num_decimals', $num_decimals );
update_option( 'woocommerce_price_thousand_sep', $thousand_sep ); update_option( 'woocommerce_price_thousand_sep', $thousand_sep );
update_option( 'woocommerce_weight_unit', $weight_unit ); update_option( 'woocommerce_weight_unit', $weight_unit );
update_option( 'woocommerce_dimension_unit', $dimension_unit ); update_option( 'woocommerce_dimension_unit', $dimension_unit );
@ -739,7 +748,7 @@ class WC_Admin_Setup_Wizard {
<?php if ( 'unknown' === get_option( 'woocommerce_allow_tracking', 'unknown' ) ) : ?> <?php if ( 'unknown' === get_option( 'woocommerce_allow_tracking', 'unknown' ) ) : ?>
<div class="woocommerce-message woocommerce-tracker"> <div class="woocommerce-message woocommerce-tracker">
<p><?php printf( __( 'Want to help make WooCommerce even more awesome? Allow WooThemes to collect non-sensitive diagnostic data and usage information, and get %s discount on your next WooThemes purchase. %sFind out more%s.', 'woocommerce' ), '20%', '<a href="http://www.woothemes.com/woocommerce/usage-tracking/" target="_blank">', '</a>' ); ?></p> <p><?php printf( __( 'Want to help make WooCommerce even more awesome? Allow WooThemes to collect non-sensitive diagnostic data and usage information. %sFind out more%s.', 'woocommerce' ), '<a href="http://www.woothemes.com/woocommerce/usage-tracking/" target="_blank">', '</a>' ); ?></p>
<p class="submit"> <p class="submit">
<a class="button-primary button button-large" href="<?php echo esc_url( wp_nonce_url( add_query_arg( 'wc_tracker_optin', 'true' ), 'wc_tracker_optin', 'wc_tracker_nonce' ) ); ?>"><?php _e( 'Allow', 'woocommerce' ); ?></a> <a class="button-primary button button-large" href="<?php echo esc_url( wp_nonce_url( add_query_arg( 'wc_tracker_optin', 'true' ), 'wc_tracker_optin', 'wc_tracker_nonce' ) ); ?>"><?php _e( 'Allow', 'woocommerce' ); ?></a>
<a class="button-secondary button button-large skip" href="<?php echo esc_url( wp_nonce_url( add_query_arg( 'wc_tracker_optout', 'true' ), 'wc_tracker_optout', 'wc_tracker_nonce' ) ); ?>"><?php _e( 'No thanks', 'woocommerce' ); ?></a> <a class="button-secondary button button-large skip" href="<?php echo esc_url( wp_nonce_url( add_query_arg( 'wc_tracker_optout', 'true' ), 'wc_tracker_optout', 'wc_tracker_nonce' ) ); ?>"><?php _e( 'No thanks', 'woocommerce' ); ?></a>

View File

@ -172,7 +172,7 @@ if ( wc_tax_enabled() ) {
<td class="label"><?php echo $tax->label; ?>:</td> <td class="label"><?php echo $tax->label; ?>:</td>
<td class="total"><?php <td class="total"><?php
if ( ( $refunded = $order->get_total_tax_refunded_by_rate_id( $tax->rate_id ) ) > 0 ) { if ( ( $refunded = $order->get_total_tax_refunded_by_rate_id( $tax->rate_id ) ) > 0 ) {
echo '<del>' . strip_tags( $tax->formatted_amount ) . '</del> <ins>' . wc_price( $tax->amount - $refunded, array( 'currency' => $order->get_order_currency() ) ) . '</ins>'; echo '<del>' . strip_tags( $tax->formatted_amount ) . '</del> <ins>' . wc_price( WC_Tax::round( $tax->amount, wc_get_price_decimals() ) - WC_Tax::round( $refunded, wc_get_price_decimals() ), array( 'currency' => $order->get_order_currency() ) ) . '</ins>';
} else { } else {
echo $tax->formatted_amount; echo $tax->formatted_amount;
} }

View File

@ -266,19 +266,22 @@ class WC_Report_Sales_By_Date extends WC_Admin_Report {
'name' => 'total_sales' 'name' => 'total_sales'
), ),
'_order_shipping' => array( '_order_shipping' => array(
'type' => 'meta', 'type' => 'meta',
'function' => '', 'function' => '',
'name' => 'total_shipping' 'name' => 'total_shipping',
'join_type' => 'LEFT'
), ),
'_order_tax' => array( '_order_tax' => array(
'type' => 'meta', 'type' => 'meta',
'function' => '', 'function' => '',
'name' => 'total_tax' 'name' => 'total_tax',
'join_type' => 'LEFT'
), ),
'_order_shipping_tax' => array( '_order_shipping_tax' => array(
'type' => 'meta', 'type' => 'meta',
'function' => '', 'function' => '',
'name' => 'total_shipping_tax' 'name' => 'total_shipping_tax',
'join_type' => 'LEFT'
), ),
'_qty' => array( '_qty' => array(
'type' => 'order_item_meta', 'type' => 'order_item_meta',
@ -292,34 +295,32 @@ class WC_Report_Sales_By_Date extends WC_Admin_Report {
'query_type' => 'get_results', 'query_type' => 'get_results',
'filter_range' => true, 'filter_range' => true,
'order_status' => false, 'order_status' => false,
'parent_order_status' => array( 'completed', 'processing', 'on-hold' ), 'parent_order_status' => array( 'completed', 'processing', 'on-hold', 'refunded' ),
) ); ) );
/** /**
* Total up values by combining full refunds and partial refunds for line items. * Total up refunds. Note: when an order is fully refunded, a refund line will be added.
*/ */
$this->report_data->total_tax_refunded = wc_format_decimal( array_sum( wp_list_pluck( $this->report_data->full_refunds, 'total_tax' ) ), 2 ); $this->report_data->total_tax_refunded = 0;
$this->report_data->total_shipping_refunded = wc_format_decimal( array_sum( wp_list_pluck( $this->report_data->full_refunds, 'total_shipping' ) ), 2 ); $this->report_data->total_shipping_refunded = 0;
$this->report_data->total_shipping_tax_refunded = wc_format_decimal( array_sum( wp_list_pluck( $this->report_data->full_refunds, 'total_shipping_tax' ) ), 2 ); $this->report_data->total_shipping_tax_refunded = 0;
$this->report_data->total_refunds = wc_format_decimal( array_sum( wp_list_pluck( $this->report_data->full_refunds, 'total_refund' ) ), 2 ); $this->report_data->total_refunds = 0;
/**
* Loop over partial refunds and increase the above values.
*/
foreach ( $this->report_data->partial_refunds as $key => $value ) { foreach ( $this->report_data->partial_refunds as $key => $value ) {
switch ( $value->item_type ) { if ( is_null( $value->item_type ) ) {
case 'shipping' : // Null when the order was refunded, but not the line items themselves.
$this->report_data->total_shipping_tax_refunded += ( $value->total_shipping_tax * -1 ); $this->report_data->total_tax_refunded += ( $value->total_tax * -1 );
$this->report_data->total_shipping_refunded += wc_format_decimal( $value->total_refund, 2 ); $this->report_data->total_refunds += $value->total_refund;
$this->report_data->total_refunds += $value->total_refund; }
elseif( 'shipping' === $value->item_type ) {
$this->report_data->total_shipping_tax_refunded += ( $value->total_shipping_tax * -1 );
break; $this->report_data->total_shipping_refunded += wc_format_decimal( $value->total_refund, 2 );
case 'line_item' : $this->report_data->total_refunds += $value->total_refund;
$this->report_data->total_tax_refunded += ( $value->total_tax * -1 ); }
$this->report_data->refunded_order_items += absint( $value->order_item_count ); elseif( 'line_item' === $value->item_type ) {
$this->report_data->total_refunds += $value->total_refund; $this->report_data->total_tax_refunded += ( $value->total_tax * -1 );
break; $this->report_data->refunded_order_items += absint( $value->order_item_count );
$this->report_data->total_refunds += $value->total_refund;
} }
} }
@ -504,7 +505,7 @@ class WC_Report_Sales_By_Date extends WC_Admin_Report {
$order_amounts = $this->prepare_chart_data( $this->report_data->orders, 'post_date', 'total_sales', $this->chart_interval, $this->start_date, $this->chart_groupby ); $order_amounts = $this->prepare_chart_data( $this->report_data->orders, 'post_date', 'total_sales', $this->chart_interval, $this->start_date, $this->chart_groupby );
$coupon_amounts = $this->prepare_chart_data( $this->report_data->coupons, 'post_date', 'discount_amount', $this->chart_interval, $this->start_date, $this->chart_groupby ); $coupon_amounts = $this->prepare_chart_data( $this->report_data->coupons, 'post_date', 'discount_amount', $this->chart_interval, $this->start_date, $this->chart_groupby );
$shipping_amounts = $this->prepare_chart_data( $this->report_data->orders, 'post_date', 'total_shipping', $this->chart_interval, $this->start_date, $this->chart_groupby ); $shipping_amounts = $this->prepare_chart_data( $this->report_data->orders, 'post_date', 'total_shipping', $this->chart_interval, $this->start_date, $this->chart_groupby );
$refund_amounts = $this->prepare_chart_data( array_merge( $this->report_data->partial_refunds, $this->report_data->full_refunds ), 'post_date', 'total_refund', $this->chart_interval, $this->start_date, $this->chart_groupby ); $refund_amounts = $this->prepare_chart_data( $this->report_data->partial_refunds, 'post_date', 'total_refund', $this->chart_interval, $this->start_date, $this->chart_groupby );
$shipping_tax_amounts = $this->prepare_chart_data( $this->report_data->orders, 'post_date', 'total_shipping_tax', $this->chart_interval, $this->start_date, $this->chart_groupby ); $shipping_tax_amounts = $this->prepare_chart_data( $this->report_data->orders, 'post_date', 'total_shipping_tax', $this->chart_interval, $this->start_date, $this->chart_groupby );
$tax_amounts = $this->prepare_chart_data( $this->report_data->orders, 'post_date', 'total_tax', $this->chart_interval, $this->start_date, $this->chart_groupby ); $tax_amounts = $this->prepare_chart_data( $this->report_data->orders, 'post_date', 'total_tax', $this->chart_interval, $this->start_date, $this->chart_groupby );

View File

@ -113,7 +113,7 @@ class WC_Settings_Payment_Gateways extends WC_Settings_Page {
'desc_tip' => __( 'Force SSL (HTTPS) on the checkout pages (an SSL Certificate is required).', 'woocommerce' ), 'desc_tip' => __( 'Force SSL (HTTPS) on the checkout pages (an SSL Certificate is required).', 'woocommerce' ),
), ),
array( 'unforce_ssl_checkout' => array(
'desc' => __( 'Force HTTP when leaving the checkout', 'woocommerce' ), 'desc' => __( 'Force HTTP when leaving the checkout', 'woocommerce' ),
'id' => 'woocommerce_unforce_ssl_checkout', 'id' => 'woocommerce_unforce_ssl_checkout',
'default' => 'no', 'default' => 'no',
@ -225,6 +225,10 @@ class WC_Settings_Payment_Gateways extends WC_Settings_Page {
) ); ) );
if ( wc_site_is_https() ) {
unset( $settings['unforce_ssl_checkout'] );
}
return apply_filters( 'woocommerce_get_settings_' . $this->id, $settings ); return apply_filters( 'woocommerce_get_settings_' . $this->id, $settings );
} }

View File

@ -244,7 +244,7 @@ class WC_Settings_Shipping extends WC_Settings_Page {
$wc_shipping->process_admin_options(); $wc_shipping->process_admin_options();
} else { } else {
foreach ( $wc_shipping->get_shipping_methods() as $method_id => $method ) { foreach ( $wc_shipping->load_shipping_methods() as $method_id => $method ) {
if ( $current_section === sanitize_title( get_class( $method ) ) ) { if ( $current_section === sanitize_title( get_class( $method ) ) ) {
do_action( 'woocommerce_update_options_' . $this->id . '_' . $method->id ); do_action( 'woocommerce_update_options_' . $this->id . '_' . $method->id );
} }

View File

@ -109,16 +109,15 @@ class WC_Settings_Tax extends WC_Settings_Page {
* Output tax rate tables. * Output tax rate tables.
*/ */
public function output_tax_rates() { public function output_tax_rates() {
global $wpdb, global $wpdb, $current_section;
$current_section;
$current_class = $this->get_current_tax_class(); $current_class = $this->get_current_tax_class();
$countries = array(); $countries = array();
foreach ( WC()->countries->get_allowed_countries() as $value => $label ) { foreach ( WC()->countries->get_allowed_countries() as $value => $label ) {
$countries[] = array( $countries[] = array(
'label' => $label,
'value' => $value, 'value' => $value,
'label' => esc_js( html_entity_decode( $label ) ),
); );
} }
@ -126,8 +125,8 @@ class WC_Settings_Tax extends WC_Settings_Page {
foreach ( WC()->countries->get_allowed_country_states() as $label ) { foreach ( WC()->countries->get_allowed_country_states() as $label ) {
foreach ( $label as $code => $state ) { foreach ( $label as $code => $state ) {
$states[] = array( $states[] = array(
'label' => $state,
'value' => $code, 'value' => $code,
'label' => esc_js( html_entity_decode( $state ) ),
); );
} }
} }

View File

@ -5,9 +5,11 @@ if ( ! defined( 'ABSPATH' ) ) {
?> ?>
<div class="wc-tax-rates-search" id="rates-search"> <div class="wc-tax-rates-search" id="rates-search">
<input type="search" class="wc-tax-rates-search-field" placeholder="<?php esc_attr_e( 'Search', 'woocommerce' ); ?>" value="<?php if ( isset( $_GET['s'] ) ) { echo esc_attr( $_GET['s'] ); } ?>" /> <input type="search" class="wc-tax-rates-search-field" placeholder="<?php esc_attr_e( 'Search&hellip;', 'woocommerce' ); ?>" value="<?php if ( isset( $_GET['s'] ) ) { echo esc_attr( $_GET['s'] ); } ?>" />
</div> </div>
<div id="rates-pagination"></div>
<h3><?php printf( __( '"%s" Tax Rates', 'woocommerce' ), $current_class ? esc_html( $current_class ) : __( 'Standard', 'woocommerce' ) ); ?></h3> <h3><?php printf( __( '"%s" Tax Rates', 'woocommerce' ), $current_class ? esc_html( $current_class ) : __( 'Standard', 'woocommerce' ) ); ?></h3>
<table class="wc_tax_rates wc_input_table sortable widefat"> <table class="wc_tax_rates wc_input_table sortable widefat">
@ -37,7 +39,7 @@ if ( ! defined( 'ABSPATH' ) ) {
</tfoot> </tfoot>
<tbody id="rates"> <tbody id="rates">
<tr> <tr>
<th colspan="10" style="text-align: center;"><?php esc_html_e( 'Loading', 'woocommerce' ); ?></th> <th colspan="10" style="text-align: center;"><?php esc_html_e( 'Loading&hellip;', 'woocommerce' ); ?></th>
</tr> </tr>
</tbody> </tbody>
</table> </table>
@ -47,7 +49,7 @@ if ( ! defined( 'ABSPATH' ) ) {
<td class="sort"></td> <td class="sort"></td>
<td class="country"> <td class="country">
<input type="text" value="{{ data.tax_rate_country }}" placeholder="*" name="tax_rate_country[{{ data.tax_rate_id }}]" class="wc_input_country_iso" data-attribute="tax_rate_country" /> <input type="text" value="{{ data.tax_rate_country }}" placeholder="*" name="tax_rate_country[{{ data.tax_rate_id }}]" class="wc_input_country_iso" data-attribute="tax_rate_country" style="text-transform:uppercase" />
</td> </td>
<td class="state"> <td class="state">

View File

@ -81,12 +81,29 @@ if ( ! defined( 'ABSPATH' ) ) {
<tr> <tr>
<td data-export-label="WP Debug Mode"><?php _e( 'WP Debug Mode', 'woocommerce' ); ?>:</td> <td data-export-label="WP Debug Mode"><?php _e( 'WP Debug Mode', 'woocommerce' ); ?>:</td>
<td class="help"><?php echo wc_help_tip( __( 'Displays whether or not WordPress is in Debug Mode.', 'woocommerce' ) ); ?></td> <td class="help"><?php echo wc_help_tip( __( 'Displays whether or not WordPress is in Debug Mode.', 'woocommerce' ) ); ?></td>
<td><?php if ( defined('WP_DEBUG') && WP_DEBUG ) echo '<mark class="yes">&#10004;</mark>'; else echo '<mark class="no">&ndash;</mark>'; ?></td> <td>
<?php if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) : ?>
<mark class="yes">&#10004;</mark>
<?php else : ?>
<mark class="no">&ndash;</mark>
<?php endif; ?>
</td>
</tr>
<tr>
<td data-export-label="WP Cron"><?php _e( 'WP Cron', 'woocommerce' ); ?>:</td>
<td class="help"><?php echo wc_help_tip( __( 'Displays whether or not WP Cron Jobs are enabled.', 'woocommerce' ) ); ?></td>
<td>
<?php if ( defined( 'DISABLE_WP_CRON' ) && DISABLE_WP_CRON ) : ?>
<mark class="no">&ndash;</mark>
<?php else : ?>
<mark class="yes">&#10004;</mark>
<?php endif; ?>
</td>
</tr> </tr>
<tr> <tr>
<td data-export-label="Language"><?php _e( 'Language', 'woocommerce' ); ?>:</td> <td data-export-label="Language"><?php _e( 'Language', 'woocommerce' ); ?>:</td>
<td class="help"><?php echo wc_help_tip( __( 'The current language used by WordPress. Default = English', 'woocommerce' ) ); ?></td> <td class="help"><?php echo wc_help_tip( __( 'The current language used by WordPress. Default = English', 'woocommerce' ) ); ?></td>
<td><?php echo get_locale() ?></td> <td><?php echo get_locale(); ?></td>
</tr> </tr>
</tbody> </tbody>
</table> </table>

View File

@ -685,7 +685,7 @@ class WC_API_Products extends WC_API_Resource {
if ( is_numeric( $image ) ) { if ( is_numeric( $image ) ) {
$image_id = absint( $image ); $image_id = absint( $image );
} else if ( ! empty( $image ) ) { } else if ( ! empty( $image ) ) {
$upload = $this->upload_product_image( esc_url_raw( $image ) ); $upload = $this->upload_product_category_image( esc_url_raw( $image ) );
$image_id = $this->set_product_category_image_as_attachment( $upload ); $image_id = $this->set_product_category_image_as_attachment( $upload );
} }
@ -751,7 +751,7 @@ class WC_API_Products extends WC_API_Resource {
if ( is_numeric( $image ) ) { if ( is_numeric( $image ) ) {
$image_id = absint( $image ); $image_id = absint( $image );
} else if ( ! empty( $image ) ) { } else if ( ! empty( $image ) ) {
$upload = $this->upload_product_image( esc_url_raw( $image ) ); $upload = $this->upload_product_category_image( esc_url_raw( $image ) );
$image_id = $this->set_product_category_image_as_attachment( $upload ); $image_id = $this->set_product_category_image_as_attachment( $upload );
} }
@ -1420,59 +1420,36 @@ class WC_API_Products extends WC_API_Resource {
} else { } else {
// Regular Price. // Regular Price
if ( isset( $data['regular_price'] ) ) { if ( isset( $data['regular_price'] ) ) {
$regular_price = ( '' === $data['regular_price'] ) ? '' : wc_format_decimal( $data['regular_price'] ); $regular_price = ( '' === $data['regular_price'] ) ? '' : $data['regular_price'];
update_post_meta( $product_id, '_regular_price', $regular_price );
} else { } else {
$regular_price = get_post_meta( $product_id, '_regular_price', true ); $regular_price = get_post_meta( $product_id, '_regular_price', true );
} }
// Sale Price. // Sale Price
if ( isset( $data['sale_price'] ) ) { if ( isset( $data['sale_price'] ) ) {
$sale_price = ( '' === $data['sale_price'] ) ? '' : wc_format_decimal( $data['sale_price'] ); $sale_price = ( '' === $data['sale_price'] ) ? '' : $data['sale_price'];
update_post_meta( $product_id, '_sale_price', $sale_price );
} else { } else {
$sale_price = get_post_meta( $product_id, '_sale_price', true ); $sale_price = get_post_meta( $product_id, '_sale_price', true );
} }
$date_from = isset( $data['sale_price_dates_from'] ) ? strtotime( $data['sale_price_dates_from'] ) : get_post_meta( $product_id, '_sale_price_dates_from', true ); if ( isset( $data['sale_price_dates_from'] ) ) {
$date_to = isset( $data['sale_price_dates_to'] ) ? strtotime( $data['sale_price_dates_to'] ) : get_post_meta( $product_id, '_sale_price_dates_to', true ); $date_from = $data['sale_price_dates_from'];
// Dates
if ( $date_from ) {
update_post_meta( $product_id, '_sale_price_dates_from', $date_from );
} else { } else {
update_post_meta( $product_id, '_sale_price_dates_from', '' ); $date_from = get_post_meta( $product_id, '_sale_price_dates_from', true );
$date_from = ( '' === $date_from ) ? '' : date( 'Y-m-d', $date_from );
} }
if ( $date_to ) { if ( isset( $data['sale_price_dates_to'] ) ) {
update_post_meta( $product_id, '_sale_price_dates_to', $date_to ); $date_to = $data['sale_price_dates_to'];
} else { } else {
update_post_meta( $product_id, '_sale_price_dates_to', '' ); $date_to = get_post_meta( $product_id, '_sale_price_dates_to', true );
$date_to = ( '' === $date_to ) ? '' : date( 'Y-m-d', $date_to );
} }
if ( $date_to && ! $date_from ) { _wc_save_product_price( $product_id, $regular_price, $sale_price, $date_from, $date_to );
$date_from = strtotime( 'NOW', current_time( 'timestamp' ) );
update_post_meta( $product_id, '_sale_price_dates_from', $date_from );
}
// Update price if on sale.
if ( '' !== $sale_price && '' == $date_to && '' == $date_from ) {
update_post_meta( $product_id, '_price', wc_format_decimal( $sale_price ) );
} else {
update_post_meta( $product_id, '_price', $regular_price );
}
if ( '' !== $sale_price && $date_from && $date_from <= strtotime( 'NOW', current_time( 'timestamp' ) ) ) {
update_post_meta( $product_id, '_price', wc_format_decimal( $sale_price ) );
}
if ( $date_to && $date_to < strtotime( 'NOW', current_time( 'timestamp' ) ) ) {
update_post_meta( $product_id, '_price', $regular_price );
update_post_meta( $product_id, '_sale_price_dates_from', '' );
update_post_meta( $product_id, '_sale_price_dates_to', '' );
}
} }
// Product parent ID for groups. // Product parent ID for groups.
@ -1545,7 +1522,7 @@ class WC_API_Products extends WC_API_Resource {
// Backorders. // Backorders.
if ( isset( $data['backorders'] ) ) { if ( isset( $data['backorders'] ) ) {
if ( 'notify' == $data['backorders'] ) { if ( 'notify' === $data['backorders'] ) {
$backorders = 'notify'; $backorders = 'notify';
} else { } else {
$backorders = ( true === $data['backorders'] ) ? 'yes' : 'no'; $backorders = ( true === $data['backorders'] ) ? 'yes' : 'no';
@ -1780,16 +1757,29 @@ class WC_API_Products extends WC_API_Resource {
} }
} }
// Thumbnail // Thumbnail.
if ( isset( $variation['image'] ) && is_array( $variation['image'] ) ) { if ( isset( $variation['image'] ) && is_array( $variation['image'] ) ) {
$image = current( $variation['image'] ); $image = current( $variation['image'] );
if ( $image && is_array( $image ) ) { if ( $image && is_array( $image ) ) {
if ( isset( $image['position'] ) && isset( $image['src'] ) && $image['position'] == 0 ) { if ( isset( $image['position'] ) && isset( $image['src'] ) && $image['position'] == 0 ) {
$upload = $this->upload_product_image( wc_clean( $image['src'] ) ); $upload = $this->upload_product_image( wc_clean( $image['src'] ) );
if ( is_wp_error( $upload ) ) { if ( is_wp_error( $upload ) ) {
throw new WC_API_Exception( 'woocommerce_api_cannot_upload_product_image', $upload->get_error_message(), 400 ); throw new WC_API_Exception( 'woocommerce_api_cannot_upload_product_image', $upload->get_error_message(), 400 );
} }
$attachment_id = $this->set_product_image_as_attachment( $upload, $id ); $attachment_id = $this->set_product_image_as_attachment( $upload, $id );
// Set the image alt if present.
if ( ! empty( $image['alt'] ) ) {
update_post_meta( $attachment_id, '_wp_attachment_image_alt', wc_clean( $image['alt'] ) );
}
// Set the image title if present.
if ( ! empty( $image['title'] ) ) {
wp_update_post( array( 'ID' => $attachment_id, 'post_title' => $image['title'] ) );
}
update_post_meta( $variation_id, '_thumbnail_id', $attachment_id ); update_post_meta( $variation_id, '_thumbnail_id', $attachment_id );
} }
} else { } else {
@ -1856,56 +1846,33 @@ class WC_API_Products extends WC_API_Resource {
// Regular Price // Regular Price
if ( isset( $variation['regular_price'] ) ) { if ( isset( $variation['regular_price'] ) ) {
$regular_price = ( '' === $variation['regular_price'] ) ? '' : wc_format_decimal( $variation['regular_price'] ); $regular_price = ( '' === $variation['regular_price'] ) ? '' : $variation['regular_price'];
update_post_meta( $variation_id, '_regular_price', $regular_price );
} else { } else {
$regular_price = get_post_meta( $variation_id, '_regular_price', true ); $regular_price = get_post_meta( $variation_id, '_regular_price', true );
} }
// Sale Price // Sale Price
if ( isset( $variation['sale_price'] ) ) { if ( isset( $variation['sale_price'] ) ) {
$sale_price = ( '' === $variation['sale_price'] ) ? '' : wc_format_decimal( $variation['sale_price'] ); $sale_price = ( '' === $variation['sale_price'] ) ? '' : $variation['sale_price'];
update_post_meta( $variation_id, '_sale_price', $sale_price );
} else { } else {
$sale_price = get_post_meta( $variation_id, '_sale_price', true ); $sale_price = get_post_meta( $variation_id, '_sale_price', true );
} }
$date_from = isset( $variation['sale_price_dates_from'] ) ? strtotime( $variation['sale_price_dates_from'] ) : get_post_meta( $variation_id, '_sale_price_dates_from', true ); if ( isset( $variation['sale_price_dates_from'] ) ) {
$date_to = isset( $variation['sale_price_dates_to'] ) ? strtotime( $variation['sale_price_dates_to'] ) : get_post_meta( $variation_id, '_sale_price_dates_to', true ); $date_from = $variation['sale_price_dates_from'];
// Save Dates
if ( $date_from ) {
update_post_meta( $variation_id, '_sale_price_dates_from', $date_from );
} else { } else {
update_post_meta( $variation_id, '_sale_price_dates_from', '' ); $date_from = get_post_meta( $variation_id, '_sale_price_dates_from', true );
$date_from = ( '' === $date_from ) ? '' : date( 'Y-m-d', $date_from );
} }
if ( $date_to ) { if ( isset( $variation['sale_price_dates_to'] ) ) {
update_post_meta( $variation_id, '_sale_price_dates_to', $date_to ); $date_to = $variation['sale_price_dates_to'];
} else { } else {
update_post_meta( $variation_id, '_sale_price_dates_to', '' ); $date_to = get_post_meta( $variation_id, '_sale_price_dates_to', true );
$date_to = ( '' === $date_to ) ? '' : date( 'Y-m-d', $date_to );
} }
if ( $date_to && ! $date_from ) { _wc_save_product_price( $variation_id, $regular_price, $sale_price, $date_from, $date_to );
update_post_meta( $variation_id, '_sale_price_dates_from', strtotime( 'NOW', current_time( 'timestamp' ) ) );
}
// Update price if on sale
if ( '' != $sale_price && '' == $date_to && '' == $date_from ) {
update_post_meta( $variation_id, '_price', $sale_price );
} else {
update_post_meta( $variation_id, '_price', $regular_price );
}
if ( '' != $sale_price && $date_from && $date_from < strtotime( 'NOW', current_time( 'timestamp' ) ) ) {
update_post_meta( $variation_id, '_price', $sale_price );
}
if ( $date_to && $date_to < strtotime( 'NOW', current_time( 'timestamp' ) ) ) {
update_post_meta( $variation_id, '_price', $regular_price );
update_post_meta( $variation_id, '_sale_price_dates_from', '' );
update_post_meta( $variation_id, '_sale_price_dates_to', '' );
}
// Tax class // Tax class
if ( isset( $variation['tax_class'] ) ) { if ( isset( $variation['tax_class'] ) ) {
@ -2236,7 +2203,7 @@ class WC_API_Products extends WC_API_Resource {
} }
/** /**
* Save product images * Save product images.
* *
* @since 2.2 * @since 2.2
* @param array $images * @param array $images
@ -2272,19 +2239,19 @@ class WC_API_Products extends WC_API_Resource {
throw new WC_API_Exception( 'woocommerce_api_cannot_upload_product_image', $upload->get_error_message(), 400 ); throw new WC_API_Exception( 'woocommerce_api_cannot_upload_product_image', $upload->get_error_message(), 400 );
} }
$gallery[] = $this->set_product_image_as_attachment( $upload, $id ); $attachment_id = $this->set_product_image_as_attachment( $upload, $id );
} else {
$gallery[] = $attachment_id;
} }
$gallery[] = $attachment_id;
} }
// Set the image alt if present. // Set the image alt if present.
if ( ! empty( $image['alt'] ) ) { if ( ! empty( $image['alt'] ) && $attachment_id ) {
update_post_meta( $attachment_id, '_wp_attachment_image_alt', wc_clean( $image['alt'] ) ); update_post_meta( $attachment_id, '_wp_attachment_image_alt', wc_clean( $image['alt'] ) );
} }
// Set the image title if present. // Set the image title if present.
if ( ! empty( $image['title'] ) ) { if ( ! empty( $image['title'] ) && $attachment_id ) {
wp_update_post( array( 'ID' => $attachment_id, 'post_title' => $image['title'] ) ); wp_update_post( array( 'ID' => $attachment_id, 'post_title' => $image['title'] ) );
} }
} }
@ -2306,14 +2273,14 @@ class WC_API_Products extends WC_API_Resource {
* @return int|WP_Error attachment id * @return int|WP_Error attachment id
*/ */
public function upload_product_image( $image_url ) { public function upload_product_image( $image_url ) {
return $this->upload_image_from_url( $image_url ); return $this->upload_image_from_url( $image_url, 'product_image' );
} }
/** /**
* Upload product category image from URL. * Upload product category image from URL.
* *
* @since 2.5.0 * @since 2.5.0
* @param string $image_url * @param string $image_url
* @return int|WP_Error attachment id * @return int|WP_Error attachment id
*/ */
public function upload_product_category_image( $image_url ) { public function upload_product_category_image( $image_url ) {
@ -2325,9 +2292,9 @@ class WC_API_Products extends WC_API_Resource {
* *
* @throws WC_API_Exception * @throws WC_API_Exception
* *
* @since 2.5.0 * @since 2.5.0
* @param string $image_url * @param string $image_url
* @param string $upload_for * @param string $upload_for
* @return int|WP_Error Attachment id * @return int|WP_Error Attachment id
*/ */
protected function upload_image_from_url( $image_url, $upload_for = 'product_image' ) { protected function upload_image_from_url( $image_url, $upload_for = 'product_image' ) {
@ -2340,10 +2307,10 @@ class WC_API_Products extends WC_API_Resource {
throw new WC_API_Exception( 'woocommerce_api_invalid_' . $upload_for, sprintf( __( 'Invalid URL %s', 'woocommerce' ), $image_url ), 400 ); throw new WC_API_Exception( 'woocommerce_api_invalid_' . $upload_for, sprintf( __( 'Invalid URL %s', 'woocommerce' ), $image_url ), 400 );
} }
// Ensure url is valid // Ensure url is valid.
$image_url = str_replace( ' ', '%20', $image_url ); $image_url = str_replace( ' ', '%20', $image_url );
// Get the file // Get the file.
$response = wp_safe_remote_get( $image_url, array( $response = wp_safe_remote_get( $image_url, array(
'timeout' => 10 'timeout' => 10
) ); ) );
@ -2352,7 +2319,7 @@ class WC_API_Products extends WC_API_Resource {
throw new WC_API_Exception( 'woocommerce_api_invalid_remote_' . $upload_for, sprintf( __( 'Error getting remote image %s', 'woocommerce' ), $image_url ), 400 ); throw new WC_API_Exception( 'woocommerce_api_invalid_remote_' . $upload_for, sprintf( __( 'Error getting remote image %s', 'woocommerce' ), $image_url ), 400 );
} }
// Ensure we have a file name and type // Ensure we have a file name and type.
if ( ! $wp_filetype['type'] ) { if ( ! $wp_filetype['type'] ) {
$headers = wp_remote_retrieve_headers( $response ); $headers = wp_remote_retrieve_headers( $response );
if ( isset( $headers['content-disposition'] ) && strstr( $headers['content-disposition'], 'filename=' ) ) { if ( isset( $headers['content-disposition'] ) && strstr( $headers['content-disposition'], 'filename=' ) ) {
@ -2365,14 +2332,14 @@ class WC_API_Products extends WC_API_Resource {
unset( $headers ); unset( $headers );
} }
// Upload the file // Upload the file.
$upload = wp_upload_bits( $file_name, '', wp_remote_retrieve_body( $response ) ); $upload = wp_upload_bits( $file_name, '', wp_remote_retrieve_body( $response ) );
if ( $upload['error'] ) { if ( $upload['error'] ) {
throw new WC_API_Exception( 'woocommerce_api_' . $upload_for . '_upload_error', $upload['error'], 400 ); throw new WC_API_Exception( 'woocommerce_api_' . $upload_for . '_upload_error', $upload['error'], 400 );
} }
// Get filesize // Get filesize.
$filesize = filesize( $upload['file'] ); $filesize = filesize( $upload['file'] );
if ( 0 == $filesize ) { if ( 0 == $filesize ) {

View File

@ -438,26 +438,27 @@ class WC_API_Resource {
* @return bool true if the current user has the permissions to perform the context on the post * @return bool true if the current user has the permissions to perform the context on the post
*/ */
private function check_permission( $post, $context ) { private function check_permission( $post, $context ) {
$permission = false;
if ( ! is_a( $post, 'WP_Post' ) ) { if ( ! is_a( $post, 'WP_Post' ) ) {
$post = get_post( $post ); $post = get_post( $post );
} }
if ( is_null( $post ) ) { if ( is_null( $post ) ) {
return false; return $permission;
} }
$post_type = get_post_type_object( $post->post_type ); $post_type = get_post_type_object( $post->post_type );
if ( 'read' === $context ) { if ( 'read' === $context ) {
return ( 'revision' !== $post->post_type && current_user_can( $post_type->cap->read_private_posts, $post->ID ) ); $permission = 'revision' !== $post->post_type && current_user_can( $post_type->cap->read_private_posts, $post->ID );
} elseif ( 'edit' === $context ) { } elseif ( 'edit' === $context ) {
return current_user_can( $post_type->cap->edit_post, $post->ID ); $permission = current_user_can( $post_type->cap->edit_post, $post->ID );
} elseif ( 'delete' === $context ) { } elseif ( 'delete' === $context ) {
return current_user_can( $post_type->cap->delete_post, $post->ID ); $permission = current_user_can( $post_type->cap->delete_post, $post->ID );
} else {
return false;
} }
return apply_filters( 'woocommerce_api_check_permission', $permission, $context, $post, $post_type );
} }
} }

View File

@ -454,13 +454,13 @@ class WC_API_Server {
'currency' => get_woocommerce_currency(), 'currency' => get_woocommerce_currency(),
'currency_format' => get_woocommerce_currency_symbol(), 'currency_format' => get_woocommerce_currency_symbol(),
'currency_position' => get_option( 'woocommerce_currency_pos' ), 'currency_position' => get_option( 'woocommerce_currency_pos' ),
'thousand_separator' => get_option( 'woocommerce_price_decimal_sep' ), 'thousand_separator' => get_option( 'woocommerce_price_thousand_sep' ),
'decimal_separator' => get_option( 'woocommerce_price_thousand_sep' ), 'decimal_separator' => get_option( 'woocommerce_price_decimal_sep' ),
'price_num_decimals' => wc_get_price_decimals(), 'price_num_decimals' => wc_get_price_decimals(),
'tax_included' => wc_prices_include_tax(), 'tax_included' => wc_prices_include_tax(),
'weight_unit' => get_option( 'woocommerce_weight_unit' ), 'weight_unit' => get_option( 'woocommerce_weight_unit' ),
'dimension_unit' => get_option( 'woocommerce_dimension_unit' ), 'dimension_unit' => get_option( 'woocommerce_dimension_unit' ),
'ssl_enabled' => ( 'yes' === get_option( 'woocommerce_force_ssl_checkout' ) ), 'ssl_enabled' => ( 'yes' === get_option( 'woocommerce_force_ssl_checkout' ) || wc_site_is_https() ),
'permalinks_enabled' => ( '' !== get_option( 'permalink_structure' ) ), 'permalinks_enabled' => ( '' !== get_option( 'permalink_structure' ) ),
'generate_password' => ( 'yes' === get_option( 'woocommerce_registration_generate_password' ) ), 'generate_password' => ( 'yes' === get_option( 'woocommerce_registration_generate_password' ) ),
'links' => array( 'links' => array(

View File

@ -965,57 +965,34 @@ class WC_API_Products extends WC_API_Resource {
// Regular Price // Regular Price
if ( isset( $data['regular_price'] ) ) { if ( isset( $data['regular_price'] ) ) {
$regular_price = ( '' === $data['regular_price'] ) ? '' : wc_format_decimal( $data['regular_price'] ); $regular_price = ( '' === $data['regular_price'] ) ? '' : $data['regular_price'];
update_post_meta( $product_id, '_regular_price', $regular_price );
} else { } else {
$regular_price = get_post_meta( $product_id, '_regular_price', true ); $regular_price = get_post_meta( $product_id, '_regular_price', true );
} }
// Sale Price // Sale Price
if ( isset( $data['sale_price'] ) ) { if ( isset( $data['sale_price'] ) ) {
$sale_price = ( '' === $data['sale_price'] ) ? '' : wc_format_decimal( $data['sale_price'] ); $sale_price = ( '' === $data['sale_price'] ) ? '' : $data['sale_price'];
update_post_meta( $product_id, '_sale_price', $sale_price );
} else { } else {
$sale_price = get_post_meta( $product_id, '_sale_price', true ); $sale_price = get_post_meta( $product_id, '_sale_price', true );
} }
$date_from = isset( $data['sale_price_dates_from'] ) ? strtotime( $data['sale_price_dates_from'] ) : get_post_meta( $product_id, '_sale_price_dates_from', true ); if ( isset( $data['sale_price_dates_from'] ) ) {
$date_to = isset( $data['sale_price_dates_to'] ) ? strtotime( $data['sale_price_dates_to'] ) : get_post_meta( $product_id, '_sale_price_dates_to', true ); $date_from = $data['sale_price_dates_from'];
// Dates
if ( $date_from ) {
update_post_meta( $product_id, '_sale_price_dates_from', $date_from );
} else { } else {
update_post_meta( $product_id, '_sale_price_dates_from', '' ); $date_from = get_post_meta( $product_id, '_sale_price_dates_from', true );
$date_from = ( '' === $date_from ) ? '' : date( 'Y-m-d', $date_from );
} }
if ( $date_to ) { if ( isset( $data['sale_price_dates_to'] ) ) {
update_post_meta( $product_id, '_sale_price_dates_to', $date_to ); $date_to = $data['sale_price_dates_to'];
} else { } else {
update_post_meta( $product_id, '_sale_price_dates_to', '' ); $date_to = get_post_meta( $product_id, '_sale_price_dates_to', true );
$date_to = ( '' === $date_to ) ? '' : date( 'Y-m-d', $date_to );
} }
if ( $date_to && ! $date_from ) { _wc_save_product_price( $product_id, $regular_price, $sale_price, $date_from, $date_to );
$date_from = strtotime( 'NOW', current_time( 'timestamp' ) );
update_post_meta( $product_id, '_sale_price_dates_from', $date_from );
}
// Update price if on sale
if ( '' !== $sale_price && '' == $date_to && '' == $date_from ) {
update_post_meta( $product_id, '_price', wc_format_decimal( $sale_price ) );
} else {
update_post_meta( $product_id, '_price', $regular_price );
}
if ( '' !== $sale_price && $date_from && $date_from <= strtotime( 'NOW', current_time( 'timestamp' ) ) ) {
update_post_meta( $product_id, '_price', wc_format_decimal( $sale_price ) );
}
if ( $date_to && $date_to < strtotime( 'NOW', current_time( 'timestamp' ) ) ) {
update_post_meta( $product_id, '_price', $regular_price );
update_post_meta( $product_id, '_sale_price_dates_from', '' );
update_post_meta( $product_id, '_sale_price_dates_to', '' );
}
} }
// Product parent ID for groups // Product parent ID for groups
@ -1389,56 +1366,33 @@ class WC_API_Products extends WC_API_Resource {
// Regular Price // Regular Price
if ( isset( $variation['regular_price'] ) ) { if ( isset( $variation['regular_price'] ) ) {
$regular_price = ( '' === $variation['regular_price'] ) ? '' : wc_format_decimal( $variation['regular_price'] ); $regular_price = ( '' === $variation['regular_price'] ) ? '' : $variation['regular_price'];
update_post_meta( $variation_id, '_regular_price', $regular_price );
} else { } else {
$regular_price = get_post_meta( $variation_id, '_regular_price', true ); $regular_price = get_post_meta( $variation_id, '_regular_price', true );
} }
// Sale Price // Sale Price
if ( isset( $variation['sale_price'] ) ) { if ( isset( $variation['sale_price'] ) ) {
$sale_price = ( '' === $variation['sale_price'] ) ? '' : wc_format_decimal( $variation['sale_price'] ); $sale_price = ( '' === $variation['sale_price'] ) ? '' : $variation['sale_price'];
update_post_meta( $variation_id, '_sale_price', $sale_price );
} else { } else {
$sale_price = get_post_meta( $variation_id, '_sale_price', true ); $sale_price = get_post_meta( $variation_id, '_sale_price', true );
} }
$date_from = isset( $variation['sale_price_dates_from'] ) ? strtotime( $variation['sale_price_dates_from'] ) : get_post_meta( $variation_id, '_sale_price_dates_from', true ); if ( isset( $variation['sale_price_dates_from'] ) ) {
$date_to = isset( $variation['sale_price_dates_to'] ) ? strtotime( $variation['sale_price_dates_to'] ) : get_post_meta( $variation_id, '_sale_price_dates_to', true ); $date_from = $variation['sale_price_dates_from'];
// Save Dates
if ( $date_from ) {
update_post_meta( $variation_id, '_sale_price_dates_from', $date_from );
} else { } else {
update_post_meta( $variation_id, '_sale_price_dates_from', '' ); $date_from = get_post_meta( $variation_id, '_sale_price_dates_from', true );
$date_from = ( '' === $date_from ) ? '' : date( 'Y-m-d', $date_from );
} }
if ( $date_to ) { if ( isset( $variation['sale_price_dates_to'] ) ) {
update_post_meta( $variation_id, '_sale_price_dates_to', $date_to ); $date_to = $variation['sale_price_dates_to'];
} else { } else {
update_post_meta( $variation_id, '_sale_price_dates_to', '' ); $date_to = get_post_meta( $variation_id, '_sale_price_dates_to', true );
$date_to = ( '' === $date_to ) ? '' : date( 'Y-m-d', $date_to );
} }
if ( $date_to && ! $date_from ) { _wc_save_product_price( $variation_id, $regular_price, $sale_price, $date_from, $date_to );
update_post_meta( $variation_id, '_sale_price_dates_from', strtotime( 'NOW', current_time( 'timestamp' ) ) );
}
// Update price if on sale
if ( '' != $sale_price && '' == $date_to && '' == $date_from ) {
update_post_meta( $variation_id, '_price', $sale_price );
} else {
update_post_meta( $variation_id, '_price', $regular_price );
}
if ( '' != $sale_price && $date_from && $date_from < strtotime( 'NOW', current_time( 'timestamp' ) ) ) {
update_post_meta( $variation_id, '_price', $sale_price );
}
if ( $date_to && $date_to < strtotime( 'NOW', current_time( 'timestamp' ) ) ) {
update_post_meta( $variation_id, '_price', $regular_price );
update_post_meta( $variation_id, '_sale_price_dates_from', '' );
update_post_meta( $variation_id, '_sale_price_dates_to', '' );
}
// Tax class // Tax class
if ( isset( $variation['tax_class'] ) ) { if ( isset( $variation['tax_class'] ) ) {

View File

@ -453,8 +453,8 @@ class WC_API_Server {
'currency' => get_woocommerce_currency(), 'currency' => get_woocommerce_currency(),
'currency_format' => get_woocommerce_currency_symbol(), 'currency_format' => get_woocommerce_currency_symbol(),
'currency_position' => get_option( 'woocommerce_currency_pos' ), 'currency_position' => get_option( 'woocommerce_currency_pos' ),
'thousand_separator' => get_option( 'woocommerce_price_decimal_sep' ), 'thousand_separator' => get_option( 'woocommerce_price_thousand_sep' ),
'decimal_separator' => get_option( 'woocommerce_price_thousand_sep' ), 'decimal_separator' => get_option( 'woocommerce_price_decimal_sep' ),
'price_num_decimals' => wc_get_price_decimals(), 'price_num_decimals' => wc_get_price_decimals(),
'tax_included' => wc_prices_include_tax(), 'tax_included' => wc_prices_include_tax(),
'weight_unit' => get_option( 'woocommerce_weight_unit' ), 'weight_unit' => get_option( 'woocommerce_weight_unit' ),

View File

@ -315,6 +315,7 @@ class WC_AJAX {
if ( isset( $_POST['country'] ) ) { if ( isset( $_POST['country'] ) ) {
WC()->customer->set_shipping_country( $_POST['country'] ); WC()->customer->set_shipping_country( $_POST['country'] );
WC()->customer->calculated_shipping( true );
} }
if ( isset( $_POST['state'] ) ) { if ( isset( $_POST['state'] ) ) {
@ -340,6 +341,7 @@ class WC_AJAX {
if ( isset( $_POST['s_country'] ) ) { if ( isset( $_POST['s_country'] ) ) {
WC()->customer->set_shipping_country( $_POST['s_country'] ); WC()->customer->set_shipping_country( $_POST['s_country'] );
WC()->customer->calculated_shipping( true );
} }
if ( isset( $_POST['s_state'] ) ) { if ( isset( $_POST['s_state'] ) ) {
@ -393,6 +395,8 @@ class WC_AJAX {
) ) ) )
); );
unset( WC()->session->refresh_totals, WC()->session->reload_checkout );
wp_send_json( $data ); wp_send_json( $data );
die(); die();
@ -414,7 +418,7 @@ class WC_AJAX {
do_action( 'woocommerce_ajax_added_to_cart', $product_id ); do_action( 'woocommerce_ajax_added_to_cart', $product_id );
if ( get_option( 'woocommerce_cart_redirect_after_add' ) == 'yes' ) { if ( get_option( 'woocommerce_cart_redirect_after_add' ) == 'yes' ) {
wc_add_to_cart_message( $product_id ); wc_add_to_cart_message( array( $product_id => $quantity ), true );
} }
// Return fragments // Return fragments
@ -2531,11 +2535,7 @@ class WC_AJAX {
$variation_data['image'] = $variation_data['_thumbnail_id'] ? wp_get_attachment_thumb_url( $variation_data['_thumbnail_id'] ) : ''; $variation_data['image'] = $variation_data['_thumbnail_id'] ? wp_get_attachment_thumb_url( $variation_data['_thumbnail_id'] ) : '';
$variation_data['shipping_class'] = $shipping_classes && ! is_wp_error( $shipping_classes ) ? current( $shipping_classes )->term_id : ''; $variation_data['shipping_class'] = $shipping_classes && ! is_wp_error( $shipping_classes ) ? current( $shipping_classes )->term_id : '';
$variation_data['menu_order'] = $variation->menu_order; $variation_data['menu_order'] = $variation->menu_order;
$variation_data['_stock'] = wc_stock_amount( $variation_data['_stock'] );
// Stock BW compat
if ( '' !== $variation_data['_stock'] ) {
$variation_data['_manage_stock'] = 'yes';
}
include( 'admin/meta-boxes/views/html-variation-admin.php' ); include( 'admin/meta-boxes/views/html-variation-admin.php' );

View File

@ -18,15 +18,26 @@ if ( ! class_exists( 'WC_API' ) ) :
class WC_API { class WC_API {
/** This is the major version for the REST API and takes /**
* This is the major version for the REST API and takes
* first-order position in endpoint URLs. * first-order position in endpoint URLs.
*
* @var string
*/ */
const VERSION = '3.1.0'; const VERSION = '3.1.0';
/** @var WC_API_Server the REST API server */ /**
* The REST API server.
*
* @var WC_API_Server
*/
public $server; public $server;
/** @var WC_API_Authentication REST API authentication class instance */ /**
* REST API authentication class instance.
*
* @var WC_API_Authentication
*/
public $authentication; public $authentication;
/** /**
@ -56,7 +67,7 @@ class WC_API {
* Add new query vars. * Add new query vars.
* *
* @since 2.0 * @since 2.0
* @param $vars * @param array $vars
* @return string[] * @return string[]
*/ */
public function add_query_vars( $vars ) { public function add_query_vars( $vars ) {

View File

@ -20,6 +20,8 @@ class WC_Auth {
/** /**
* Version. * Version.
*
* @var int
*/ */
const VERSION = 1; const VERSION = 1;
@ -44,7 +46,7 @@ class WC_Auth {
* *
* @since 2.4.0 * @since 2.4.0
* *
* @param $vars * @param array $vars
* *
* @return string[] * @return string[]
*/ */

View File

@ -30,7 +30,7 @@ class WC_Breadcrumb {
*/ */
public function add_crumb( $name, $link = '' ) { public function add_crumb( $name, $link = '' ) {
$this->crumbs[] = array( $this->crumbs[] = array(
$name, strip_tags( $name ),
$link $link
); );
} }

View File

@ -94,25 +94,53 @@ class WC_Cart {
'fees' => array() 'fees' => array()
); );
/** @var array An array of fees. */ /**
public $fees = array(); * An array of fees.
*
* @var array
*/
public $fees = array();
/** @var boolean Prices inc tax */ /**
* Prices include tax.
*
* @var bool
*/
public $prices_include_tax; public $prices_include_tax;
/** @var boolean */ /**
* Round at subtotal.
*
* @var bool
*/
public $round_at_subtotal; public $round_at_subtotal;
/** @var string */ /**
* Tax display cart.
*
* @var string
*/
public $tax_display_cart; public $tax_display_cart;
/** @var int Prices inc tax */ /**
* Prices inc tax.
*
* @var int
*/
public $dp; public $dp;
/** @var boolean */ /**
* Display totals excluding tax.
*
* @var bool
*/
public $display_totals_ex_tax; public $display_totals_ex_tax;
/** @var boolean */ /**
* Display cart excluding tax.
*
* @var bool
*/
public $display_cart_ex_tax; public $display_cart_ex_tax;
/** /**
@ -449,18 +477,18 @@ class WC_Cart {
* @return bool|WP_Error * @return bool|WP_Error
*/ */
public function check_cart_item_validity() { public function check_cart_item_validity() {
foreach ( $this->get_cart() as $cart_item_key => $values ) { $return = true;
foreach ( $this->get_cart() as $cart_item_key => $values ) {
$_product = $values['data']; $_product = $values['data'];
if ( ! $_product || ! $_product->exists() || $_product->post->post_status == 'trash' ) { if ( ! $_product || ! $_product->exists() || 'trash' === $_product->post->post_status ) {
$this->set_quantity( $cart_item_key, 0 ); $this->set_quantity( $cart_item_key, 0 );
$return = new WP_Error( 'invalid', __( 'An item which is no longer available was removed from your cart.', 'woocommerce' ) );
return new WP_Error( 'invalid', __( 'An item which is no longer available was removed from your cart.', 'woocommerce' ) );
} }
} }
return true; return $return;
} }
/** /**
@ -859,9 +887,9 @@ class WC_Cart {
/** /**
* Add a product to the cart. * Add a product to the cart.
* *
* @param integer $product_id contains the id of the product to add to the cart * @param int $product_id contains the id of the product to add to the cart
* @param integer $quantity contains the quantity of the item to add * @param int $quantity contains the quantity of the item to add
* @param integer $variation_id * @param int $variation_id
* @param array $variation attribute values * @param array $variation attribute values
* @param array $cart_item_data extra cart item data we want to pass into the item * @param array $cart_item_data extra cart item data we want to pass into the item
* @return string $cart_item_key * @return string $cart_item_key
@ -1029,9 +1057,9 @@ class WC_Cart {
/** /**
* Set the quantity for an item in the cart. * Set the quantity for an item in the cart.
* *
* @param string cart_item_key contains the id of the cart item * @param string $cart_item_key contains the id of the cart item
* @param string quantity contains the quantity of the item * @param string $quantity contains the quantity of the item
* @param boolean $refresh_totals whether or not to calculate totals after setting the new qty * @param bool $refresh_totals whether or not to calculate totals after setting the new qty
* *
* @return bool * @return bool
*/ */
@ -1382,7 +1410,7 @@ class WC_Cart {
} }
/** /**
* remove_taxes function. * Remove taxes.
*/ */
public function remove_taxes() { public function remove_taxes() {
$this->shipping_tax_total = $this->tax_total = 0; $this->shipping_tax_total = $this->tax_total = 0;
@ -1402,7 +1430,7 @@ class WC_Cart {
} }
/** /**
* looks at the totals to see if payment is actually required. * Looks at the totals to see if payment is actually required.
* *
* @return bool * @return bool
*/ */
@ -1902,7 +1930,7 @@ class WC_Cart {
* *
* @access private * @access private
* @param string $code * @param string $code
* @param integer $count * @param int $count
*/ */
private function increase_coupon_applied_count( $code, $count = 1 ) { private function increase_coupon_applied_count( $code, $count = 1 ) {
if ( empty( $this->coupon_applied_count[ $code ] ) ) { if ( empty( $this->coupon_applied_count[ $code ] ) ) {
@ -1946,7 +1974,7 @@ class WC_Cart {
} }
/** /**
* get_fees function. * Get fees.
* *
* @return array * @return array
*/ */
@ -2171,8 +2199,8 @@ class WC_Cart {
/** /**
* Get tax row amounts with or without compound taxes includes. * Get tax row amounts with or without compound taxes includes.
* *
* @param boolean $compound True if getting compound taxes * @param bool $compound True if getting compound taxes
* @param boolean $display True if getting total to display * @param bool $display True if getting total to display
* @return float price * @return float price
*/ */
public function get_taxes_total( $compound = true, $display = true ) { public function get_taxes_total( $compound = true, $display = true ) {
@ -2243,7 +2271,7 @@ class WC_Cart {
* Get the total of all order discounts (after tax discounts). * Get the total of all order discounts (after tax discounts).
* *
* @deprecated Order discounts (after tax) removed in 2.3 * @deprecated Order discounts (after tax) removed in 2.3
* @return integer * @return int
*/ */
public function get_order_discount_total() { public function get_order_discount_total() {
_deprecated_function( 'get_order_discount_total', '2.3' ); _deprecated_function( 'get_order_discount_total', '2.3' );

View File

@ -155,17 +155,15 @@ class WC_Checkout {
} }
/** /**
* Create an order. * Create an order. Error codes:
* * 520 - Cannot insert order into the database.
* Error codes: * 521 - Cannot get order after creation.
* 400 - Cannot insert order into the database. * 522 - Cannot update order.
* 401 - Cannote update existing order. * 525 - Cannot create line item.
* 402 - Cannot create line item. * 526 - Cannot create fee item.
* 403 - Cannot create fee item. * 527 - Cannot create shipping item.
* 404 - Cannot create shipping item. * 528 - Cannot create tax item.
* 405 - Cannot create tax item. * 529 - Cannot create coupon item.
* 406 - Cannot create coupon item.
*
* @access public * @access public
* @throws Exception * @throws Exception
* @return int|WP_ERROR * @return int|WP_ERROR
@ -199,7 +197,7 @@ class WC_Checkout {
$order = wc_update_order( $order_data ); $order = wc_update_order( $order_data );
if ( is_wp_error( $order ) ) { if ( is_wp_error( $order ) ) {
throw new Exception( sprintf( __( 'Error %d: Unable to create order. Please try again.', 'woocommerce' ), 401 ) ); throw new Exception( sprintf( __( 'Error %d: Unable to create order. Please try again.', 'woocommerce' ), 522 ) );
} else { } else {
$order->remove_order_items(); $order->remove_order_items();
do_action( 'woocommerce_resume_order', $order_id ); do_action( 'woocommerce_resume_order', $order_id );
@ -210,7 +208,9 @@ class WC_Checkout {
$order = wc_create_order( $order_data ); $order = wc_create_order( $order_data );
if ( is_wp_error( $order ) ) { if ( is_wp_error( $order ) ) {
throw new Exception( sprintf( __( 'Error %d: Unable to create order. Please try again.', 'woocommerce' ), 400 ) ); throw new Exception( sprintf( __( 'Error %d: Unable to create order. Please try again.', 'woocommerce' ), 520 ) );
} elseif ( false === $order ) {
throw new Exception( sprintf( __( 'Error %d: Unable to create order. Please try again.', 'woocommerce' ), 521 ) );
} else { } else {
$order_id = $order->id; $order_id = $order->id;
do_action( 'woocommerce_new_order', $order_id ); do_action( 'woocommerce_new_order', $order_id );
@ -235,7 +235,7 @@ class WC_Checkout {
); );
if ( ! $item_id ) { if ( ! $item_id ) {
throw new Exception( sprintf( __( 'Error %d: Unable to create order. Please try again.', 'woocommerce' ), 402 ) ); throw new Exception( sprintf( __( 'Error %d: Unable to create order. Please try again.', 'woocommerce' ), 525 ) );
} }
// Allow plugins to add order item meta // Allow plugins to add order item meta
@ -247,7 +247,7 @@ class WC_Checkout {
$item_id = $order->add_fee( $fee ); $item_id = $order->add_fee( $fee );
if ( ! $item_id ) { if ( ! $item_id ) {
throw new Exception( sprintf( __( 'Error %d: Unable to create order. Please try again.', 'woocommerce' ), 403 ) ); throw new Exception( sprintf( __( 'Error %d: Unable to create order. Please try again.', 'woocommerce' ), 526 ) );
} }
// Allow plugins to add order item meta to fees // Allow plugins to add order item meta to fees
@ -260,7 +260,7 @@ class WC_Checkout {
$item_id = $order->add_shipping( $package['rates'][ $this->shipping_methods[ $package_key ] ] ); $item_id = $order->add_shipping( $package['rates'][ $this->shipping_methods[ $package_key ] ] );
if ( ! $item_id ) { if ( ! $item_id ) {
throw new Exception( sprintf( __( 'Error %d: Unable to create order. Please try again.', 'woocommerce' ), 404 ) ); throw new Exception( sprintf( __( 'Error %d: Unable to create order. Please try again.', 'woocommerce' ), 527 ) );
} }
// Allows plugins to add order item meta to shipping // Allows plugins to add order item meta to shipping
@ -271,14 +271,14 @@ class WC_Checkout {
// Store tax rows // Store tax rows
foreach ( array_keys( WC()->cart->taxes + WC()->cart->shipping_taxes ) as $tax_rate_id ) { foreach ( array_keys( WC()->cart->taxes + WC()->cart->shipping_taxes ) as $tax_rate_id ) {
if ( $tax_rate_id && ! $order->add_tax( $tax_rate_id, WC()->cart->get_tax_amount( $tax_rate_id ), WC()->cart->get_shipping_tax_amount( $tax_rate_id ) ) && apply_filters( 'woocommerce_cart_remove_taxes_zero_rate_id', 'zero-rated' ) !== $tax_rate_id ) { if ( $tax_rate_id && ! $order->add_tax( $tax_rate_id, WC()->cart->get_tax_amount( $tax_rate_id ), WC()->cart->get_shipping_tax_amount( $tax_rate_id ) ) && apply_filters( 'woocommerce_cart_remove_taxes_zero_rate_id', 'zero-rated' ) !== $tax_rate_id ) {
throw new Exception( sprintf( __( 'Error %d: Unable to create order. Please try again.', 'woocommerce' ), 405 ) ); throw new Exception( sprintf( __( 'Error %d: Unable to create order. Please try again.', 'woocommerce' ), 528 ) );
} }
} }
// Store coupons // Store coupons
foreach ( WC()->cart->get_coupons() as $code => $coupon ) { foreach ( WC()->cart->get_coupons() as $code => $coupon ) {
if ( ! $order->add_coupon( $code, WC()->cart->get_coupon_discount_amount( $code ), WC()->cart->get_coupon_discount_tax_amount( $code ) ) ) { if ( ! $order->add_coupon( $code, WC()->cart->get_coupon_discount_amount( $code ), WC()->cart->get_coupon_discount_tax_amount( $code ) ) ) {
throw new Exception( sprintf( __( 'Error %d: Unable to create order. Please try again.', 'woocommerce' ), 406 ) ); throw new Exception( sprintf( __( 'Error %d: Unable to create order. Please try again.', 'woocommerce' ), 529 ) );
} }
} }

View File

@ -213,6 +213,8 @@ class WC_Comments {
/** /**
* Modify recipient of review email. * Modify recipient of review email.
* @param array $emails
* @param int $comment_id
* @return array * @return array
*/ */
public static function comment_moderation_recipients( $emails, $comment_id ) { public static function comment_moderation_recipients( $emails, $comment_id ) {

View File

@ -194,7 +194,7 @@ class WC_Countries {
} }
/** /**
* get_allowed_country_states function. * Get allowed country states.
* @return array * @return array
*/ */
public function get_allowed_country_states() { public function get_allowed_country_states() {
@ -216,7 +216,7 @@ class WC_Countries {
} }
/** /**
* get_shipping_country_states function. * Get shipping country states.
* @return array * @return array
*/ */
public function get_shipping_country_states() { public function get_shipping_country_states() {
@ -264,22 +264,24 @@ class WC_Countries {
* Gets the correct string for shipping - either 'to the' or 'to' * Gets the correct string for shipping - either 'to the' or 'to'
* @return string * @return string
*/ */
public function shipping_to_prefix() { public function shipping_to_prefix( $country_code = '' ) {
$countries = array( 'GB', 'US', 'AE', 'CZ', 'DO', 'NL', 'PH', 'USAF' ); $country_code = $country_code ? $country_code : WC()->customer->get_shipping_country();
$return = in_array( WC()->customer->get_shipping_country(), $countries ) ? __( 'to the', 'woocommerce' ) : __( 'to', 'woocommerce' ); $countries = array( 'GB', 'US', 'AE', 'CZ', 'DO', 'NL', 'PH', 'USAF' );
$return = in_array( $country_code, $countries ) ? __( 'to the', 'woocommerce' ) : __( 'to', 'woocommerce' );
return apply_filters( 'woocommerce_countries_shipping_to_prefix', $return, WC()->customer->get_shipping_country() ); return apply_filters( 'woocommerce_countries_shipping_to_prefix', $return, $country_code );
} }
/** /**
* Prefix certain countries with 'the' * Prefix certain countries with 'the'
* @return string * @return string
*/ */
public function estimated_for_prefix() { public function estimated_for_prefix( $country_code = '' ) {
$countries = array( 'GB', 'US', 'AE', 'CZ', 'DO', 'NL', 'PH', 'USAF' ); $country_code = $country_code ? $country_code : $this->get_base_country();
$return = in_array( $this->get_base_country(), $countries ) ? __( 'the', 'woocommerce' ) . ' ' : ''; $countries = array( 'GB', 'US', 'AE', 'CZ', 'DO', 'NL', 'PH', 'USAF' );
$return = in_array( $country_code, $countries ) ? __( 'the', 'woocommerce' ) . ' ' : '';
return apply_filters( 'woocommerce_countries_estimated_for_prefix', $return, $this->get_base_country() ); return apply_filters( 'woocommerce_countries_estimated_for_prefix', $return, $country_code );
} }
/** /**
@ -316,6 +318,7 @@ class WC_Countries {
* Outputs the list of countries and states for use in dropdown boxes. * Outputs the list of countries and states for use in dropdown boxes.
* @param string $selected_country (default: '') * @param string $selected_country (default: '')
* @param string $selected_state (default: '') * @param string $selected_state (default: '')
* @param bool $escape (default: false)
* @param bool $escape (default: false) * @param bool $escape (default: false)
*/ */
public function country_dropdown_options( $selected_country = '', $selected_state = '', $escape = false ) { public function country_dropdown_options( $selected_country = '', $selected_state = '', $escape = false ) {
@ -475,7 +478,7 @@ class WC_Countries {
/** /**
* Trim white space and commas off a line. * Trim white space and commas off a line.
* @param string * @param string $line
* @return string * @return string
*/ */
private function trim_formatted_address_line( $line ) { private function trim_formatted_address_line( $line ) {
@ -489,57 +492,64 @@ class WC_Countries {
public function get_default_address_fields() { public function get_default_address_fields() {
$fields = array( $fields = array(
'first_name' => array( 'first_name' => array(
'label' => __( 'First Name', 'woocommerce' ), 'label' => __( 'First Name', 'woocommerce' ),
'required' => true, 'required' => true,
'class' => array( 'form-row-first' ), 'class' => array( 'form-row-first' ),
'autocomplete' => 'given-name',
), ),
'last_name' => array( 'last_name' => array(
'label' => __( 'Last Name', 'woocommerce' ), 'label' => __( 'Last Name', 'woocommerce' ),
'required' => true, 'required' => true,
'class' => array( 'form-row-last' ), 'class' => array( 'form-row-last' ),
'clear' => true 'clear' => true,
'autocomplete' => 'family-name',
), ),
'company' => array( 'company' => array(
'label' => __( 'Company Name', 'woocommerce' ), 'label' => __( 'Company Name', 'woocommerce' ),
'class' => array( 'form-row-wide' ), 'class' => array( 'form-row-wide' ),
'autocomplete' => 'organization',
), ),
'country' => array( 'country' => array(
'type' => 'country', 'type' => 'country',
'label' => __( 'Country', 'woocommerce' ), 'label' => __( 'Country', 'woocommerce' ),
'required' => true, 'required' => true,
'class' => array( 'form-row-wide', 'address-field', 'update_totals_on_change' ), 'class' => array( 'form-row-wide', 'address-field', 'update_totals_on_change' ),
'autocomplete' => 'country',
), ),
'address_1' => array( 'address_1' => array(
'label' => __( 'Address', 'woocommerce' ), 'label' => __( 'Address', 'woocommerce' ),
'placeholder' => _x( 'Street address', 'placeholder', 'woocommerce' ), 'placeholder' => _x( 'Street address', 'placeholder', 'woocommerce' ),
'required' => true, 'required' => true,
'class' => array( 'form-row-wide', 'address-field' ) 'class' => array( 'form-row-wide', 'address-field' ),
'autocomplete' => 'address-line1',
), ),
'address_2' => array( 'address_2' => array(
'placeholder' => _x( 'Apartment, suite, unit etc. (optional)', 'placeholder', 'woocommerce' ), 'placeholder' => _x( 'Apartment, suite, unit etc. (optional)', 'placeholder', 'woocommerce' ),
'class' => array( 'form-row-wide', 'address-field' ), 'class' => array( 'form-row-wide', 'address-field' ),
'required' => false 'required' => false,
'autocomplete' => 'address-line2',
), ),
'city' => array( 'city' => array(
'label' => __( 'Town / City', 'woocommerce' ), 'label' => __( 'Town / City', 'woocommerce' ),
'placeholder' => __( 'Town / City', 'woocommerce' ), 'required' => true,
'required' => true, 'class' => array( 'form-row-wide', 'address-field' ),
'class' => array( 'form-row-wide', 'address-field' ) 'autocomplete' => 'address-level2',
), ),
'state' => array( 'state' => array(
'type' => 'state', 'type' => 'state',
'label' => __( 'State / County', 'woocommerce' ), 'label' => __( 'State / County', 'woocommerce' ),
'required' => true, 'required' => true,
'class' => array( 'form-row-first', 'address-field' ), 'class' => array( 'form-row-first', 'address-field' ),
'validate' => array( 'state' ) 'validate' => array( 'state' ),
'autocomplete' => 'address-level1',
), ),
'postcode' => array( 'postcode' => array(
'label' => __( 'Postcode / ZIP', 'woocommerce' ), 'label' => __( 'Postcode / ZIP', 'woocommerce' ),
'placeholder' => __( 'Postcode / ZIP', 'woocommerce' ), 'required' => true,
'required' => true, 'class' => array( 'form-row-last', 'address-field' ),
'class' => array( 'form-row-last', 'address-field' ), 'clear' => true,
'clear' => true, 'validate' => array( 'postcode' ),
'validate' => array( 'postcode' ) 'autocomplete' => 'postal-code',
), ),
); );
@ -591,15 +601,12 @@ class WC_Countries {
'AU' => array( 'AU' => array(
'city' => array( 'city' => array(
'label' => __( 'Suburb', 'woocommerce' ), 'label' => __( 'Suburb', 'woocommerce' ),
'placeholder' => __( 'Suburb', 'woocommerce' ),
), ),
'postcode' => array( 'postcode' => array(
'label' => __( 'Postcode', 'woocommerce' ), 'label' => __( 'Postcode', 'woocommerce' ),
'placeholder' => __( 'Postcode', 'woocommerce' ),
), ),
'state' => array( 'state' => array(
'label' => __( 'State', 'woocommerce' ), 'label' => __( 'State', 'woocommerce' ),
//'placeholder' => __( 'State', 'woocommerce' ),
) )
), ),
'AX' => array( 'AX' => array(
@ -614,7 +621,6 @@ class WC_Countries {
), ),
'state' => array( 'state' => array(
'label' => __( 'District', 'woocommerce' ), 'label' => __( 'District', 'woocommerce' ),
//'placeholder' => __( 'District', 'woocommerce' ),
) )
), ),
'BE' => array( 'BE' => array(
@ -622,7 +628,6 @@ class WC_Countries {
'state' => array( 'state' => array(
'required' => false, 'required' => false,
'label' => __( 'Province', 'woocommerce' ), 'label' => __( 'Province', 'woocommerce' ),
//'placeholder' => __( 'Province', 'woocommerce' ),
), ),
), ),
'BI' => array( 'BI' => array(
@ -645,14 +650,12 @@ class WC_Countries {
'CA' => array( 'CA' => array(
'state' => array( 'state' => array(
'label' => __( 'Province', 'woocommerce' ), 'label' => __( 'Province', 'woocommerce' ),
//'placeholder' => __( 'Province', 'woocommerce' ),
) )
), ),
'CH' => array( 'CH' => array(
'postcode_before_city' => true, 'postcode_before_city' => true,
'state' => array( 'state' => array(
'label' => __( 'Canton', 'woocommerce' ), 'label' => __( 'Canton', 'woocommerce' ),
//'placeholder' => __( 'Canton', 'woocommerce' ),
'required' => false 'required' => false
) )
), ),
@ -665,13 +668,11 @@ class WC_Countries {
), ),
'state' => array( 'state' => array(
'label' => __( 'Region', 'woocommerce' ), 'label' => __( 'Region', 'woocommerce' ),
//'placeholder' => __( 'Region', 'woocommerce' )
) )
), ),
'CN' => array( 'CN' => array(
'state' => array( 'state' => array(
'label' => __( 'Province', 'woocommerce' ), 'label' => __( 'Province', 'woocommerce' ),
//'placeholder' => __( 'Province', 'woocommerce' ),
) )
), ),
'CO' => array( 'CO' => array(
@ -720,23 +721,19 @@ class WC_Countries {
), ),
'city' => array( 'city' => array(
'label' => __( 'Town / District', 'woocommerce' ), 'label' => __( 'Town / District', 'woocommerce' ),
'placeholder' => __( 'Town / District', 'woocommerce' )
), ),
'state' => array( 'state' => array(
'label' => __( 'Region', 'woocommerce' ), 'label' => __( 'Region', 'woocommerce' ),
//'placeholder' => __( 'Region', 'woocommerce' ),
) )
), ),
'HU' => array( 'HU' => array(
'state' => array( 'state' => array(
'label' => __( 'County', 'woocommerce' ), 'label' => __( 'County', 'woocommerce' ),
//'placeholder' => __( 'County', 'woocommerce' ),
) )
), ),
'ID' => array( 'ID' => array(
'state' => array( 'state' => array(
'label' => __( 'Province', 'woocommerce' ), 'label' => __( 'Province', 'woocommerce' ),
//'placeholder' => __( 'Province', 'woocommerce' ),
) )
), ),
'IS' => array( 'IS' => array(
@ -756,7 +753,6 @@ class WC_Countries {
'state' => array( 'state' => array(
'required' => true, 'required' => true,
'label' => __( 'Province', 'woocommerce' ), 'label' => __( 'Province', 'woocommerce' ),
//'placeholder' => __( 'Province', 'woocommerce' ),
) )
), ),
'JP' => array( 'JP' => array(
@ -774,7 +770,6 @@ class WC_Countries {
'state' => array( 'state' => array(
'required' => false, 'required' => false,
'label' => __( 'Province', 'woocommerce' ), 'label' => __( 'Province', 'woocommerce' ),
//'placeholder' => __( 'Province', 'woocommerce' ),
) )
), ),
'NZ' => array( 'NZ' => array(
@ -791,7 +786,6 @@ class WC_Countries {
'NP' => array( 'NP' => array(
'state' => array( 'state' => array(
'label' => __( 'State / Zone', 'woocommerce' ), 'label' => __( 'State / Zone', 'woocommerce' ),
//'placeholder' => __( 'State / Zone', 'woocommerce' ),
), ),
'postcode' => array( 'postcode' => array(
'required' => false 'required' => false
@ -834,14 +828,12 @@ class WC_Countries {
'postcode_before_city' => true, 'postcode_before_city' => true,
'state' => array( 'state' => array(
'label' => __( 'Province', 'woocommerce' ), 'label' => __( 'Province', 'woocommerce' ),
//'placeholder' => __( 'Province', 'woocommerce' ),
) )
), ),
'LI' => array( 'LI' => array(
'postcode_before_city' => true, 'postcode_before_city' => true,
'state' => array( 'state' => array(
'label' => __( 'Municipality', 'woocommerce' ), 'label' => __( 'Municipality', 'woocommerce' ),
//'placeholder' => __( 'Municipality', 'woocommerce' ),
'required' => false 'required' => false
) )
), ),
@ -860,27 +852,22 @@ class WC_Countries {
'postcode_before_city' => true, 'postcode_before_city' => true,
'state' => array( 'state' => array(
'label' => __( 'Province', 'woocommerce' ), 'label' => __( 'Province', 'woocommerce' ),
//'placeholder' => __( 'Province', 'woocommerce' ),
) )
), ),
'US' => array( 'US' => array(
'postcode' => array( 'postcode' => array(
'label' => __( 'ZIP', 'woocommerce' ), 'label' => __( 'ZIP', 'woocommerce' ),
'placeholder' => __( 'ZIP', 'woocommerce' ),
), ),
'state' => array( 'state' => array(
'label' => __( 'State', 'woocommerce' ), 'label' => __( 'State', 'woocommerce' ),
//'placeholder' => __( 'State', 'woocommerce' ),
) )
), ),
'GB' => array( 'GB' => array(
'postcode' => array( 'postcode' => array(
'label' => __( 'Postcode', 'woocommerce' ), 'label' => __( 'Postcode', 'woocommerce' ),
'placeholder' => __( 'Postcode', 'woocommerce' ),
), ),
'state' => array( 'state' => array(
'label' => __( 'County', 'woocommerce' ), 'label' => __( 'County', 'woocommerce' ),
//'placeholder' => __( 'County', 'woocommerce' ),
'required' => false 'required' => false
) )
), ),
@ -907,7 +894,6 @@ class WC_Countries {
'ZA' => array( 'ZA' => array(
'state' => array( 'state' => array(
'label' => __( 'Province', 'woocommerce' ), 'label' => __( 'Province', 'woocommerce' ),
//'placeholder' => __( 'Province', 'woocommerce' ),
) )
), ),
'ZW' => array( 'ZW' => array(
@ -938,7 +924,7 @@ class WC_Countries {
/** /**
* Apply locale and get address fields. * Apply locale and get address fields.
* @param mixed $country * @param mixed $country (default: '')
* @param string $type (default: 'billing_') * @param string $type (default: 'billing_')
* @return array * @return array
*/ */
@ -964,19 +950,21 @@ class WC_Countries {
// Add email and phone after company or last // Add email and phone after company or last
if ( $type == 'billing_' && ( 'company' === $key || ( ! array_key_exists( 'company', $fields ) && $key === end( $keys ) ) ) ) { if ( $type == 'billing_' && ( 'company' === $key || ( ! array_key_exists( 'company', $fields ) && $key === end( $keys ) ) ) ) {
$address_fields['billing_email'] = array( $address_fields['billing_email'] = array(
'label' => __( 'Email Address', 'woocommerce' ), 'label' => __( 'Email Address', 'woocommerce' ),
'required' => true, 'required' => true,
'type' => 'email', 'type' => 'email',
'class' => array( 'form-row-first' ), 'class' => array( 'form-row-first' ),
'validate' => array( 'email' ), 'validate' => array( 'email' ),
'autocomplete' => 'email',
); );
$address_fields['billing_phone'] = array( $address_fields['billing_phone'] = array(
'label' => __( 'Phone', 'woocommerce' ), 'label' => __( 'Phone', 'woocommerce' ),
'required' => true, 'required' => true,
'type' => 'tel', 'type' => 'tel',
'class' => array( 'form-row-last' ), 'class' => array( 'form-row-last' ),
'clear' => true, 'clear' => true,
'validate' => array( 'phone' ), 'validate' => array( 'phone' ),
'autocomplete' => 'tel',
); );
} }
} }

View File

@ -331,6 +331,8 @@ class WC_Coupon {
/** /**
* Ensure coupon exists or throw exception. * Ensure coupon exists or throw exception.
*
* @throws Exception
*/ */
private function validate_exists() { private function validate_exists() {
if ( ! $this->exists ) { if ( ! $this->exists ) {
@ -340,6 +342,8 @@ class WC_Coupon {
/** /**
* Ensure coupon usage limit is valid or throw exception. * Ensure coupon usage limit is valid or throw exception.
*
* @throws Exception
*/ */
private function validate_usage_limit() { private function validate_usage_limit() {
if ( $this->usage_limit > 0 && $this->usage_count >= $this->usage_limit ) { if ( $this->usage_limit > 0 && $this->usage_count >= $this->usage_limit ) {
@ -362,11 +366,7 @@ class WC_Coupon {
} }
if ( $this->usage_limit_per_user > 0 && is_user_logged_in() && $this->id ) { if ( $this->usage_limit_per_user > 0 && is_user_logged_in() && $this->id ) {
global $wpdb; global $wpdb;
$wpdb->get_var( $wpdb->prepare( "SELECT COUNT( `meta_id` ) $usage_count = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT( meta_id ) FROM {$wpdb->postmeta} WHERE post_id = %d AND meta_key = '_used_by' AND meta_value = %d;", $this->id, $user_id ) );
FROM {$wpdb->postmeta}
WHERE `post_id` = %d
AND `meta_key` = '_used_by'
AND `meta_value` = %d", $this->id, $user_id ) );
if ( $usage_count >= $this->usage_limit_per_user ) { if ( $usage_count >= $this->usage_limit_per_user ) {
throw new Exception( self::E_WC_COUPON_USAGE_LIMIT_REACHED ); throw new Exception( self::E_WC_COUPON_USAGE_LIMIT_REACHED );
@ -376,6 +376,8 @@ class WC_Coupon {
/** /**
* Ensure coupon date is valid or throw exception. * Ensure coupon date is valid or throw exception.
*
* @throws Exception
*/ */
private function validate_expiry_date() { private function validate_expiry_date() {
if ( $this->expiry_date && current_time( 'timestamp' ) > $this->expiry_date ) { if ( $this->expiry_date && current_time( 'timestamp' ) > $this->expiry_date ) {
@ -385,6 +387,8 @@ class WC_Coupon {
/** /**
* Ensure coupon amount is valid or throw exception. * Ensure coupon amount is valid or throw exception.
*
* @throws Exception
*/ */
private function validate_minimum_amount() { private function validate_minimum_amount() {
if ( $this->minimum_amount > 0 && wc_format_decimal( $this->minimum_amount ) > wc_format_decimal( WC()->cart->subtotal ) ) { if ( $this->minimum_amount > 0 && wc_format_decimal( $this->minimum_amount ) > wc_format_decimal( WC()->cart->subtotal ) ) {
@ -394,6 +398,8 @@ class WC_Coupon {
/** /**
* Ensure coupon amount is valid or throw exception. * Ensure coupon amount is valid or throw exception.
*
* @throws Exception
*/ */
private function validate_maximum_amount() { private function validate_maximum_amount() {
if ( $this->maximum_amount > 0 && wc_format_decimal( $this->maximum_amount ) < wc_format_decimal( WC()->cart->subtotal ) ) { if ( $this->maximum_amount > 0 && wc_format_decimal( $this->maximum_amount ) < wc_format_decimal( WC()->cart->subtotal ) ) {
@ -403,6 +409,8 @@ class WC_Coupon {
/** /**
* Ensure coupon is valid for products in the cart is valid or throw exception. * Ensure coupon is valid for products in the cart is valid or throw exception.
*
* @throws Exception
*/ */
private function validate_product_ids() { private function validate_product_ids() {
if ( sizeof( $this->product_ids ) > 0 ) { if ( sizeof( $this->product_ids ) > 0 ) {
@ -422,6 +430,8 @@ class WC_Coupon {
/** /**
* Ensure coupon is valid for product categories in the cart is valid or throw exception. * Ensure coupon is valid for product categories in the cart is valid or throw exception.
*
* @throws Exception
*/ */
private function validate_product_categories() { private function validate_product_categories() {
if ( sizeof( $this->product_categories ) > 0 ) { if ( sizeof( $this->product_categories ) > 0 ) {
@ -430,6 +440,7 @@ class WC_Coupon {
foreach( WC()->cart->get_cart() as $cart_item_key => $cart_item ) { foreach( WC()->cart->get_cart() as $cart_item_key => $cart_item ) {
$product_cats = wc_get_product_cat_ids( $cart_item['product_id'] ); $product_cats = wc_get_product_cat_ids( $cart_item['product_id'] );
// If we find an item with a cat in our allowed cat list, the coupon is valid
if ( sizeof( array_intersect( $product_cats, $this->product_categories ) ) > 0 ) { if ( sizeof( array_intersect( $product_cats, $this->product_categories ) ) > 0 ) {
$valid_for_cart = true; $valid_for_cart = true;
} }
@ -441,8 +452,34 @@ class WC_Coupon {
} }
} }
/**
* Ensure coupon is valid for product categories in the cart is valid or throw exception.
*
* @throws Exception
*/
private function validate_excluded_product_categories() {
if ( sizeof( $this->exclude_product_categories ) > 0 ) {
$valid_for_cart = false;
if ( ! WC()->cart->is_empty() ) {
foreach( WC()->cart->get_cart() as $cart_item_key => $cart_item ) {
$product_cats = wc_get_product_cat_ids( $cart_item['product_id'] );
// If we find an item with a cat NOT in our disallowed cat list, the coupon is valid
if ( empty( $product_cats ) || sizeof( array_diff( $product_cats, $this->exclude_product_categories ) ) > 0 ) {
$valid_for_cart = true;
}
}
}
if ( ! $valid_for_cart ) {
throw new Exception( self::E_WC_COUPON_NOT_APPLICABLE );
}
}
}
/** /**
* Ensure coupon is valid for sale items in the cart is valid or throw exception. * Ensure coupon is valid for sale items in the cart is valid or throw exception.
*
* @throws Exception
*/ */
private function validate_sale_items() { private function validate_sale_items() {
if ( 'yes' === $this->exclude_sale_items && $this->is_type( wc_get_product_coupon_types() ) ) { if ( 'yes' === $this->exclude_sale_items && $this->is_type( wc_get_product_coupon_types() ) ) {
@ -479,6 +516,8 @@ class WC_Coupon {
/** /**
* Exclude products from cart. * Exclude products from cart.
*
* @throws Exception
*/ */
private function validate_cart_excluded_product_ids() { private function validate_cart_excluded_product_ids() {
// Exclude Products // Exclude Products
@ -499,6 +538,8 @@ class WC_Coupon {
/** /**
* Exclude categories from cart. * Exclude categories from cart.
*
* @throws Exception
*/ */
private function validate_cart_excluded_product_categories() { private function validate_cart_excluded_product_categories() {
if ( sizeof( $this->exclude_product_categories ) > 0 ) { if ( sizeof( $this->exclude_product_categories ) > 0 ) {
@ -521,6 +562,8 @@ class WC_Coupon {
/** /**
* Exclude sale items from cart. * Exclude sale items from cart.
*
* @throws Exception
*/ */
private function validate_cart_excluded_sale_items() { private function validate_cart_excluded_sale_items() {
if ( $this->exclude_sale_items == 'yes' ) { if ( $this->exclude_sale_items == 'yes' ) {
@ -547,6 +590,7 @@ class WC_Coupon {
* Check if a coupon is valid. * Check if a coupon is valid.
* *
* @return boolean validity * @return boolean validity
* @throws Exception
*/ */
public function is_valid() { public function is_valid() {
try { try {
@ -558,6 +602,7 @@ class WC_Coupon {
$this->validate_maximum_amount(); $this->validate_maximum_amount();
$this->validate_product_ids(); $this->validate_product_ids();
$this->validate_product_categories(); $this->validate_product_categories();
$this->validate_excluded_product_categories();
$this->validate_sale_items(); $this->validate_sale_items();
$this->validate_cart_excluded_items(); $this->validate_cart_excluded_items();

View File

@ -142,7 +142,7 @@ class WC_Customer {
} }
/** /**
* has_calculated_shipping function. * Has calculated shipping?
* *
* @return bool * @return bool
*/ */
@ -322,7 +322,7 @@ class WC_Customer {
} }
/** /**
* get_taxable_address function. * Get taxable address.
* *
* @return array * @return array
*/ */
@ -550,7 +550,7 @@ class WC_Customer {
} }
/** /**
* calculated_shipping function. * Calculated shipping.
* *
* @param boolean $calculated * @param boolean $calculated
*/ */

View File

@ -275,16 +275,7 @@ class WC_Emails {
* @return string * @return string
*/ */
public function order_meta( $order, $sent_to_admin = false, $plain_text = false ) { public function order_meta( $order, $sent_to_admin = false, $plain_text = false ) {
$fields = array(); $fields = apply_filters( 'woocommerce_email_order_meta_fields', array(), $sent_to_admin, $order );
if ( $order->customer_note ) {
$fields['customer_note'] = array(
'label' => __( 'Note', 'woocommerce' ),
'value' => wptexturize( $order->customer_note )
);
}
$fields = apply_filters( 'woocommerce_email_order_meta_fields', $fields, $sent_to_admin, $order );
/** /**
* Deprecated woocommerce_email_order_meta_keys filter. * Deprecated woocommerce_email_order_meta_keys filter.
@ -347,6 +338,13 @@ class WC_Emails {
public function customer_details( $order, $sent_to_admin = false, $plain_text = false ) { public function customer_details( $order, $sent_to_admin = false, $plain_text = false ) {
$fields = array(); $fields = array();
if ( $order->customer_note ) {
$fields['customer_note'] = array(
'label' => __( 'Note', 'woocommerce' ),
'value' => wptexturize( $order->customer_note )
);
}
if ( $order->billing_email ) { if ( $order->billing_email ) {
$fields['billing_email'] = array( $fields['billing_email'] = array(
'label' => __( 'Email', 'woocommerce' ), 'label' => __( 'Email', 'woocommerce' ),

View File

@ -346,7 +346,7 @@ class WC_Form_Handler {
* Process the add payment method form. * Process the add payment method form.
*/ */
public static function add_payment_method_action() { public static function add_payment_method_action() {
if ( isset( $_POST['woocommerce_add_payment_method'] ) && isset( $_POST['_wpnonce'] ) && wp_verify_nonce( $_POST['_wpnonce'], 'woocommerce-add-payment-method' ) ) { if ( isset( $_POST['woocommerce_add_payment_method'], $_POST['payment_method'], $_POST['_wpnonce'] ) && wp_verify_nonce( $_POST['_wpnonce'], 'woocommerce-add-payment-method' ) ) {
ob_start(); ob_start();
@ -648,7 +648,7 @@ class WC_Form_Handler {
$passed_validation = apply_filters( 'woocommerce_add_to_cart_validation', true, $product_id, $quantity ); $passed_validation = apply_filters( 'woocommerce_add_to_cart_validation', true, $product_id, $quantity );
if ( $passed_validation && WC()->cart->add_to_cart( $product_id, $quantity ) !== false ) { if ( $passed_validation && WC()->cart->add_to_cart( $product_id, $quantity ) !== false ) {
wc_add_to_cart_message( $product_id ); wc_add_to_cart_message( array( $product_id => $quantity ), true );
return true; return true;
} }
return false; return false;
@ -678,7 +678,7 @@ class WC_Form_Handler {
if ( $passed_validation && WC()->cart->add_to_cart( $item, $quantity ) !== false ) { if ( $passed_validation && WC()->cart->add_to_cart( $item, $quantity ) !== false ) {
$was_added_to_cart = true; $was_added_to_cart = true;
$added_to_cart[] = $item; $added_to_cart[ $item ] = $quantity;
} }
} }
@ -752,7 +752,7 @@ class WC_Form_Handler {
$passed_validation = apply_filters( 'woocommerce_add_to_cart_validation', true, $product_id, $quantity, $variation_id, $variations ); $passed_validation = apply_filters( 'woocommerce_add_to_cart_validation', true, $product_id, $quantity, $variation_id, $variations );
if ( $passed_validation && WC()->cart->add_to_cart( $product_id, $quantity, $variation_id, $variations ) !== false ) { if ( $passed_validation && WC()->cart->add_to_cart( $product_id, $quantity, $variation_id, $variations ) !== false ) {
wc_add_to_cart_message( $product_id ); wc_add_to_cart_message( array( $product_id => $quantity ), true );
return true; return true;
} }
} }

View File

@ -183,8 +183,9 @@ class WC_Frontend_Scripts {
self::enqueue_script( 'select2' ); self::enqueue_script( 'select2' );
self::enqueue_style( 'select2', $assets_path . 'css/select2.css' ); self::enqueue_style( 'select2', $assets_path . 'css/select2.css' );
// Password strength meter js called for checkout page. // Password strength meter.
if ( 'no' === get_option( 'woocommerce_registration_generate_password' ) && ! is_user_logged_in() ) { // Load in checkout, account login and edit account page.
if ( ( 'no' === get_option( 'woocommerce_registration_generate_password' ) && ! is_user_logged_in() ) || is_edit_account_page() ) {
self::enqueue_script( 'wc-password-strength-meter' ); self::enqueue_script( 'wc-password-strength-meter' );
} }
} }
@ -322,8 +323,8 @@ class WC_Frontend_Scripts {
break; break;
case 'wc-country-select' : case 'wc-country-select' :
return array( return array(
'countries' => json_encode( array_merge( WC()->countries->get_allowed_country_states(), WC()->countries->get_shipping_country_states() ) ), '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' ), 'i18n_select_state_text' => esc_attr__( 'Select an option&hellip;', 'woocommerce' ),
'i18n_matches_1' => _x( 'One result is available, press enter to select it.', 'enhanced select', 'woocommerce' ), 'i18n_matches_1' => _x( 'One result is available, press enter to select it.', 'enhanced select', 'woocommerce' ),
'i18n_matches_n' => _x( '%qty% results are available, use up and down arrow keys to navigate.', 'enhanced select', 'woocommerce' ), 'i18n_matches_n' => _x( '%qty% results are available, use up and down arrow keys to navigate.', 'enhanced select', 'woocommerce' ),
'i18n_no_matches' => _x( 'No matches found', 'enhanced select', 'woocommerce' ), 'i18n_no_matches' => _x( 'No matches found', 'enhanced select', 'woocommerce' ),
@ -338,6 +339,12 @@ class WC_Frontend_Scripts {
'i18n_searching' => _x( 'Searching&hellip;', 'enhanced select', 'woocommerce' ), 'i18n_searching' => _x( 'Searching&hellip;', 'enhanced select', 'woocommerce' ),
); );
break; break;
case 'wc-password-strength-meter' :
return array(
'i18n_password_error' => esc_attr__( 'Please enter a stronger password to continue.', 'woocommerce' ),
'i18n_password_hint' => esc_attr__( 'The password should be at least seven characters long. To make it stronger, use upper and lower case letters, numbers and symbols like ! " ? $ % ^ &amp; ).', 'woocommerce' )
);
break;
} }
return false; return false;
} }

View File

@ -15,7 +15,7 @@ if ( ! defined( 'ABSPATH' ) ) {
} }
/** /**
* WC_Geolocation Class. * WC_Geo_IP Class.
*/ */
class WC_Geo_IP { class WC_Geo_IP {
@ -54,20 +54,60 @@ class WC_Geo_IP {
const GEOIP_ORG_EDITION_V6 = 23; const GEOIP_ORG_EDITION_V6 = 23;
const GEOIP_DOMAIN_EDITION_V6 = 24; const GEOIP_DOMAIN_EDITION_V6 = 24;
/**
* Flags.
*
* @var array
*/
public $flags; public $flags;
/**
* File handler.
*
* @var resource
*/
public $filehandle; public $filehandle;
/**
* Memory buffer.
*
* @var array
*/
public $memory_buffer; public $memory_buffer;
/**
* Database type.
*
* @var string
*/
public $databaseType; public $databaseType;
/**
* Database segments.
*
* @var int
*/
public $databaseSegments; public $databaseSegments;
/**
* Record length.
*
* @var int
*/
public $record_length; public $record_length;
/**
* Shmid.
*
* @var string
*/
public $shmid; public $shmid;
/**
* Two letters country codes.
*
* @var array
*/
public $GEOIP_COUNTRY_CODES = array( public $GEOIP_COUNTRY_CODES = array(
'', '',
'AP', 'AP',
@ -327,6 +367,11 @@ class WC_Geo_IP {
'O1' 'O1'
); );
/**
* 3 letters country codes.
*
* @var array
*/
public $GEOIP_COUNTRY_CODES3 = array( public $GEOIP_COUNTRY_CODES3 = array(
'', '',
'AP', 'AP',
@ -586,6 +631,11 @@ class WC_Geo_IP {
'O1' 'O1'
); );
/**
* Contry names.
*
* @var array
*/
public $GEOIP_COUNTRY_NAMES = array( public $GEOIP_COUNTRY_NAMES = array(
'', '',
'Asia/Pacific Region', 'Asia/Pacific Region',
@ -845,6 +895,11 @@ class WC_Geo_IP {
'Other' 'Other'
); );
/**
* 2 letters continent codes.
*
* @var array
*/
public $GEOIP_CONTINENT_CODES = array( public $GEOIP_CONTINENT_CODES = array(
'--', '--',
'AS', 'AS',
@ -1667,16 +1722,91 @@ class WC_Geo_IP {
* Geo IP Record class. * Geo IP Record class.
*/ */
class WC_Geo_IP_Record { class WC_Geo_IP_Record {
/**
* Country code.
*
* @var string
*/
public $country_code; public $country_code;
/**
* 3 letters country code.
*
* @var string
*/
public $country_code3; public $country_code3;
/**
* Country name.
*
* @var string
*/
public $country_name; public $country_name;
/**
* Region.
*
* @var string
*/
public $region; public $region;
/**
* City.
*
* @var string
*/
public $city; public $city;
/**
* Postal code.
*
* @var string
*/
public $postal_code; public $postal_code;
/**
* Latitude
*
* @var float
*/
public $latitude; public $latitude;
/**
* Longitude.
*
* @var float
*/
public $longitude; public $longitude;
/**
* Area code.
*
* @var string
*/
public $area_code; public $area_code;
public $dma_code; // metro and dma code are the same. use metro_code
/**
* DMA Code.
*
* Metro and DMA code are the same.
* Use metro code instead.
*
* @var int
*/
public $dma_code;
/**
* Metro code.
*
* @var int
*/
public $metro_code; public $metro_code;
/**
* Continent code.
*
* @var string
*/
public $continent_code; public $continent_code;
} }

View File

@ -19,7 +19,7 @@ class WC_HTTPS {
* Hook in our HTTPS functions if we're on the frontend. This will ensure any links output to a page (when viewing via HTTPS) are also served over HTTPS. * Hook in our HTTPS functions if we're on the frontend. This will ensure any links output to a page (when viewing via HTTPS) are also served over HTTPS.
*/ */
public static function init() { public static function init() {
if ( 'yes' == get_option( 'woocommerce_force_ssl_checkout' ) && ! is_admin() ) { if ( 'yes' === get_option( 'woocommerce_force_ssl_checkout' ) && ! is_admin() ) {
// HTTPS urls with SSL on // HTTPS urls with SSL on
$filters = array( $filters = array(
'post_thumbnail_html', 'post_thumbnail_html',
@ -48,7 +48,7 @@ class WC_HTTPS {
} }
/** /**
* force_https_url function. * Force https for urls.
* *
* @param mixed $content * @param mixed $content
* @return string * @return string
@ -72,7 +72,7 @@ class WC_HTTPS {
public static function force_https_page_link( $link, $page_id ) { public static function force_https_page_link( $link, $page_id ) {
if ( in_array( $page_id, array( get_option( 'woocommerce_checkout_page_id' ), get_option( 'woocommerce_myaccount_page_id' ) ) ) ) { if ( in_array( $page_id, array( get_option( 'woocommerce_checkout_page_id' ), get_option( 'woocommerce_myaccount_page_id' ) ) ) ) {
$link = str_replace( 'http:', 'https:', $link ); $link = str_replace( 'http:', 'https:', $link );
} elseif ( 'yes' == get_option( 'woocommerce_unforce_ssl_checkout' ) ) { } elseif ( 'yes' === get_option( 'woocommerce_unforce_ssl_checkout' ) && ! wc_site_is_https() ) {
$link = str_replace( 'https:', 'http:', $link ); $link = str_replace( 'https:', 'http:', $link );
} }
return $link; return $link;
@ -102,7 +102,7 @@ class WC_HTTPS {
return; return;
} }
if ( is_ssl() && $_SERVER['REQUEST_URI'] && ! is_checkout() && ! is_ajax() && ! is_account_page() && apply_filters( 'woocommerce_unforce_ssl_checkout', true ) ) { if ( ! wc_site_is_https() && is_ssl() && $_SERVER['REQUEST_URI'] && ! is_checkout() && ! is_ajax() && ! is_account_page() && apply_filters( 'woocommerce_unforce_ssl_checkout', true ) ) {
if ( 0 === strpos( $_SERVER['REQUEST_URI'], 'http' ) ) { if ( 0 === strpos( $_SERVER['REQUEST_URI'], 'http' ) ) {
wp_safe_redirect( preg_replace( '|^https://|', 'http://', $_SERVER['REQUEST_URI'] ) ); wp_safe_redirect( preg_replace( '|^https://|', 'http://', $_SERVER['REQUEST_URI'] ) );

View File

@ -33,7 +33,7 @@ class WC_Install {
* Hook in tabs. * Hook in tabs.
*/ */
public static function init() { public static function init() {
add_action( 'admin_init', array( __CLASS__, 'check_version' ), 5 ); add_action( 'init', array( __CLASS__, 'check_version' ), 5 );
add_action( 'admin_init', array( __CLASS__, 'install_actions' ) ); add_action( 'admin_init', array( __CLASS__, 'install_actions' ) );
add_action( 'in_plugin_update_message-woocommerce/woocommerce.php', array( __CLASS__, 'in_plugin_update_message' ) ); add_action( 'in_plugin_update_message-woocommerce/woocommerce.php', array( __CLASS__, 'in_plugin_update_message' ) );
add_filter( 'plugin_action_links_' . WC_PLUGIN_BASENAME, array( __CLASS__, 'plugin_action_links' ) ); add_filter( 'plugin_action_links_' . WC_PLUGIN_BASENAME, array( __CLASS__, 'plugin_action_links' ) );
@ -43,17 +43,21 @@ class WC_Install {
} }
/** /**
* check_version function. * Check WooCommerce version and run the updater is required.
*
* This check is done on all requests and runs if he versions do not match.
*/ */
public static function check_version() { public static function check_version() {
if ( ! defined( 'IFRAME_REQUEST' ) && ( get_option( 'woocommerce_version' ) != WC()->version ) ) { if ( ! defined( 'IFRAME_REQUEST' ) && get_option( 'woocommerce_version' ) !== WC()->version ) {
self::install(); self::install();
do_action( 'woocommerce_updated' ); do_action( 'woocommerce_updated' );
} }
} }
/** /**
* Install actions when a update button is clicked. * Install actions when a update button is clicked within the admin area.
*
* This function is hooked into admin_init to affect admin only.
*/ */
public static function install_actions() { public static function install_actions() {
if ( ! empty( $_GET['do_update_woocommerce'] ) ) { if ( ! empty( $_GET['do_update_woocommerce'] ) ) {
@ -356,12 +360,7 @@ class WC_Install {
$collate = ''; $collate = '';
if ( $wpdb->has_cap( 'collation' ) ) { if ( $wpdb->has_cap( 'collation' ) ) {
if ( ! empty( $wpdb->charset ) ) { $collate = $wpdb->get_charset_collate();
$collate .= "DEFAULT CHARACTER SET $wpdb->charset";
}
if ( ! empty( $wpdb->collate ) ) {
$collate .= " COLLATE $wpdb->collate";
}
} }
return " return "

View File

@ -17,7 +17,11 @@ if ( ! defined( 'ABSPATH' ) ) {
*/ */
class WC_Integrations { class WC_Integrations {
/** Array of integration classes */ /**
* Array of integrations.
*
* @var array
*/
public $integrations = array(); public $integrations = array();
/** /**

View File

@ -16,7 +16,9 @@ if ( ! defined( 'ABSPATH' ) ) {
class WC_Logger { class WC_Logger {
/** /**
* @var array Stores open file _handles. * Stores open file _handles.
*
* @var array
* @access private * @access private
*/ */
private $_handles; private $_handles;

View File

@ -18,7 +18,7 @@ if ( ! defined( 'ABSPATH' ) ) {
class WC_Order_Factory { class WC_Order_Factory {
/** /**
* get_order function. * Get order.
* *
* @param bool $the_order (default: false) * @param bool $the_order (default: false)
* @return WC_Order|bool * @return WC_Order|bool

View File

@ -289,7 +289,7 @@ class WC_Order extends WC_Abstract_Order {
* @return string * @return string
*/ */
public function get_remaining_refund_amount() { public function get_remaining_refund_amount() {
return wc_format_decimal( $this->get_total() - $this->get_total_refunded() ); return wc_format_decimal( $this->get_total() - $this->get_total_refunded(), wc_get_price_decimals() );
} }
/** /**

View File

@ -17,6 +17,11 @@ if ( ! defined( 'ABSPATH' ) ) {
*/ */
class WC_Post_Data { class WC_Post_Data {
/**
* Editing term.
*
* @var object
*/
private static $editing_term = null; private static $editing_term = null;
/** /**

View File

@ -18,7 +18,7 @@ if ( ! defined( 'ABSPATH' ) ) {
class WC_Product_External extends WC_Product { class WC_Product_External extends WC_Product {
/** /**
* __construct function. * Constructor.
* *
* @access public * @access public
* @param mixed $product * @param mixed $product
@ -69,7 +69,7 @@ class WC_Product_External extends WC_Product {
} }
/** /**
* get_product_url function. * Get product url.
* *
* @access public * @access public
* @return string * @return string
@ -79,7 +79,7 @@ class WC_Product_External extends WC_Product {
} }
/** /**
* get_button_text function. * Get button text.
* *
* @access public * @access public
* @return string * @return string

View File

@ -18,7 +18,7 @@ if ( ! defined( 'ABSPATH' ) ) {
class WC_Product_Factory { class WC_Product_Factory {
/** /**
* get_product function. * Get product.
* *
* @param bool $the_product (default: false) * @param bool $the_product (default: false)
* @param array $args (default: array()) * @param array $args (default: array())

View File

@ -21,7 +21,7 @@ class WC_Product_Grouped extends WC_Product {
public $children; public $children;
/** /**
* __construct function. * Constructor.
* *
* @access public * @access public
* @param mixed $product * @param mixed $product

View File

@ -148,7 +148,7 @@ class WC_Product_Variable extends WC_Product {
} }
/** /**
* get_child function. * Get child product.
* *
* @access public * @access public
* @param mixed $child_id * @param mixed $child_id
@ -263,73 +263,77 @@ class WC_Product_Variable extends WC_Product {
$price_hash = md5( json_encode( apply_filters( 'woocommerce_get_variation_prices_hash', $price_hash, $this, $display ) ) ); $price_hash = md5( json_encode( apply_filters( 'woocommerce_get_variation_prices_hash', $price_hash, $this, $display ) ) );
// If the value has already been generated, return it now // If the value has already been generated, we don't need to grab the values again.
if ( ! empty( $this->prices_array[ $price_hash ] ) ) {
return $this->prices_array[ $price_hash ];
}
// Get value of transient
$this->prices_array = array_filter( (array) json_decode( strval( get_transient( $transient_name ) ), true ) );
// If the product version has changed, reset cache
if ( empty( $this->prices_array['version'] ) || $this->prices_array['version'] !== WC_Cache_Helper::get_transient_version( 'product' ) ) {
$this->prices_array = array( 'version' => WC_Cache_Helper::get_transient_version( 'product' ) );
}
// If the prices are not stored for this hash, generate them
if ( empty( $this->prices_array[ $price_hash ] ) ) { if ( empty( $this->prices_array[ $price_hash ] ) ) {
$prices = array();
$regular_prices = array();
$sale_prices = array();
$variation_ids = $this->get_children( true );
foreach ( $variation_ids as $variation_id ) { // Get value of transient
if ( $variation = $this->get_child( $variation_id ) ) { $this->prices_array = array_filter( (array) json_decode( strval( get_transient( $transient_name ) ), true ) );
$price = apply_filters( 'woocommerce_variation_prices_price', $variation->price, $variation, $this );
$regular_price = apply_filters( 'woocommerce_variation_prices_regular_price', $variation->regular_price, $variation, $this );
$sale_price = apply_filters( 'woocommerce_variation_prices_sale_price', $variation->sale_price, $variation, $this );
// If sale price does not equal price, the product is not yet on sale // If the product version has changed, reset cache
if ( $sale_price === $regular_price || $sale_price !== $price ) { if ( empty( $this->prices_array['version'] ) || $this->prices_array['version'] !== WC_Cache_Helper::get_transient_version( 'product' ) ) {
$sale_price = $regular_price; $this->prices_array = array( 'version' => WC_Cache_Helper::get_transient_version( 'product' ) );
}
// If we are getting prices for display, we need to account for taxes
if ( $display ) {
if ( 'incl' === get_option( 'woocommerce_tax_display_shop' ) ) {
$price = '' === $price ? '' : $variation->get_price_including_tax( 1, $price );
$regular_price = '' === $regular_price ? '' : $variation->get_price_including_tax( 1, $regular_price );
$sale_price = '' === $sale_price ? '' : $variation->get_price_including_tax( 1, $sale_price );
} else {
$price = '' === $price ? '' : $variation->get_price_excluding_tax( 1, $price );
$regular_price = '' === $regular_price ? '' : $variation->get_price_excluding_tax( 1, $regular_price );
$sale_price = '' === $sale_price ? '' : $variation->get_price_excluding_tax( 1, $sale_price );
}
}
$prices[ $variation_id ] = $price;
$regular_prices[ $variation_id ] = $regular_price;
$sale_prices[ $variation_id ] = $sale_price;
}
} }
asort( $prices ); // If the prices are not stored for this hash, generate them
asort( $regular_prices ); if ( empty( $this->prices_array[ $price_hash ] ) ) {
asort( $sale_prices ); $prices = array();
$regular_prices = array();
$sale_prices = array();
$variation_ids = $this->get_children( true );
$this->prices_array[ $price_hash ] = array( foreach ( $variation_ids as $variation_id ) {
'price' => $prices, if ( $variation = $this->get_child( $variation_id ) ) {
'regular_price' => $regular_prices, $price = apply_filters( 'woocommerce_variation_prices_price', $variation->price, $variation, $this );
'sale_price' => $sale_prices $regular_price = apply_filters( 'woocommerce_variation_prices_regular_price', $variation->regular_price, $variation, $this );
); $sale_price = apply_filters( 'woocommerce_variation_prices_sale_price', $variation->sale_price, $variation, $this );
set_transient( $transient_name, json_encode( $this->prices_array ), DAY_IN_SECONDS * 30 ); // If sale price does not equal price, the product is not yet on sale
if ( $sale_price === $regular_price || $sale_price !== $price ) {
$sale_price = $regular_price;
}
// If we are getting prices for display, we need to account for taxes
if ( $display ) {
if ( 'incl' === get_option( 'woocommerce_tax_display_shop' ) ) {
$price = '' === $price ? '' : $variation->get_price_including_tax( 1, $price );
$regular_price = '' === $regular_price ? '' : $variation->get_price_including_tax( 1, $regular_price );
$sale_price = '' === $sale_price ? '' : $variation->get_price_including_tax( 1, $sale_price );
} else {
$price = '' === $price ? '' : $variation->get_price_excluding_tax( 1, $price );
$regular_price = '' === $regular_price ? '' : $variation->get_price_excluding_tax( 1, $regular_price );
$sale_price = '' === $sale_price ? '' : $variation->get_price_excluding_tax( 1, $sale_price );
}
}
$prices[ $variation_id ] = $price;
$regular_prices[ $variation_id ] = $regular_price;
$sale_prices[ $variation_id ] = $sale_price;
}
}
asort( $prices );
asort( $regular_prices );
asort( $sale_prices );
$this->prices_array[ $price_hash ] = array(
'price' => $prices,
'regular_price' => $regular_prices,
'sale_price' => $sale_prices
);
set_transient( $transient_name, json_encode( $this->prices_array ), DAY_IN_SECONDS * 30 );
}
/**
* Give plugins one last chance to filter the variation prices array which has been generated.
*/
$this->prices_array[ $price_hash ] = apply_filters( 'woocommerce_variation_prices', $this->prices_array[ $price_hash ], $this, $display );
} }
/** /**
* Give plugins one last chance to filter the variation prices array which is being returned. * Return the values.
*/ */
return $this->prices_array[ $price_hash ] = apply_filters( 'woocommerce_variation_prices', $this->prices_array[ $price_hash ], $this, $display ); return $this->prices_array[ $price_hash ];
} }
/** /**

View File

@ -471,7 +471,9 @@ class WC_Product_Variation extends WC_Product {
} }
/** /**
* set_stock_status function. * Set stock status.
*
* @param string $status
*/ */
public function set_stock_status( $status ) { public function set_stock_status( $status ) {
$status = 'outofstock' === $status ? 'outofstock' : 'instock'; $status = 'outofstock' === $status ? 'outofstock' : 'instock';
@ -588,7 +590,7 @@ class WC_Product_Variation extends WC_Product {
} }
/** /**
* is_on_backorder function. * Is on backorder?
* *
* @param int $qty_in_cart (default: 0) * @param int $qty_in_cart (default: 0)
* @return bool * @return bool

View File

@ -144,7 +144,7 @@ class WC_Query {
} }
/** /**
* add_query_vars function. * Add query vars.
* *
* @access public * @access public
* @param array $vars * @param array $vars
@ -212,7 +212,7 @@ class WC_Query {
} }
// Fix for verbose page rules // Fix for verbose page rules
if ( $GLOBALS['wp_rewrite']->use_verbose_page_rules && isset( $q->queried_object->ID ) && $q->queried_object->ID === wc_get_page_id('shop') ) { if ( $GLOBALS['wp_rewrite']->use_verbose_page_rules && isset( $q->queried_object->ID ) && $q->queried_object->ID === wc_get_page_id( 'shop' ) ) {
$q->set( 'post_type', 'product' ); $q->set( 'post_type', 'product' );
$q->set( 'page', '' ); $q->set( 'page', '' );
$q->set( 'pagename', '' ); $q->set( 'pagename', '' );
@ -225,30 +225,30 @@ class WC_Query {
} }
// Fix for endpoints on the homepage // Fix for endpoints on the homepage
if ( $q->is_home() && 'page' == get_option('show_on_front') && get_option('page_on_front') != $q->get('page_id') ) { if ( $q->is_home() && 'page' === get_option( 'show_on_front' ) && absint( get_option( 'page_on_front' ) ) !== absint( $q->get( 'page_id' ) ) ) {
$_query = wp_parse_args( $q->query ); $_query = wp_parse_args( $q->query );
if ( ! empty( $_query ) && array_intersect( array_keys( $_query ), array_keys( $this->query_vars ) ) ) { if ( ! empty( $_query ) && array_intersect( array_keys( $_query ), array_keys( $this->query_vars ) ) ) {
$q->is_page = true; $q->is_page = true;
$q->is_home = false; $q->is_home = false;
$q->is_singular = true; $q->is_singular = true;
$q->set( 'page_id', (int) get_option( 'page_on_front' ) );
$q->set( 'page_id', get_option('page_on_front') ); add_filter( 'redirect_canonical', '__return_false' );
} }
} }
// When orderby is set, WordPress shows posts. Get around that here. // When orderby is set, WordPress shows posts. Get around that here.
if ( $q->is_home() && 'page' == get_option('show_on_front') && get_option('page_on_front') == wc_get_page_id('shop') ) { if ( $q->is_home() && 'page' === get_option( 'show_on_front' ) && absint( get_option( 'page_on_front' ) ) === wc_get_page_id( 'shop' ) ) {
$_query = wp_parse_args( $q->query ); $_query = wp_parse_args( $q->query );
if ( empty( $_query ) || ! array_diff( array_keys( $_query ), array( 'preview', 'page', 'paged', 'cpage', 'orderby' ) ) ) { if ( empty( $_query ) || ! array_diff( array_keys( $_query ), array( 'preview', 'page', 'paged', 'cpage', 'orderby' ) ) ) {
$q->is_page = true; $q->is_page = true;
$q->is_home = false; $q->is_home = false;
$q->set( 'page_id', get_option('page_on_front') ); $q->set( 'page_id', (int) get_option( 'page_on_front' ) );
$q->set( 'post_type', 'product' ); $q->set( 'post_type', 'product' );
} }
} }
// Special check for shops with the product archive on front // Special check for shops with the product archive on front
if ( $q->is_page() && 'page' == get_option( 'show_on_front' ) && $q->get( 'page_id' ) == wc_get_page_id( 'shop' ) ) { if ( $q->is_page() && 'page' === get_option( 'show_on_front' ) && absint( $q->get( 'page_id' ) ) === wc_get_page_id( 'shop' ) ) {
// This is a front-page shop // This is a front-page shop
$q->set( 'post_type', 'product' ); $q->set( 'post_type', 'product' );
@ -308,7 +308,7 @@ class WC_Query {
} }
/** /**
* search_post_excerpt function. * Search post excerpt.
* *
* @access public * @access public
* @param string $where (default: '') * @param string $where (default: '')
@ -329,7 +329,8 @@ class WC_Query {
} }
/** /**
* wpseo_metadesc function. * WP SEO meta description.
*
* Hooked into wpseo_ hook already, so no need for function_exist. * Hooked into wpseo_ hook already, so no need for function_exist.
* *
* @access public * @access public
@ -340,7 +341,8 @@ class WC_Query {
} }
/** /**
* wpseo_metakey function. * WP SEO meta key.
*
* Hooked into wpseo_ hook already, so no need for function_exist. * Hooked into wpseo_ hook already, so no need for function_exist.
* *
* @access public * @access public
@ -487,24 +489,24 @@ class WC_Query {
if ( false === ( $unfiltered_product_ids = get_transient( $transient_name ) ) ) { if ( false === ( $unfiltered_product_ids = get_transient( $transient_name ) ) ) {
// Get all visible posts, regardless of filters // Get all visible posts, regardless of filters
$unfiltered_product_ids = get_posts( $unfiltered_args = array_merge(
array_merge( $current_wp_query,
$current_wp_query, array(
array( 'post_type' => 'product',
'post_type' => 'product', 'numberposts' => -1,
'numberposts' => -1, 'post_status' => 'publish',
'post_status' => 'publish', 'meta_query' => $this->meta_query,
'meta_query' => $this->meta_query, 'fields' => 'ids',
'fields' => 'ids', 'no_found_rows' => true,
'no_found_rows' => true, 'update_post_meta_cache' => false,
'update_post_meta_cache' => false, 'update_post_term_cache' => false,
'update_post_term_cache' => false, 'pagename' => '',
'pagename' => '', 'wc_query' => 'get_products_in_view'
'wc_query' => 'get_products_in_view'
)
) )
); );
$unfiltered_product_ids = apply_filters( 'woocommerce_unfiltered_product_ids', get_posts( $unfiltered_args ), $unfiltered_args );
set_transient( $transient_name, $unfiltered_product_ids, DAY_IN_SECONDS * 30 ); set_transient( $transient_name, $unfiltered_product_ids, DAY_IN_SECONDS * 30 );
} }
@ -605,7 +607,7 @@ class WC_Query {
} }
/** /**
* order_by_rating_post_clauses function. * Order by rating post clauses.
* *
* @access public * @access public
* @param array $args * @param array $args
@ -751,29 +753,29 @@ class WC_Query {
if ( sizeof( $data['terms'] ) > 0 ) { if ( sizeof( $data['terms'] ) > 0 ) {
foreach ( $data['terms'] as $value ) { foreach ( $data['terms'] as $value ) {
$posts = get_posts( $args = array(
array( 'post_type' => 'product',
'post_type' => 'product', 'numberposts' => -1,
'numberposts' => -1, 'post_status' => 'publish',
'post_status' => 'publish', 'fields' => 'ids',
'fields' => 'ids', 'no_found_rows' => true,
'no_found_rows' => true, 'tax_query' => array(
'tax_query' => array( array(
array( 'taxonomy' => $attribute,
'taxonomy' => $attribute, 'terms' => $value,
'terms' => $value, 'field' => 'term_id'
'field' => 'term_id'
)
) )
) )
); );
if ( ! is_wp_error( $posts ) ) { $post_ids = apply_filters( 'woocommerce_layered_nav_query_post_ids', get_posts( $args ), $args, $attribute, $value );
if ( ! is_wp_error( $post_ids ) ) {
if ( sizeof( $matched_products_from_attribute ) > 0 || $filtered ) { if ( sizeof( $matched_products_from_attribute ) > 0 || $filtered ) {
$matched_products_from_attribute = $data['query_type'] == 'or' ? array_merge( $posts, $matched_products_from_attribute ) : array_intersect( $posts, $matched_products_from_attribute ); $matched_products_from_attribute = $data['query_type'] == 'or' ? array_merge( $post_ids, $matched_products_from_attribute ) : array_intersect( $post_ids, $matched_products_from_attribute );
} else { } else {
$matched_products_from_attribute = $posts; $matched_products_from_attribute = $post_ids;
} }
$filtered = true; $filtered = true;

View File

@ -66,7 +66,6 @@ class WC_Session_Handler extends WC_Session {
add_action( 'shutdown', array( $this, 'save_data' ), 20 ); add_action( 'shutdown', array( $this, 'save_data' ), 20 );
add_action( 'wp_logout', array( $this, 'destroy_session' ) ); add_action( 'wp_logout', array( $this, 'destroy_session' ) );
if ( ! is_user_logged_in() ) { if ( ! is_user_logged_in() ) {
add_action( 'woocommerce_thankyou', array( $this, 'destroy_session' ) );
add_filter( 'nonce_user_logged_out', array( $this, 'nonce_user_logged_out' ) ); add_filter( 'nonce_user_logged_out', array( $this, 'nonce_user_logged_out' ) );
} }
} }
@ -141,7 +140,7 @@ class WC_Session_Handler extends WC_Session {
$to_hash = $customer_id . '|' . $session_expiration; $to_hash = $customer_id . '|' . $session_expiration;
$hash = hash_hmac( 'md5', $to_hash, wp_hash( $to_hash ) ); $hash = hash_hmac( 'md5', $to_hash, wp_hash( $to_hash ) );
if ( ! hash_equals( $hash, $cookie_hash ) ) { if ( empty( $cookie_hash ) || ! hash_equals( $hash, $cookie_hash ) ) {
return false; return false;
} }

View File

@ -50,7 +50,7 @@ class WC_Shipping_Rate {
} }
/** /**
* get_shipping_tax function. * Get shipping tax.
* *
* @return array * @return array
*/ */

View File

@ -82,7 +82,7 @@ class WC_Shipping {
} }
/** /**
* init function. * Initialize shipping.
*/ */
public function init() { public function init() {
do_action( 'woocommerce_shipping_init' ); do_action( 'woocommerce_shipping_init' );
@ -91,8 +91,6 @@ class WC_Shipping {
} }
/** /**
* load_shipping_methods function.
*
* Loads all shipping methods which are hooked in. If a $package is passed some methods may add themselves conditionally. * Loads all shipping methods which are hooked in. If a $package is passed some methods may add themselves conditionally.
* *
* Methods are sorted into their user-defined order after being loaded. * Methods are sorted into their user-defined order after being loaded.
@ -189,8 +187,6 @@ class WC_Shipping {
} }
/** /**
* get_shipping_methods function.
*
* Returns all registered shipping methods for usage. * Returns all registered shipping methods for usage.
* *
* @access public * @access public
@ -201,8 +197,6 @@ class WC_Shipping {
} }
/** /**
* get_shipping_classes function.
*
* Load shipping classes taxonomy terms. * Load shipping classes taxonomy terms.
* *
* @access public * @access public
@ -261,8 +255,6 @@ class WC_Shipping {
} }
/** /**
* calculate_shipping function.
*
* Calculate shipping for (multiple) packages of cart items. * Calculate shipping for (multiple) packages of cart items.
* *
* @param array $packages multi-dimensional array of cart items to calc shipping for * @param array $packages multi-dimensional array of cart items to calc shipping for

View File

@ -446,9 +446,9 @@ class WC_Shortcodes {
return ''; return '';
} }
$product = wc_setup_product_data( $product_data ); if ( is_object( $product_data ) ) {
$product = wc_setup_product_data( $product_data );
if ( ! $product ) { } else {
return ''; return '';
} }
@ -494,6 +494,12 @@ class WC_Shortcodes {
return ''; return '';
} }
if ( is_object( $product_data ) ) {
$product = wc_setup_product_data( $product_data );
} else {
return '';
}
if ( 'product' !== $product_data->post_type ) { if ( 'product' !== $product_data->post_type ) {
return ''; return '';
} }

View File

@ -15,7 +15,18 @@ if ( ! defined( 'ABSPATH' ) ) {
*/ */
class WC_Tax { class WC_Tax {
/**
* Precision.
*
* @var int
*/
public static $precision; public static $precision;
/**
* Round at subtotal.
*
* @var bool
*/
public static $round_at_subtotal; public static $round_at_subtotal;
/** /**

View File

@ -84,7 +84,7 @@ class WC_Template_Loader {
} }
/** /**
* comments_template_loader function. * Load comments template.
* *
* @param mixed $template * @param mixed $template
* @return string * @return string

View File

@ -44,6 +44,8 @@ class WC_Email_Cancelled_Order extends WC_Email {
/** /**
* Trigger. * Trigger.
*
* @param int $order_id
*/ */
public function trigger( $order_id ) { public function trigger( $order_id ) {
if ( $order_id ) { if ( $order_id ) {
@ -62,7 +64,7 @@ class WC_Email_Cancelled_Order extends WC_Email {
} }
/** /**
* get_content_html function. * Get content html.
* *
* @access public * @access public
* @return string * @return string

View File

@ -48,6 +48,8 @@ class WC_Email_Customer_Completed_Order extends WC_Email {
/** /**
* Trigger. * Trigger.
*
* @param int $order_id
*/ */
function trigger( $order_id ) { function trigger( $order_id ) {
@ -70,7 +72,7 @@ class WC_Email_Customer_Completed_Order extends WC_Email {
} }
/** /**
* get_subject function. * Get email subject.
* *
* @access public * @access public
* @return string * @return string
@ -84,7 +86,7 @@ class WC_Email_Customer_Completed_Order extends WC_Email {
} }
/** /**
* get_heading function. * Get email heading.
* *
* @access public * @access public
* @return string * @return string
@ -98,7 +100,7 @@ class WC_Email_Customer_Completed_Order extends WC_Email {
} }
/** /**
* get_content_html function. * Get content html.
* *
* @access public * @access public
* @return string * @return string

View File

@ -19,7 +19,18 @@ if ( ! class_exists( 'WC_Email_Customer_Invoice' ) ) :
*/ */
class WC_Email_Customer_Invoice extends WC_Email { class WC_Email_Customer_Invoice extends WC_Email {
/**
* Strings to find in subjects/headings.
*
* @var array
*/
public $find; public $find;
/**
* Strings to replace in subjects/headings.
*
* @var array
*/
public $replace; public $replace;
/** /**
@ -51,6 +62,8 @@ class WC_Email_Customer_Invoice extends WC_Email {
/** /**
* Trigger. * Trigger.
*
* @param int|WC_Order $order
*/ */
function trigger( $order ) { function trigger( $order ) {
@ -77,7 +90,7 @@ class WC_Email_Customer_Invoice extends WC_Email {
} }
/** /**
* get_subject function. * Get email subject.
* *
* @access public * @access public
* @return string * @return string
@ -91,7 +104,7 @@ class WC_Email_Customer_Invoice extends WC_Email {
} }
/** /**
* get_heading function. * Get email heading.
* *
* @access public * @access public
* @return string * @return string
@ -105,7 +118,7 @@ class WC_Email_Customer_Invoice extends WC_Email {
} }
/** /**
* get_content_html function. * Get content html.
* *
* @access public * @access public
* @return string * @return string
@ -121,7 +134,7 @@ class WC_Email_Customer_Invoice extends WC_Email {
} }
/** /**
* get_content_plain function. * Get content plain.
* *
* @access public * @access public
* @return string * @return string

View File

@ -19,9 +19,32 @@ if ( ! class_exists( 'WC_Email_Customer_New_Account' ) ) :
*/ */
class WC_Email_Customer_New_Account extends WC_Email { class WC_Email_Customer_New_Account extends WC_Email {
/**
* User login name.
*
* @var string
*/
public $user_login; public $user_login;
/**
* User email.
*
* @var string
*/
public $user_email; public $user_email;
/**
* User password.
*
* @var string
*/
public $user_pass; public $user_pass;
/**
* Is the password generated?
*
* @var bool
*/
public $password_generated; public $password_generated;
/** /**
@ -46,6 +69,10 @@ class WC_Email_Customer_New_Account extends WC_Email {
/** /**
* Trigger. * Trigger.
*
* @param int $user_id
* @param string $user_pass
* @param bool $password_generated
*/ */
function trigger( $user_id, $user_pass = '', $password_generated = false ) { function trigger( $user_id, $user_pass = '', $password_generated = false ) {
@ -67,7 +94,7 @@ class WC_Email_Customer_New_Account extends WC_Email {
} }
/** /**
* get_content_html function. * Get content html.
* *
* @access public * @access public
* @return string * @return string
@ -86,7 +113,7 @@ class WC_Email_Customer_New_Account extends WC_Email {
} }
/** /**
* get_content_plain function. * Get content plain.
* *
* @access public * @access public
* @return string * @return string

View File

@ -19,6 +19,11 @@ if ( ! class_exists( 'WC_Email_Customer_Note' ) ) :
*/ */
class WC_Email_Customer_Note extends WC_Email { class WC_Email_Customer_Note extends WC_Email {
/**
* Customer note.
*
* @var string
*/
public $customer_note; public $customer_note;
/** /**
@ -46,6 +51,8 @@ class WC_Email_Customer_Note extends WC_Email {
/** /**
* Trigger. * Trigger.
*
* @param array $args
*/ */
function trigger( $args ) { function trigger( $args ) {
@ -82,7 +89,7 @@ class WC_Email_Customer_Note extends WC_Email {
} }
/** /**
* get_content_html function. * Get content html.
* *
* @access public * @access public
* @return string * @return string
@ -99,7 +106,7 @@ class WC_Email_Customer_Note extends WC_Email {
} }
/** /**
* get_content_plain function. * Get content plain.
* *
* @access public * @access public
* @return string * @return string

View File

@ -42,6 +42,8 @@ class WC_Email_Customer_Processing_Order extends WC_Email {
/** /**
* Trigger. * Trigger.
*
* @param int $order_id
*/ */
function trigger( $order_id ) { function trigger( $order_id ) {
@ -64,7 +66,7 @@ class WC_Email_Customer_Processing_Order extends WC_Email {
} }
/** /**
* get_content_html function. * Get content html.
* *
* @access public * @access public
* @return string * @return string
@ -80,7 +82,7 @@ class WC_Email_Customer_Processing_Order extends WC_Email {
} }
/** /**
* get_content_plain function. * Get content plain.
* *
* @access public * @access public
* @return string * @return string

View File

@ -19,7 +19,18 @@ if ( ! class_exists( 'WC_Email_Customer_Refunded_Order' ) ) :
*/ */
class WC_Email_Customer_Refunded_Order extends WC_Email { class WC_Email_Customer_Refunded_Order extends WC_Email {
/**
* Refund order.
*
* @var WC_Order
*/
public $refund; public $refund;
/**
* Is the order partial refunded?
*
* @var bool
*/
public $partial_refund; public $partial_refund;
/** /**
@ -37,6 +48,11 @@ class WC_Email_Customer_Refunded_Order extends WC_Email {
parent::__construct(); parent::__construct();
} }
/**
* Set email strings.
*
* @param bool $partial_refund
*/
public function set_email_strings( $partial_refund = false ) { public function set_email_strings( $partial_refund = false ) {
$this->subject_partial = $this->get_option( 'subject_partial', __( 'Your {site_title} order from {order_date} has been partially refunded', 'woocommerce' ) ); $this->subject_partial = $this->get_option( 'subject_partial', __( 'Your {site_title} order from {order_date} has been partially refunded', 'woocommerce' ) );
$this->subject_full = $this->get_option( 'subject_full', __( 'Your {site_title} order from {order_date} has been refunded', 'woocommerce' ) ); $this->subject_full = $this->get_option( 'subject_full', __( 'Your {site_title} order from {order_date} has been refunded', 'woocommerce' ) );
@ -66,6 +82,9 @@ class WC_Email_Customer_Refunded_Order extends WC_Email {
/** /**
* Full refund notification. * Full refund notification.
*
* @param int $order_id
* @param int $refund_id
*/ */
public function trigger_full( $order_id, $refund_id = null ) { public function trigger_full( $order_id, $refund_id = null ) {
$this->trigger( $order_id, false, $refund_id ); $this->trigger( $order_id, false, $refund_id );
@ -73,6 +92,9 @@ class WC_Email_Customer_Refunded_Order extends WC_Email {
/** /**
* Partial refund notification. * Partial refund notification.
*
* @param int $order_id
* @param int $refund_id
*/ */
public function trigger_partial( $order_id, $refund_id = null ) { public function trigger_partial( $order_id, $refund_id = null ) {
$this->trigger( $order_id, true, $refund_id ); $this->trigger( $order_id, true, $refund_id );
@ -80,6 +102,10 @@ class WC_Email_Customer_Refunded_Order extends WC_Email {
/** /**
* Trigger. * Trigger.
*
* @param int $order_id
* @param bool $partial_refund
* @param int $refund_id
*/ */
public function trigger( $order_id, $partial_refund = false, $refund_id = null ) { public function trigger( $order_id, $partial_refund = false, $refund_id = null ) {
$this->partial_refund = $partial_refund; $this->partial_refund = $partial_refund;
@ -110,7 +136,7 @@ class WC_Email_Customer_Refunded_Order extends WC_Email {
} }
/** /**
* get_subject function. * Get email subject.
* *
* @access public * @access public
* @return string * @return string
@ -120,7 +146,7 @@ class WC_Email_Customer_Refunded_Order extends WC_Email {
} }
/** /**
* get_heading function. * Get email heading.
* *
* @access public * @access public
* @return string * @return string
@ -130,7 +156,7 @@ class WC_Email_Customer_Refunded_Order extends WC_Email {
} }
/** /**
* get_content_html function. * Get content html.
* *
* @access public * @access public
* @return string * @return string

View File

@ -19,13 +19,25 @@ if ( ! class_exists( 'WC_Email_Customer_Reset_Password' ) ) :
*/ */
class WC_Email_Customer_Reset_Password extends WC_Email { class WC_Email_Customer_Reset_Password extends WC_Email {
/** @var string */ /**
* User login name.
*
* @var string
*/
public $user_login; public $user_login;
/** @var string */ /**
* User email.
*
* @var string
*/
public $user_email; public $user_email;
/** @var string */ /**
* Reset key.
*
* @var string
*/
public $reset_key; public $reset_key;
/** /**
@ -53,6 +65,9 @@ class WC_Email_Customer_Reset_Password extends WC_Email {
/** /**
* Trigger. * Trigger.
*
* @param string $user_login
* @param string $reset_key
*/ */
function trigger( $user_login = '', $reset_key = '' ) { function trigger( $user_login = '', $reset_key = '' ) {
if ( $user_login && $reset_key ) { if ( $user_login && $reset_key ) {
@ -73,7 +88,7 @@ class WC_Email_Customer_Reset_Password extends WC_Email {
} }
/** /**
* get_content_html function. * Get content html.
* *
* @access public * @access public
* @return string * @return string
@ -91,7 +106,7 @@ class WC_Email_Customer_Reset_Password extends WC_Email {
} }
/** /**
* get_content_plain function. * Get content plain.
* *
* @access public * @access public
* @return string * @return string

View File

@ -44,6 +44,8 @@ class WC_Email_Failed_Order extends WC_Email {
/** /**
* Trigger. * Trigger.
*
* @param int $order_id
*/ */
public function trigger( $order_id ) { public function trigger( $order_id ) {
if ( $order_id ) { if ( $order_id ) {
@ -62,7 +64,7 @@ class WC_Email_Failed_Order extends WC_Email {
} }
/** /**
* get_content_html function. * Get content html.
* *
* @access public * @access public
* @return string * @return string

View File

@ -48,6 +48,8 @@ class WC_Email_New_Order extends WC_Email {
/** /**
* Trigger. * Trigger.
*
* @param int $order_id
*/ */
public function trigger( $order_id ) { public function trigger( $order_id ) {
if ( $order_id ) { if ( $order_id ) {
@ -66,7 +68,7 @@ class WC_Email_New_Order extends WC_Email {
} }
/** /**
* get_content_html function. * Get content html.
* *
* @access public * @access public
* @return string * @return string
@ -82,7 +84,7 @@ class WC_Email_New_Order extends WC_Email {
} }
/** /**
* get_content_plain function. * Get content plain.
* *
* @access public * @access public
* @return string * @return string

View File

@ -220,7 +220,7 @@ class WC_Email extends WC_Settings_API {
} }
/** /**
* handle_multipart function. * Handle multipart mail.
* *
* @param PHPMailer $mailer * @param PHPMailer $mailer
* @return PHPMailer * @return PHPMailer
@ -234,7 +234,7 @@ class WC_Email extends WC_Settings_API {
} }
/** /**
* format_string function. * Format email string.
* *
* @param mixed $string * @param mixed $string
* @return string * @return string
@ -244,7 +244,7 @@ class WC_Email extends WC_Settings_API {
} }
/** /**
* get_subject function. * Get email subject.
* *
* @return string * @return string
*/ */
@ -253,7 +253,7 @@ class WC_Email extends WC_Settings_API {
} }
/** /**
* get_heading function. * Get email heading.
* *
* @return string * @return string
*/ */
@ -273,7 +273,7 @@ class WC_Email extends WC_Settings_API {
} }
/** /**
* get_headers function. * Get email headers.
* *
* @return string * @return string
*/ */
@ -282,7 +282,7 @@ class WC_Email extends WC_Settings_API {
} }
/** /**
* get_attachments function. * Get email attachments.
* *
* @return string|array * @return string|array
*/ */
@ -300,7 +300,7 @@ class WC_Email extends WC_Settings_API {
} }
/** /**
* get_content_type function. * Get email content type.
* *
* @return string * @return string
*/ */
@ -368,7 +368,7 @@ class WC_Email extends WC_Settings_API {
} }
/** /**
* get_blogname function. * Get WordPress blog name.
* *
* @return string * @return string
*/ */
@ -377,7 +377,7 @@ class WC_Email extends WC_Settings_API {
} }
/** /**
* get_content function. * Get email content.
* *
* @return string * @return string
*/ */

View File

@ -105,7 +105,9 @@ class WC_Gateway_BACS extends WC_Payment_Gateway {
} }
/** /**
* generate_account_details_html function. * Generate account details html.
*
* @return string
*/ */
public function generate_account_details_html() { public function generate_account_details_html() {
@ -224,6 +226,8 @@ class WC_Gateway_BACS extends WC_Payment_Gateway {
/** /**
* Output for the order received page. * Output for the order received page.
*
* @param int $order_id
*/ */
public function thankyou_page( $order_id ) { public function thankyou_page( $order_id ) {
@ -254,6 +258,8 @@ class WC_Gateway_BACS extends WC_Payment_Gateway {
/** /**
* Get bank details and place into a list format. * Get bank details and place into a list format.
*
* @param int $order_id
*/ */
private function bank_details( $order_id = '' ) { private function bank_details( $order_id = '' ) {
@ -350,7 +356,6 @@ class WC_Gateway_BACS extends WC_Payment_Gateway {
* *
* @return array * @return array
*/ */
public function get_country_locale() { public function get_country_locale() {
if ( ! $this->locale ) { if ( ! $this->locale ) {

View File

@ -20,7 +20,7 @@ if ( ! defined( 'ABSPATH' ) ) {
*/ */
class WC_Gateway_Paypal extends WC_Payment_Gateway { class WC_Gateway_Paypal extends WC_Payment_Gateway {
/** @var boolean Whether or not logging is enabled */ /** @var bool Whether or not logging is enabled */
public static $log_enabled = false; public static $log_enabled = false;
/** @var WC_Logger Logger instance */ /** @var WC_Logger Logger instance */
@ -84,7 +84,7 @@ class WC_Gateway_Paypal extends WC_Payment_Gateway {
} }
/** /**
* get_icon function. * Get gateway icon.
* @return string * @return string
*/ */
public function get_icon() { public function get_icon() {
@ -106,13 +106,17 @@ class WC_Gateway_Paypal extends WC_Payment_Gateway {
* @return string * @return string
*/ */
protected function get_icon_url( $country ) { protected function get_icon_url( $country ) {
$countries = array( 'DZ', 'AU', 'BH', 'BE', 'BQ', 'BW', 'CA', 'CN', 'CW', 'CZ', 'DK', 'FI', 'FR', 'DE', 'GR', 'HK', 'HU', 'IN', 'ID', 'IT', 'JO', 'KE', 'KW', 'LU', 'MY', 'MA', 'NL', 'NO', 'OM', 'PH', 'PL', 'PT', 'QA', 'IE', 'RU', 'BL', 'SX', 'MF', 'SA', 'SG', 'SK', 'KR', 'SS', 'ES', 'SE', 'TW', 'TH', 'TR', 'AE', 'GB', 'US', 'VN' ); $url = 'https://www.paypal.com/' . strtolower( $country );
$home_counties = array( 'BE', 'CZ', 'DK', 'HU', 'IT', 'JP', 'NL', 'NO', 'ES', 'SE', 'TR');
$countries = array( 'DZ', 'AU', 'BH', 'BQ', 'BW', 'CA', 'CN', 'CW', 'FI', 'FR', 'DE', 'GR', 'HK', 'IN', 'ID', 'JO', 'KE', 'KW', 'LU', 'MY', 'MA', 'OM', 'PH', 'PL', 'PT', 'QA', 'IE', 'RU', 'BL', 'SX', 'MF', 'SA', 'SG', 'SK', 'KR', 'SS', 'TW', 'TH', 'AE', 'GB', 'US', 'VN' );
if ( in_array( $country, $countries ) ) { if ( in_array( $country, $home_counties ) ) {
return 'https://www.paypal.com/' . strtolower( $country ) . '/webapps/mpp/paypal-popup'; return $url . '/webapps/mpp/home';
} else if ( in_array( $country, $countries ) ) {
return $url . '/webapps/mpp/paypal-popup';
} else {
return $url . '/cgi-bin/webscr?cmd=xpt/Marketing/general/WIPaypal-outside';
} }
return 'https://www.paypal.com/' . strtolower( $country ) . '/cgi-bin/webscr?cmd=xpt/Marketing/general/WIPaypal-outside';
} }
/** /**
@ -257,7 +261,7 @@ class WC_Gateway_Paypal extends WC_Payment_Gateway {
* @param int $order_id * @param int $order_id
* @param float $amount * @param float $amount
* @param string $reason * @param string $reason
* @return boolean True or false based on success, or a WP_Error object * @return bool True or false based on success, or a WP_Error object
*/ */
public function process_refund( $order_id, $amount = null, $reason = '' ) { public function process_refund( $order_id, $amount = null, $reason = '' ) {
$order = wc_get_order( $order_id ); $order = wc_get_order( $order_id );

View File

@ -16,6 +16,9 @@ class WC_Gateway_Paypal_IPN_Handler extends WC_Gateway_Paypal_Response {
/** /**
* Constructor. * Constructor.
*
* @param bool $sandbox
* @param string $receiver_email
*/ */
public function __construct( $sandbox = false, $receiver_email = '' ) { public function __construct( $sandbox = false, $receiver_email = '' ) {
add_action( 'woocommerce_api_wc_gateway_paypal', array( $this, 'check_response' ) ); add_action( 'woocommerce_api_wc_gateway_paypal', array( $this, 'check_response' ) );
@ -135,6 +138,7 @@ class WC_Gateway_Paypal_IPN_Handler extends WC_Gateway_Paypal_Response {
/** /**
* Check payment amount from IPN matches the order. * Check payment amount from IPN matches the order.
* @param WC_Order $order * @param WC_Order $order
* @param int $amount
*/ */
protected function validate_amount( $order, $amount ) { protected function validate_amount( $order, $amount ) {
if ( number_format( $order->get_total(), 2, '.', '' ) != number_format( $amount, 2, '.', '' ) ) { if ( number_format( $order->get_total(), 2, '.', '' ) != number_format( $amount, 2, '.', '' ) ) {
@ -150,6 +154,7 @@ class WC_Gateway_Paypal_IPN_Handler extends WC_Gateway_Paypal_Response {
* Check receiver email from PayPal. If the receiver email in the IPN is different than what is stored in. * Check receiver email from PayPal. If the receiver email in the IPN is different than what is stored in.
* WooCommerce -> Settings -> Checkout -> PayPal, it will log an error about it. * WooCommerce -> Settings -> Checkout -> PayPal, it will log an error about it.
* @param WC_Order $order * @param WC_Order $order
* @param string $receiver_email
*/ */
protected function validate_receiver_email( $order, $receiver_email ) { protected function validate_receiver_email( $order, $receiver_email ) {
if ( strcasecmp( trim( $receiver_email ), trim( $this->receiver_email ) ) != 0 ) { if ( strcasecmp( trim( $receiver_email ), trim( $this->receiver_email ) ) != 0 ) {
@ -164,6 +169,7 @@ class WC_Gateway_Paypal_IPN_Handler extends WC_Gateway_Paypal_Response {
/** /**
* Handle a completed payment. * Handle a completed payment.
* @param WC_Order $order * @param WC_Order $order
* @param array $posted
*/ */
protected function payment_status_completed( $order, $posted ) { protected function payment_status_completed( $order, $posted ) {
if ( $order->has_status( 'completed' ) ) { if ( $order->has_status( 'completed' ) ) {
@ -193,6 +199,7 @@ class WC_Gateway_Paypal_IPN_Handler extends WC_Gateway_Paypal_Response {
/** /**
* Handle a pending payment. * Handle a pending payment.
* @param WC_Order $order * @param WC_Order $order
* @param array $posted
*/ */
protected function payment_status_pending( $order, $posted ) { protected function payment_status_pending( $order, $posted ) {
$this->payment_status_completed( $order, $posted ); $this->payment_status_completed( $order, $posted );
@ -201,6 +208,7 @@ class WC_Gateway_Paypal_IPN_Handler extends WC_Gateway_Paypal_Response {
/** /**
* Handle a failed payment. * Handle a failed payment.
* @param WC_Order $order * @param WC_Order $order
* @param array $posted
*/ */
protected function payment_status_failed( $order, $posted ) { protected function payment_status_failed( $order, $posted ) {
$order->update_status( 'failed', sprintf( __( 'Payment %s via IPN.', 'woocommerce' ), wc_clean( $posted['payment_status'] ) ) ); $order->update_status( 'failed', sprintf( __( 'Payment %s via IPN.', 'woocommerce' ), wc_clean( $posted['payment_status'] ) ) );
@ -209,6 +217,7 @@ class WC_Gateway_Paypal_IPN_Handler extends WC_Gateway_Paypal_Response {
/** /**
* Handle a denied payment. * Handle a denied payment.
* @param WC_Order $order * @param WC_Order $order
* @param array $posted
*/ */
protected function payment_status_denied( $order, $posted ) { protected function payment_status_denied( $order, $posted ) {
$this->payment_status_failed( $order, $posted ); $this->payment_status_failed( $order, $posted );
@ -217,6 +226,7 @@ class WC_Gateway_Paypal_IPN_Handler extends WC_Gateway_Paypal_Response {
/** /**
* Handle an expired payment. * Handle an expired payment.
* @param WC_Order $order * @param WC_Order $order
* @param array $posted
*/ */
protected function payment_status_expired( $order, $posted ) { protected function payment_status_expired( $order, $posted ) {
$this->payment_status_failed( $order, $posted ); $this->payment_status_failed( $order, $posted );
@ -225,6 +235,7 @@ class WC_Gateway_Paypal_IPN_Handler extends WC_Gateway_Paypal_Response {
/** /**
* Handle a voided payment. * Handle a voided payment.
* @param WC_Order $order * @param WC_Order $order
* @param array $posted
*/ */
protected function payment_status_voided( $order, $posted ) { protected function payment_status_voided( $order, $posted ) {
$this->payment_status_failed( $order, $posted ); $this->payment_status_failed( $order, $posted );
@ -233,6 +244,7 @@ class WC_Gateway_Paypal_IPN_Handler extends WC_Gateway_Paypal_Response {
/** /**
* Handle a refunded order. * Handle a refunded order.
* @param WC_Order $order * @param WC_Order $order
* @param array $posted
*/ */
protected function payment_status_refunded( $order, $posted ) { protected function payment_status_refunded( $order, $posted ) {
// Only handle full refunds, not partial. // Only handle full refunds, not partial.
@ -251,6 +263,7 @@ class WC_Gateway_Paypal_IPN_Handler extends WC_Gateway_Paypal_Response {
/** /**
* Handle a reveral. * Handle a reveral.
* @param WC_Order $order * @param WC_Order $order
* @param array $posted
*/ */
protected function payment_status_reversed( $order, $posted ) { protected function payment_status_reversed( $order, $posted ) {
$order->update_status( 'on-hold', sprintf( __( 'Payment %s via IPN.', 'woocommerce' ), wc_clean( $posted['payment_status'] ) ) ); $order->update_status( 'on-hold', sprintf( __( 'Payment %s via IPN.', 'woocommerce' ), wc_clean( $posted['payment_status'] ) ) );
@ -264,6 +277,7 @@ class WC_Gateway_Paypal_IPN_Handler extends WC_Gateway_Paypal_Response {
/** /**
* Handle a cancelled reveral. * Handle a cancelled reveral.
* @param WC_Order $order * @param WC_Order $order
* @param array $posted
*/ */
protected function payment_status_canceled_reversal( $order, $posted ) { protected function payment_status_canceled_reversal( $order, $posted ) {
$this->send_ipn_email_notification( $this->send_ipn_email_notification(
@ -275,6 +289,7 @@ class WC_Gateway_Paypal_IPN_Handler extends WC_Gateway_Paypal_Response {
/** /**
* Save important data from the IPN to the order. * Save important data from the IPN to the order.
* @param WC_Order $order * @param WC_Order $order
* @param array $posted
*/ */
protected function save_paypal_meta_data( $order, $posted ) { protected function save_paypal_meta_data( $order, $posted ) {
if ( ! empty( $posted['payer_email'] ) ) { if ( ! empty( $posted['payer_email'] ) ) {
@ -301,6 +316,6 @@ class WC_Gateway_Paypal_IPN_Handler extends WC_Gateway_Paypal_Response {
$mailer = WC()->mailer(); $mailer = WC()->mailer();
$message = $mailer->wrap_message( $subject, $message ); $message = $mailer->wrap_message( $subject, $message );
$mailer->send( ! empty( $new_order_settings['recipient'] ) ? $new_order_settings['recipient'] : get_option( 'admin_email' ), $subject, $message ); $mailer->send( ! empty( $new_order_settings['recipient'] ) ? $new_order_settings['recipient'] : get_option( 'admin_email' ), strip_tags( $subject ), $message );
} }
} }

View File

@ -16,6 +16,9 @@ class WC_Gateway_Paypal_PDT_Handler extends WC_Gateway_Paypal_Response {
/** /**
* Constructor. * Constructor.
*
* @param bool $sandbox
* @param string $identity_token
*/ */
public function __construct( $sandbox = false, $identity_token = '' ) { public function __construct( $sandbox = false, $identity_token = '' ) {
add_action( 'woocommerce_thankyou_paypal', array( $this, 'check_response' ) ); add_action( 'woocommerce_thankyou_paypal', array( $this, 'check_response' ) );

View File

@ -49,7 +49,7 @@ class WC_Gateway_Paypal_Refund {
* @param WC_Order $order * @param WC_Order $order
* @param float $amount * @param float $amount
* @param string $reason * @param string $reason
* @param boolean $sandbox * @param bool $sandbox
* @return array|wp_error The parsed response from paypal, or a WP_Error object * @return array|wp_error The parsed response from paypal, or a WP_Error object
*/ */
public static function refund_order( $order, $amount = null, $reason = '', $sandbox = false ) { public static function refund_order( $order, $amount = null, $reason = '', $sandbox = false ) {

View File

@ -39,7 +39,7 @@ class WC_Gateway_Paypal_Request {
/** /**
* Get the PayPal request URL for an order. * Get the PayPal request URL for an order.
* @param WC_Order $order * @param WC_Order $order
* @param boolean $sandbox * @param bool $sandbox
* @return string * @return string
*/ */
public function get_request_url( $order, $sandbox = false ) { public function get_request_url( $order, $sandbox = false ) {
@ -276,8 +276,8 @@ class WC_Gateway_Paypal_Request {
/** /**
* Add PayPal Line Item. * Add PayPal Line Item.
* @param string $item_name * @param string $item_name
* @param integer $quantity * @param int $quantity
* @param integer $amount * @param int $amount
* @param string $item_number * @param string $item_number
* @return bool successfully added or not * @return bool successfully added or not
*/ */

View File

@ -276,7 +276,7 @@ class WC_Addons_Gateway_Simplify_Commerce extends WC_Gateway_Simplify_Commerce {
* process_subscription_payment function. * process_subscription_payment function.
* *
* @param WC_order $order * @param WC_order $order
* @param integer $amount (default: 0) * @param int $amount (default: 0)
* @uses Simplify_BadRequestException * @uses Simplify_BadRequestException
* @return bool|WP_Error * @return bool|WP_Error
*/ */
@ -420,7 +420,7 @@ class WC_Addons_Gateway_Simplify_Commerce extends WC_Gateway_Simplify_Commerce {
* Process a pre-order payment when the pre-order is released. * Process a pre-order payment when the pre-order is released.
* *
* @param WC_Order $order * @param WC_Order $order
* @return wp_error|null * @return WP_Error|null
*/ */
public function process_pre_order_release_payment( $order ) { public function process_pre_order_release_payment( $order ) {

View File

@ -158,6 +158,8 @@ class WC_Gateway_Simplify_Commerce extends WC_Payment_Gateway {
/** /**
* Check if this gateway is enabled. * Check if this gateway is enabled.
*
* @return bool
*/ */
public function is_available() { public function is_available() {
if ( 'yes' !== $this->enabled ) { if ( 'yes' !== $this->enabled ) {
@ -277,8 +279,6 @@ class WC_Gateway_Simplify_Commerce extends WC_Payment_Gateway {
} }
/** /**
* payment_scripts function.
*
* Outputs scripts used for simplify payment. * Outputs scripts used for simplify payment.
*/ */
public function payment_scripts() { public function payment_scripts() {
@ -377,7 +377,7 @@ class WC_Gateway_Simplify_Commerce extends WC_Payment_Gateway {
/** /**
* Process the payment. * Process the payment.
* *
* @param integer $order_id * @param int $order_id
*/ */
public function process_payment( $order_id ) { public function process_payment( $order_id ) {
$cart_token = isset( $_POST['simplify_token'] ) ? wc_clean( $_POST['simplify_token'] ) : ''; $cart_token = isset( $_POST['simplify_token'] ) ? wc_clean( $_POST['simplify_token'] ) : '';
@ -535,7 +535,7 @@ class WC_Gateway_Simplify_Commerce extends WC_Payment_Gateway {
} }
/** /**
* get_icon function. * Get gateway icon.
* *
* @access public * @access public
* @return string * @return string

View File

@ -13,7 +13,11 @@ if ( ! defined( 'ABSPATH' ) ) {
*/ */
class WC_Shipping_Flat_Rate extends WC_Shipping_Method { class WC_Shipping_Flat_Rate extends WC_Shipping_Method {
/** @var string cost passed to [fee] shortcode */ /**
* Cost passed to [fee] shortcode.
*
* @var string
*/
protected $fee_cost = ''; protected $fee_cost = '';
/** /**
@ -30,7 +34,7 @@ class WC_Shipping_Flat_Rate extends WC_Shipping_Method {
} }
/** /**
* init function. * Initialize flat rate shipping.
*/ */
public function init() { public function init() {
// Load the settings. // Load the settings.
@ -48,7 +52,7 @@ class WC_Shipping_Flat_Rate extends WC_Shipping_Method {
} }
/** /**
* Initialise Settings Form Fields. * Initialize Settings Form Fields.
*/ */
public function init_form_fields() { public function init_form_fields() {
$this->form_fields = include( 'includes/settings-flat-rate.php' ); $this->form_fields = include( 'includes/settings-flat-rate.php' );
@ -63,9 +67,10 @@ class WC_Shipping_Flat_Rate extends WC_Shipping_Method {
protected function evaluate_cost( $sum, $args = array() ) { protected function evaluate_cost( $sum, $args = array() ) {
include_once( 'includes/class-wc-eval-math.php' ); include_once( 'includes/class-wc-eval-math.php' );
$locale = localeconv(); // Allow 3rd parties to process shipping cost arguments
$decimals = array( wc_get_price_decimal_separator(), $locale['decimal_point'], $locale['mon_decimal_point'] ); $args = apply_filters( 'woocommerce_evaluate_shipping_cost_args', $args, $sum, $this );
$locale = localeconv();
$decimals = array( wc_get_price_decimal_separator(), $locale['decimal_point'], $locale['mon_decimal_point'] );
$this->fee_cost = $args['cost']; $this->fee_cost = $args['cost'];
// Expand shortcodes // Expand shortcodes

View File

@ -9,20 +9,41 @@ if ( ! defined( 'ABSPATH' ) ) {
* Based on EvalMath by Miles Kaufman Copyright (C) 2005 Miles Kaufmann http://www.twmagic.com/. * Based on EvalMath by Miles Kaufman Copyright (C) 2005 Miles Kaufmann http://www.twmagic.com/.
*/ */
class WC_Eval_Math { class WC_Eval_Math {
/** @var string */
/**
* Last error.
*
* @var string
*/
public static $last_error = null; public static $last_error = null;
/** @var array */ /**
public static $v = array( 'e' => 2.71, 'pi' => 3.14 ); // variables (and constants) * Variables (and constants).
*
* @var array
*/
public static $v = array( 'e' => 2.71, 'pi' => 3.14 );
/** @var array */ /**
public static $f = array(); // user-defined functions * User-defined functions.
*
* @var array
*/
public static $f = array();
/** @var array */ /**
public static $vb = array( 'e', 'pi' ); // constants * Constants.
*
* @var array
*/
public static $vb = array( 'e', 'pi' );
/** @var array */ /**
public static $fb = array(); // built-in functions * Built-in functions.
*
* @var array
*/
public static $fb = array();
/** /**
* Evaluate maths string. * Evaluate maths string.
@ -201,7 +222,14 @@ class WC_Eval_Math {
return $output; return $output;
} }
// evaluate postfix notation /**
* Evaluate postfix notation.
*
* @param mixed $tokens
* @param array $vars
*
* @return mixed
*/
private static function pfx( $tokens, $vars = array() ) { private static function pfx( $tokens, $vars = array() ) {
if ( $tokens == false ) return false; if ( $tokens == false ) return false;
@ -246,7 +274,13 @@ class WC_Eval_Math {
return $stack->pop(); return $stack->pop();
} }
// trigger an error, but nicely, if need be /**
* Trigger an error, but nicely, if need be.
*
* @param string $msg
*
* @return bool
*/
private static function trigger( $msg ) { private static function trigger( $msg ) {
self::$last_error = $msg; self::$last_error = $msg;
if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) { if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) {
@ -257,10 +291,12 @@ class WC_Eval_Math {
return false; return false;
} }
// Prints the file name, function name, and /**
// line number which called your function * Prints the file name, function name, and
// (not this function, then one that called * line number which called your function
// it to begin with) * (not this function, then one that called
* it to begin with)
*/
private static function debugPrintCallingFunction() { private static function debugPrintCallingFunction() {
$file = 'n/a'; $file = 'n/a';
$func = 'n/a'; $func = 'n/a';
@ -280,17 +316,35 @@ class WC_Eval_Math {
*/ */
class WC_Eval_Math_Stack { class WC_Eval_Math_Stack {
/** @var array */ /**
* Stack array.
*
* @var array
*/
public $stack = array(); public $stack = array();
/** @var integer */ /**
* Stack counter.
*
* @var integer
*/
public $count = 0; public $count = 0;
/**
* Push value into stack.
*
* @param mixed $val
*/
public function push( $val ) { public function push( $val ) {
$this->stack[ $this->count ] = $val; $this->stack[ $this->count ] = $val;
$this->count++; $this->count++;
} }
/**
* Pop value from stack.
*
* @return mixed
*/
public function pop() { public function pop() {
if ( $this->count > 0 ) { if ( $this->count > 0 ) {
$this->count--; $this->count--;
@ -299,7 +353,14 @@ class WC_Eval_Math_Stack {
return null; return null;
} }
public function last( $n=1 ) { /**
* Get last value from stack.
*
* @param int $n
*
* @return mixed
*/
public function last( $n = 1 ) {
$key = $this->count - $n; $key = $this->count - $n;
return array_key_exists( $key, $this->stack ) ? $this->stack[ $key ] : null; return array_key_exists( $key, $this->stack ) ? $this->stack[ $key ] : null;
} }

View File

@ -16,10 +16,18 @@ if ( ! defined( 'ABSPATH' ) ) {
*/ */
class WC_Shipping_Free_Shipping extends WC_Shipping_Method { class WC_Shipping_Free_Shipping extends WC_Shipping_Method {
/** @var float Min amount to be valid */ /**
* Min amount to be valid.
*
* @var float
*/
public $min_amount; public $min_amount;
/** @var string Requires option */ /**
* Requires option.
*
* @var string
*/
public $requires; public $requires;
/** /**
@ -32,7 +40,7 @@ class WC_Shipping_Free_Shipping extends WC_Shipping_Method {
} }
/** /**
* init function. * Initialize free shipping.
*/ */
public function init() { public function init() {
@ -53,7 +61,7 @@ class WC_Shipping_Free_Shipping extends WC_Shipping_Method {
} }
/** /**
* Initialise Gateway Settings Form Fields. * Initialize Gateway Settings Form Fields.
*/ */
public function init_form_fields() { public function init_form_fields() {
$this->form_fields = array( $this->form_fields = array(
@ -116,7 +124,8 @@ class WC_Shipping_Free_Shipping extends WC_Shipping_Method {
} }
/** /**
* is_available function. * Check if free shipping is available.
*
* @param array $package * @param array $package
* @return bool * @return bool
*/ */
@ -193,7 +202,8 @@ class WC_Shipping_Free_Shipping extends WC_Shipping_Method {
} }
/** /**
* calculate_shipping function. * Calculate free shipping.
*
* @return array * @return array
*/ */
public function calculate_shipping() { public function calculate_shipping() {

View File

@ -26,7 +26,7 @@ class WC_Shipping_International_Delivery extends WC_Shipping_Flat_Rate {
} }
/** /**
* Initialise settings form fields. * Initialize settings form fields.
*/ */
public function init_form_fields() { public function init_form_fields() {
parent::init_form_fields(); parent::init_form_fields();
@ -44,7 +44,7 @@ class WC_Shipping_International_Delivery extends WC_Shipping_Flat_Rate {
} }
/** /**
* is_available function. * Check if international delivery is available.
* *
* @param array $package * @param array $package
* @return bool * @return bool

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