2011-08-09 15:16:18 +00:00
< ? php
2015-11-06 09:22:19 +00:00
if ( ! defined ( 'ABSPATH' ) ) {
exit ; // Exit if accessed directly
}
2011-08-09 15:16:18 +00:00
/**
2015-11-03 13:53:50 +00:00
* Checkout
2012-08-10 11:15:32 +00:00
*
2011-08-10 17:11:11 +00:00
* The WooCommerce checkout class handles the checkout process , collecting user data and processing the payment .
2011-08-09 15:16:18 +00:00
*
2015-04-27 19:57:16 +00:00
* @ class WC_Checkout
2013-09-12 13:41:02 +00:00
* @ version 2.1 . 0
2012-08-14 22:43:48 +00:00
* @ package WooCommerce / Classes
2014-12-12 21:18:16 +00:00
* @ category Class
2012-08-14 19:42:38 +00:00
* @ author WooThemes
2011-08-09 15:16:18 +00:00
*/
2012-01-27 16:38:39 +00:00
class WC_Checkout {
2012-08-10 11:15:32 +00:00
2012-08-15 17:08:42 +00:00
/** @var array Array of posted form data. */
2012-12-14 21:27:29 +00:00
public $posted ;
2012-08-14 19:42:38 +00:00
2012-08-15 17:08:42 +00:00
/** @var array Array of fields to display on the checkout. */
2012-12-14 21:27:29 +00:00
public $checkout_fields ;
2012-08-14 19:42:38 +00:00
2012-08-15 17:08:42 +00:00
/** @var bool Whether or not the user must create an account to checkout. */
2012-12-14 21:27:29 +00:00
public $must_create_account ;
2012-08-14 19:42:38 +00:00
2012-12-10 12:34:55 +00:00
/** @var bool Whether or not signups are allowed. */
2012-12-14 21:27:29 +00:00
public $enable_signup ;
2012-12-10 12:34:55 +00:00
2012-12-27 19:24:33 +00:00
/** @var object The shipping method being used. */
private $shipping_method ;
2015-02-03 15:27:40 +00:00
/** @var WC_Payment_Gateway|string The payment gateway being used. */
2012-12-27 19:24:33 +00:00
private $payment_method ;
2013-02-15 21:18:46 +00:00
/** @var int ID of customer. */
private $customer_id ;
2015-02-03 15:27:40 +00:00
/** @var array Where shipping_methods are stored. */
public $shipping_methods ;
2013-09-12 13:41:02 +00:00
/**
2014-06-19 19:43:05 +00:00
* @ var WC_Checkout The single instance of the class
2013-09-12 13:41:02 +00:00
* @ since 2.1
*/
protected static $_instance = null ;
2015-02-03 15:27:40 +00:00
/** @var Bool */
public $enable_guest_checkout ;
2013-09-12 13:41:02 +00:00
/**
2015-11-03 13:31:20 +00:00
* Main WC_Checkout Instance .
2013-09-12 13:41:02 +00:00
*
2014-06-19 19:43:05 +00:00
* Ensures only one instance of WC_Checkout is loaded or can be loaded .
2013-09-12 13:41:02 +00:00
*
* @ since 2.1
* @ static
2014-06-19 19:43:05 +00:00
* @ return WC_Checkout Main instance
2013-09-12 13:41:02 +00:00
*/
public static function instance () {
if ( is_null ( self :: $_instance ) )
self :: $_instance = new self ();
return self :: $_instance ;
}
/**
* Cloning is forbidden .
*
* @ since 2.1
*/
public function __clone () {
2014-02-17 13:14:41 +00:00
_doing_it_wrong ( __FUNCTION__ , __ ( 'Cheatin’ huh?' , 'woocommerce' ), '2.1' );
2013-09-12 13:41:02 +00:00
}
/**
* Unserializing instances of this class is forbidden .
*
* @ since 2.1
*/
public function __wakeup () {
2014-02-17 13:14:41 +00:00
_doing_it_wrong ( __FUNCTION__ , __ ( 'Cheatin’ huh?' , 'woocommerce' ), '2.1' );
2013-09-12 13:41:02 +00:00
}
2012-08-14 19:42:38 +00:00
/**
2013-03-03 17:07:31 +00:00
* Constructor for the checkout class . Hooks in methods and defines checkout fields .
2012-08-14 19:42:38 +00:00
*
* @ access public
*/
2016-08-27 04:06:25 +00:00
public function __construct () {
2016-08-27 02:14:16 +00:00
add_action ( 'woocommerce_checkout_billing' , array ( $this , 'checkout_form_billing' ) );
add_action ( 'woocommerce_checkout_shipping' , array ( $this , 'checkout_form_shipping' ) );
2012-08-10 11:15:32 +00:00
2012-12-10 12:34:55 +00:00
$this -> enable_signup = get_option ( 'woocommerce_enable_signup_and_login_from_checkout' ) == 'yes' ? true : false ;
$this -> enable_guest_checkout = get_option ( 'woocommerce_enable_guest_checkout' ) == 'yes' ? true : false ;
$this -> must_create_account = $this -> enable_guest_checkout || is_user_logged_in () ? false : true ;
2011-12-21 16:03:45 +00:00
// Define all Checkout fields
2014-09-22 12:23:28 +00:00
$this -> checkout_fields [ 'billing' ] = WC () -> countries -> get_address_fields ( $this -> get_value ( 'billing_country' ), 'billing_' );
$this -> checkout_fields [ 'shipping' ] = WC () -> countries -> get_address_fields ( $this -> get_value ( 'shipping_country' ), 'shipping_' );
2012-08-10 11:15:32 +00:00
2013-06-03 15:09:04 +00:00
if ( get_option ( 'woocommerce_registration_generate_username' ) == 'no' ) {
2012-08-10 11:15:32 +00:00
$this -> checkout_fields [ 'account' ][ 'account_username' ] = array (
'type' => 'text' ,
'label' => __ ( 'Account username' , 'woocommerce' ),
2013-07-19 05:58:45 +00:00
'required' => true ,
2016-10-24 07:31:07 +00:00
'placeholder' => esc_attr__ ( 'Username' , 'woocommerce' ),
2011-12-21 16:03:45 +00:00
);
2012-08-10 11:15:32 +00:00
}
2013-06-03 15:09:04 +00:00
if ( get_option ( 'woocommerce_registration_generate_password' ) == 'no' ) {
$this -> checkout_fields [ 'account' ][ 'account_password' ] = array (
'type' => 'password' ,
'label' => __ ( 'Account password' , 'woocommerce' ),
2013-07-19 05:58:45 +00:00
'required' => true ,
2016-10-24 07:31:07 +00:00
'placeholder' => esc_attr__ ( 'Password' , 'woocommerce' ),
2013-06-03 15:09:04 +00:00
);
}
2012-08-10 11:15:32 +00:00
2011-12-21 16:03:45 +00:00
$this -> checkout_fields [ 'order' ] = array (
2012-08-10 11:15:32 +00:00
'order_comments' => array (
'type' => 'textarea' ,
2016-08-27 02:23:54 +00:00
'class' => array ( 'notes' ),
2016-10-12 10:16:30 +00:00
'label' => __ ( 'Order notes' , 'woocommerce' ),
2016-10-24 07:31:07 +00:00
'placeholder' => esc_attr__ ( 'Notes about your order, e.g. special notes for delivery.' , 'woocommerce' ),
2016-08-27 01:46:45 +00:00
),
2014-09-22 12:23:28 +00:00
);
2012-12-10 12:34:55 +00:00
$this -> checkout_fields = apply_filters ( 'woocommerce_checkout_fields' , $this -> checkout_fields );
do_action ( 'woocommerce_checkout_init' , $this );
2011-08-09 15:16:18 +00:00
}
2012-08-10 11:15:32 +00:00
2012-08-14 19:42:38 +00:00
/**
2015-11-03 13:31:20 +00:00
* Checkout process .
2012-08-14 19:42:38 +00:00
*/
2013-09-04 10:26:19 +00:00
public function check_cart_items () {
2012-02-12 11:36:33 +00:00
// When we process the checkout, lets ensure cart items are rechecked to prevent checkout
2016-09-02 01:51:31 +00:00
do_action ( 'woocommerce_check_cart_items' );
2012-02-12 11:36:33 +00:00
}
2012-08-10 11:15:32 +00:00
2012-08-14 19:42:38 +00:00
/**
2015-11-03 13:31:20 +00:00
* Output the billing information form .
2012-08-14 19:42:38 +00:00
*/
2012-12-14 21:27:29 +00:00
public function checkout_form_billing () {
2013-11-25 12:45:04 +00:00
wc_get_template ( 'checkout/form-billing.php' , array ( 'checkout' => $this ) );
2011-08-09 15:16:18 +00:00
}
2012-08-10 11:15:32 +00:00
2012-08-14 19:42:38 +00:00
/**
2015-11-03 13:31:20 +00:00
* Output the shipping information form .
2012-08-14 19:42:38 +00:00
*/
2012-12-14 21:27:29 +00:00
public function checkout_form_shipping () {
2013-11-25 12:45:04 +00:00
wc_get_template ( 'checkout/form-shipping.php' , array ( 'checkout' => $this ) );
2011-08-09 15:16:18 +00:00
}
2012-12-12 21:14:19 +00:00
/**
2016-01-11 10:47:10 +00:00
* Create an order . Error codes :
* 520 - Cannot insert order into the database .
* 521 - Cannot get order after creation .
* 522 - Cannot update order .
* 525 - Cannot create line item .
* 526 - Cannot create fee item .
* 527 - Cannot create shipping item .
* 528 - Cannot create tax item .
* 529 - Cannot create coupon item .
2013-10-06 04:44:04 +00:00
* @ throws Exception
2014-06-18 15:03:46 +00:00
* @ return int | WP_ERROR
2012-12-12 21:14:19 +00:00
*/
2012-12-14 21:27:29 +00:00
public function create_order () {
2013-10-24 12:15:42 +00:00
global $wpdb ;
2012-12-12 21:14:19 +00:00
2013-02-13 09:38:54 +00:00
// Give plugins the opportunity to create an order themselves
2014-06-11 14:10:03 +00:00
if ( $order_id = apply_filters ( 'woocommerce_create_order' , null , $this ) ) {
2013-02-13 09:38:54 +00:00
return $order_id ;
2014-06-11 14:10:03 +00:00
}
2013-02-13 09:38:54 +00:00
2014-06-18 15:03:46 +00:00
try {
// Start transaction if available
2015-11-04 14:11:40 +00:00
wc_transaction_query ( 'start' );
2012-12-12 21:14:19 +00:00
2014-06-18 15:03:46 +00:00
// Insert or update the post data
2016-08-09 13:02:40 +00:00
$order_id = absint ( WC () -> session -> order_awaiting_payment );
$cart_hash = md5 ( json_encode ( wc_clean ( WC () -> cart -> get_cart_for_session () ) ) . WC () -> cart -> total );
2012-12-12 21:14:19 +00:00
2016-02-05 09:41:25 +00:00
/**
* If there is an order pending payment , we can resume it here so
* long as it has not changed . If the order has changed , i . e .
* different items or cost , create a new order . We use a hash to
* detect changes which is based on cart items + order total .
*/
2016-08-09 13:02:40 +00:00
if ( $order_id && ( $order = wc_get_order ( $order_id ) ) && $order -> has_cart_hash ( $cart_hash ) && $order -> has_status ( array ( 'pending' , 'failed' ) ) ) {
// Action for 3rd parties.
do_action ( 'woocommerce_resume_order' , $order_id );
2012-12-12 21:14:19 +00:00
2016-08-09 13:02:40 +00:00
// Remove all items - we will re-add them later.
$order -> remove_order_items ();
/**
* Not resuming - lets create a new order object .
*/
2014-06-11 14:10:03 +00:00
} else {
2016-08-09 13:02:40 +00:00
$order = new WC_Order ();
}
2012-12-12 21:14:19 +00:00
2016-08-09 13:02:40 +00:00
$order -> set_created_via ( 'checkout' );
$order -> set_cart_hash ( $cart_hash );
$order -> set_customer_id ( $this -> customer_id );
$order -> set_currency ( get_woocommerce_currency () );
$order -> set_prices_include_tax ( 'yes' === get_option ( 'woocommerce_prices_include_tax' ) );
$order -> set_customer_ip_address ( WC_Geolocation :: get_ip_address () );
$order -> set_customer_user_agent ( wc_get_user_agent () );
$order -> set_customer_note ( isset ( $this -> posted [ 'order_comments' ] ) ? $this -> posted [ 'order_comments' ] : '' );
$order -> set_payment_method ( $this -> payment_method );
$order -> set_shipping_total ( WC () -> cart -> shipping_total );
$order -> set_discount_total ( WC () -> cart -> get_cart_discount_total () );
$order -> set_discount_tax ( WC () -> cart -> get_cart_discount_tax_total () );
$order -> set_cart_tax ( WC () -> cart -> tax_total );
$order -> set_shipping_tax ( WC () -> cart -> shipping_tax_total );
$order -> set_total ( WC () -> cart -> total );
2012-12-12 21:14:19 +00:00
2016-08-09 13:02:40 +00:00
// Billing and shipping addresses
if ( $address_keys = array_merge ( array_keys ( $this -> checkout_fields [ 'billing' ] ), array_keys ( $this -> checkout_fields [ 'shipping' ] ) ) ) {
foreach ( $address_keys as $key ) {
if ( is_callable ( array ( $order , " set_ { $key } " ) ) ) {
$order -> { " set_ { $key } " }( $this -> get_posted_address_data ( str_replace ( array ( 'billing_' , 'shipping_' ), '' , $key ), strstr ( $key , 'billing_' ) ? 'billing' : 'shipping' ) );
}
2014-06-18 15:03:46 +00:00
}
2012-12-12 21:14:19 +00:00
}
2016-08-09 13:02:40 +00:00
// Add line items.
2014-06-18 15:03:46 +00:00
foreach ( WC () -> cart -> get_cart () as $cart_item_key => $values ) {
2016-08-09 13:02:40 +00:00
$product = $values [ 'data' ];
2016-11-17 21:30:34 +00:00
$item = new WC_Order_Item_Product ();
$item -> set_props ( array (
2016-08-17 10:45:07 +00:00
'quantity' => $values [ 'quantity' ],
WIP - Product CRUD (#12065)
* Created function to get the catalog visibility options
* First methods for WP_Product crud
* Product set methods
* Fixed several erros while setting data
* First methods for WP_Product crud
* Product set methods
* Fixed several erros while setting data
* Hardcode the get_type per product class
* Initial look through getters and setters and abstract data
* Missing var
* Add related product functions and deprecate those in class.
* No need to exclude ID
* Fixed coding standards and improved the docblocks
* Get cached terms from wc_get_related_terms()
* Fixed wrong variable in wc_get_related_terms
* Use count() instead of sizeof()
* Sanitize ids later
* Remove unneeded comments
* wc_get_product_term_ids instead of related wording and use in other places.
get_the_terms is used here and also handles caching, something
wp_get_post_terms does not.
* Clean up the abstract product class a bit, deprecate two functions we have renamed, make update & create work properly, and add some tests for it.
* Bump template version
* Handle PR feedback: Remove duplicate regular_price update, allow changing of post status for products, remove deprecation for get_title since we might still offer it as a function
* Made abstract function useful
* External Product CRUD
* _virtual meta should be 'no', not taxable, in product unit test helper
* Grouped product class
* Tests
* Move children to meta and update test
* Use get_upsell_ids
* Spacing in query
* Moving and refactoring methods
* Availability html
* Tidy/add todos
* Rename method
* Put back review functions (still todo)
* missing $this
* get_price_including_tax/excluding_tax functions
* wc_get_price_to_display
* Price handling
* [Product CRUD] Variable (#12146)
* [Product CRUD] Variable Products
* Handle PR feedback.
* [Product CRUD] Grouped Handling (#12151)
* Handle grouped product saving
* Update routine
* [Product CRUD] Product crud terms (#12149)
* Category and tag id handling
* Replace template functions
* Remove todo
* Handle default name in save function
* Product crud admin save routine (#12174)
* Initial props
* Work on admin saving
* Set/get attributes
* Atom was moaning about this before but no longer.
* Update get_shipping_class
* WC_Product_Attribute
* Use getter in admin panel
* Fix attribute saving
* Spacing
* Fix comment
* wc_implode_text_attributes helper function
* [Product CRUD] Product crud admin use getters (#12196)
* Initial props
* Work on admin saving
* Set/get attributes
* Atom was moaning about this before but no longer.
* Update get_shipping_class
* WC_Product_Attribute
* Use getter in admin panel
* Fix attribute saving
* Move settings into new files
* Refactor panels and use getters
* Use getters for variation panel
* Revert save variation changes for now
* Add todos
* Fix downloads
* REST API CRUD Updates
* Additional API updates/fixes. Added some todos
* Fix final failing tests and implementing setters/getters and attributes functionality.
* Fix comparison for is_on_sale and remove download_type from WC_Product.
* Add a wc_get_products wrapper.
* Remove the download type input from the product data metabox for downloadable products. (#12221)
* [Product CRUD] Variations - setters, getters and admin. (#12228)
* Started on variation changes
* Stock functions
* Variation class
* Bulk change ->id to get_id() to fix variation form display
* Missing status
* Fix add to cart
* Start on stored data save
* save variation
* Save_variations
* Variation edit panel
* Save variations code works.
* Remove stored data code and fix save
* Improve legacy class
* wc_bool_to_string
* prepare_set_attributes
* Use wc_get_products
* More feedback fixes
* Feedback fixes
* Implement CRUD in the legacy REST API
* Handle PR feedback
* [Product CRUD] Getter setter proxy methods (#12236)
* Started on variation changes
* Stock functions
* Variation class
* Bulk change ->id to get_id() to fix variation form display
* Missing status
* Fix add to cart
* Start on stored data save
* save variation
* Save_variations
* Variation edit panel
* Save variations code works.
* Remove stored data code and fix save
* Improve legacy class
* wc_bool_to_string
* prepare_set_attributes
* Use wc_get_products
* More feedback fixes
* get_prop implementation in abstract and data classes
* Implement set_prop
* Change handling
* Array key exists
* set_object_read
* Use get_the_terms() instead of wp_get_post_terms()
wp_get_post_terms() is a wrapper around wp_get_object_terms() which does not
use the object cache, and generates a database query every time it is used.
get_the_terms() however can use data from the object cache if present.
* Allow WP_Query to preload post data, and meta in wc_get_products()
Allow WP_Query to bulk query for post data and meta if more than
just IDs are requested from wc_get_products(). Reduces query count
significantly.
* [Product CRUD] Variable, variation, notices, and stock handling (#12277)
* No longer needed
* Remove old todos
* Use getters in admin list
* Related and upsells update for CRUD
* Fix notice in gallery
* Variable fixes and todos
* Context
* Price sync
* Revert variation attributes change
* Return parent data in view context
* Defer term counting
* wc_find_matching_product_variation
* Stock manage tweaks
* Stock fixes
* Correct id
* correct id
* Better sync
* Data logic setter fix
* feedback
* First methods for WP_Product crud
* Product set methods
* Fixed several erros while setting data
* Hardcode the get_type per product class
* Initial look through getters and setters and abstract data
* Missing var
* Fixed coding standards and improved the docblocks
* Get cached terms from wc_get_related_terms()
* Fixed wrong variable in wc_get_related_terms
* Use count() instead of sizeof()
* Add related product functions and deprecate those in class.
* No need to exclude ID
* Sanitize ids later
* Clean up the abstract product class a bit, deprecate two functions we have renamed, make update & create work properly, and add some tests for it.
* Remove unneeded comments
* wc_get_product_term_ids instead of related wording and use in other places.
get_the_terms is used here and also handles caching, something
wp_get_post_terms does not.
* Handle PR feedback: Remove duplicate regular_price update, allow changing of post status for products, remove deprecation for get_title since we might still offer it as a function
* External Product CRUD
* _virtual meta should be 'no', not taxable, in product unit test helper
* Bump template version
* Made abstract function useful
* Grouped product class
* Tests
* Move children to meta and update test
* Use get_upsell_ids
* Spacing in query
* Moving and refactoring methods
* Availability html
* Tidy/add todos
* Rename method
* Put back review functions (still todo)
* missing $this
* get_price_including_tax/excluding_tax functions
* wc_get_price_to_display
* Price handling
* [Product CRUD] Variable (#12146)
* [Product CRUD] Variable Products
* Handle PR feedback.
* [Product CRUD] Grouped Handling (#12151)
* Handle grouped product saving
* Update routine
* [Product CRUD] Product crud terms (#12149)
* Category and tag id handling
* Replace template functions
* Remove todo
* Handle default name in save function
* Product crud admin save routine (#12174)
* Initial props
* Work on admin saving
* Set/get attributes
* Atom was moaning about this before but no longer.
* Update get_shipping_class
* WC_Product_Attribute
* Use getter in admin panel
* Fix attribute saving
* Spacing
* Fix comment
* wc_implode_text_attributes helper function
* [Product CRUD] Product crud admin use getters (#12196)
* Initial props
* Work on admin saving
* Set/get attributes
* Atom was moaning about this before but no longer.
* Update get_shipping_class
* WC_Product_Attribute
* Use getter in admin panel
* Fix attribute saving
* Move settings into new files
* Refactor panels and use getters
* Use getters for variation panel
* Revert save variation changes for now
* Add todos
* Fix downloads
* REST API CRUD Updates
* Additional API updates/fixes. Added some todos
* Fix final failing tests and implementing setters/getters and attributes functionality.
* Fix comparison for is_on_sale and remove download_type from WC_Product.
* Add a wc_get_products wrapper.
* Remove the download type input from the product data metabox for downloadable products. (#12221)
* [Product CRUD] Variations - setters, getters and admin. (#12228)
* Started on variation changes
* Stock functions
* Variation class
* Bulk change ->id to get_id() to fix variation form display
* Missing status
* Fix add to cart
* Start on stored data save
* save variation
* Save_variations
* Variation edit panel
* Save variations code works.
* Remove stored data code and fix save
* Improve legacy class
* wc_bool_to_string
* prepare_set_attributes
* Use wc_get_products
* More feedback fixes
* Feedback fixes
* Implement CRUD in the legacy REST API
* Handle PR feedback
* [Product CRUD] Getter setter proxy methods (#12236)
* Started on variation changes
* Stock functions
* Variation class
* Bulk change ->id to get_id() to fix variation form display
* Missing status
* Fix add to cart
* Start on stored data save
* save variation
* Save_variations
* Variation edit panel
* Save variations code works.
* Remove stored data code and fix save
* Improve legacy class
* wc_bool_to_string
* prepare_set_attributes
* Use wc_get_products
* More feedback fixes
* get_prop implementation in abstract and data classes
* Implement set_prop
* Change handling
* Array key exists
* set_object_read
* Use get_the_terms() instead of wp_get_post_terms()
wp_get_post_terms() is a wrapper around wp_get_object_terms() which does not
use the object cache, and generates a database query every time it is used.
get_the_terms() however can use data from the object cache if present.
* [Product CRUD] Variable, variation, notices, and stock handling (#12277)
* No longer needed
* Remove old todos
* Use getters in admin list
* Related and upsells update for CRUD
* Fix notice in gallery
* Variable fixes and todos
* Context
* Price sync
* Revert variation attributes change
* Return parent data in view context
* Defer term counting
* wc_find_matching_product_variation
* Stock manage tweaks
* Stock fixes
* Correct id
* correct id
* Better sync
* Data logic setter fix
* feedback
* Prevent notices
* Handle image_id from parent
* Fix error
* Remove _wc_save_product_price
* Remove todo
* Fixed wrong variation URLs
* Fixed undefined $image_id in WC_Product_Variation::get_image_id()
* Allow wc_rest_prepare_date_response() handle timestamps
* Updated get methods on REST API for variations
* Use variations CRUD to save variations metadata
* [Product CRUD] Abstract todos (#12305)
* Get dimensions and weights, with soft deprecation
* Product attributes
* Ratings
* Fix read method
* Downloads
* Feedback
* Revert "[Product CRUD] Abstract todos (#12305)"
This reverts commit 9a6136fcf88fec16f97457b7c8a4388f7587bfa2.
* Remove deprecated get_variation_id()
* New default attributes method
* [Product CRUD] Product Datastore (#12317)
* Fix up tests in the product/* folder.
* Handle data store updates for grouped, variable, external, simple, and general data store updates for products.
* Variations & variable changes.
* Update -functions.php calls to use data store.
* Add an interface for the public product data store methods.
* Finished product factory tests
* Correctly delete in the api, fix up some comments, and implement an interface for the public variable methods.
* Fix up delete in all versions of the api
* Handle feedback
* Match protected decloration to parent
* Product crud abstract todos (#12316)
* Get dimensions and weights, with soft deprecation
* Product attributes
* Ratings
* Fix read method
* Downloads
* Feedback
* Fix up store
* Fixed method returning in write context
* Fix error in variation admin
* Check for parent value - fixes tax class
* Remove old/complete todos
* Allow set tax class as "parent"
* Removed duplicated sync
* Fixed wrong variation URLs
* Fixed undefined $image_id in WC_Product_Variation::get_image_id()
* Allow wc_rest_prepare_date_response() handle timestamps
* Updated get methods on REST API for variations
* Use variations CRUD to save variations metadata
* Remove deprecated get_variation_id()
* New default attributes method
* Fixed method returning in write context
* Allow set tax class as "parent"
* Removed duplicated sync
* Fixed coding standards
* TODO is not accurate.
* Should pass WC_Product instancies to WC_Comments methods (#12327)
* Use new method in abstract order class to prevent headers sent issue in tests
* Fixed variable description in REST API
* Updated how create initial product variation
* Fixed a few fatal errors and warnings in Products CRUD (#12329)
* Fixed a few fatal errors and warnings in Products CRUD
* Fixed sync functions
* Add variations CRUD to legacy API (#12331)
* Apply crud to variable products in legacy API v1
* New REST API do not need fallback for default attributes
* Apply variations CRUD to legacy API v2
* Legacy v2 - save default attributes
* Variations in legacy API v2 do not have descriptions
* Fixed legacy API v2 variations params
* Applied variations CRUD to legacy API v3
* Sync before save in legacy apis
* Punc
* Removed API todos
* Removed test
* Products endpoint tweaks (#12354)
* Var type already normalized on CRUD
* Let Product CRUD handle with validation, sanitization and conditional checks
* Set downloads using WC_Product_Download
* Stop try catch exceptions more than one time
* Handle WC_Data_Exception in legacy API
* Complete remove products when fails on creating
* On creating I mean!
* Already have a method to complete delete products
* Fixed standards using WP CodeSniffer
* get_the_terms() returns false when empty
* get_manage_stock returns boolean
@claudiosanches
* Merge conflict
* Variations API endpoint fixes
* Product CRUD improvements (#12359)
* args is not used any more - remove todo
* Added test for attributes
* wc_get_price_excluding_tax usage
* parent usage
* Fix rating counts
* Test fixes
* Cleanup after tests
* Make sure status transition code runs even during API calls, not just in admin.
* Default visibility
* Fix attribute setting in API
* Use get name instead of get title
* variation id usage
* Improved cross sell templates
* variation_data
* Grouped product sync
* Notices
* Sync is not needed in API
* Delete
* Rename interfaces
* Update counts in data store
2016-11-16 12:38:24 +00:00
'name' => $product ? $product -> get_name () : '' ,
2016-08-09 13:02:40 +00:00
'tax_class' => $product ? $product -> get_tax_class () : '' ,
WIP - Product CRUD (#12065)
* Created function to get the catalog visibility options
* First methods for WP_Product crud
* Product set methods
* Fixed several erros while setting data
* First methods for WP_Product crud
* Product set methods
* Fixed several erros while setting data
* Hardcode the get_type per product class
* Initial look through getters and setters and abstract data
* Missing var
* Add related product functions and deprecate those in class.
* No need to exclude ID
* Fixed coding standards and improved the docblocks
* Get cached terms from wc_get_related_terms()
* Fixed wrong variable in wc_get_related_terms
* Use count() instead of sizeof()
* Sanitize ids later
* Remove unneeded comments
* wc_get_product_term_ids instead of related wording and use in other places.
get_the_terms is used here and also handles caching, something
wp_get_post_terms does not.
* Clean up the abstract product class a bit, deprecate two functions we have renamed, make update & create work properly, and add some tests for it.
* Bump template version
* Handle PR feedback: Remove duplicate regular_price update, allow changing of post status for products, remove deprecation for get_title since we might still offer it as a function
* Made abstract function useful
* External Product CRUD
* _virtual meta should be 'no', not taxable, in product unit test helper
* Grouped product class
* Tests
* Move children to meta and update test
* Use get_upsell_ids
* Spacing in query
* Moving and refactoring methods
* Availability html
* Tidy/add todos
* Rename method
* Put back review functions (still todo)
* missing $this
* get_price_including_tax/excluding_tax functions
* wc_get_price_to_display
* Price handling
* [Product CRUD] Variable (#12146)
* [Product CRUD] Variable Products
* Handle PR feedback.
* [Product CRUD] Grouped Handling (#12151)
* Handle grouped product saving
* Update routine
* [Product CRUD] Product crud terms (#12149)
* Category and tag id handling
* Replace template functions
* Remove todo
* Handle default name in save function
* Product crud admin save routine (#12174)
* Initial props
* Work on admin saving
* Set/get attributes
* Atom was moaning about this before but no longer.
* Update get_shipping_class
* WC_Product_Attribute
* Use getter in admin panel
* Fix attribute saving
* Spacing
* Fix comment
* wc_implode_text_attributes helper function
* [Product CRUD] Product crud admin use getters (#12196)
* Initial props
* Work on admin saving
* Set/get attributes
* Atom was moaning about this before but no longer.
* Update get_shipping_class
* WC_Product_Attribute
* Use getter in admin panel
* Fix attribute saving
* Move settings into new files
* Refactor panels and use getters
* Use getters for variation panel
* Revert save variation changes for now
* Add todos
* Fix downloads
* REST API CRUD Updates
* Additional API updates/fixes. Added some todos
* Fix final failing tests and implementing setters/getters and attributes functionality.
* Fix comparison for is_on_sale and remove download_type from WC_Product.
* Add a wc_get_products wrapper.
* Remove the download type input from the product data metabox for downloadable products. (#12221)
* [Product CRUD] Variations - setters, getters and admin. (#12228)
* Started on variation changes
* Stock functions
* Variation class
* Bulk change ->id to get_id() to fix variation form display
* Missing status
* Fix add to cart
* Start on stored data save
* save variation
* Save_variations
* Variation edit panel
* Save variations code works.
* Remove stored data code and fix save
* Improve legacy class
* wc_bool_to_string
* prepare_set_attributes
* Use wc_get_products
* More feedback fixes
* Feedback fixes
* Implement CRUD in the legacy REST API
* Handle PR feedback
* [Product CRUD] Getter setter proxy methods (#12236)
* Started on variation changes
* Stock functions
* Variation class
* Bulk change ->id to get_id() to fix variation form display
* Missing status
* Fix add to cart
* Start on stored data save
* save variation
* Save_variations
* Variation edit panel
* Save variations code works.
* Remove stored data code and fix save
* Improve legacy class
* wc_bool_to_string
* prepare_set_attributes
* Use wc_get_products
* More feedback fixes
* get_prop implementation in abstract and data classes
* Implement set_prop
* Change handling
* Array key exists
* set_object_read
* Use get_the_terms() instead of wp_get_post_terms()
wp_get_post_terms() is a wrapper around wp_get_object_terms() which does not
use the object cache, and generates a database query every time it is used.
get_the_terms() however can use data from the object cache if present.
* Allow WP_Query to preload post data, and meta in wc_get_products()
Allow WP_Query to bulk query for post data and meta if more than
just IDs are requested from wc_get_products(). Reduces query count
significantly.
* [Product CRUD] Variable, variation, notices, and stock handling (#12277)
* No longer needed
* Remove old todos
* Use getters in admin list
* Related and upsells update for CRUD
* Fix notice in gallery
* Variable fixes and todos
* Context
* Price sync
* Revert variation attributes change
* Return parent data in view context
* Defer term counting
* wc_find_matching_product_variation
* Stock manage tweaks
* Stock fixes
* Correct id
* correct id
* Better sync
* Data logic setter fix
* feedback
* First methods for WP_Product crud
* Product set methods
* Fixed several erros while setting data
* Hardcode the get_type per product class
* Initial look through getters and setters and abstract data
* Missing var
* Fixed coding standards and improved the docblocks
* Get cached terms from wc_get_related_terms()
* Fixed wrong variable in wc_get_related_terms
* Use count() instead of sizeof()
* Add related product functions and deprecate those in class.
* No need to exclude ID
* Sanitize ids later
* Clean up the abstract product class a bit, deprecate two functions we have renamed, make update & create work properly, and add some tests for it.
* Remove unneeded comments
* wc_get_product_term_ids instead of related wording and use in other places.
get_the_terms is used here and also handles caching, something
wp_get_post_terms does not.
* Handle PR feedback: Remove duplicate regular_price update, allow changing of post status for products, remove deprecation for get_title since we might still offer it as a function
* External Product CRUD
* _virtual meta should be 'no', not taxable, in product unit test helper
* Bump template version
* Made abstract function useful
* Grouped product class
* Tests
* Move children to meta and update test
* Use get_upsell_ids
* Spacing in query
* Moving and refactoring methods
* Availability html
* Tidy/add todos
* Rename method
* Put back review functions (still todo)
* missing $this
* get_price_including_tax/excluding_tax functions
* wc_get_price_to_display
* Price handling
* [Product CRUD] Variable (#12146)
* [Product CRUD] Variable Products
* Handle PR feedback.
* [Product CRUD] Grouped Handling (#12151)
* Handle grouped product saving
* Update routine
* [Product CRUD] Product crud terms (#12149)
* Category and tag id handling
* Replace template functions
* Remove todo
* Handle default name in save function
* Product crud admin save routine (#12174)
* Initial props
* Work on admin saving
* Set/get attributes
* Atom was moaning about this before but no longer.
* Update get_shipping_class
* WC_Product_Attribute
* Use getter in admin panel
* Fix attribute saving
* Spacing
* Fix comment
* wc_implode_text_attributes helper function
* [Product CRUD] Product crud admin use getters (#12196)
* Initial props
* Work on admin saving
* Set/get attributes
* Atom was moaning about this before but no longer.
* Update get_shipping_class
* WC_Product_Attribute
* Use getter in admin panel
* Fix attribute saving
* Move settings into new files
* Refactor panels and use getters
* Use getters for variation panel
* Revert save variation changes for now
* Add todos
* Fix downloads
* REST API CRUD Updates
* Additional API updates/fixes. Added some todos
* Fix final failing tests and implementing setters/getters and attributes functionality.
* Fix comparison for is_on_sale and remove download_type from WC_Product.
* Add a wc_get_products wrapper.
* Remove the download type input from the product data metabox for downloadable products. (#12221)
* [Product CRUD] Variations - setters, getters and admin. (#12228)
* Started on variation changes
* Stock functions
* Variation class
* Bulk change ->id to get_id() to fix variation form display
* Missing status
* Fix add to cart
* Start on stored data save
* save variation
* Save_variations
* Variation edit panel
* Save variations code works.
* Remove stored data code and fix save
* Improve legacy class
* wc_bool_to_string
* prepare_set_attributes
* Use wc_get_products
* More feedback fixes
* Feedback fixes
* Implement CRUD in the legacy REST API
* Handle PR feedback
* [Product CRUD] Getter setter proxy methods (#12236)
* Started on variation changes
* Stock functions
* Variation class
* Bulk change ->id to get_id() to fix variation form display
* Missing status
* Fix add to cart
* Start on stored data save
* save variation
* Save_variations
* Variation edit panel
* Save variations code works.
* Remove stored data code and fix save
* Improve legacy class
* wc_bool_to_string
* prepare_set_attributes
* Use wc_get_products
* More feedback fixes
* get_prop implementation in abstract and data classes
* Implement set_prop
* Change handling
* Array key exists
* set_object_read
* Use get_the_terms() instead of wp_get_post_terms()
wp_get_post_terms() is a wrapper around wp_get_object_terms() which does not
use the object cache, and generates a database query every time it is used.
get_the_terms() however can use data from the object cache if present.
* [Product CRUD] Variable, variation, notices, and stock handling (#12277)
* No longer needed
* Remove old todos
* Use getters in admin list
* Related and upsells update for CRUD
* Fix notice in gallery
* Variable fixes and todos
* Context
* Price sync
* Revert variation attributes change
* Return parent data in view context
* Defer term counting
* wc_find_matching_product_variation
* Stock manage tweaks
* Stock fixes
* Correct id
* correct id
* Better sync
* Data logic setter fix
* feedback
* Prevent notices
* Handle image_id from parent
* Fix error
* Remove _wc_save_product_price
* Remove todo
* Fixed wrong variation URLs
* Fixed undefined $image_id in WC_Product_Variation::get_image_id()
* Allow wc_rest_prepare_date_response() handle timestamps
* Updated get methods on REST API for variations
* Use variations CRUD to save variations metadata
* [Product CRUD] Abstract todos (#12305)
* Get dimensions and weights, with soft deprecation
* Product attributes
* Ratings
* Fix read method
* Downloads
* Feedback
* Revert "[Product CRUD] Abstract todos (#12305)"
This reverts commit 9a6136fcf88fec16f97457b7c8a4388f7587bfa2.
* Remove deprecated get_variation_id()
* New default attributes method
* [Product CRUD] Product Datastore (#12317)
* Fix up tests in the product/* folder.
* Handle data store updates for grouped, variable, external, simple, and general data store updates for products.
* Variations & variable changes.
* Update -functions.php calls to use data store.
* Add an interface for the public product data store methods.
* Finished product factory tests
* Correctly delete in the api, fix up some comments, and implement an interface for the public variable methods.
* Fix up delete in all versions of the api
* Handle feedback
* Match protected decloration to parent
* Product crud abstract todos (#12316)
* Get dimensions and weights, with soft deprecation
* Product attributes
* Ratings
* Fix read method
* Downloads
* Feedback
* Fix up store
* Fixed method returning in write context
* Fix error in variation admin
* Check for parent value - fixes tax class
* Remove old/complete todos
* Allow set tax class as "parent"
* Removed duplicated sync
* Fixed wrong variation URLs
* Fixed undefined $image_id in WC_Product_Variation::get_image_id()
* Allow wc_rest_prepare_date_response() handle timestamps
* Updated get methods on REST API for variations
* Use variations CRUD to save variations metadata
* Remove deprecated get_variation_id()
* New default attributes method
* Fixed method returning in write context
* Allow set tax class as "parent"
* Removed duplicated sync
* Fixed coding standards
* TODO is not accurate.
* Should pass WC_Product instancies to WC_Comments methods (#12327)
* Use new method in abstract order class to prevent headers sent issue in tests
* Fixed variable description in REST API
* Updated how create initial product variation
* Fixed a few fatal errors and warnings in Products CRUD (#12329)
* Fixed a few fatal errors and warnings in Products CRUD
* Fixed sync functions
* Add variations CRUD to legacy API (#12331)
* Apply crud to variable products in legacy API v1
* New REST API do not need fallback for default attributes
* Apply variations CRUD to legacy API v2
* Legacy v2 - save default attributes
* Variations in legacy API v2 do not have descriptions
* Fixed legacy API v2 variations params
* Applied variations CRUD to legacy API v3
* Sync before save in legacy apis
* Punc
* Removed API todos
* Removed test
* Products endpoint tweaks (#12354)
* Var type already normalized on CRUD
* Let Product CRUD handle with validation, sanitization and conditional checks
* Set downloads using WC_Product_Download
* Stop try catch exceptions more than one time
* Handle WC_Data_Exception in legacy API
* Complete remove products when fails on creating
* On creating I mean!
* Already have a method to complete delete products
* Fixed standards using WP CodeSniffer
* get_the_terms() returns false when empty
* get_manage_stock returns boolean
@claudiosanches
* Merge conflict
* Variations API endpoint fixes
* Product CRUD improvements (#12359)
* args is not used any more - remove todo
* Added test for attributes
* wc_get_price_excluding_tax usage
* parent usage
* Fix rating counts
* Test fixes
* Cleanup after tests
* Make sure status transition code runs even during API calls, not just in admin.
* Default visibility
* Fix attribute setting in API
* Use get name instead of get title
* variation id usage
* Improved cross sell templates
* variation_data
* Grouped product sync
* Notices
* Sync is not needed in API
* Delete
* Rename interfaces
* Update counts in data store
2016-11-16 12:38:24 +00:00
'product_id' => $product ? ( $product -> is_type ( 'variation' ) ? $product -> get_parent_id () : $product -> get_id () ) : 0 ,
'variation_id' => $product && $product -> is_type ( 'variation' ) ? $product -> get_id () : 0 ,
2016-08-09 13:02:40 +00:00
'variation' => $values [ 'variation' ],
'subtotal' => $values [ 'line_subtotal' ],
'total' => $values [ 'line_total' ],
'subtotal_tax' => $values [ 'line_subtotal_tax' ],
'total_tax' => $values [ 'line_tax' ],
'taxes' => $values [ 'line_tax_data' ],
) );
2016-08-15 10:02:38 +00:00
$item -> set_backorder_meta ();
WIP - Product CRUD (#12065)
* Created function to get the catalog visibility options
* First methods for WP_Product crud
* Product set methods
* Fixed several erros while setting data
* First methods for WP_Product crud
* Product set methods
* Fixed several erros while setting data
* Hardcode the get_type per product class
* Initial look through getters and setters and abstract data
* Missing var
* Add related product functions and deprecate those in class.
* No need to exclude ID
* Fixed coding standards and improved the docblocks
* Get cached terms from wc_get_related_terms()
* Fixed wrong variable in wc_get_related_terms
* Use count() instead of sizeof()
* Sanitize ids later
* Remove unneeded comments
* wc_get_product_term_ids instead of related wording and use in other places.
get_the_terms is used here and also handles caching, something
wp_get_post_terms does not.
* Clean up the abstract product class a bit, deprecate two functions we have renamed, make update & create work properly, and add some tests for it.
* Bump template version
* Handle PR feedback: Remove duplicate regular_price update, allow changing of post status for products, remove deprecation for get_title since we might still offer it as a function
* Made abstract function useful
* External Product CRUD
* _virtual meta should be 'no', not taxable, in product unit test helper
* Grouped product class
* Tests
* Move children to meta and update test
* Use get_upsell_ids
* Spacing in query
* Moving and refactoring methods
* Availability html
* Tidy/add todos
* Rename method
* Put back review functions (still todo)
* missing $this
* get_price_including_tax/excluding_tax functions
* wc_get_price_to_display
* Price handling
* [Product CRUD] Variable (#12146)
* [Product CRUD] Variable Products
* Handle PR feedback.
* [Product CRUD] Grouped Handling (#12151)
* Handle grouped product saving
* Update routine
* [Product CRUD] Product crud terms (#12149)
* Category and tag id handling
* Replace template functions
* Remove todo
* Handle default name in save function
* Product crud admin save routine (#12174)
* Initial props
* Work on admin saving
* Set/get attributes
* Atom was moaning about this before but no longer.
* Update get_shipping_class
* WC_Product_Attribute
* Use getter in admin panel
* Fix attribute saving
* Spacing
* Fix comment
* wc_implode_text_attributes helper function
* [Product CRUD] Product crud admin use getters (#12196)
* Initial props
* Work on admin saving
* Set/get attributes
* Atom was moaning about this before but no longer.
* Update get_shipping_class
* WC_Product_Attribute
* Use getter in admin panel
* Fix attribute saving
* Move settings into new files
* Refactor panels and use getters
* Use getters for variation panel
* Revert save variation changes for now
* Add todos
* Fix downloads
* REST API CRUD Updates
* Additional API updates/fixes. Added some todos
* Fix final failing tests and implementing setters/getters and attributes functionality.
* Fix comparison for is_on_sale and remove download_type from WC_Product.
* Add a wc_get_products wrapper.
* Remove the download type input from the product data metabox for downloadable products. (#12221)
* [Product CRUD] Variations - setters, getters and admin. (#12228)
* Started on variation changes
* Stock functions
* Variation class
* Bulk change ->id to get_id() to fix variation form display
* Missing status
* Fix add to cart
* Start on stored data save
* save variation
* Save_variations
* Variation edit panel
* Save variations code works.
* Remove stored data code and fix save
* Improve legacy class
* wc_bool_to_string
* prepare_set_attributes
* Use wc_get_products
* More feedback fixes
* Feedback fixes
* Implement CRUD in the legacy REST API
* Handle PR feedback
* [Product CRUD] Getter setter proxy methods (#12236)
* Started on variation changes
* Stock functions
* Variation class
* Bulk change ->id to get_id() to fix variation form display
* Missing status
* Fix add to cart
* Start on stored data save
* save variation
* Save_variations
* Variation edit panel
* Save variations code works.
* Remove stored data code and fix save
* Improve legacy class
* wc_bool_to_string
* prepare_set_attributes
* Use wc_get_products
* More feedback fixes
* get_prop implementation in abstract and data classes
* Implement set_prop
* Change handling
* Array key exists
* set_object_read
* Use get_the_terms() instead of wp_get_post_terms()
wp_get_post_terms() is a wrapper around wp_get_object_terms() which does not
use the object cache, and generates a database query every time it is used.
get_the_terms() however can use data from the object cache if present.
* Allow WP_Query to preload post data, and meta in wc_get_products()
Allow WP_Query to bulk query for post data and meta if more than
just IDs are requested from wc_get_products(). Reduces query count
significantly.
* [Product CRUD] Variable, variation, notices, and stock handling (#12277)
* No longer needed
* Remove old todos
* Use getters in admin list
* Related and upsells update for CRUD
* Fix notice in gallery
* Variable fixes and todos
* Context
* Price sync
* Revert variation attributes change
* Return parent data in view context
* Defer term counting
* wc_find_matching_product_variation
* Stock manage tweaks
* Stock fixes
* Correct id
* correct id
* Better sync
* Data logic setter fix
* feedback
* First methods for WP_Product crud
* Product set methods
* Fixed several erros while setting data
* Hardcode the get_type per product class
* Initial look through getters and setters and abstract data
* Missing var
* Fixed coding standards and improved the docblocks
* Get cached terms from wc_get_related_terms()
* Fixed wrong variable in wc_get_related_terms
* Use count() instead of sizeof()
* Add related product functions and deprecate those in class.
* No need to exclude ID
* Sanitize ids later
* Clean up the abstract product class a bit, deprecate two functions we have renamed, make update & create work properly, and add some tests for it.
* Remove unneeded comments
* wc_get_product_term_ids instead of related wording and use in other places.
get_the_terms is used here and also handles caching, something
wp_get_post_terms does not.
* Handle PR feedback: Remove duplicate regular_price update, allow changing of post status for products, remove deprecation for get_title since we might still offer it as a function
* External Product CRUD
* _virtual meta should be 'no', not taxable, in product unit test helper
* Bump template version
* Made abstract function useful
* Grouped product class
* Tests
* Move children to meta and update test
* Use get_upsell_ids
* Spacing in query
* Moving and refactoring methods
* Availability html
* Tidy/add todos
* Rename method
* Put back review functions (still todo)
* missing $this
* get_price_including_tax/excluding_tax functions
* wc_get_price_to_display
* Price handling
* [Product CRUD] Variable (#12146)
* [Product CRUD] Variable Products
* Handle PR feedback.
* [Product CRUD] Grouped Handling (#12151)
* Handle grouped product saving
* Update routine
* [Product CRUD] Product crud terms (#12149)
* Category and tag id handling
* Replace template functions
* Remove todo
* Handle default name in save function
* Product crud admin save routine (#12174)
* Initial props
* Work on admin saving
* Set/get attributes
* Atom was moaning about this before but no longer.
* Update get_shipping_class
* WC_Product_Attribute
* Use getter in admin panel
* Fix attribute saving
* Spacing
* Fix comment
* wc_implode_text_attributes helper function
* [Product CRUD] Product crud admin use getters (#12196)
* Initial props
* Work on admin saving
* Set/get attributes
* Atom was moaning about this before but no longer.
* Update get_shipping_class
* WC_Product_Attribute
* Use getter in admin panel
* Fix attribute saving
* Move settings into new files
* Refactor panels and use getters
* Use getters for variation panel
* Revert save variation changes for now
* Add todos
* Fix downloads
* REST API CRUD Updates
* Additional API updates/fixes. Added some todos
* Fix final failing tests and implementing setters/getters and attributes functionality.
* Fix comparison for is_on_sale and remove download_type from WC_Product.
* Add a wc_get_products wrapper.
* Remove the download type input from the product data metabox for downloadable products. (#12221)
* [Product CRUD] Variations - setters, getters and admin. (#12228)
* Started on variation changes
* Stock functions
* Variation class
* Bulk change ->id to get_id() to fix variation form display
* Missing status
* Fix add to cart
* Start on stored data save
* save variation
* Save_variations
* Variation edit panel
* Save variations code works.
* Remove stored data code and fix save
* Improve legacy class
* wc_bool_to_string
* prepare_set_attributes
* Use wc_get_products
* More feedback fixes
* Feedback fixes
* Implement CRUD in the legacy REST API
* Handle PR feedback
* [Product CRUD] Getter setter proxy methods (#12236)
* Started on variation changes
* Stock functions
* Variation class
* Bulk change ->id to get_id() to fix variation form display
* Missing status
* Fix add to cart
* Start on stored data save
* save variation
* Save_variations
* Variation edit panel
* Save variations code works.
* Remove stored data code and fix save
* Improve legacy class
* wc_bool_to_string
* prepare_set_attributes
* Use wc_get_products
* More feedback fixes
* get_prop implementation in abstract and data classes
* Implement set_prop
* Change handling
* Array key exists
* set_object_read
* Use get_the_terms() instead of wp_get_post_terms()
wp_get_post_terms() is a wrapper around wp_get_object_terms() which does not
use the object cache, and generates a database query every time it is used.
get_the_terms() however can use data from the object cache if present.
* [Product CRUD] Variable, variation, notices, and stock handling (#12277)
* No longer needed
* Remove old todos
* Use getters in admin list
* Related and upsells update for CRUD
* Fix notice in gallery
* Variable fixes and todos
* Context
* Price sync
* Revert variation attributes change
* Return parent data in view context
* Defer term counting
* wc_find_matching_product_variation
* Stock manage tweaks
* Stock fixes
* Correct id
* correct id
* Better sync
* Data logic setter fix
* feedback
* Prevent notices
* Handle image_id from parent
* Fix error
* Remove _wc_save_product_price
* Remove todo
* Fixed wrong variation URLs
* Fixed undefined $image_id in WC_Product_Variation::get_image_id()
* Allow wc_rest_prepare_date_response() handle timestamps
* Updated get methods on REST API for variations
* Use variations CRUD to save variations metadata
* [Product CRUD] Abstract todos (#12305)
* Get dimensions and weights, with soft deprecation
* Product attributes
* Ratings
* Fix read method
* Downloads
* Feedback
* Revert "[Product CRUD] Abstract todos (#12305)"
This reverts commit 9a6136fcf88fec16f97457b7c8a4388f7587bfa2.
* Remove deprecated get_variation_id()
* New default attributes method
* [Product CRUD] Product Datastore (#12317)
* Fix up tests in the product/* folder.
* Handle data store updates for grouped, variable, external, simple, and general data store updates for products.
* Variations & variable changes.
* Update -functions.php calls to use data store.
* Add an interface for the public product data store methods.
* Finished product factory tests
* Correctly delete in the api, fix up some comments, and implement an interface for the public variable methods.
* Fix up delete in all versions of the api
* Handle feedback
* Match protected decloration to parent
* Product crud abstract todos (#12316)
* Get dimensions and weights, with soft deprecation
* Product attributes
* Ratings
* Fix read method
* Downloads
* Feedback
* Fix up store
* Fixed method returning in write context
* Fix error in variation admin
* Check for parent value - fixes tax class
* Remove old/complete todos
* Allow set tax class as "parent"
* Removed duplicated sync
* Fixed wrong variation URLs
* Fixed undefined $image_id in WC_Product_Variation::get_image_id()
* Allow wc_rest_prepare_date_response() handle timestamps
* Updated get methods on REST API for variations
* Use variations CRUD to save variations metadata
* Remove deprecated get_variation_id()
* New default attributes method
* Fixed method returning in write context
* Allow set tax class as "parent"
* Removed duplicated sync
* Fixed coding standards
* TODO is not accurate.
* Should pass WC_Product instancies to WC_Comments methods (#12327)
* Use new method in abstract order class to prevent headers sent issue in tests
* Fixed variable description in REST API
* Updated how create initial product variation
* Fixed a few fatal errors and warnings in Products CRUD (#12329)
* Fixed a few fatal errors and warnings in Products CRUD
* Fixed sync functions
* Add variations CRUD to legacy API (#12331)
* Apply crud to variable products in legacy API v1
* New REST API do not need fallback for default attributes
* Apply variations CRUD to legacy API v2
* Legacy v2 - save default attributes
* Variations in legacy API v2 do not have descriptions
* Fixed legacy API v2 variations params
* Applied variations CRUD to legacy API v3
* Sync before save in legacy apis
* Punc
* Removed API todos
* Removed test
* Products endpoint tweaks (#12354)
* Var type already normalized on CRUD
* Let Product CRUD handle with validation, sanitization and conditional checks
* Set downloads using WC_Product_Download
* Stop try catch exceptions more than one time
* Handle WC_Data_Exception in legacy API
* Complete remove products when fails on creating
* On creating I mean!
* Already have a method to complete delete products
* Fixed standards using WP CodeSniffer
* get_the_terms() returns false when empty
* get_manage_stock returns boolean
@claudiosanches
* Merge conflict
* Variations API endpoint fixes
* Product CRUD improvements (#12359)
* args is not used any more - remove todo
* Added test for attributes
* wc_get_price_excluding_tax usage
* parent usage
* Fix rating counts
* Test fixes
* Cleanup after tests
* Make sure status transition code runs even during API calls, not just in admin.
* Default visibility
* Fix attribute setting in API
* Use get name instead of get title
* variation id usage
* Improved cross sell templates
* variation_data
* Grouped product sync
* Notices
* Sync is not needed in API
* Delete
* Rename interfaces
* Update counts in data store
2016-11-16 12:38:24 +00:00
// Set this to pass to legacy actions.
2016-08-09 13:02:40 +00:00
$item -> legacy_values = $values ;
$item -> legacy_cart_item_key = $cart_item_key ;
$order -> add_item ( $item );
2014-06-18 15:03:46 +00:00
}
2012-12-12 21:14:19 +00:00
2016-08-09 13:02:40 +00:00
// Add fees
2014-06-18 15:03:46 +00:00
foreach ( WC () -> cart -> get_fees () as $fee_key => $fee ) {
2016-11-17 21:30:34 +00:00
$item = new WC_Order_Item_Fee ();
$item -> set_props ( array (
2016-08-09 13:02:40 +00:00
'name' => $fee -> name ,
'tax_class' => $fee -> taxable ? $fee -> tax_class : 0 ,
'total' => $fee -> amount ,
'total_tax' => $fee -> tax ,
'taxes' => array (
'total' => $fee -> tax_data ,
),
) );
WIP - Product CRUD (#12065)
* Created function to get the catalog visibility options
* First methods for WP_Product crud
* Product set methods
* Fixed several erros while setting data
* First methods for WP_Product crud
* Product set methods
* Fixed several erros while setting data
* Hardcode the get_type per product class
* Initial look through getters and setters and abstract data
* Missing var
* Add related product functions and deprecate those in class.
* No need to exclude ID
* Fixed coding standards and improved the docblocks
* Get cached terms from wc_get_related_terms()
* Fixed wrong variable in wc_get_related_terms
* Use count() instead of sizeof()
* Sanitize ids later
* Remove unneeded comments
* wc_get_product_term_ids instead of related wording and use in other places.
get_the_terms is used here and also handles caching, something
wp_get_post_terms does not.
* Clean up the abstract product class a bit, deprecate two functions we have renamed, make update & create work properly, and add some tests for it.
* Bump template version
* Handle PR feedback: Remove duplicate regular_price update, allow changing of post status for products, remove deprecation for get_title since we might still offer it as a function
* Made abstract function useful
* External Product CRUD
* _virtual meta should be 'no', not taxable, in product unit test helper
* Grouped product class
* Tests
* Move children to meta and update test
* Use get_upsell_ids
* Spacing in query
* Moving and refactoring methods
* Availability html
* Tidy/add todos
* Rename method
* Put back review functions (still todo)
* missing $this
* get_price_including_tax/excluding_tax functions
* wc_get_price_to_display
* Price handling
* [Product CRUD] Variable (#12146)
* [Product CRUD] Variable Products
* Handle PR feedback.
* [Product CRUD] Grouped Handling (#12151)
* Handle grouped product saving
* Update routine
* [Product CRUD] Product crud terms (#12149)
* Category and tag id handling
* Replace template functions
* Remove todo
* Handle default name in save function
* Product crud admin save routine (#12174)
* Initial props
* Work on admin saving
* Set/get attributes
* Atom was moaning about this before but no longer.
* Update get_shipping_class
* WC_Product_Attribute
* Use getter in admin panel
* Fix attribute saving
* Spacing
* Fix comment
* wc_implode_text_attributes helper function
* [Product CRUD] Product crud admin use getters (#12196)
* Initial props
* Work on admin saving
* Set/get attributes
* Atom was moaning about this before but no longer.
* Update get_shipping_class
* WC_Product_Attribute
* Use getter in admin panel
* Fix attribute saving
* Move settings into new files
* Refactor panels and use getters
* Use getters for variation panel
* Revert save variation changes for now
* Add todos
* Fix downloads
* REST API CRUD Updates
* Additional API updates/fixes. Added some todos
* Fix final failing tests and implementing setters/getters and attributes functionality.
* Fix comparison for is_on_sale and remove download_type from WC_Product.
* Add a wc_get_products wrapper.
* Remove the download type input from the product data metabox for downloadable products. (#12221)
* [Product CRUD] Variations - setters, getters and admin. (#12228)
* Started on variation changes
* Stock functions
* Variation class
* Bulk change ->id to get_id() to fix variation form display
* Missing status
* Fix add to cart
* Start on stored data save
* save variation
* Save_variations
* Variation edit panel
* Save variations code works.
* Remove stored data code and fix save
* Improve legacy class
* wc_bool_to_string
* prepare_set_attributes
* Use wc_get_products
* More feedback fixes
* Feedback fixes
* Implement CRUD in the legacy REST API
* Handle PR feedback
* [Product CRUD] Getter setter proxy methods (#12236)
* Started on variation changes
* Stock functions
* Variation class
* Bulk change ->id to get_id() to fix variation form display
* Missing status
* Fix add to cart
* Start on stored data save
* save variation
* Save_variations
* Variation edit panel
* Save variations code works.
* Remove stored data code and fix save
* Improve legacy class
* wc_bool_to_string
* prepare_set_attributes
* Use wc_get_products
* More feedback fixes
* get_prop implementation in abstract and data classes
* Implement set_prop
* Change handling
* Array key exists
* set_object_read
* Use get_the_terms() instead of wp_get_post_terms()
wp_get_post_terms() is a wrapper around wp_get_object_terms() which does not
use the object cache, and generates a database query every time it is used.
get_the_terms() however can use data from the object cache if present.
* Allow WP_Query to preload post data, and meta in wc_get_products()
Allow WP_Query to bulk query for post data and meta if more than
just IDs are requested from wc_get_products(). Reduces query count
significantly.
* [Product CRUD] Variable, variation, notices, and stock handling (#12277)
* No longer needed
* Remove old todos
* Use getters in admin list
* Related and upsells update for CRUD
* Fix notice in gallery
* Variable fixes and todos
* Context
* Price sync
* Revert variation attributes change
* Return parent data in view context
* Defer term counting
* wc_find_matching_product_variation
* Stock manage tweaks
* Stock fixes
* Correct id
* correct id
* Better sync
* Data logic setter fix
* feedback
* First methods for WP_Product crud
* Product set methods
* Fixed several erros while setting data
* Hardcode the get_type per product class
* Initial look through getters and setters and abstract data
* Missing var
* Fixed coding standards and improved the docblocks
* Get cached terms from wc_get_related_terms()
* Fixed wrong variable in wc_get_related_terms
* Use count() instead of sizeof()
* Add related product functions and deprecate those in class.
* No need to exclude ID
* Sanitize ids later
* Clean up the abstract product class a bit, deprecate two functions we have renamed, make update & create work properly, and add some tests for it.
* Remove unneeded comments
* wc_get_product_term_ids instead of related wording and use in other places.
get_the_terms is used here and also handles caching, something
wp_get_post_terms does not.
* Handle PR feedback: Remove duplicate regular_price update, allow changing of post status for products, remove deprecation for get_title since we might still offer it as a function
* External Product CRUD
* _virtual meta should be 'no', not taxable, in product unit test helper
* Bump template version
* Made abstract function useful
* Grouped product class
* Tests
* Move children to meta and update test
* Use get_upsell_ids
* Spacing in query
* Moving and refactoring methods
* Availability html
* Tidy/add todos
* Rename method
* Put back review functions (still todo)
* missing $this
* get_price_including_tax/excluding_tax functions
* wc_get_price_to_display
* Price handling
* [Product CRUD] Variable (#12146)
* [Product CRUD] Variable Products
* Handle PR feedback.
* [Product CRUD] Grouped Handling (#12151)
* Handle grouped product saving
* Update routine
* [Product CRUD] Product crud terms (#12149)
* Category and tag id handling
* Replace template functions
* Remove todo
* Handle default name in save function
* Product crud admin save routine (#12174)
* Initial props
* Work on admin saving
* Set/get attributes
* Atom was moaning about this before but no longer.
* Update get_shipping_class
* WC_Product_Attribute
* Use getter in admin panel
* Fix attribute saving
* Spacing
* Fix comment
* wc_implode_text_attributes helper function
* [Product CRUD] Product crud admin use getters (#12196)
* Initial props
* Work on admin saving
* Set/get attributes
* Atom was moaning about this before but no longer.
* Update get_shipping_class
* WC_Product_Attribute
* Use getter in admin panel
* Fix attribute saving
* Move settings into new files
* Refactor panels and use getters
* Use getters for variation panel
* Revert save variation changes for now
* Add todos
* Fix downloads
* REST API CRUD Updates
* Additional API updates/fixes. Added some todos
* Fix final failing tests and implementing setters/getters and attributes functionality.
* Fix comparison for is_on_sale and remove download_type from WC_Product.
* Add a wc_get_products wrapper.
* Remove the download type input from the product data metabox for downloadable products. (#12221)
* [Product CRUD] Variations - setters, getters and admin. (#12228)
* Started on variation changes
* Stock functions
* Variation class
* Bulk change ->id to get_id() to fix variation form display
* Missing status
* Fix add to cart
* Start on stored data save
* save variation
* Save_variations
* Variation edit panel
* Save variations code works.
* Remove stored data code and fix save
* Improve legacy class
* wc_bool_to_string
* prepare_set_attributes
* Use wc_get_products
* More feedback fixes
* Feedback fixes
* Implement CRUD in the legacy REST API
* Handle PR feedback
* [Product CRUD] Getter setter proxy methods (#12236)
* Started on variation changes
* Stock functions
* Variation class
* Bulk change ->id to get_id() to fix variation form display
* Missing status
* Fix add to cart
* Start on stored data save
* save variation
* Save_variations
* Variation edit panel
* Save variations code works.
* Remove stored data code and fix save
* Improve legacy class
* wc_bool_to_string
* prepare_set_attributes
* Use wc_get_products
* More feedback fixes
* get_prop implementation in abstract and data classes
* Implement set_prop
* Change handling
* Array key exists
* set_object_read
* Use get_the_terms() instead of wp_get_post_terms()
wp_get_post_terms() is a wrapper around wp_get_object_terms() which does not
use the object cache, and generates a database query every time it is used.
get_the_terms() however can use data from the object cache if present.
* [Product CRUD] Variable, variation, notices, and stock handling (#12277)
* No longer needed
* Remove old todos
* Use getters in admin list
* Related and upsells update for CRUD
* Fix notice in gallery
* Variable fixes and todos
* Context
* Price sync
* Revert variation attributes change
* Return parent data in view context
* Defer term counting
* wc_find_matching_product_variation
* Stock manage tweaks
* Stock fixes
* Correct id
* correct id
* Better sync
* Data logic setter fix
* feedback
* Prevent notices
* Handle image_id from parent
* Fix error
* Remove _wc_save_product_price
* Remove todo
* Fixed wrong variation URLs
* Fixed undefined $image_id in WC_Product_Variation::get_image_id()
* Allow wc_rest_prepare_date_response() handle timestamps
* Updated get methods on REST API for variations
* Use variations CRUD to save variations metadata
* [Product CRUD] Abstract todos (#12305)
* Get dimensions and weights, with soft deprecation
* Product attributes
* Ratings
* Fix read method
* Downloads
* Feedback
* Revert "[Product CRUD] Abstract todos (#12305)"
This reverts commit 9a6136fcf88fec16f97457b7c8a4388f7587bfa2.
* Remove deprecated get_variation_id()
* New default attributes method
* [Product CRUD] Product Datastore (#12317)
* Fix up tests in the product/* folder.
* Handle data store updates for grouped, variable, external, simple, and general data store updates for products.
* Variations & variable changes.
* Update -functions.php calls to use data store.
* Add an interface for the public product data store methods.
* Finished product factory tests
* Correctly delete in the api, fix up some comments, and implement an interface for the public variable methods.
* Fix up delete in all versions of the api
* Handle feedback
* Match protected decloration to parent
* Product crud abstract todos (#12316)
* Get dimensions and weights, with soft deprecation
* Product attributes
* Ratings
* Fix read method
* Downloads
* Feedback
* Fix up store
* Fixed method returning in write context
* Fix error in variation admin
* Check for parent value - fixes tax class
* Remove old/complete todos
* Allow set tax class as "parent"
* Removed duplicated sync
* Fixed wrong variation URLs
* Fixed undefined $image_id in WC_Product_Variation::get_image_id()
* Allow wc_rest_prepare_date_response() handle timestamps
* Updated get methods on REST API for variations
* Use variations CRUD to save variations metadata
* Remove deprecated get_variation_id()
* New default attributes method
* Fixed method returning in write context
* Allow set tax class as "parent"
* Removed duplicated sync
* Fixed coding standards
* TODO is not accurate.
* Should pass WC_Product instancies to WC_Comments methods (#12327)
* Use new method in abstract order class to prevent headers sent issue in tests
* Fixed variable description in REST API
* Updated how create initial product variation
* Fixed a few fatal errors and warnings in Products CRUD (#12329)
* Fixed a few fatal errors and warnings in Products CRUD
* Fixed sync functions
* Add variations CRUD to legacy API (#12331)
* Apply crud to variable products in legacy API v1
* New REST API do not need fallback for default attributes
* Apply variations CRUD to legacy API v2
* Legacy v2 - save default attributes
* Variations in legacy API v2 do not have descriptions
* Fixed legacy API v2 variations params
* Applied variations CRUD to legacy API v3
* Sync before save in legacy apis
* Punc
* Removed API todos
* Removed test
* Products endpoint tweaks (#12354)
* Var type already normalized on CRUD
* Let Product CRUD handle with validation, sanitization and conditional checks
* Set downloads using WC_Product_Download
* Stop try catch exceptions more than one time
* Handle WC_Data_Exception in legacy API
* Complete remove products when fails on creating
* On creating I mean!
* Already have a method to complete delete products
* Fixed standards using WP CodeSniffer
* get_the_terms() returns false when empty
* get_manage_stock returns boolean
@claudiosanches
* Merge conflict
* Variations API endpoint fixes
* Product CRUD improvements (#12359)
* args is not used any more - remove todo
* Added test for attributes
* wc_get_price_excluding_tax usage
* parent usage
* Fix rating counts
* Test fixes
* Cleanup after tests
* Make sure status transition code runs even during API calls, not just in admin.
* Default visibility
* Fix attribute setting in API
* Use get name instead of get title
* variation id usage
* Improved cross sell templates
* variation_data
* Grouped product sync
* Notices
* Sync is not needed in API
* Delete
* Rename interfaces
* Update counts in data store
2016-11-16 12:38:24 +00:00
// Set this to pass to legacy actions.
2016-08-09 13:02:40 +00:00
$item -> legacy_fee = $fee ;
$item -> legacy_fee_key = $fee_key ;
$order -> add_item ( $item );
2013-08-08 11:37:42 +00:00
}
2014-06-18 15:03:46 +00:00
// Store shipping for all packages
foreach ( WC () -> shipping -> get_packages () as $package_key => $package ) {
if ( isset ( $package [ 'rates' ][ $this -> shipping_methods [ $package_key ] ] ) ) {
2016-08-09 13:02:40 +00:00
$shipping_rate = $package [ 'rates' ][ $this -> shipping_methods [ $package_key ] ];
2016-11-17 21:30:34 +00:00
$item = new WC_Order_Item_Shipping ();
$item -> set_props ( array (
2016-08-09 13:02:40 +00:00
'method_title' => $shipping_rate -> label ,
'method_id' => $shipping_rate -> id ,
'total' => wc_format_decimal ( $shipping_rate -> cost ),
'taxes' => $shipping_rate -> taxes ,
'meta_data' => $shipping_rate -> get_meta_data (),
) );
WIP - Product CRUD (#12065)
* Created function to get the catalog visibility options
* First methods for WP_Product crud
* Product set methods
* Fixed several erros while setting data
* First methods for WP_Product crud
* Product set methods
* Fixed several erros while setting data
* Hardcode the get_type per product class
* Initial look through getters and setters and abstract data
* Missing var
* Add related product functions and deprecate those in class.
* No need to exclude ID
* Fixed coding standards and improved the docblocks
* Get cached terms from wc_get_related_terms()
* Fixed wrong variable in wc_get_related_terms
* Use count() instead of sizeof()
* Sanitize ids later
* Remove unneeded comments
* wc_get_product_term_ids instead of related wording and use in other places.
get_the_terms is used here and also handles caching, something
wp_get_post_terms does not.
* Clean up the abstract product class a bit, deprecate two functions we have renamed, make update & create work properly, and add some tests for it.
* Bump template version
* Handle PR feedback: Remove duplicate regular_price update, allow changing of post status for products, remove deprecation for get_title since we might still offer it as a function
* Made abstract function useful
* External Product CRUD
* _virtual meta should be 'no', not taxable, in product unit test helper
* Grouped product class
* Tests
* Move children to meta and update test
* Use get_upsell_ids
* Spacing in query
* Moving and refactoring methods
* Availability html
* Tidy/add todos
* Rename method
* Put back review functions (still todo)
* missing $this
* get_price_including_tax/excluding_tax functions
* wc_get_price_to_display
* Price handling
* [Product CRUD] Variable (#12146)
* [Product CRUD] Variable Products
* Handle PR feedback.
* [Product CRUD] Grouped Handling (#12151)
* Handle grouped product saving
* Update routine
* [Product CRUD] Product crud terms (#12149)
* Category and tag id handling
* Replace template functions
* Remove todo
* Handle default name in save function
* Product crud admin save routine (#12174)
* Initial props
* Work on admin saving
* Set/get attributes
* Atom was moaning about this before but no longer.
* Update get_shipping_class
* WC_Product_Attribute
* Use getter in admin panel
* Fix attribute saving
* Spacing
* Fix comment
* wc_implode_text_attributes helper function
* [Product CRUD] Product crud admin use getters (#12196)
* Initial props
* Work on admin saving
* Set/get attributes
* Atom was moaning about this before but no longer.
* Update get_shipping_class
* WC_Product_Attribute
* Use getter in admin panel
* Fix attribute saving
* Move settings into new files
* Refactor panels and use getters
* Use getters for variation panel
* Revert save variation changes for now
* Add todos
* Fix downloads
* REST API CRUD Updates
* Additional API updates/fixes. Added some todos
* Fix final failing tests and implementing setters/getters and attributes functionality.
* Fix comparison for is_on_sale and remove download_type from WC_Product.
* Add a wc_get_products wrapper.
* Remove the download type input from the product data metabox for downloadable products. (#12221)
* [Product CRUD] Variations - setters, getters and admin. (#12228)
* Started on variation changes
* Stock functions
* Variation class
* Bulk change ->id to get_id() to fix variation form display
* Missing status
* Fix add to cart
* Start on stored data save
* save variation
* Save_variations
* Variation edit panel
* Save variations code works.
* Remove stored data code and fix save
* Improve legacy class
* wc_bool_to_string
* prepare_set_attributes
* Use wc_get_products
* More feedback fixes
* Feedback fixes
* Implement CRUD in the legacy REST API
* Handle PR feedback
* [Product CRUD] Getter setter proxy methods (#12236)
* Started on variation changes
* Stock functions
* Variation class
* Bulk change ->id to get_id() to fix variation form display
* Missing status
* Fix add to cart
* Start on stored data save
* save variation
* Save_variations
* Variation edit panel
* Save variations code works.
* Remove stored data code and fix save
* Improve legacy class
* wc_bool_to_string
* prepare_set_attributes
* Use wc_get_products
* More feedback fixes
* get_prop implementation in abstract and data classes
* Implement set_prop
* Change handling
* Array key exists
* set_object_read
* Use get_the_terms() instead of wp_get_post_terms()
wp_get_post_terms() is a wrapper around wp_get_object_terms() which does not
use the object cache, and generates a database query every time it is used.
get_the_terms() however can use data from the object cache if present.
* Allow WP_Query to preload post data, and meta in wc_get_products()
Allow WP_Query to bulk query for post data and meta if more than
just IDs are requested from wc_get_products(). Reduces query count
significantly.
* [Product CRUD] Variable, variation, notices, and stock handling (#12277)
* No longer needed
* Remove old todos
* Use getters in admin list
* Related and upsells update for CRUD
* Fix notice in gallery
* Variable fixes and todos
* Context
* Price sync
* Revert variation attributes change
* Return parent data in view context
* Defer term counting
* wc_find_matching_product_variation
* Stock manage tweaks
* Stock fixes
* Correct id
* correct id
* Better sync
* Data logic setter fix
* feedback
* First methods for WP_Product crud
* Product set methods
* Fixed several erros while setting data
* Hardcode the get_type per product class
* Initial look through getters and setters and abstract data
* Missing var
* Fixed coding standards and improved the docblocks
* Get cached terms from wc_get_related_terms()
* Fixed wrong variable in wc_get_related_terms
* Use count() instead of sizeof()
* Add related product functions and deprecate those in class.
* No need to exclude ID
* Sanitize ids later
* Clean up the abstract product class a bit, deprecate two functions we have renamed, make update & create work properly, and add some tests for it.
* Remove unneeded comments
* wc_get_product_term_ids instead of related wording and use in other places.
get_the_terms is used here and also handles caching, something
wp_get_post_terms does not.
* Handle PR feedback: Remove duplicate regular_price update, allow changing of post status for products, remove deprecation for get_title since we might still offer it as a function
* External Product CRUD
* _virtual meta should be 'no', not taxable, in product unit test helper
* Bump template version
* Made abstract function useful
* Grouped product class
* Tests
* Move children to meta and update test
* Use get_upsell_ids
* Spacing in query
* Moving and refactoring methods
* Availability html
* Tidy/add todos
* Rename method
* Put back review functions (still todo)
* missing $this
* get_price_including_tax/excluding_tax functions
* wc_get_price_to_display
* Price handling
* [Product CRUD] Variable (#12146)
* [Product CRUD] Variable Products
* Handle PR feedback.
* [Product CRUD] Grouped Handling (#12151)
* Handle grouped product saving
* Update routine
* [Product CRUD] Product crud terms (#12149)
* Category and tag id handling
* Replace template functions
* Remove todo
* Handle default name in save function
* Product crud admin save routine (#12174)
* Initial props
* Work on admin saving
* Set/get attributes
* Atom was moaning about this before but no longer.
* Update get_shipping_class
* WC_Product_Attribute
* Use getter in admin panel
* Fix attribute saving
* Spacing
* Fix comment
* wc_implode_text_attributes helper function
* [Product CRUD] Product crud admin use getters (#12196)
* Initial props
* Work on admin saving
* Set/get attributes
* Atom was moaning about this before but no longer.
* Update get_shipping_class
* WC_Product_Attribute
* Use getter in admin panel
* Fix attribute saving
* Move settings into new files
* Refactor panels and use getters
* Use getters for variation panel
* Revert save variation changes for now
* Add todos
* Fix downloads
* REST API CRUD Updates
* Additional API updates/fixes. Added some todos
* Fix final failing tests and implementing setters/getters and attributes functionality.
* Fix comparison for is_on_sale and remove download_type from WC_Product.
* Add a wc_get_products wrapper.
* Remove the download type input from the product data metabox for downloadable products. (#12221)
* [Product CRUD] Variations - setters, getters and admin. (#12228)
* Started on variation changes
* Stock functions
* Variation class
* Bulk change ->id to get_id() to fix variation form display
* Missing status
* Fix add to cart
* Start on stored data save
* save variation
* Save_variations
* Variation edit panel
* Save variations code works.
* Remove stored data code and fix save
* Improve legacy class
* wc_bool_to_string
* prepare_set_attributes
* Use wc_get_products
* More feedback fixes
* Feedback fixes
* Implement CRUD in the legacy REST API
* Handle PR feedback
* [Product CRUD] Getter setter proxy methods (#12236)
* Started on variation changes
* Stock functions
* Variation class
* Bulk change ->id to get_id() to fix variation form display
* Missing status
* Fix add to cart
* Start on stored data save
* save variation
* Save_variations
* Variation edit panel
* Save variations code works.
* Remove stored data code and fix save
* Improve legacy class
* wc_bool_to_string
* prepare_set_attributes
* Use wc_get_products
* More feedback fixes
* get_prop implementation in abstract and data classes
* Implement set_prop
* Change handling
* Array key exists
* set_object_read
* Use get_the_terms() instead of wp_get_post_terms()
wp_get_post_terms() is a wrapper around wp_get_object_terms() which does not
use the object cache, and generates a database query every time it is used.
get_the_terms() however can use data from the object cache if present.
* [Product CRUD] Variable, variation, notices, and stock handling (#12277)
* No longer needed
* Remove old todos
* Use getters in admin list
* Related and upsells update for CRUD
* Fix notice in gallery
* Variable fixes and todos
* Context
* Price sync
* Revert variation attributes change
* Return parent data in view context
* Defer term counting
* wc_find_matching_product_variation
* Stock manage tweaks
* Stock fixes
* Correct id
* correct id
* Better sync
* Data logic setter fix
* feedback
* Prevent notices
* Handle image_id from parent
* Fix error
* Remove _wc_save_product_price
* Remove todo
* Fixed wrong variation URLs
* Fixed undefined $image_id in WC_Product_Variation::get_image_id()
* Allow wc_rest_prepare_date_response() handle timestamps
* Updated get methods on REST API for variations
* Use variations CRUD to save variations metadata
* [Product CRUD] Abstract todos (#12305)
* Get dimensions and weights, with soft deprecation
* Product attributes
* Ratings
* Fix read method
* Downloads
* Feedback
* Revert "[Product CRUD] Abstract todos (#12305)"
This reverts commit 9a6136fcf88fec16f97457b7c8a4388f7587bfa2.
* Remove deprecated get_variation_id()
* New default attributes method
* [Product CRUD] Product Datastore (#12317)
* Fix up tests in the product/* folder.
* Handle data store updates for grouped, variable, external, simple, and general data store updates for products.
* Variations & variable changes.
* Update -functions.php calls to use data store.
* Add an interface for the public product data store methods.
* Finished product factory tests
* Correctly delete in the api, fix up some comments, and implement an interface for the public variable methods.
* Fix up delete in all versions of the api
* Handle feedback
* Match protected decloration to parent
* Product crud abstract todos (#12316)
* Get dimensions and weights, with soft deprecation
* Product attributes
* Ratings
* Fix read method
* Downloads
* Feedback
* Fix up store
* Fixed method returning in write context
* Fix error in variation admin
* Check for parent value - fixes tax class
* Remove old/complete todos
* Allow set tax class as "parent"
* Removed duplicated sync
* Fixed wrong variation URLs
* Fixed undefined $image_id in WC_Product_Variation::get_image_id()
* Allow wc_rest_prepare_date_response() handle timestamps
* Updated get methods on REST API for variations
* Use variations CRUD to save variations metadata
* Remove deprecated get_variation_id()
* New default attributes method
* Fixed method returning in write context
* Allow set tax class as "parent"
* Removed duplicated sync
* Fixed coding standards
* TODO is not accurate.
* Should pass WC_Product instancies to WC_Comments methods (#12327)
* Use new method in abstract order class to prevent headers sent issue in tests
* Fixed variable description in REST API
* Updated how create initial product variation
* Fixed a few fatal errors and warnings in Products CRUD (#12329)
* Fixed a few fatal errors and warnings in Products CRUD
* Fixed sync functions
* Add variations CRUD to legacy API (#12331)
* Apply crud to variable products in legacy API v1
* New REST API do not need fallback for default attributes
* Apply variations CRUD to legacy API v2
* Legacy v2 - save default attributes
* Variations in legacy API v2 do not have descriptions
* Fixed legacy API v2 variations params
* Applied variations CRUD to legacy API v3
* Sync before save in legacy apis
* Punc
* Removed API todos
* Removed test
* Products endpoint tweaks (#12354)
* Var type already normalized on CRUD
* Let Product CRUD handle with validation, sanitization and conditional checks
* Set downloads using WC_Product_Download
* Stop try catch exceptions more than one time
* Handle WC_Data_Exception in legacy API
* Complete remove products when fails on creating
* On creating I mean!
* Already have a method to complete delete products
* Fixed standards using WP CodeSniffer
* get_the_terms() returns false when empty
* get_manage_stock returns boolean
@claudiosanches
* Merge conflict
* Variations API endpoint fixes
* Product CRUD improvements (#12359)
* args is not used any more - remove todo
* Added test for attributes
* wc_get_price_excluding_tax usage
* parent usage
* Fix rating counts
* Test fixes
* Cleanup after tests
* Make sure status transition code runs even during API calls, not just in admin.
* Default visibility
* Fix attribute setting in API
* Use get name instead of get title
* variation id usage
* Improved cross sell templates
* variation_data
* Grouped product sync
* Notices
* Sync is not needed in API
* Delete
* Rename interfaces
* Update counts in data store
2016-11-16 12:38:24 +00:00
// Set this to pass to legacy actions.
2016-08-09 13:02:40 +00:00
$item -> legacy_package_key = $package_key ;
$order -> add_item ( $item );
2012-12-12 21:14:19 +00:00
}
}
2014-06-18 15:03:46 +00:00
// Store tax rows
foreach ( array_keys ( WC () -> cart -> taxes + WC () -> cart -> shipping_taxes ) as $tax_rate_id ) {
2016-09-07 22:32:24 +00:00
if ( $tax_rate_id && apply_filters ( 'woocommerce_cart_remove_taxes_zero_rate_id' , 'zero-rated' ) !== $tax_rate_id ) {
2016-11-17 21:30:34 +00:00
$item = new WC_Order_Item_Tax ();
$item -> set_props ( array (
2016-08-09 13:02:40 +00:00
'rate_id' => $tax_rate_id ,
'tax_total' => WC () -> cart -> get_tax_amount ( $tax_rate_id ),
'shipping_tax_total' => WC () -> cart -> get_shipping_tax_amount ( $tax_rate_id ),
'rate_code' => WC_Tax :: get_rate_code ( $tax_rate_id ),
'label' => WC_Tax :: get_rate_label ( $tax_rate_id ),
'compound' => WC_Tax :: is_compound ( $tax_rate_id ),
2016-11-17 21:30:34 +00:00
) );
$order -> add_item ( $item );
2014-03-19 12:58:35 +00:00
}
2013-08-16 15:43:26 +00:00
}
2014-06-18 15:03:46 +00:00
// Store coupons
foreach ( WC () -> cart -> get_coupons () as $code => $coupon ) {
2016-11-17 21:30:34 +00:00
$item = new WC_Order_Item_Coupon ();
$item -> set_props ( array (
2016-08-09 13:02:40 +00:00
'code' => $code ,
'discount' => WC () -> cart -> get_coupon_discount_amount ( $code ),
'discount_tax' => WC () -> cart -> get_coupon_discount_tax_amount ( $code ),
) );
$order -> add_item ( $item );
2012-12-12 21:14:19 +00:00
}
2016-08-09 13:02:40 +00:00
// Save the order
$order_id = $order -> save ();
2014-06-18 15:03:46 +00:00
// Update user meta
2016-08-09 13:02:40 +00:00
$this -> update_customer_data ();
2012-12-12 21:14:19 +00:00
2016-08-09 13:02:40 +00:00
// Let plugins add their own meta data
2014-06-18 15:03:46 +00:00
do_action ( 'woocommerce_checkout_update_order_meta' , $order_id , $this -> posted );
// If we got here, the order was created without problems!
2015-11-04 14:11:40 +00:00
wc_transaction_query ( 'commit' );
2014-06-18 15:03:46 +00:00
} catch ( Exception $e ) {
// There was an error adding order data!
2015-11-04 14:11:40 +00:00
wc_transaction_query ( 'rollback' );
2014-06-18 15:03:46 +00:00
return new WP_Error ( 'checkout-error' , $e -> getMessage () );
2014-02-13 15:51:16 +00:00
}
2012-12-12 21:14:19 +00:00
return $order_id ;
}
2016-08-09 13:02:40 +00:00
/**
* Store customer data to meta .
* @ since 2.7 . 0
*/
protected function update_customer_data () {
if ( $this -> customer_id ) {
if ( apply_filters ( 'woocommerce_checkout_update_customer_data' , true , $this ) ) {
$customer = new WC_Customer ( $this -> customer_id );
if ( $keys = array_keys ( $this -> checkout_fields [ 'billing' ] ) ) {
foreach ( $keys as $key ) {
if ( is_callable ( array ( $customer , " set_ { $key } " ) ) ) {
$customer -> { " set_ { $key } " }( $this -> get_posted_address_data ( str_replace ( array ( 'billing_' , 'shipping_' ), '' , $key ) ) );
}
}
}
if ( WC () -> cart -> needs_shipping () && ( $keys = array_keys ( $this -> checkout_fields [ 'shipping' ] ) ) ) {
foreach ( $keys as $key ) {
if ( is_callable ( array ( $customer , " set_ { $key } " ) ) ) {
$customer -> { " set_ { $key } " }( $this -> get_posted_address_data ( str_replace ( array ( 'billing_' , 'shipping_' ), '' , $key ), 'shipping' ) );
}
}
}
$customer -> save ();
}
do_action ( 'woocommerce_checkout_update_user_meta' , $this -> customer_id , $this -> posted );
}
}
2011-09-12 15:34:29 +00:00
/**
2015-11-03 13:31:20 +00:00
* Process the checkout after the confirm order button is pressed .
2011-09-12 15:34:29 +00:00
*/
2012-12-14 21:27:29 +00:00
public function process_checkout () {
2014-10-31 15:03:53 +00:00
try {
if ( empty ( $_POST [ '_wpnonce' ] ) || ! wp_verify_nonce ( $_POST [ '_wpnonce' ], 'woocommerce-process_checkout' ) ) {
WC () -> session -> set ( 'refresh_totals' , true );
throw new Exception ( __ ( 'We were unable to process your order, please try again.' , 'woocommerce' ) );
}
2012-12-12 21:14:19 +00:00
2014-10-31 15:03:53 +00:00
if ( ! defined ( 'WOOCOMMERCE_CHECKOUT' ) ) {
define ( 'WOOCOMMERCE_CHECKOUT' , true );
}
2012-08-10 11:15:32 +00:00
2014-10-31 15:03:53 +00:00
// Prevent timeout
2016-09-02 01:51:31 +00:00
@ set_time_limit ( 0 );
2012-08-10 11:15:32 +00:00
2014-10-31 15:03:53 +00:00
do_action ( 'woocommerce_before_checkout_process' );
2012-01-12 00:43:30 +00:00
2015-05-14 21:18:53 +00:00
if ( WC () -> cart -> is_empty () ) {
2016-05-17 22:00:09 +00:00
throw new Exception ( sprintf ( __ ( 'Sorry, your session has expired. <a href="%s" class="wc-backward">Return to shop</a>' , 'woocommerce' ), esc_url ( wc_get_page_permalink ( 'shop' ) ) ) );
2014-10-31 15:03:53 +00:00
}
2012-08-10 11:15:32 +00:00
2014-10-31 15:03:53 +00:00
do_action ( 'woocommerce_checkout_process' );
2012-01-12 00:43:30 +00:00
2014-10-31 15:03:53 +00:00
// Checkout fields (not defined in checkout_fields)
$this -> posted [ 'terms' ] = isset ( $_POST [ 'terms' ] ) ? 1 : 0 ;
$this -> posted [ 'createaccount' ] = isset ( $_POST [ 'createaccount' ] ) && ! empty ( $_POST [ 'createaccount' ] ) ? 1 : 0 ;
$this -> posted [ 'payment_method' ] = isset ( $_POST [ 'payment_method' ] ) ? stripslashes ( $_POST [ 'payment_method' ] ) : '' ;
$this -> posted [ 'shipping_method' ] = isset ( $_POST [ 'shipping_method' ] ) ? $_POST [ 'shipping_method' ] : '' ;
2016-07-22 11:59:51 +00:00
$this -> posted [ 'ship_to_different_address' ] = ! empty ( $_POST [ 'ship_to_different_address' ] );
2013-05-28 13:19:08 +00:00
2014-10-31 15:03:53 +00:00
if ( isset ( $_POST [ 'shiptobilling' ] ) ) {
_deprecated_argument ( 'WC_Checkout::process_checkout()' , '2.1' , 'The "shiptobilling" field is deprecated. The template files are out of date' );
2013-05-28 13:19:08 +00:00
2014-10-31 15:03:53 +00:00
$this -> posted [ 'ship_to_different_address' ] = $_POST [ 'shiptobilling' ] ? false : true ;
}
2012-08-10 11:15:32 +00:00
2014-10-31 15:03:53 +00:00
// Ship to billing only option
2015-10-28 18:03:24 +00:00
if ( wc_ship_to_billing_address_only () ) {
2014-10-31 15:03:53 +00:00
$this -> posted [ 'ship_to_different_address' ] = false ;
}
2012-08-10 11:15:32 +00:00
2014-10-31 15:03:53 +00:00
// Update customer shipping and payment method to posted method
$chosen_shipping_methods = WC () -> session -> get ( 'chosen_shipping_methods' );
2013-08-14 20:00:34 +00:00
2014-10-31 15:03:53 +00:00
if ( isset ( $this -> posted [ 'shipping_method' ] ) && is_array ( $this -> posted [ 'shipping_method' ] ) ) {
foreach ( $this -> posted [ 'shipping_method' ] as $i => $value ) {
$chosen_shipping_methods [ $i ] = wc_clean ( $value );
}
2014-05-01 13:40:00 +00:00
}
2013-08-14 20:00:34 +00:00
2014-10-31 15:03:53 +00:00
WC () -> session -> set ( 'chosen_shipping_methods' , $chosen_shipping_methods );
WC () -> session -> set ( 'chosen_payment_method' , $this -> posted [ 'payment_method' ] );
2012-08-10 11:15:32 +00:00
2014-10-31 15:03:53 +00:00
// Note if we skip shipping
$skipped_shipping = false ;
2012-08-10 11:15:32 +00:00
2014-10-31 15:03:53 +00:00
// Get posted checkout_fields and do validation
foreach ( $this -> checkout_fields as $fieldset_key => $fieldset ) {
2012-08-10 11:15:32 +00:00
2014-10-31 15:03:53 +00:00
// Skip shipping if not needed
2016-09-07 22:32:24 +00:00
if ( 'shipping' === $fieldset_key && ( false == $this -> posted [ 'ship_to_different_address' ] || ! WC () -> cart -> needs_shipping_address () ) ) {
2014-10-31 15:03:53 +00:00
$skipped_shipping = true ;
continue ;
}
2012-08-10 11:15:32 +00:00
2014-10-31 15:03:53 +00:00
// Skip account if not needed
2016-06-06 18:39:23 +00:00
if ( 'account' === $fieldset_key && ( is_user_logged_in () || ( false === $this -> must_create_account && empty ( $this -> posted [ 'createaccount' ] ) ) ) ) {
2014-10-31 15:03:53 +00:00
continue ;
}
2013-07-19 05:58:45 +00:00
2014-10-31 15:03:53 +00:00
foreach ( $fieldset as $key => $field ) {
2012-08-10 11:15:32 +00:00
2014-10-31 15:03:53 +00:00
if ( ! isset ( $field [ 'type' ] ) ) {
$field [ 'type' ] = 'text' ;
}
2012-08-10 11:15:32 +00:00
2014-10-31 15:03:53 +00:00
// Get Value
switch ( $field [ 'type' ] ) {
2016-09-13 22:04:33 +00:00
case 'checkbox' :
$this -> posted [ $key ] = ( int ) isset ( $_POST [ $key ] );
break ;
case 'multiselect' :
2014-10-31 15:03:53 +00:00
$this -> posted [ $key ] = isset ( $_POST [ $key ] ) ? implode ( ', ' , array_map ( 'wc_clean' , $_POST [ $key ] ) ) : '' ;
2016-09-13 22:04:33 +00:00
break ;
case 'textarea' :
2014-10-31 15:03:53 +00:00
$this -> posted [ $key ] = isset ( $_POST [ $key ] ) ? wp_strip_all_tags ( wp_check_invalid_utf8 ( stripslashes ( $_POST [ $key ] ) ) ) : '' ;
2016-09-13 22:04:33 +00:00
break ;
2014-10-31 15:03:53 +00:00
default :
$this -> posted [ $key ] = isset ( $_POST [ $key ] ) ? ( is_array ( $_POST [ $key ] ) ? array_map ( 'wc_clean' , $_POST [ $key ] ) : wc_clean ( $_POST [ $key ] ) ) : '' ;
2016-09-13 22:04:33 +00:00
break ;
2014-10-31 15:03:53 +00:00
}
2012-08-10 11:15:32 +00:00
2014-10-31 15:03:53 +00:00
// Hooks to allow modification of value
$this -> posted [ $key ] = apply_filters ( 'woocommerce_process_checkout_' . sanitize_title ( $field [ 'type' ] ) . '_field' , $this -> posted [ $key ] );
$this -> posted [ $key ] = apply_filters ( 'woocommerce_process_checkout_field_' . $key , $this -> posted [ $key ] );
2012-08-10 11:15:32 +00:00
2014-10-31 15:03:53 +00:00
// Validation: Required fields
2016-05-31 17:02:15 +00:00
if ( isset ( $field [ 'required' ] ) && $field [ 'required' ] && ( ! isset ( $this -> posted [ $key ] ) || " " === $this -> posted [ $key ] ) ) {
2016-03-14 11:54:12 +00:00
switch ( $fieldset_key ) {
case 'shipping' :
2016-10-24 07:31:07 +00:00
/* translators: %s: field name */
$field_label = sprintf ( __ ( 'Shipping %s' , 'woocommerce' ), $field [ 'label' ] );
2016-03-14 11:54:12 +00:00
break ;
case 'billing' :
2016-10-24 07:31:07 +00:00
/* translators: %s: field name */
$field_label = sprintf ( __ ( 'Billing %s' , 'woocommerce' ), $field [ 'label' ] );
2016-03-14 11:54:12 +00:00
break ;
default :
$field_label = $field [ 'label' ];
break ;
}
2016-10-24 07:31:07 +00:00
/* translators: %s: field name */
wc_add_notice ( apply_filters ( 'woocommerce_checkout_required_field_notice' , sprintf ( __ ( '%s is a required field.' , 'woocommerce' ), '<strong>' . $field_label . '</strong>' ), $field_label ), 'error' );
2014-10-31 15:03:53 +00:00
}
2012-08-10 11:15:32 +00:00
2014-10-31 15:03:53 +00:00
if ( ! empty ( $this -> posted [ $key ] ) ) {
// Validation rules
if ( ! empty ( $field [ 'validate' ] ) && is_array ( $field [ 'validate' ] ) ) {
foreach ( $field [ 'validate' ] as $rule ) {
switch ( $rule ) {
case 'postcode' :
$this -> posted [ $key ] = strtoupper ( str_replace ( ' ' , '' , $this -> posted [ $key ] ) );
2016-09-13 22:04:33 +00:00
if ( ! WC_Validation :: is_postcode ( $this -> posted [ $key ], $_POST [ $fieldset_key . '_country' ] ) ) {
2016-10-11 01:39:13 +00:00
wc_add_notice ( __ ( 'Please enter a valid postcode / ZIP.' , 'woocommerce' ), 'error' );
2016-09-13 22:04:33 +00:00
} else {
2014-10-31 15:03:53 +00:00
$this -> posted [ $key ] = wc_format_postcode ( $this -> posted [ $key ], $_POST [ $fieldset_key . '_country' ] );
2016-09-13 22:04:33 +00:00
}
break ;
2014-10-31 15:03:53 +00:00
case 'phone' :
$this -> posted [ $key ] = wc_format_phone_number ( $this -> posted [ $key ] );
2016-09-13 22:04:33 +00:00
if ( ! WC_Validation :: is_phone ( $this -> posted [ $key ] ) ) {
2016-10-29 12:57:09 +00:00
/* translators: %s: phone number */
2016-10-26 16:35:52 +00:00
wc_add_notice ( sprintf ( __ ( '%s is not a valid phone number.' , 'woocommerce' ), '<strong>' . $field [ 'label' ] . '</strong>' ), 'error' );
2016-09-13 22:04:33 +00:00
}
break ;
2014-10-31 15:03:53 +00:00
case 'email' :
$this -> posted [ $key ] = strtolower ( $this -> posted [ $key ] );
2016-09-13 22:04:33 +00:00
if ( ! is_email ( $this -> posted [ $key ] ) ) {
2016-10-29 12:57:09 +00:00
/* translators: %s: email address */
2016-10-26 16:35:52 +00:00
wc_add_notice ( sprintf ( __ ( '%s is not a valid email address.' , 'woocommerce' ), '<strong>' . $field [ 'label' ] . '</strong>' ), 'error' );
2016-09-13 22:04:33 +00:00
}
break ;
2014-10-31 15:03:53 +00:00
case 'state' :
// Get valid states
$valid_states = WC () -> countries -> get_states ( isset ( $_POST [ $fieldset_key . '_country' ] ) ? $_POST [ $fieldset_key . '_country' ] : ( 'billing' === $fieldset_key ? WC () -> customer -> get_country () : WC () -> customer -> get_shipping_country () ) );
if ( ! empty ( $valid_states ) && is_array ( $valid_states ) ) {
$valid_state_values = array_flip ( array_map ( 'strtolower' , $valid_states ) );
// Convert value to key if set
if ( isset ( $valid_state_values [ strtolower ( $this -> posted [ $key ] ) ] ) ) {
2016-09-13 22:04:33 +00:00
$this -> posted [ $key ] = $valid_state_values [ strtolower ( $this -> posted [ $key ] ) ];
2014-10-31 15:03:53 +00:00
}
2014-09-22 12:23:28 +00:00
}
2013-09-19 13:39:49 +00:00
2014-10-31 15:03:53 +00:00
// Only validate if the country has specific state options
if ( ! empty ( $valid_states ) && is_array ( $valid_states ) && sizeof ( $valid_states ) > 0 ) {
if ( ! in_array ( $this -> posted [ $key ], array_keys ( $valid_states ) ) ) {
2016-10-29 12:57:09 +00:00
/* translators: 1: state field 2: valid states */
2016-10-26 21:58:46 +00:00
wc_add_notice ( sprintf ( __ ( '%1$s is not valid. Please enter one of the following: %2$s' , 'woocommerce' ), '<strong>' . $field [ 'label' ] . '</strong>' , implode ( ', ' , $valid_states ) ), 'error' );
2014-10-31 15:03:53 +00:00
}
2014-09-22 12:23:28 +00:00
}
2016-09-13 22:04:33 +00:00
break ;
2014-10-31 15:03:53 +00:00
}
2013-09-19 13:39:49 +00:00
}
}
2012-07-16 19:21:44 +00:00
}
}
}
2012-08-10 11:15:32 +00:00
2012-01-12 00:54:45 +00:00
// Update customer location to posted location so we can correctly check available shipping methods
2014-09-22 12:23:28 +00:00
if ( isset ( $this -> posted [ 'billing_country' ] ) ) {
2016-08-04 20:13:07 +00:00
WC () -> customer -> set_billing_country ( $this -> posted [ 'billing_country' ] );
2014-09-22 12:23:28 +00:00
}
if ( isset ( $this -> posted [ 'billing_state' ] ) ) {
2016-08-04 20:13:07 +00:00
WC () -> customer -> set_billing_state ( $this -> posted [ 'billing_state' ] );
2014-09-22 12:23:28 +00:00
}
if ( isset ( $this -> posted [ 'billing_postcode' ] ) ) {
2016-08-04 20:13:07 +00:00
WC () -> customer -> set_billing_postcode ( $this -> posted [ 'billing_postcode' ] );
2014-09-22 12:23:28 +00:00
}
2012-08-10 11:15:32 +00:00
2014-10-31 15:03:53 +00:00
// Shipping Information
if ( ! $skipped_shipping ) {
2012-08-10 11:15:32 +00:00
2014-10-31 15:03:53 +00:00
// Update customer location to posted location so we can correctly check available shipping methods
if ( isset ( $this -> posted [ 'shipping_country' ] ) ) {
WC () -> customer -> set_shipping_country ( $this -> posted [ 'shipping_country' ] );
}
if ( isset ( $this -> posted [ 'shipping_state' ] ) ) {
WC () -> customer -> set_shipping_state ( $this -> posted [ 'shipping_state' ] );
}
if ( isset ( $this -> posted [ 'shipping_postcode' ] ) ) {
WC () -> customer -> set_shipping_postcode ( $this -> posted [ 'shipping_postcode' ] );
}
} else {
2012-08-10 11:15:32 +00:00
2014-10-31 15:03:53 +00:00
// Update customer location to posted location so we can correctly check available shipping methods
if ( isset ( $this -> posted [ 'billing_country' ] ) ) {
WC () -> customer -> set_shipping_country ( $this -> posted [ 'billing_country' ] );
}
if ( isset ( $this -> posted [ 'billing_state' ] ) ) {
WC () -> customer -> set_shipping_state ( $this -> posted [ 'billing_state' ] );
}
if ( isset ( $this -> posted [ 'billing_postcode' ] ) ) {
WC () -> customer -> set_shipping_postcode ( $this -> posted [ 'billing_postcode' ] );
}
2014-09-22 12:23:28 +00:00
}
2013-08-02 15:54:28 +00:00
2016-03-09 20:49:02 +00:00
WC () -> customer -> save ();
2014-10-31 15:03:53 +00:00
// Update cart totals now we have customer address
WC () -> cart -> calculate_totals ();
2012-08-10 11:15:32 +00:00
2014-10-31 15:03:53 +00:00
// Terms
2015-10-06 11:33:45 +00:00
if ( ! isset ( $_POST [ 'woocommerce_checkout_update_totals' ] ) && empty ( $this -> posted [ 'terms' ] ) && wc_get_page_id ( 'terms' ) > 0 && apply_filters ( 'woocommerce_checkout_show_terms' , true ) ) {
2014-10-31 15:03:53 +00:00
wc_add_notice ( __ ( 'You must accept our Terms & Conditions.' , 'woocommerce' ), 'error' );
2012-12-12 21:14:19 +00:00
}
2012-08-10 11:15:32 +00:00
2014-10-31 15:03:53 +00:00
if ( WC () -> cart -> needs_shipping () ) {
2016-04-22 18:03:10 +00:00
$shipping_country = WC () -> customer -> get_shipping_country ();
2014-10-31 15:03:53 +00:00
2016-04-22 18:03:10 +00:00
if ( empty ( $shipping_country ) ) {
2016-04-18 13:51:39 +00:00
wc_add_notice ( __ ( 'Please enter an address to continue.' , 'woocommerce' ), 'error' );
} elseif ( ! in_array ( WC () -> customer -> get_shipping_country (), array_keys ( WC () -> countries -> get_shipping_countries () ) ) ) {
2014-10-31 15:03:53 +00:00
wc_add_notice ( sprintf ( __ ( 'Unfortunately <strong>we do not ship %s</strong>. Please enter an alternative shipping address.' , 'woocommerce' ), WC () -> countries -> shipping_to_prefix () . ' ' . WC () -> customer -> get_shipping_country () ), 'error' );
}
2012-08-10 11:15:32 +00:00
2014-10-31 15:03:53 +00:00
// Validate Shipping Methods
$packages = WC () -> shipping -> get_packages ();
2016-06-07 13:02:02 +00:00
$this -> shipping_methods = ( array ) WC () -> session -> get ( 'chosen_shipping_methods' );
2012-08-10 11:15:32 +00:00
2014-10-31 15:03:53 +00:00
foreach ( $packages as $i => $package ) {
if ( ! isset ( $package [ 'rates' ][ $this -> shipping_methods [ $i ] ] ) ) {
2016-03-31 17:54:33 +00:00
wc_add_notice ( __ ( 'No shipping method has been selected. Please double check your address, or contact us if you need any help.' , 'woocommerce' ), 'error' );
2014-10-31 15:03:53 +00:00
$this -> shipping_methods [ $i ] = '' ;
}
}
2012-12-12 21:14:19 +00:00
}
2012-08-10 11:15:32 +00:00
2014-10-31 15:03:53 +00:00
if ( WC () -> cart -> needs_payment () ) {
// Payment Method
$available_gateways = WC () -> payment_gateways -> get_available_payment_gateways ();
2012-08-10 11:15:32 +00:00
2014-10-31 15:03:53 +00:00
if ( ! isset ( $available_gateways [ $this -> posted [ 'payment_method' ] ] ) ) {
$this -> payment_method = '' ;
wc_add_notice ( __ ( 'Invalid payment method.' , 'woocommerce' ), 'error' );
} else {
$this -> payment_method = $available_gateways [ $this -> posted [ 'payment_method' ] ];
$this -> payment_method -> validate_fields ();
}
2015-02-03 15:27:40 +00:00
} else {
$available_gateways = array ();
2014-10-31 15:03:53 +00:00
}
// Action after validation
do_action ( 'woocommerce_after_checkout_validation' , $this -> posted );
if ( ! isset ( $_POST [ 'woocommerce_checkout_update_totals' ] ) && wc_notice_count ( 'error' ) == 0 ) {
2012-08-10 11:15:32 +00:00
2013-06-04 15:33:05 +00:00
// Customer accounts
2013-07-30 13:50:53 +00:00
$this -> customer_id = apply_filters ( 'woocommerce_checkout_customer_id' , get_current_user_id () );
2012-08-10 11:15:32 +00:00
2013-06-04 15:33:05 +00:00
if ( ! is_user_logged_in () && ( $this -> must_create_account || ! empty ( $this -> posted [ 'createaccount' ] ) ) ) {
2012-08-10 11:15:32 +00:00
2013-06-04 15:33:05 +00:00
$username = ! empty ( $this -> posted [ 'account_username' ] ) ? $this -> posted [ 'account_username' ] : '' ;
$password = ! empty ( $this -> posted [ 'account_password' ] ) ? $this -> posted [ 'account_password' ] : '' ;
2013-11-25 12:52:53 +00:00
$new_customer = wc_create_new_customer ( $this -> posted [ 'billing_email' ], $username , $password );
2012-08-10 11:15:32 +00:00
2015-03-27 15:15:40 +00:00
if ( is_wp_error ( $new_customer ) ) {
throw new Exception ( $new_customer -> get_error_message () );
2016-06-07 13:02:02 +00:00
} else {
$this -> customer_id = absint ( $new_customer );
2015-03-27 15:15:40 +00:00
}
2012-12-28 18:45:06 +00:00
2015-03-27 15:15:40 +00:00
wc_set_customer_auth_cookie ( $this -> customer_id );
2013-06-05 11:07:23 +00:00
2015-03-27 15:15:40 +00:00
// As we are now logged in, checkout will need to refresh to show logged in data
WC () -> session -> set ( 'reload_checkout' , true );
2014-07-19 04:08:02 +00:00
2015-03-27 15:15:40 +00:00
// Also, recalculate cart totals to reveal any role-based discounts that were unavailable before registering
2014-05-20 10:08:09 +00:00
WC () -> cart -> calculate_totals ();
2013-09-02 16:43:53 +00:00
2015-03-27 15:15:40 +00:00
// Add customer info from other billing fields
if ( $this -> posted [ 'billing_first_name' ] && apply_filters ( 'woocommerce_checkout_update_customer_data' , true , $this ) ) {
$userdata = array (
2014-07-19 04:08:02 +00:00
'ID' => $this -> customer_id ,
'first_name' => $this -> posted [ 'billing_first_name' ] ? $this -> posted [ 'billing_first_name' ] : '' ,
2013-12-03 12:27:53 +00:00
'last_name' => $this -> posted [ 'billing_last_name' ] ? $this -> posted [ 'billing_last_name' ] : '' ,
2016-08-27 01:46:45 +00:00
'display_name' => $this -> posted [ 'billing_first_name' ] ? $this -> posted [ 'billing_first_name' ] : '' ,
2015-03-27 15:15:40 +00:00
);
wp_update_user ( apply_filters ( 'woocommerce_checkout_customer_userdata' , $userdata , $this ) );
}
2012-09-07 17:26:13 +00:00
}
2012-08-10 11:15:32 +00:00
2013-09-04 10:26:19 +00:00
// Do a final stock check at this point
$this -> check_cart_items ();
2012-12-12 21:14:19 +00:00
// Abort if errors are present
2016-08-25 16:48:36 +00:00
if ( wc_notice_count ( 'error' ) > 0 ) {
return false ;
}
2012-08-10 11:15:32 +00:00
2012-12-12 21:14:19 +00:00
$order_id = $this -> create_order ();
2012-08-10 11:15:32 +00:00
2014-06-18 15:03:46 +00:00
if ( is_wp_error ( $order_id ) ) {
throw new Exception ( $order_id -> get_error_message () );
}
2012-09-07 17:26:13 +00:00
do_action ( 'woocommerce_checkout_order_processed' , $order_id , $this -> posted );
2012-08-10 11:15:32 +00:00
2012-01-12 00:54:45 +00:00
// Process payment
2013-10-24 12:15:42 +00:00
if ( WC () -> cart -> needs_payment () ) {
2012-08-10 11:15:32 +00:00
2012-01-12 00:54:45 +00:00
// Store Order ID in session so it can be re-used after payment failure
2013-10-24 12:15:42 +00:00
WC () -> session -> order_awaiting_payment = $order_id ;
2012-01-10 16:43:06 +00:00
2012-01-12 00:54:45 +00:00
// Process Payment
2012-09-07 17:26:13 +00:00
$result = $available_gateways [ $this -> posted [ 'payment_method' ] ] -> process_payment ( $order_id );
2012-08-10 11:15:32 +00:00
2012-01-12 00:54:45 +00:00
// Redirect to success/confirmation/payment page
2015-12-15 01:15:22 +00:00
if ( isset ( $result [ 'result' ] ) && 'success' === $result [ 'result' ] ) {
2012-08-10 11:15:32 +00:00
2013-12-23 15:47:56 +00:00
$result = apply_filters ( 'woocommerce_payment_successful_result' , $result , $order_id );
2012-08-10 11:15:32 +00:00
2012-09-07 17:26:13 +00:00
if ( is_ajax () ) {
2015-05-15 12:51:51 +00:00
wp_send_json ( $result );
2012-09-07 17:26:13 +00:00
} else {
2012-02-24 20:44:58 +00:00
wp_redirect ( $result [ 'redirect' ] );
2011-08-09 15:16:18 +00:00
exit ;
2012-09-07 17:26:13 +00:00
}
}
} else {
2012-08-10 11:15:32 +00:00
2014-09-22 12:23:28 +00:00
if ( empty ( $order ) ) {
2014-08-15 12:29:21 +00:00
$order = wc_get_order ( $order_id );
2014-09-22 12:23:28 +00:00
}
2012-08-10 11:15:32 +00:00
2012-01-12 00:54:45 +00:00
// No payment was required for order
$order -> payment_complete ();
2012-08-10 11:15:32 +00:00
2012-01-12 00:54:45 +00:00
// Empty the Cart
2013-10-24 12:15:42 +00:00
WC () -> cart -> empty_cart ();
2012-08-10 11:15:32 +00:00
2012-03-05 13:25:02 +00:00
// Get redirect
2013-05-31 15:13:14 +00:00
$return_url = $order -> get_checkout_order_received_url ();
2012-08-10 11:15:32 +00:00
2012-01-12 00:54:45 +00:00
// Redirect to success/confirmation/payment page
2012-09-07 17:26:13 +00:00
if ( is_ajax () ) {
2015-05-15 12:51:51 +00:00
wp_send_json ( array (
'result' => 'success' ,
2016-08-27 01:46:45 +00:00
'redirect' => apply_filters ( 'woocommerce_checkout_no_payment_needed_redirect' , $return_url , $order ),
2015-05-15 12:51:51 +00:00
) );
2012-09-07 17:26:13 +00:00
} else {
2012-08-10 11:15:32 +00:00
wp_safe_redirect (
2013-05-31 15:13:14 +00:00
apply_filters ( 'woocommerce_checkout_no_payment_needed_redirect' , $return_url , $order )
2012-01-18 12:32:39 +00:00
);
2012-01-12 00:54:45 +00:00
exit ;
2012-09-07 17:26:13 +00:00
}
}
}
2014-10-31 15:03:53 +00:00
} catch ( Exception $e ) {
2016-10-28 15:53:54 +00:00
wc_add_notice ( $e -> getMessage (), 'error' );
2014-10-31 15:03:53 +00:00
}
2012-08-10 11:15:32 +00:00
2012-01-12 00:54:45 +00:00
// If we reached this point then there were errors
2012-09-07 17:26:13 +00:00
if ( is_ajax () ) {
2012-08-10 11:15:32 +00:00
2014-07-04 21:22:58 +00:00
// only print notices if not reloading the checkout, otherwise they're lost in the page reload
if ( ! isset ( WC () -> session -> reload_checkout ) ) {
ob_start ();
wc_print_notices ();
$messages = ob_get_clean ();
}
2015-05-15 12:51:51 +00:00
$response = array (
'result' => 'failure' ,
'messages' => isset ( $messages ) ? $messages : '' ,
'refresh' => isset ( WC () -> session -> refresh_totals ) ? 'true' : 'false' ,
2016-08-27 01:46:45 +00:00
'reload' => isset ( WC () -> session -> reload_checkout ) ? 'true' : 'false' ,
2015-05-15 12:51:51 +00:00
);
2012-08-10 11:15:32 +00:00
2013-10-24 12:15:42 +00:00
unset ( WC () -> session -> refresh_totals , WC () -> session -> reload_checkout );
2015-05-15 12:51:51 +00:00
wp_send_json ( $response );
2012-09-07 17:26:13 +00:00
}
2011-08-09 15:16:18 +00:00
}
2012-08-10 11:15:32 +00:00
2014-06-11 14:10:03 +00:00
/**
* Get a posted address field after sanitization and validation .
* @ param string $key
* @ param string $type billing for shipping
* @ return string
*/
public function get_posted_address_data ( $key , $type = 'billing' ) {
if ( 'billing' === $type || false === $this -> posted [ 'ship_to_different_address' ] ) {
$return = isset ( $this -> posted [ 'billing_' . $key ] ) ? $this -> posted [ 'billing_' . $key ] : '' ;
} else {
$return = isset ( $this -> posted [ 'shipping_' . $key ] ) ? $this -> posted [ 'shipping_' . $key ] : '' ;
}
// Use logged in user's billing email if neccessary
if ( 'email' === $key && empty ( $return ) && is_user_logged_in () ) {
$current_user = wp_get_current_user ();
$return = $current_user -> user_email ;
}
return $return ;
}
2012-08-14 19:42:38 +00:00
/**
2015-11-03 13:31:20 +00:00
* Gets the value either from the posted data , or from the users meta data .
2012-08-14 19:42:38 +00:00
*
* @ access public
* @ param string $input
2014-02-13 09:52:43 +00:00
* @ return string | null
2012-08-14 19:42:38 +00:00
*/
2012-12-14 21:27:29 +00:00
public function get_value ( $input ) {
2012-10-19 17:59:17 +00:00
if ( ! empty ( $_POST [ $input ] ) ) {
2012-08-10 11:15:32 +00:00
2013-11-25 13:34:21 +00:00
return wc_clean ( $_POST [ $input ] );
2012-08-10 11:15:32 +00:00
2013-01-07 15:58:19 +00:00
} else {
2012-08-10 11:15:32 +00:00
2013-09-10 14:23:26 +00:00
$value = apply_filters ( 'woocommerce_checkout_get_value' , null , $input );
2016-09-07 22:32:24 +00:00
if ( null !== $value ) {
2013-09-19 14:02:14 +00:00
return $value ;
2014-09-22 12:23:28 +00:00
}
2013-09-10 14:23:26 +00:00
2014-10-21 21:56:20 +00:00
// Get the billing_ and shipping_ address fields
2016-02-12 12:51:08 +00:00
if ( isset ( $this -> checkout_fields [ 'shipping' ] ) && isset ( $this -> checkout_fields [ 'billing' ] ) ) {
2014-10-21 21:56:20 +00:00
2016-02-12 12:51:08 +00:00
$address_fields = array_merge ( $this -> checkout_fields [ 'billing' ], $this -> checkout_fields [ 'shipping' ] );
2012-08-10 11:15:32 +00:00
2016-02-12 12:51:08 +00:00
if ( is_user_logged_in () && is_array ( $address_fields ) && array_key_exists ( $input , $address_fields ) ) {
$current_user = wp_get_current_user ();
if ( $meta = get_user_meta ( $current_user -> ID , $input , true ) ) {
return $meta ;
}
2012-08-10 11:15:32 +00:00
2016-09-07 22:32:24 +00:00
if ( 'billing_email' === $input ) {
2016-02-12 12:51:08 +00:00
return $current_user -> user_email ;
}
2014-09-22 12:23:28 +00:00
}
2013-01-07 15:58:19 +00:00
}
2012-08-10 11:15:32 +00:00
2013-09-19 14:02:14 +00:00
switch ( $input ) {
2014-10-21 21:56:20 +00:00
case 'billing_country' :
2016-08-04 20:13:07 +00:00
return apply_filters ( 'default_checkout_country' , WC () -> customer -> get_billing_country () ? WC () -> customer -> get_billing_country () : '' , 'billing' );
2014-10-21 21:56:20 +00:00
case 'billing_state' :
2016-08-04 20:13:07 +00:00
return apply_filters ( 'default_checkout_state' , WC () -> customer -> get_billing_state () ? WC () -> customer -> get_billing_state () : '' , 'billing' );
2014-10-21 21:56:20 +00:00
case 'billing_postcode' :
2016-03-17 19:39:29 +00:00
return apply_filters ( 'default_checkout_postcode' , WC () -> customer -> get_billing_postcode () ? WC () -> customer -> get_billing_postcode () : '' , 'billing' );
2014-10-21 21:56:20 +00:00
case 'shipping_country' :
2016-03-30 11:55:29 +00:00
return apply_filters ( 'default_checkout_country' , WC () -> customer -> get_shipping_country () ? WC () -> customer -> get_shipping_country () : '' , 'shipping' );
2014-10-21 21:56:20 +00:00
case 'shipping_state' :
2016-03-30 11:55:29 +00:00
return apply_filters ( 'default_checkout_state' , WC () -> customer -> get_shipping_state () ? WC () -> customer -> get_shipping_state () : '' , 'shipping' );
2014-10-21 21:56:20 +00:00
case 'shipping_postcode' :
2013-10-24 12:15:42 +00:00
return apply_filters ( 'default_checkout_postcode' , WC () -> customer -> get_shipping_postcode () ? WC () -> customer -> get_shipping_postcode () : '' , 'shipping' );
2013-09-19 14:02:14 +00:00
default :
2014-02-13 09:52:43 +00:00
return apply_filters ( 'default_checkout_' . $input , null , $input );
2012-04-19 11:09:52 +00:00
}
2012-10-19 17:59:17 +00:00
}
2011-08-09 15:16:18 +00:00
}
2013-01-22 21:30:14 +00:00
}