Merge pull request #11645 from woothemes/orders-crud-function-update

Orders crud functions
This commit is contained in:
Mike Jolley 2016-08-10 12:19:38 +01:00 committed by GitHub
commit efd390e951
72 changed files with 943 additions and 910 deletions

View File

@ -364,7 +364,7 @@ abstract class WC_Abstract_Legacy_Order extends WC_Data {
* @param array $item
*/
public function display_item_meta( $item ) {
_deprecated_function( 'get_item_meta', '2.7', 'wc_display_item_meta' );
_deprecated_function( 'display_item_meta', '2.7', 'wc_display_item_meta' );
$product = $item->get_product();
$item_meta = new WC_Order_Item_Meta( $item, $product );
$item_meta->display();

View File

@ -33,7 +33,7 @@ abstract class WC_Abstract_Order extends WC_Abstract_Legacy_Order {
protected $_data = array(
'id' => 0,
'parent_id' => 0,
'status' => 'pending',
'status' => '',
'type' => 'shop_order',
'order_key' => '',
'currency' => '',
@ -63,6 +63,19 @@ abstract class WC_Abstract_Order extends WC_Abstract_Legacy_Order {
'_payment_tokens',
);
/**
* Order items will be stored here, sometimes before they persist in the DB.
* @since 2.7.0
* @var array
*/
protected $_items = array(
'line_items' => null,
'coupon_lines' => null,
'shipping_lines' => null,
'fee_lines' => null,
'tax_lines' => null,
);
/**
* Internal meta type used to store order data.
* @var string
@ -92,6 +105,10 @@ abstract class WC_Abstract_Order extends WC_Abstract_Legacy_Order {
} elseif ( ! empty( $order->ID ) ) {
$this->read( absint( $order->ID ) );
}
// Set default status if none were read.
if ( ! $this->get_status() ) {
$this->set_status( apply_filters( 'woocommerce_default_order_status', 'pending' ) );
}
}
/*
@ -267,12 +284,55 @@ abstract class WC_Abstract_Order extends WC_Abstract_Legacy_Order {
$this->update();
}
$this->save_items();
clean_post_cache( $this->get_id() );
wc_delete_shop_order_transients( $this->get_id() );
return $this->get_id();
}
/**
* Save all order items which are part of this order.
*/
protected function save_items() {
foreach ( $this->_items as $item_group => $items ) {
if ( is_array( $items ) ) {
foreach ( $items as $item_key => $item ) {
$item->set_order_id( $this->get_id() );
$item_id = $item->save();
// If ID changed (new item saved to DB)...
if ( $item_id !== $item_key ) {
$this->_items[ $item_group ][ $item_id ] = $item;
unset( $this->_items[ $item_group ][ $item_key ] );
// Legacy action handler
switch ( $item_group ) {
case 'fee_lines' :
if ( has_action( 'woocommerce_add_order_fee_meta' ) && isset( $item->legacy_fee, $item->legacy_fee_key ) ) {
_deprecated_function( 'Action: woocommerce_add_order_fee_meta', '2.7', 'Use woocommerce_new_order_item action instead.' );
do_action( 'woocommerce_add_order_fee_meta', $this->get_id(), $item_id, $item->legacy_fee, $item->legacy_fee_key );
}
break;
case 'shipping_lines' :
if ( has_action( 'woocommerce_add_shipping_order_item' ) && isset( $item->legacy_package_key ) ) {
_deprecated_function( 'Action: woocommerce_add_shipping_order_item', '2.7', 'Use woocommerce_new_order_item action instead.' );
do_action( 'woocommerce_add_shipping_order_item', $item_id, $item->legacy_package_key );
}
break;
case 'line_items' :
if ( has_action( 'woocommerce_add_order_item_meta' ) && isset( $item->legacy_values, $item->legacy_cart_item_key ) ) {
_deprecated_function( 'Action: woocommerce_add_order_item_meta', '2.7', 'Use woocommerce_new_order_item action instead.' );
do_action( 'woocommerce_add_order_item_meta', $item_id, $item->legacy_values, $item->legacy_cart_item_key );
}
break;
}
}
}
}
}
}
/*
|--------------------------------------------------------------------------
| Getters
@ -588,25 +648,25 @@ abstract class WC_Abstract_Order extends WC_Abstract_Legacy_Order {
}
/**
<<<<<<< HEAD
* Set order status.
* @since 2.7.0
* @param string $new_status Status to change the order to. No internal wc- prefix is required.
* @param array details of change
*/
public function set_status( $new_status ) {
$old_status = $this->get_status();
$new_status = 'wc-' === substr( $new_status, 0, 3 ) ? substr( $new_status, 3 ) : $new_status;
$old_status = $this->get_status();
$new_status = 'wc-' === substr( $new_status, 0, 3 ) ? substr( $new_status, 3 ) : $new_status;
// If the old status is unknown (e.g. draft) assume its pending for action usage.
if ( ! in_array( 'wc-' . $old_status, array_keys( wc_get_order_statuses() ) ) ) {
$old_status = 'pending';
// Only allow valid new status
if ( ! in_array( 'wc-' . $new_status, array_keys( wc_get_order_statuses() ) ) ) {
$new_status = 'pending';
}
if ( in_array( 'wc-' . $new_status, array_keys( wc_get_order_statuses() ) ) && $new_status !== $old_status ) {
$this->_data['status'] = 'wc-' . $new_status;
} else {
$new_status = $old_status;
$this->_data['status'] = 'wc-' . $new_status;
// If the old status is set but unknown (e.g. draft) assume its pending for action usage.
if ( $old_status && ! in_array( 'wc-' . $old_status, array_keys( wc_get_order_statuses() ) ) ) {
$old_status = 'pending';
}
return array(
@ -769,12 +829,43 @@ abstract class WC_Abstract_Order extends WC_Abstract_Legacy_Order {
/**
* Return an array of items/products within this order.
* @param string|array $type Types of line items to get (array or string).
* @param string|array $types Types of line items to get (array or string).
* @return Array of WC_Order_item
*/
public function get_items( $type = 'line_item' ) {
public function get_items( $types = 'line_item' ) {
$type_to_group = array(
'line_item' => 'line_items',
'tax' => 'tax_lines',
'shipping' => 'shipping_lines',
'fee' => 'fee_lines',
'coupon' => 'coupon_lines',
);
$items = array();
$types = array_filter( (array) $types );
foreach ( $types as $type ) {
if ( isset( $type_to_group[ $type ] ) ) {
if ( is_null( $this->_items[ $type_to_group[ $type ] ] ) ) {
$this->_items[ $type_to_group[ $type ] ] = $this->get_items_from_db( $type );
}
$items = array_merge( $items, $this->_items[ $type_to_group[ $type ] ] );
}
}
return apply_filters( 'woocommerce_order_get_items', $items, $this );
}
/**
* Gets items from the database by type.
* @param string $type
* @return array
*/
protected function get_items_from_db( $type ) {
global $wpdb;
$get_items_sql = $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}woocommerce_order_items WHERE order_id = %d ", $this->get_id() ) . "AND order_item_type IN ( '" . implode( "','", array_map( 'esc_sql', (array) $type ) ) . "' ) ORDER BY order_item_id;";
$get_items_sql = $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}woocommerce_order_items WHERE order_id = %d AND order_item_type = %s ORDER BY order_item_id;", $this->get_id(), $type ) ;
$items = $wpdb->get_results( $get_items_sql );
if ( ! empty( $items ) ) {
@ -783,7 +874,7 @@ abstract class WC_Abstract_Order extends WC_Abstract_Legacy_Order {
$items = array();
}
return apply_filters( 'woocommerce_order_get_items', $items, $this );
return $items;
}
/**
@ -863,6 +954,39 @@ abstract class WC_Abstract_Order extends WC_Abstract_Legacy_Order {
return WC_Order_Factory::get_order_item( $item_id );
}
/**
* Adds an order item to this order. The order item will not persist until save.
* @param object Order item (product, shipping, fee, coupon, tax)
*/
public function add_item( $item ) {
if ( is_a( $item, 'WC_Order_Item_Product' ) ) {
$item_type = 'line_item';
$items_key = 'line_items';
} elseif ( is_a( $item, 'WC_Order_Item_Fee' ) ) {
$item_type = 'fee';
$items_key = 'fee_lines';
} elseif ( is_a( $item, 'WC_Order_Item_Shipping' ) ) {
$item_type = 'shipping';
$items_key = 'shipping_lines';
} elseif ( is_a( $item, 'WC_Order_Item_Tax' ) ) {
$item_type = 'tax';
$items_key = 'tax_lines';
} elseif ( is_a( $item, 'WC_Order_Item_Coupon' ) ) {
$item_type = 'coupon';
$items_key = 'coupon_lines';
} else {
return false;
}
// Make sure existing items are loaded so we can append this new one.
if ( is_null( $this->_items[ $items_key ] ) ) {
$this->_items[ $items_key ] = $this->get_items( $item_type );
}
// Append new row with generated temporary ID
$this->_items[ $items_key ][ 'new:' . md5( json_encode( $item ) ) ] = $item;
}
/**
* Add a product line item to the order.
* Order must be saved prior to adding items.
@ -879,17 +1003,21 @@ abstract class WC_Abstract_Order extends WC_Abstract_Legacy_Order {
$args['qty'] = $qty;
}
if ( empty( $args['qty'] ) ) {
$args['qty'] = 1;
}
$args = wp_parse_args( $args, array(
'qty' => 1,
'name' => $product ? $product->get_title() : '',
'tax_class' => $product ? $product->get_tax_class() : '',
'product_id' => $product ? $product->get_id() : '',
'variation_id' => $product && isset( $product->variation_id ) ? $product->variation_id : 0,
'variation' => $product && isset( $product->variation_id ) ? $product->get_variation_attributes() : array(),
'subtotal' => $product ? $product->get_price_excluding_tax( $args['qty'] ) : '',
'total' => $product ? $product->get_price_excluding_tax( $args['qty'] ) : '',
'subtotal_tax' => 0,
'total_tax' => 0,
'variation' => array(),
'taxes' => array(
'subtotal' => array(),
'total' => array(),
@ -1198,7 +1326,7 @@ abstract class WC_Abstract_Order extends WC_Abstract_Legacy_Order {
// Inherit tax class from items
if ( '' === $shipping_tax_class ) {
$tax_rates = array();
$tax_classes = WC_Tax::get_tax_classes();
$tax_classes = array_merge( array( '' ), WC_Tax::get_tax_classes() );
$found_tax_classes = $this->get_items_tax_classes();
foreach ( $tax_classes as $tax_class ) {

View File

@ -228,7 +228,7 @@ class WC_Admin_Assets {
if ( $post_id && in_array( get_post_type( $post_id ), wc_get_order_types( 'order-meta-boxes' ) ) ) {
$order = wc_get_order( $post_id );
$currency = $order->get_order_currency();
$currency = $order->get_currency();
}
$params = array(

View File

@ -607,7 +607,7 @@ class WC_Admin_Post_Types {
public function render_shop_order_columns( $column ) {
global $post, $woocommerce, $the_order;
if ( empty( $the_order ) || $the_order->id != $post->ID ) {
if ( empty( $the_order ) || $the_order->get_id() != $post->ID ) {
$the_order = wc_get_order( $post->ID );
}
@ -630,8 +630,8 @@ class WC_Admin_Post_Types {
break;
case 'customer_message' :
if ( $the_order->customer_message ) {
echo '<span class="note-on tips" data-tip="' . wc_sanitize_tooltip( $the_order->customer_message ) . '">' . __( 'Yes', 'woocommerce' ) . '</span>';
if ( $the_order->get_customer_note() ) {
echo '<span class="note-on tips" data-tip="' . wc_sanitize_tooltip( $the_order->get_customer_note() ) . '">' . __( 'Yes', 'woocommerce' ) . '</span>';
} else {
echo '<span class="na">&ndash;</span>';
}
@ -678,8 +678,8 @@ class WC_Admin_Post_Types {
echo '&ndash;';
}
if ( $the_order->billing_phone ) {
echo '<small class="meta">' . __( 'Tel:', 'woocommerce' ) . ' ' . esc_html( $the_order->billing_phone ) . '</small>';
if ( $the_order->get_billing_phone() ) {
echo '<small class="meta">' . __( 'Tel:', 'woocommerce' ) . ' ' . esc_html( $the_order->get_billing_phone() ) . '</small>';
}
break;
@ -727,14 +727,14 @@ class WC_Admin_Post_Types {
case 'order_total' :
echo $the_order->get_formatted_order_total();
if ( $the_order->payment_method_title ) {
echo '<small class="meta">' . __( 'Via', 'woocommerce' ) . ' ' . esc_html( $the_order->payment_method_title ) . '</small>';
if ( $the_order->get_payment_method_title() ) {
echo '<small class="meta">' . __( 'Via', 'woocommerce' ) . ' ' . esc_html( $the_order->get_payment_method_title() ) . '</small>';
}
break;
case 'order_title' :
if ( $the_order->user_id ) {
$user_info = get_userdata( $the_order->user_id );
if ( $the_order->get_user_id() ) {
$user_info = get_userdata( $the_order->get_user_id() );
}
if ( ! empty( $user_info ) ) {
@ -750,10 +750,10 @@ class WC_Admin_Post_Types {
$username .= '</a>';
} else {
if ( $the_order->billing_first_name || $the_order->billing_last_name ) {
$username = trim( sprintf( _x( '%1$s %2$s', 'full name', 'woocommerce' ), $the_order->billing_first_name, $the_order->billing_last_name ) );
} else if ( $the_order->billing_company ) {
$username = trim( $the_order->billing_company );
if ( $the_order->get_billing_first_name()|| $the_order->get_billing_last_name() ) {
$username = trim( sprintf( _x( '%1$s %2$s', 'full name', 'woocommerce' ), $the_order->get_billing_first_name(), $the_order->get_billing_last_name() ) );
} else if ( $the_order->get_billing_company() ) {
$username = trim( $the_order->get_billing_company() );
} else {
$username = __( 'Guest', 'woocommerce' );
}
@ -761,8 +761,8 @@ class WC_Admin_Post_Types {
printf( _x( '%s by %s', 'Order number by X', 'woocommerce' ), '<a href="' . admin_url( 'post.php?post=' . absint( $post->ID ) . '&action=edit' ) . '" class="row-title"><strong>#' . esc_attr( $the_order->get_order_number() ) . '</strong></a>', $username );
if ( $the_order->billing_email ) {
echo '<small class="meta email"><a href="' . esc_url( 'mailto:' . $the_order->billing_email ) . '">' . esc_html( $the_order->billing_email ) . '</a></small>';
if ( $the_order->get_billing_email() ) {
echo '<small class="meta email"><a href="' . esc_url( 'mailto:' . $the_order->get_billing_email() ) . '">' . esc_html( $the_order->get_billing_email() ) . '</a></small>';
}
echo '<button type="button" class="toggle-row"><span class="screen-reader-text">' . __( 'Show more details', 'woocommerce' ) . '</span></button>';
@ -2203,12 +2203,12 @@ class WC_Admin_Post_Types {
foreach ( $existing_permissions as $existing_permission ) {
$order = wc_get_order( $existing_permission->order_id );
if ( ! empty( $order->id ) ) {
if ( ! empty( $order->get_id() ) ) {
// Remove permissions
if ( ! empty( $removed_download_ids ) ) {
foreach ( $removed_download_ids as $download_id ) {
if ( apply_filters( 'woocommerce_process_product_file_download_paths_remove_access_to_old_file', true, $download_id, $product_id, $order ) ) {
$wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->prefix}woocommerce_downloadable_product_permissions WHERE order_id = %d AND product_id = %d AND download_id = %s", $order->id, $product_id, $download_id ) );
$wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->prefix}woocommerce_downloadable_product_permissions WHERE order_id = %d AND product_id = %d AND download_id = %s", $order->get_id(), $product_id, $download_id ) );
}
}
}
@ -2219,7 +2219,7 @@ class WC_Admin_Post_Types {
if ( apply_filters( 'woocommerce_process_product_file_download_paths_grant_access_to_new_file', true, $download_id, $product_id, $order ) ) {
// grant permission if it doesn't already exist
if ( ! $wpdb->get_var( $wpdb->prepare( "SELECT 1=1 FROM {$wpdb->prefix}woocommerce_downloadable_product_permissions WHERE order_id = %d AND product_id = %d AND download_id = %s", $order->id, $product_id, $download_id ) ) ) {
if ( ! $wpdb->get_var( $wpdb->prepare( "SELECT 1=1 FROM {$wpdb->prefix}woocommerce_downloadable_product_permissions WHERE order_id = %d AND product_id = %d AND download_id = %s", $order->get_id(), $product_id, $download_id ) ) ) {
wc_downloadable_file_permission( $download_id, $product_id, $order );
}
}

View File

@ -125,7 +125,7 @@ class WC_Meta_Box_Order_Actions {
if ( ! empty( $mails ) ) {
foreach ( $mails as $mail ) {
if ( $mail->id == $email_to_send ) {
$mail->trigger( $order->id );
$mail->trigger( $order->get_id() );
$order->add_order_note( sprintf( __( '%s email notification manually sent.', 'woocommerce' ), $mail->title ), false, true );
}
}

View File

@ -153,7 +153,7 @@ class WC_Meta_Box_Order_Data {
$payment_gateways = array();
}
$payment_method = ! empty( $order->payment_method ) ? $order->payment_method : '';
$payment_method = ! empty( $order->get_payment_method() ) ? $order->get_payment_method() : '';
$order_type_object = get_post_type_object( $post->post_type );
wp_nonce_field( 'woocommerce_save_data', 'woocommerce_meta_nonce' );
@ -180,8 +180,8 @@ class WC_Meta_Box_Order_Data {
}
}
if ( $order->paid_date ) {
printf( ' ' . _x( 'on %s @ %s', 'on date at time', 'woocommerce' ), date_i18n( get_option( 'date_format' ), strtotime( $order->paid_date ) ), date_i18n( get_option( 'time_format' ), strtotime( $order->paid_date ) ) );
if ( $order->get_date_paid() ) {
printf( ' ' . _x( 'on %s @ %s', 'on date at time', 'woocommerce' ), date_i18n( get_option( 'date_format' ), $order->get_date_paid() ), date_i18n( get_option( 'time_format' ), $order->get_date_paid() ) );
}
echo '. ';
@ -219,10 +219,10 @@ class WC_Meta_Box_Order_Data {
<p class="form-field form-field-wide wc-customer-user">
<label for="customer_user"><?php _e( 'Customer:', 'woocommerce' ) ?> <?php
if ( ! empty( $order->customer_user ) ) {
if ( ! empty( $order->get_user_id() ) ) {
$args = array( 'post_status' => 'all',
'post_type' => 'shop_order',
'_customer_user' => absint( $order->customer_user )
'_customer_user' => absint( $order->get_user_id() )
);
printf( '<a href="%s">%s &rarr;</a>',
esc_url( add_query_arg( $args, admin_url( 'edit.php' ) ) ),
@ -233,8 +233,8 @@ class WC_Meta_Box_Order_Data {
<?php
$user_string = '';
$user_id = '';
if ( ! empty( $order->customer_user ) ) {
$user_id = absint( $order->customer_user );
if ( ! empty( $order->get_user_id() ) ) {
$user_id = absint( $order->get_user_id() );
$user = get_user_by( 'id', $user_id );
$user_string = esc_html( $user->display_name ) . ' (#' . absint( $user->ID ) . ' &ndash; ' . esc_html( $user->user_email ) . ')';
}
@ -266,8 +266,8 @@ class WC_Meta_Box_Order_Data {
$field_name = 'billing_' . $key;
if ( $order->$field_name ) {
echo '<p><strong>' . esc_html( $field['label'] ) . ':</strong> ' . make_clickable( esc_html( $order->$field_name ) ) . '</p>';
if ( is_callable( array( $order, 'get_' . $field_name ) ) ) {
echo '<p><strong>' . esc_html( $field['label'] ) . ':</strong> ' . make_clickable( esc_html( call_user_func( array( $order, 'get_' . $field_name ) ) ) ) . '</p>';
}
}
@ -352,8 +352,8 @@ class WC_Meta_Box_Order_Data {
$field_name = 'shipping_' . $key;
if ( ! empty( $order->$field_name ) ) {
echo '<p><strong>' . esc_html( $field['label'] ) . ':</strong> ' . make_clickable( esc_html( $order->$field_name ) ) . '</p>';
if ( is_callable( array( $order, 'get_' . $field_name ) ) ) {
echo '<p><strong>' . esc_html( $field['label'] ) . ':</strong> ' . make_clickable( esc_html( call_user_func( array( $order, 'get_' . $field_name ) ) ) ) . '</p>';
}
}
}

View File

@ -1,13 +1,9 @@
<div class="view">
<?php
global $wpdb;
if ( $metadata = $order->has_meta( $item_id ) ) {
echo '<table cellspacing="0" class="display_meta">';
foreach ( $metadata as $meta ) {
<?php if ( $meta_data = $item->get_formatted_meta_data() ) : ?>
<table cellspacing="0" class="display_meta">
<?php foreach ( $meta_data as $meta_id => $meta ) :
// Skip hidden core fields
if ( in_array( $meta['meta_key'], apply_filters( 'woocommerce_hidden_order_itemmeta', array(
if ( in_array( $meta->key, apply_filters( 'woocommerce_hidden_order_itemmeta', array(
'_qty',
'_tax_class',
'_product_id',
@ -21,36 +17,22 @@
) ) ) ) {
continue;
}
// Skip serialised meta
if ( is_serialized( $meta['meta_value'] ) ) {
continue;
}
// Get attribute data
if ( taxonomy_exists( wc_sanitize_taxonomy_name( $meta['meta_key'] ) ) ) {
$term = get_term_by( 'slug', $meta['meta_value'], wc_sanitize_taxonomy_name( $meta['meta_key'] ) );
$meta['meta_key'] = wc_attribute_label( wc_sanitize_taxonomy_name( $meta['meta_key'] ) );
$meta['meta_value'] = isset( $term->name ) ? $term->name : $meta['meta_value'];
} else {
$meta['meta_key'] = wc_attribute_label( $meta['meta_key'], $_product );
}
echo '<tr><th>' . wp_kses_post( rawurldecode( $meta['meta_key'] ) ) . ':</th><td>' . wp_kses_post( wpautop( make_clickable( rawurldecode( $meta['meta_value'] ) ) ) ) . '</td></tr>';
}
echo '</table>';
}
?>
?>
<tr>
<th><?php echo wp_kses_post( $meta->display_key ); ?>:</th>
<td><?php echo wp_kses_post( $meta->display_value ); ?></td>
</tr>
<?php endforeach; ?>
</table>
<?php endif; ?>
</div>
<div class="edit" style="display: none;">
<table class="meta" cellspacing="0">
<tbody class="meta_items">
<?php
if ( $metadata = $order->has_meta( $item_id )) {
foreach ( $metadata as $meta ) {
<?php if ( $meta_data = $item->get_formatted_meta_data() ) : ?>
<?php foreach ( $meta_data as $meta_id => $meta ) :
// Skip hidden core fields
if ( in_array( $meta['meta_key'], apply_filters( 'woocommerce_hidden_order_itemmeta', array(
if ( in_array( $meta->key, apply_filters( 'woocommerce_hidden_order_itemmeta', array(
'_qty',
'_tax_class',
'_product_id',
@ -64,26 +46,16 @@
) ) ) ) {
continue;
}
// Skip serialised meta
if ( is_serialized( $meta['meta_value'] ) ) {
continue;
}
$meta['meta_key'] = rawurldecode( $meta['meta_key'] );
$meta['meta_value'] = esc_textarea( rawurldecode( $meta['meta_value'] ) ); // using a <textarea />
$meta['meta_id'] = absint( $meta['meta_id'] );
echo '<tr data-meta_id="' . esc_attr( $meta['meta_id'] ) . '">
?>
<tr data-meta_id="<?php echo esc_attr( $meta_id ); ?>">
<td>
<input type="text" name="meta_key[' . $meta['meta_id'] . ']" value="' . esc_attr( $meta['meta_key'] ) . '" />
<textarea name="meta_value[' . $meta['meta_id'] . ']">' . $meta['meta_value'] . '</textarea>
<input type="text" name="meta_key[<?php echo esc_attr( $meta_id ); ?>]" value="<?php echo esc_attr( $meta->key ); ?>" />
<textarea name="meta_value[<?php echo esc_attr( $meta_id ); ?>]"><?php echo esc_textarea( rawurldecode( $meta->value ) ); ?></textarea>
</td>
<td width="1%"><button class="remove_order_item_meta button">&times;</button></td>
</tr>';
}
}
?>
</tr>
<?php endforeach; ?>
<?php endif; ?>
</tbody>
<tfoot>
<tr>

View File

@ -9,6 +9,7 @@
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
$_product = $order->get_product_from_item( $item );
$product_link = $_product ? admin_url( 'post.php?post=' . absint( $_product->id ) . '&action=edit' ) : '';
$thumbnail = $_product ? apply_filters( 'woocommerce_admin_order_item_thumbnail', $_product->get_image( 'thumbnail', array( 'title' => '' ), false ), $item_id, $item ) : '';
$tax_data = empty( $legacy_order ) && wc_tax_enabled() ? maybe_unserialize( isset( $item['line_tax_data'] ) ? $item['line_tax_data'] : '' ) : false;
@ -53,10 +54,10 @@ $item_subtotal = ( isset( $item['line_subtotal'] ) ) ? esc_attr( wc_format_local
<div class="view">
<?php
if ( isset( $item['line_total'] ) ) {
echo wc_price( $order->get_item_total( $item, false, true ), array( 'currency' => $order->get_order_currency() ) );
echo wc_price( $order->get_item_total( $item, false, true ), array( 'currency' => $order->get_currency() ) );
if ( isset( $item['line_subtotal'] ) && $item['line_subtotal'] != $item['line_total'] ) {
echo '<span class="wc-order-item-discount">-' . wc_price( wc_format_decimal( $order->get_item_subtotal( $item, false, false ) - $order->get_item_total( $item, false, false ), '' ), array( 'currency' => $order->get_order_currency() ) ) . '</span>';
echo '<span class="wc-order-item-discount">-' . wc_price( wc_format_decimal( $order->get_item_subtotal( $item, false, false ) - $order->get_item_total( $item, false, false ), '' ), array( 'currency' => $order->get_currency() ) ) . '</span>';
}
}
?>
@ -84,15 +85,15 @@ $item_subtotal = ( isset( $item['line_subtotal'] ) ) ? esc_attr( wc_format_local
<div class="view">
<?php
if ( isset( $item['line_total'] ) ) {
echo wc_price( $item['line_total'], array( 'currency' => $order->get_order_currency() ) );
echo wc_price( $item['line_total'], array( 'currency' => $order->get_currency() ) );
}
if ( isset( $item['line_subtotal'] ) && $item['line_subtotal'] !== $item['line_total'] ) {
echo '<span class="wc-order-item-discount">-' . wc_price( wc_format_decimal( $item['line_subtotal'] - $item['line_total'], '' ), array( 'currency' => $order->get_order_currency() ) ) . '</span>';
echo '<span class="wc-order-item-discount">-' . wc_price( wc_format_decimal( $item['line_subtotal'] - $item['line_total'], '' ), array( 'currency' => $order->get_currency() ) ) . '</span>';
}
if ( $refunded = $order->get_total_refunded_for_item( $item_id ) ) {
echo '<small class="refunded">' . wc_price( $refunded, array( 'currency' => $order->get_order_currency() ) ) . '</small>';
echo '<small class="refunded">' . wc_price( $refunded, array( 'currency' => $order->get_currency() ) ) . '</small>';
}
?>
</div>
@ -124,17 +125,17 @@ $item_subtotal = ( isset( $item['line_subtotal'] ) ) ? esc_attr( wc_format_local
<div class="view">
<?php
if ( '' != $tax_item_total ) {
echo wc_price( wc_round_tax_total( $tax_item_total ), array( 'currency' => $order->get_order_currency() ) );
echo wc_price( wc_round_tax_total( $tax_item_total ), array( 'currency' => $order->get_currency() ) );
} else {
echo '&ndash;';
}
if ( isset( $item['line_subtotal'] ) && $item['line_subtotal'] !== $item['line_total'] ) {
echo '<span class="wc-order-item-discount">-' . wc_price( wc_round_tax_total( $tax_item_subtotal - $tax_item_total ), array( 'currency' => $order->get_order_currency() ) ) . '</span>';
echo '<span class="wc-order-item-discount">-' . wc_price( wc_round_tax_total( $tax_item_subtotal - $tax_item_total ), array( 'currency' => $order->get_currency() ) ) . '</span>';
}
if ( $refunded = $order->get_tax_refunded_for_item( $item_id, $tax_item_id ) ) {
echo '<small class="refunded">' . wc_price( $refunded, array( 'currency' => $order->get_order_currency() ) ) . '</small>';
echo '<small class="refunded">' . wc_price( $refunded, array( 'currency' => $order->get_currency() ) ) . '</small>';
}
?>
</div>

View File

@ -75,16 +75,13 @@ if ( wc_tax_enabled() ) {
<tbody id="order_line_items">
<?php
foreach ( $line_items as $item_id => $item ) {
$_product = $order->get_product_from_item( $item );
$item_meta = $order->get_item_meta( $item_id );
do_action( 'woocommerce_before_order_item_' . $item['type'] . '_html', $item_id, $item, $order );
do_action( 'woocommerce_before_order_item_' . $item->get_type() . '_html', $item_id, $item, $order );
include( 'html-order-item.php' );
do_action( 'woocommerce_order_item_' . $item['type'] . '_html', $item_id, $item, $order );
do_action( 'woocommerce_order_item_' . $item->get_type() . '_html', $item_id, $item, $order );
}
do_action( 'woocommerce_admin_order_items_after_line_items', $order->id );
do_action( 'woocommerce_admin_order_items_after_line_items', $order->get_id() );
?>
</tbody>
<tbody id="order_shipping_line_items">
@ -93,7 +90,7 @@ if ( wc_tax_enabled() ) {
foreach ( $line_items_shipping as $item_id => $item ) {
include( 'html-order-shipping.php' );
}
do_action( 'woocommerce_admin_order_items_after_shipping', $order->id );
do_action( 'woocommerce_admin_order_items_after_shipping', $order->get_id() );
?>
</tbody>
<tbody id="order_fee_line_items">
@ -101,7 +98,7 @@ if ( wc_tax_enabled() ) {
foreach ( $line_items_fee as $item_id => $item ) {
include( 'html-order-fee.php' );
}
do_action( 'woocommerce_admin_order_items_after_fees', $order->id );
do_action( 'woocommerce_admin_order_items_after_fees', $order->get_id() );
?>
</tbody>
<tbody id="order_refunds">
@ -110,7 +107,7 @@ if ( wc_tax_enabled() ) {
foreach ( $refunds as $refund ) {
include( 'html-order-refund.php' );
}
do_action( 'woocommerce_admin_order_items_after_refunds', $order->id );
do_action( 'woocommerce_admin_order_items_after_refunds', $order->get_id() );
}
?>
</tbody>
@ -129,13 +126,12 @@ if ( wc_tax_enabled() ) {
?>
<div class="wc-used-coupons">
<ul class="wc_coupon_list"><?php
echo '<li><strong>' . __( 'Coupon(s) Used', 'woocommerce' ) . '</strong></li>';
echo '<li><strong>' . __( 'Coupon(s)', 'woocommerce' ) . '</strong></li>';
foreach ( $coupons as $item_id => $item ) {
$post_id = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM {$wpdb->posts} WHERE post_title = %s AND post_type = 'shop_coupon' AND post_status = 'publish' LIMIT 1;", $item['name'] ) );
$post_id = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM {$wpdb->posts} WHERE post_title = %s AND post_type = 'shop_coupon' AND post_status = 'publish' LIMIT 1;", $item->get_code() ) );
$link = $post_id ? add_query_arg( array( 'post' => $post_id, 'action' => 'edit' ), admin_url( 'post.php' ) ) : add_query_arg( array( 's' => $item->get_code(), 'post_status' => 'all', 'post_type' => 'shop_coupon' ), admin_url( 'edit.php' ) );
$link = $post_id ? add_query_arg( array( 'post' => $post_id, 'action' => 'edit' ), admin_url( 'post.php' ) ) : add_query_arg( array( 's' => $item['name'], 'post_status' => 'all', 'post_type' => 'shop_coupon' ), admin_url( 'edit.php' ) );
echo '<li class="code"><a href="' . esc_url( $link ) . '" class="tips" data-tip="' . esc_attr( wc_price( $item['discount_amount'], array( 'currency' => $order->get_order_currency() ) ) ) . '"><span>' . esc_html( $item['name'] ). '</span></a></li>';
echo '<li class="code"><a href="' . esc_url( $link ) . '" class="tips" data-tip="' . esc_attr( wc_price( $item->get_discount(), array( 'currency' => $order->get_currency() ) ) ) . '"><span>' . esc_html( $item->get_code() ). '</span></a></li>';
}
?></ul>
</div>
@ -147,25 +143,25 @@ if ( wc_tax_enabled() ) {
<td class="label"><?php echo wc_help_tip( __( 'This is the total discount. Discounts are defined per line item.', 'woocommerce' ) ); ?> <?php _e( 'Discount', 'woocommerce' ); ?>:</td>
<td width="1%"></td>
<td class="total">
<?php echo wc_price( $order->get_total_discount(), array( 'currency' => $order->get_order_currency() ) ); ?>
<?php echo wc_price( $order->get_total_discount(), array( 'currency' => $order->get_currency() ) ); ?>
</td>
</tr>
<?php do_action( 'woocommerce_admin_order_totals_after_discount', $order->id ); ?>
<?php do_action( 'woocommerce_admin_order_totals_after_discount', $order->get_id() ); ?>
<tr>
<td class="label"><?php echo wc_help_tip( __( 'This is the shipping and handling total costs for the order.', 'woocommerce' ) ); ?> <?php _e( 'Shipping', 'woocommerce' ); ?>:</td>
<td width="1%"></td>
<td class="total"><?php
if ( ( $refunded = $order->get_total_shipping_refunded() ) > 0 ) {
echo '<del>' . strip_tags( wc_price( $order->get_total_shipping(), array( 'currency' => $order->get_order_currency() ) ) ) . '</del> <ins>' . wc_price( $order->get_total_shipping() - $refunded, array( 'currency' => $order->get_order_currency() ) ) . '</ins>';
echo '<del>' . strip_tags( wc_price( $order->get_total_shipping(), array( 'currency' => $order->get_currency() ) ) ) . '</del> <ins>' . wc_price( $order->get_total_shipping() - $refunded, array( 'currency' => $order->get_currency() ) ) . '</ins>';
} else {
echo wc_price( $order->get_total_shipping(), array( 'currency' => $order->get_order_currency() ) );
echo wc_price( $order->get_total_shipping(), array( 'currency' => $order->get_currency() ) );
}
?></td>
</tr>
<?php do_action( 'woocommerce_admin_order_totals_after_shipping', $order->id ); ?>
<?php do_action( 'woocommerce_admin_order_totals_after_shipping', $order->get_id() ); ?>
<?php if ( wc_tax_enabled() ) : ?>
<?php foreach ( $order->get_tax_totals() as $code => $tax ) : ?>
@ -174,7 +170,7 @@ if ( wc_tax_enabled() ) {
<td width="1%"></td>
<td class="total"><?php
if ( ( $refunded = $order->get_total_tax_refunded_by_rate_id( $tax->rate_id ) ) > 0 ) {
echo '<del>' . strip_tags( $tax->formatted_amount ) . '</del> <ins>' . wc_price( WC_Tax::round( $tax->amount, wc_get_price_decimals() ) - WC_Tax::round( $refunded, wc_get_price_decimals() ), array( 'currency' => $order->get_order_currency() ) ) . '</ins>';
echo '<del>' . strip_tags( $tax->formatted_amount ) . '</del> <ins>' . wc_price( WC_Tax::round( $tax->amount, wc_get_price_decimals() ) - WC_Tax::round( $refunded, wc_get_price_decimals() ), array( 'currency' => $order->get_currency() ) ) . '</ins>';
} else {
echo $tax->formatted_amount;
}
@ -183,7 +179,7 @@ if ( wc_tax_enabled() ) {
<?php endforeach; ?>
<?php endif; ?>
<?php do_action( 'woocommerce_admin_order_totals_after_tax', $order->id ); ?>
<?php do_action( 'woocommerce_admin_order_totals_after_tax', $order->get_id() ); ?>
<tr>
<td class="label"><?php _e( 'Order Total', 'woocommerce' ); ?>:</td>
@ -203,15 +199,15 @@ if ( wc_tax_enabled() ) {
</td>
</tr>
<?php do_action( 'woocommerce_admin_order_totals_after_total', $order->id ); ?>
<?php do_action( 'woocommerce_admin_order_totals_after_total', $order->get_id() ); ?>
<tr>
<td class="label refunded-total"><?php _e( 'Refunded', 'woocommerce' ); ?>:</td>
<td width="1%"></td>
<td class="total refunded-total">-<?php echo wc_price( $order->get_total_refunded(), array( 'currency' => $order->get_order_currency() ) ); ?></td>
<td class="total refunded-total">-<?php echo wc_price( $order->get_total_refunded(), array( 'currency' => $order->get_currency() ) ); ?></td>
</tr>
<?php do_action( 'woocommerce_admin_order_totals_after_refunded', $order->id ); ?>
<?php do_action( 'woocommerce_admin_order_totals_after_refunded', $order->get_id() ); ?>
</table>
<div class="clear"></div>
@ -259,11 +255,11 @@ if ( wc_tax_enabled() ) {
</tr>
<tr>
<td class="label"><?php _e( 'Amount already refunded', 'woocommerce' ); ?>:</td>
<td class="total">-<?php echo wc_price( $order->get_total_refunded(), array( 'currency' => $order->get_order_currency() ) ); ?></td>
<td class="total">-<?php echo wc_price( $order->get_total_refunded(), array( 'currency' => $order->get_currency() ) ); ?></td>
</tr>
<tr>
<td class="label"><?php _e( 'Total available to refund', 'woocommerce' ); ?>:</td>
<td class="total"><?php echo wc_price( $order->get_total() - $order->get_total_refunded(), array( 'currency' => $order->get_order_currency() ) ); ?></td>
<td class="total"><?php echo wc_price( $order->get_total() - $order->get_total_refunded(), array( 'currency' => $order->get_currency() ) ); ?></td>
</tr>
<tr>
<td class="label"><label for="refund_amount"><?php _e( 'Refund amount', 'woocommerce' ); ?>:</label></td>
@ -283,7 +279,7 @@ if ( wc_tax_enabled() ) {
<div class="clear"></div>
<div class="refund-actions">
<?php
$refund_amount = '<span class="wc-order-refund-amount">' . wc_price( 0, array( 'currency' => $order->get_order_currency() ) ) . '</span>';
$refund_amount = '<span class="wc-order-refund-amount">' . wc_price( 0, array( 'currency' => $order->get_currency() ) ) . '</span>';
$gateway_supports_refunds = false !== $payment_gateway && $payment_gateway->supports( 'refunds' );
$gateway_name = false !== $payment_gateway ? ( ! empty( $payment_gateway->method_title ) ? $payment_gateway->method_title : $payment_gateway->get_title() ) : __( 'Payment Gateway', 'woocommerce' );
?>

View File

@ -60,10 +60,10 @@ if ( ! defined( 'ABSPATH' ) ) {
<td class="line_cost" width="1%">
<div class="view">
<?php
echo ( isset( $item['cost'] ) ) ? wc_price( wc_round_tax_total( $item['cost'] ), array( 'currency' => $order->get_order_currency() ) ) : '';
echo ( isset( $item['cost'] ) ) ? wc_price( wc_round_tax_total( $item['cost'] ), array( 'currency' => $order->get_currency() ) ) : '';
if ( $refunded = $order->get_total_refunded_for_item( $item_id, 'shipping' ) ) {
echo '<small class="refunded">-' . wc_price( $refunded, array( 'currency' => $order->get_order_currency() ) ) . '</small>';
echo '<small class="refunded">-' . wc_price( $refunded, array( 'currency' => $order->get_currency() ) ) . '</small>';
}
?>
</div>
@ -87,10 +87,10 @@ if ( ! defined( 'ABSPATH' ) ) {
<td class="line_tax" width="1%">
<div class="view">
<?php
echo ( '' != $tax_item_total ) ? wc_price( wc_round_tax_total( $tax_item_total ), array( 'currency' => $order->get_order_currency() ) ) : '&ndash;';
echo ( '' != $tax_item_total ) ? wc_price( wc_round_tax_total( $tax_item_total ), array( 'currency' => $order->get_currency() ) ) : '&ndash;';
if ( $refunded = $order->get_tax_refunded_for_item( $item_id, $tax_item_id, 'shipping' ) ) {
echo '<small class="refunded">-' . wc_price( $refunded, array( 'currency' => $order->get_order_currency() ) ) . '</small>';
echo '<small class="refunded">-' . wc_price( $refunded, array( 'currency' => $order->get_currency() ) ) . '</small>';
}
?>
</div>

View File

@ -133,7 +133,7 @@ class WC_Report_Customer_List extends WP_List_Table {
if ( ! empty( $orders ) ) {
$order = $orders[0];
return '<a href="' . admin_url( 'post.php?post=' . $order->id . '&action=edit' ) . '">' . _x( '#', 'hash before order number', 'woocommerce' ) . $order->get_order_number() . '</a> &ndash; ' . date_i18n( get_option( 'date_format' ), strtotime( $order->order_date ) );
return '<a href="' . admin_url( 'post.php?post=' . $order->get_id() . '&action=edit' ) . '">' . _x( '#', 'hash before order number', 'woocommerce' ) . $order->get_order_number() . '</a> &ndash; ' . date_i18n( get_option( 'date_format' ), $order->get_date_created() );
} else {
return '-';
}

View File

@ -484,7 +484,7 @@ class WC_REST_Customers_Controller extends WC_REST_Controller {
'last_name' => $customer->last_name,
'username' => $customer->user_login,
'last_order' => array(
'id' => is_object( $last_order ) ? $last_order->id : null,
'id' => is_object( $last_order ) ? $last_order->get_id() : null,
'date' => is_object( $last_order ) ? wc_rest_prepare_date_response( $last_order->post->post_date_gmt ) : null
),
'orders_count' => wc_get_customer_order_count( $customer->ID ),

View File

@ -228,7 +228,7 @@ class WC_REST_Order_Notes_Controller extends WC_REST_Controller {
$response = $this->prepare_item_for_response( $note, $request );
$response = rest_ensure_response( $response );
$response->set_status( 201 );
$response->header( 'Location', rest_url( sprintf( '/%s/%s/%d', $this->namespace, str_replace( '(?P<order_id>[\d]+)', $order->id, $this->rest_base ), $note_id ) ) );
$response->header( 'Location', rest_url( sprintf( '/%s/%s/%d', $this->namespace, str_replace( '(?P<order_id>[\d]+)', $order->get_id(), $this->rest_base ), $note_id ) ) );
return $response;
}

View File

@ -114,7 +114,7 @@ class WC_REST_Order_Refunds_Controller extends WC_REST_Posts_Controller {
$refund = wc_get_order( $post );
if ( ! $refund || intval( $refund->post->post_parent ) !== intval( $order->id ) ) {
if ( ! $refund || intval( $refund->post->post_parent ) !== intval( $order->get_id() ) ) {
return new WP_Error( 'woocommerce_rest_invalid_order_refund_id', __( 'Invalid order refund ID.', 'woocommerce' ), 404 );
}
@ -299,8 +299,8 @@ class WC_REST_Order_Refunds_Controller extends WC_REST_Posts_Controller {
$order = wc_get_order( $order_data );
if ( isset( $payment_gateways[ $order->payment_method ] ) && $payment_gateways[ $order->payment_method ]->supports( 'refunds' ) ) {
$result = $payment_gateways[ $order->payment_method ]->process_refund( $order_id, $refund->get_refund_amount(), $refund->get_refund_reason() );
if ( isset( $payment_gateways[ $order->get_payment_method() ] ) && $payment_gateways[ $order->get_payment_method() ]->supports( 'refunds' ) ) {
$result = $payment_gateways[ $order->get_payment_method() ]->process_refund( $order_id, $refund->get_refund_amount(), $refund->get_refund_reason() );
if ( is_wp_error( $result ) ) {
return $result;

View File

@ -125,12 +125,12 @@ class WC_REST_Orders_Controller extends WC_REST_Posts_Controller {
$dp = $request['dp'];
$data = array(
'id' => $order->id,
'id' => $order->get_id(),
'parent_id' => $post->post_parent,
'status' => $order->get_status(),
'order_key' => $order->order_key,
'order_key' => $order->get_order_key(),
'number' => $order->get_order_number(),
'currency' => $order->get_order_currency(),
'currency' => $order->get_currency(),
'version' => $order->order_version,
'prices_include_tax' => $order->prices_include_tax,
'date_created' => wc_rest_prepare_date_response( $post->post_date_gmt ),
@ -145,16 +145,16 @@ class WC_REST_Orders_Controller extends WC_REST_Posts_Controller {
'total_tax' => wc_format_decimal( $order->get_total_tax(), $dp ),
'billing' => array(),
'shipping' => array(),
'payment_method' => $order->payment_method,
'payment_method_title' => $order->payment_method_title,
'payment_method' => $order->get_payment_method(),
'payment_method_title' => $order->get_payment_method_title(),
'transaction_id' => $order->get_transaction_id(),
'customer_ip_address' => $order->customer_ip_address,
'customer_user_agent' => $order->customer_user_agent,
'customer_ip_address' => $order->get_customer_ip_address(),
'customer_user_agent' => $order->get_user_agent(),
'created_via' => $order->created_via,
'customer_note' => $order->customer_note,
'customer_note' => $order->get_customer_note(),
'date_completed' => wc_rest_prepare_date_response( $order->completed_date ),
'date_paid' => $order->paid_date,
'cart_hash' => $order->cart_hash,
'date_paid' => $order->get_date_paid(),
'cart_hash' => $order->get_cart_hash(),
'line_items' => array(),
'tax_lines' => array(),
'shipping_lines' => array(),
@ -364,7 +364,7 @@ class WC_REST_Orders_Controller extends WC_REST_Posts_Controller {
protected function prepare_links( $order ) {
$links = array(
'self' => array(
'href' => rest_url( sprintf( '/%s/%s/%d', $this->namespace, $this->rest_base, $order->id ) ),
'href' => rest_url( sprintf( '/%s/%s/%d', $this->namespace, $this->rest_base, $order->get_id() ) ),
),
'collection' => array(
'href' => rest_url( sprintf( '/%s/%s', $this->namespace, $this->rest_base ) ),
@ -517,7 +517,7 @@ class WC_REST_Orders_Controller extends WC_REST_Posts_Controller {
}
// Set currency.
update_post_meta( $order->id, '_order_currency', $request['currency'] );
update_post_meta( $order->get_id(), '_order_currency', $request['currency'] );
// Set lines.
$lines = array(
@ -541,10 +541,10 @@ class WC_REST_Orders_Controller extends WC_REST_Posts_Controller {
// Set payment method.
if ( ! empty( $request['payment_method'] ) ) {
update_post_meta( $order->id, '_payment_method', $request['payment_method'] );
update_post_meta( $order->get_id(), '_payment_method', $request['payment_method'] );
}
if ( ! empty( $request['payment_method_title'] ) ) {
update_post_meta( $order->id, '_payment_method_title', $request['payment_method_title'] );
update_post_meta( $order->get_id(), '_payment_method_title', $request['payment_method_title'] );
}
if ( true === $request['set_paid'] ) {
$order->payment_complete( $request['transaction_id'] );
@ -552,12 +552,12 @@ class WC_REST_Orders_Controller extends WC_REST_Posts_Controller {
// Set meta data.
if ( ! empty( $request['meta_data'] ) && is_array( $request['meta_data'] ) ) {
$this->update_meta_data( $order->id, $request['meta_data'] );
$this->update_meta_data( $order->get_id(), $request['meta_data'] );
}
wc_transaction_query( 'commit' );
return $order->id;
return $order->get_id();
} catch ( WC_REST_Exception $e ) {
wc_transaction_query( 'rollback' );
@ -934,7 +934,7 @@ class WC_REST_Orders_Controller extends WC_REST_Posts_Controller {
$result = $wpdb->get_row(
$wpdb->prepare( "SELECT * FROM {$wpdb->prefix}woocommerce_order_items WHERE order_item_id = %d AND order_id = %d",
absint( $item['id'] ),
absint( $order->id )
absint( $order->get_id() )
) );
if ( is_null( $result ) ) {
@ -975,7 +975,7 @@ class WC_REST_Orders_Controller extends WC_REST_Posts_Controller {
try {
$update_totals = false;
$order = wc_get_order( $post );
$order_args = array( 'order_id' => $order->id );
$order_args = array( 'order_id' => $order->get_id() );
// Customer note.
if ( isset( $request['customer_note'] ) ) {
@ -989,7 +989,7 @@ class WC_REST_Orders_Controller extends WC_REST_Posts_Controller {
throw new WC_REST_Exception( 'woocommerce_rest_invalid_customer_id', __( 'Customer ID is invalid.', 'woocommerce' ), 400 );
}
update_post_meta( $order->id, '_customer_user', $request['customer_id'] );
update_post_meta( $order->get_id(), '_customer_user', $request['customer_id'] );
}
// Update addresses.
@ -1032,10 +1032,10 @@ class WC_REST_Orders_Controller extends WC_REST_Posts_Controller {
// Set payment method.
if ( ! empty( $request['payment_method'] ) ) {
update_post_meta( $order->id, '_payment_method', $request['payment_method'] );
update_post_meta( $order->get_id(), '_payment_method', $request['payment_method'] );
}
if ( ! empty( $request['payment_method_title'] ) ) {
update_post_meta( $order->id, '_payment_method_title', $request['payment_method'] );
update_post_meta( $order->get_id(), '_payment_method_title', $request['payment_method'] );
}
if ( $order->needs_payment() && isset( $request['set_paid'] ) && true === $request['set_paid'] ) {
$order->payment_complete( ! empty( $request['transaction_id'] ) ? $request['transaction_id'] : '' );
@ -1043,7 +1043,7 @@ class WC_REST_Orders_Controller extends WC_REST_Posts_Controller {
// Set order currency.
if ( isset( $request['currency'] ) ) {
update_post_meta( $order->id, '_order_currency', $request['currency'] );
update_post_meta( $order->get_id(), '_order_currency', $request['currency'] );
}
// If items have changed, recalculate order totals.
@ -1053,7 +1053,7 @@ class WC_REST_Orders_Controller extends WC_REST_Posts_Controller {
// Update meta data.
if ( ! empty( $request['meta_data'] ) && is_array( $request['meta_data'] ) ) {
$this->update_meta_data( $order->id, $request['meta_data'] );
$this->update_meta_data( $order->get_id(), $request['meta_data'] );
}
// Update the order post to set customer note/modified date.
@ -1064,7 +1064,7 @@ class WC_REST_Orders_Controller extends WC_REST_Posts_Controller {
$order->update_status( $request['status'], isset( $request['status_note'] ) ? $request['status_note'] : '' );
}
return $order->id;
return $order->get_id();
} catch ( WC_REST_Exception $e ) {
return new WP_Error( $e->getErrorCode(), $e->getMessage(), array( 'status' => $e->getCode() ) );
}

View File

@ -146,7 +146,7 @@ class WC_API_Customers extends WC_API_Resource {
'first_name' => $customer->first_name,
'last_name' => $customer->last_name,
'username' => $customer->user_login,
'last_order_id' => is_object( $last_order ) ? $last_order->id : null,
'last_order_id' => is_object( $last_order ) ? $last_order->get_id() : null,
'last_order_date' => is_object( $last_order ) ? $this->server->format_datetime( $last_order->post_date_gmt ) : null,
'orders_count' => (int) $customer->_order_count,
'total_spent' => wc_format_decimal( $customer->_money_spent, 2 ),
@ -359,43 +359,43 @@ class WC_API_Customers extends WC_API_Resource {
*/
public function add_customer_data( $order_data, $order ) {
if ( 0 == $order->customer_user ) {
if ( 0 == $order->get_user_id() ) {
// add customer data from order
$order_data['customer'] = array(
'id' => 0,
'email' => $order->billing_email,
'first_name' => $order->billing_first_name,
'last_name' => $order->billing_last_name,
'email' => $order->get_billing_email(),
'first_name' => $order->get_billing_first_name(),
'last_name' => $order->get_billing_last_name(),
'billing_address' => array(
'first_name' => $order->billing_first_name,
'last_name' => $order->billing_last_name,
'company' => $order->billing_company,
'address_1' => $order->billing_address_1,
'address_2' => $order->billing_address_2,
'city' => $order->billing_city,
'state' => $order->billing_state,
'postcode' => $order->billing_postcode,
'country' => $order->billing_country,
'email' => $order->billing_email,
'phone' => $order->billing_phone,
'first_name' => $order->get_billing_first_name(),
'last_name' => $order->get_billing_last_name(),
'company' => $order->get_billing_company(),
'address_1' => $order->get_billing_address_1(),
'address_2' => $order->get_billing_address_2(),
'city' => $order->get_billing_city(),
'state' => $order->get_billing_state(),
'postcode' => $order->get_billing_postcode(),
'country' => $order->get_billing_country(),
'email' => $order->get_billing_email(),
'phone' => $order->get_billing_phone(),
),
'shipping_address' => array(
'first_name' => $order->shipping_first_name,
'last_name' => $order->shipping_last_name,
'company' => $order->shipping_company,
'address_1' => $order->shipping_address_1,
'address_2' => $order->shipping_address_2,
'city' => $order->shipping_city,
'state' => $order->shipping_state,
'postcode' => $order->shipping_postcode,
'country' => $order->shipping_country,
'first_name' => $order->get_shipping_first_name(),
'last_name' => $order->get_shipping_last_name(),
'company' => $order->get_shipping_company(),
'address_1' => $order->get_shipping_address_1(),
'address_2' => $order->get_shipping_address_2(),
'city' => $order->get_shipping_city(),
'state' => $order->get_shipping_state(),
'postcode' => $order->get_shipping_postcode(),
'country' => $order->get_shipping_country(),
),
);
} else {
$order_data['customer'] = current( $this->get_customer( $order->customer_user ) );
$order_data['customer'] = current( $this->get_customer( $order->get_user_id() ) );
}
return $order_data;

View File

@ -114,7 +114,7 @@ class WC_API_Orders extends WC_API_Resource {
$order_post = get_post( $id );
$order_data = array(
'id' => $order->id,
'id' => $order->get_id(),
'order_number' => $order->get_order_number(),
'created_at' => $this->server->format_datetime( $order_post->post_date_gmt ),
'updated_at' => $this->server->format_datetime( $order_post->post_modified_gmt ),
@ -133,38 +133,38 @@ class WC_API_Orders extends WC_API_Resource {
'order_discount' => wc_format_decimal( $order->get_order_discount(), 2 ),
'shipping_methods' => $order->get_shipping_method(),
'payment_details' => array(
'method_id' => $order->payment_method,
'method_title' => $order->payment_method_title,
'paid' => isset( $order->paid_date ),
'method_id' => $order->get_payment_method(),
'method_title' => $order->get_payment_method_title(),
'paid' => 0 < $order->get_date_paid(),
),
'billing_address' => array(
'first_name' => $order->billing_first_name,
'last_name' => $order->billing_last_name,
'company' => $order->billing_company,
'address_1' => $order->billing_address_1,
'address_2' => $order->billing_address_2,
'city' => $order->billing_city,
'state' => $order->billing_state,
'postcode' => $order->billing_postcode,
'country' => $order->billing_country,
'email' => $order->billing_email,
'phone' => $order->billing_phone,
'first_name' => $order->get_billing_first_name(),
'last_name' => $order->get_billing_last_name(),
'company' => $order->get_billing_company(),
'address_1' => $order->get_billing_address_1(),
'address_2' => $order->get_billing_address_2(),
'city' => $order->get_billing_city(),
'state' => $order->get_billing_state(),
'postcode' => $order->get_billing_postcode(),
'country' => $order->get_billing_country(),
'email' => $order->get_billing_email(),
'phone' => $order->get_billing_phone(),
),
'shipping_address' => array(
'first_name' => $order->shipping_first_name,
'last_name' => $order->shipping_last_name,
'company' => $order->shipping_company,
'address_1' => $order->shipping_address_1,
'address_2' => $order->shipping_address_2,
'city' => $order->shipping_city,
'state' => $order->shipping_state,
'postcode' => $order->shipping_postcode,
'country' => $order->shipping_country,
'first_name' => $order->get_shipping_first_name(),
'last_name' => $order->get_shipping_last_name(),
'company' => $order->get_shipping_company(),
'address_1' => $order->get_shipping_address_1(),
'address_2' => $order->get_shipping_address_2(),
'city' => $order->get_shipping_city(),
'state' => $order->get_shipping_state(),
'postcode' => $order->get_shipping_postcode(),
'country' => $order->get_shipping_country(),
),
'note' => $order->customer_note,
'customer_ip' => $order->customer_ip_address,
'customer_user_agent' => $order->customer_user_agent,
'customer_id' => $order->customer_user,
'note' => $order->get_customer_note(),
'customer_ip' => $order->get_customer_ip_address(),
'customer_user_agent' => $order->get_user_agent(),
'customer_id' => $order->get_user_id(),
'view_order_url' => $order->get_view_order_url(),
'line_items' => array(),
'shipping_lines' => array(),

View File

@ -169,7 +169,7 @@ class WC_API_Customers extends WC_API_Resource {
'last_name' => $customer->last_name,
'username' => $customer->user_login,
'role' => $roles[0],
'last_order_id' => is_object( $last_order ) ? $last_order->id : null,
'last_order_id' => is_object( $last_order ) ? $last_order->get_id() : null,
'last_order_date' => is_object( $last_order ) ? $this->server->format_datetime( $last_order->post_date_gmt ) : null,
'orders_count' => wc_get_customer_order_count( $customer->ID ),
'total_spent' => wc_format_decimal( wc_get_customer_total_spent( $customer->ID ), 2 ),
@ -622,43 +622,43 @@ class WC_API_Customers extends WC_API_Resource {
*/
public function add_customer_data( $order_data, $order ) {
if ( 0 == $order->customer_user ) {
if ( 0 == $order->get_user_id() ) {
// add customer data from order
$order_data['customer'] = array(
'id' => 0,
'email' => $order->billing_email,
'first_name' => $order->billing_first_name,
'last_name' => $order->billing_last_name,
'email' => $order->get_billing_email(),
'first_name' => $order->get_billing_first_name(),
'last_name' => $order->get_billing_last_name(),
'billing_address' => array(
'first_name' => $order->billing_first_name,
'last_name' => $order->billing_last_name,
'company' => $order->billing_company,
'address_1' => $order->billing_address_1,
'address_2' => $order->billing_address_2,
'city' => $order->billing_city,
'state' => $order->billing_state,
'postcode' => $order->billing_postcode,
'country' => $order->billing_country,
'email' => $order->billing_email,
'phone' => $order->billing_phone,
'first_name' => $order->get_billing_first_name(),
'last_name' => $order->get_billing_last_name(),
'company' => $order->get_billing_company(),
'address_1' => $order->get_billing_address_1(),
'address_2' => $order->get_billing_address_2(),
'city' => $order->get_billing_city(),
'state' => $order->get_billing_state(),
'postcode' => $order->get_billing_postcode(),
'country' => $order->get_billing_country(),
'email' => $order->get_billing_email(),
'phone' => $order->get_billing_phone(),
),
'shipping_address' => array(
'first_name' => $order->shipping_first_name,
'last_name' => $order->shipping_last_name,
'company' => $order->shipping_company,
'address_1' => $order->shipping_address_1,
'address_2' => $order->shipping_address_2,
'city' => $order->shipping_city,
'state' => $order->shipping_state,
'postcode' => $order->shipping_postcode,
'country' => $order->shipping_country,
'first_name' => $order->get_shipping_first_name(),
'last_name' => $order->get_shipping_last_name(),
'company' => $order->get_shipping_company(),
'address_1' => $order->get_shipping_address_1(),
'address_2' => $order->get_shipping_address_2(),
'city' => $order->get_shipping_city(),
'state' => $order->get_shipping_state(),
'postcode' => $order->get_shipping_postcode(),
'country' => $order->get_shipping_country(),
),
);
} else {
$order_data['customer'] = current( $this->get_customer( $order->customer_user ) );
$order_data['customer'] = current( $this->get_customer( $order->get_user_id() ) );
}
return $order_data;

View File

@ -154,13 +154,13 @@ class WC_API_Orders extends WC_API_Resource {
$order_post = get_post( $id );
$order_data = array(
'id' => $order->id,
'id' => $order->get_id(),
'order_number' => $order->get_order_number(),
'created_at' => $this->server->format_datetime( $order_post->post_date_gmt ),
'updated_at' => $this->server->format_datetime( $order_post->post_modified_gmt ),
'completed_at' => $this->server->format_datetime( $order->completed_date, true ),
'status' => $order->get_status(),
'currency' => $order->get_order_currency(),
'currency' => $order->get_currency(),
'total' => wc_format_decimal( $order->get_total(), $dp ),
'subtotal' => wc_format_decimal( $order->get_subtotal(), $dp ),
'total_line_items_quantity' => $order->get_item_count(),
@ -171,37 +171,37 @@ class WC_API_Orders extends WC_API_Resource {
'total_discount' => wc_format_decimal( $order->get_total_discount(), $dp ),
'shipping_methods' => $order->get_shipping_method(),
'payment_details' => array(
'method_id' => $order->payment_method,
'method_title' => $order->payment_method_title,
'paid' => isset( $order->paid_date ),
'method_id' => $order->get_payment_method(),
'method_title' => $order->get_payment_method_title(),
'paid' => 0 < $order->get_date_paid(),
),
'billing_address' => array(
'first_name' => $order->billing_first_name,
'last_name' => $order->billing_last_name,
'company' => $order->billing_company,
'address_1' => $order->billing_address_1,
'address_2' => $order->billing_address_2,
'city' => $order->billing_city,
'state' => $order->billing_state,
'postcode' => $order->billing_postcode,
'country' => $order->billing_country,
'email' => $order->billing_email,
'phone' => $order->billing_phone,
'first_name' => $order->get_billing_first_name(),
'last_name' => $order->get_billing_last_name(),
'company' => $order->get_billing_company(),
'address_1' => $order->get_billing_address_1(),
'address_2' => $order->get_billing_address_2(),
'city' => $order->get_billing_city(),
'state' => $order->get_billing_state(),
'postcode' => $order->get_billing_postcode(),
'country' => $order->get_billing_country(),
'email' => $order->get_billing_email(),
'phone' => $order->get_billing_phone(),
),
'shipping_address' => array(
'first_name' => $order->shipping_first_name,
'last_name' => $order->shipping_last_name,
'company' => $order->shipping_company,
'address_1' => $order->shipping_address_1,
'address_2' => $order->shipping_address_2,
'city' => $order->shipping_city,
'state' => $order->shipping_state,
'postcode' => $order->shipping_postcode,
'country' => $order->shipping_country,
'first_name' => $order->get_shipping_first_name(),
'last_name' => $order->get_shipping_last_name(),
'company' => $order->get_shipping_company(),
'address_1' => $order->get_shipping_address_1(),
'address_2' => $order->get_shipping_address_2(),
'city' => $order->get_shipping_city(),
'state' => $order->get_shipping_state(),
'postcode' => $order->get_shipping_postcode(),
'country' => $order->get_shipping_country(),
),
'note' => $order->customer_note,
'customer_ip' => $order->customer_ip_address,
'customer_user_agent' => $order->customer_user_agent,
'note' => $order->get_customer_note(),
'customer_ip' => $order->get_customer_ip_address(),
'customer_user_agent' => $order->get_user_agent(),
'customer_id' => $order->get_user_id(),
'view_order_url' => $order->get_view_order_url(),
'line_items' => array(),
@ -451,8 +451,8 @@ class WC_API_Orders extends WC_API_Resource {
throw new WC_API_Exception( 'woocommerce_invalid_payment_details', __( 'Payment method ID and title are required', 'woocommerce' ), 400 );
}
update_post_meta( $order->id, '_payment_method', $data['payment_details']['method_id'] );
update_post_meta( $order->id, '_payment_method_title', $data['payment_details']['method_title'] );
update_post_meta( $order->get_id(), '_payment_method', $data['payment_details']['method_id'] );
update_post_meta( $order->get_id(), '_payment_method_title', $data['payment_details']['method_title'] );
// mark as paid if set
if ( isset( $data['payment_details']['paid'] ) && true === $data['payment_details']['paid'] ) {
@ -467,24 +467,24 @@ class WC_API_Orders extends WC_API_Resource {
throw new WC_API_Exception( 'woocommerce_invalid_order_currency', __( 'Provided order currency is invalid', 'woocommerce'), 400 );
}
update_post_meta( $order->id, '_order_currency', $data['currency'] );
update_post_meta( $order->get_id(), '_order_currency', $data['currency'] );
}
// set order meta
if ( isset( $data['order_meta'] ) && is_array( $data['order_meta'] ) ) {
$this->set_order_meta( $order->id, $data['order_meta'] );
$this->set_order_meta( $order->get_id(), $data['order_meta'] );
}
// HTTP 201 Created
$this->server->send_status( 201 );
wc_delete_shop_order_transients( $order->id );
wc_delete_shop_order_transients( $order->get_id() );
do_action( 'woocommerce_api_create_order', $order->id, $data, $this );
do_action( 'woocommerce_api_create_order', $order->get_id(), $data, $this );
wc_transaction_query( 'commit' );
return $this->get_order( $order->id );
return $this->get_order( $order->get_id() );
} catch ( WC_API_Exception $e ) {
@ -538,7 +538,7 @@ class WC_API_Orders extends WC_API_Resource {
throw new WC_API_Exception( 'woocommerce_api_invalid_order_id', __( 'Order ID is invalid', 'woocommerce' ), 400 );
}
$order_args = array( 'order_id' => $order->id );
$order_args = array( 'order_id' => $order->get_id() );
// Customer note.
if ( isset( $data['note'] ) ) {
@ -552,7 +552,7 @@ class WC_API_Orders extends WC_API_Resource {
throw new WC_API_Exception( 'woocommerce_api_invalid_customer_id', __( 'Customer ID is invalid', 'woocommerce' ), 400 );
}
update_post_meta( $order->id, '_customer_user', $data['customer_id'] );
update_post_meta( $order->get_id(), '_customer_user', $data['customer_id'] );
}
// Billing/shipping address.
@ -597,12 +597,12 @@ class WC_API_Orders extends WC_API_Resource {
// Method ID.
if ( isset( $data['payment_details']['method_id'] ) ) {
update_post_meta( $order->id, '_payment_method', $data['payment_details']['method_id'] );
update_post_meta( $order->get_id(), '_payment_method', $data['payment_details']['method_id'] );
}
// Method title.
if ( isset( $data['payment_details']['method_title'] ) ) {
update_post_meta( $order->id, '_payment_method_title', $data['payment_details']['method_title'] );
update_post_meta( $order->get_id(), '_payment_method_title', $data['payment_details']['method_title'] );
}
// Mark as paid if set.
@ -617,7 +617,7 @@ class WC_API_Orders extends WC_API_Resource {
throw new WC_API_Exception( 'woocommerce_invalid_order_currency', __( 'Provided order currency is invalid', 'woocommerce' ), 400 );
}
update_post_meta( $order->id, '_order_currency', $data['currency'] );
update_post_meta( $order->get_id(), '_order_currency', $data['currency'] );
}
// If items have changed, recalculate order totals.
@ -627,7 +627,7 @@ class WC_API_Orders extends WC_API_Resource {
// Update order meta.
if ( isset( $data['order_meta'] ) && is_array( $data['order_meta'] ) ) {
$this->set_order_meta( $order->id, $data['order_meta'] );
$this->set_order_meta( $order->get_id(), $data['order_meta'] );
}
// Update the order post to set customer note/modified date.
@ -638,9 +638,9 @@ class WC_API_Orders extends WC_API_Resource {
$order->update_status( $data['status'], isset( $data['status_note'] ) ? $data['status_note'] : '', true );
}
wc_delete_shop_order_transients( $order->id );
wc_delete_shop_order_transients( $order->get_id() );
do_action( 'woocommerce_api_edit_order', $order->id, $data, $this );
do_action( 'woocommerce_api_edit_order', $order->get_id(), $data, $this );
return $this->get_order( $id );
@ -835,7 +835,7 @@ class WC_API_Orders extends WC_API_Resource {
$result = $wpdb->get_row(
$wpdb->prepare( "SELECT * FROM {$wpdb->prefix}woocommerce_order_items WHERE order_item_id = %d AND order_id = %d",
absint( $item['id'] ),
absint( $order->id )
absint( $order->get_id() )
) );
if ( is_null( $result ) ) {
@ -1321,7 +1321,7 @@ class WC_API_Orders extends WC_API_Resource {
do_action( 'woocommerce_api_create_order_note', $note_id, $order_id, $this );
return $this->get_order_note( $order->id, $note_id );
return $this->get_order_note( $order->get_id(), $note_id );
} catch ( WC_API_Exception $e ) {
return new WP_Error( $e->getErrorCode(), $e->getMessage(), array( 'status' => $e->getCode() ) );
}
@ -1368,11 +1368,11 @@ class WC_API_Orders extends WC_API_Resource {
}
// Ensure note ID is associated with given order
if ( $note->comment_post_ID != $order->id ) {
if ( $note->comment_post_ID != $order->get_id() ) {
throw new WC_API_Exception( 'woocommerce_api_invalid_order_note_id', __( 'The order note ID provided is not associated with the order', 'woocommerce' ), 400 );
}
$data = apply_filters( 'woocommerce_api_edit_order_note_data', $data, $note->comment_ID, $order->id, $this );
$data = apply_filters( 'woocommerce_api_edit_order_note_data', $data, $note->comment_ID, $order->get_id(), $this );
// Note content
if ( isset( $data['note'] ) ) {
@ -1391,9 +1391,9 @@ class WC_API_Orders extends WC_API_Resource {
update_comment_meta( $note->comment_ID, 'is_customer_note', true === $data['customer_note'] ? 1 : 0 );
}
do_action( 'woocommerce_api_edit_order_note', $note->comment_ID, $order->id, $this );
do_action( 'woocommerce_api_edit_order_note', $note->comment_ID, $order->get_id(), $this );
return $this->get_order_note( $order->id, $note->comment_ID );
return $this->get_order_note( $order->get_id(), $note->comment_ID );
} catch ( WC_API_Exception $e ) {
return new WP_Error( $e->getErrorCode(), $e->getMessage(), array( 'status' => $e->getCode() ) );
}
@ -1614,8 +1614,8 @@ class WC_API_Orders extends WC_API_Resource {
$order = wc_get_order( $order_id );
if ( isset( $payment_gateways[ $order->payment_method ] ) && $payment_gateways[ $order->payment_method ]->supports( 'refunds' ) ) {
$result = $payment_gateways[ $order->payment_method ]->process_refund( $order_id, $refund->get_refund_amount(), $refund->get_refund_reason() );
if ( isset( $payment_gateways[ $order->get_payment_method() ] ) && $payment_gateways[ $order->get_payment_method() ]->supports( 'refunds' ) ) {
$result = $payment_gateways[ $order->get_payment_method() ]->process_refund( $order_id, $refund->get_refund_amount(), $refund->get_refund_reason() );
if ( is_wp_error( $result ) ) {
return $result;

View File

@ -170,7 +170,7 @@ class WC_API_Customers extends WC_API_Resource {
'last_name' => $customer->last_name,
'username' => $customer->user_login,
'role' => $roles[0],
'last_order_id' => is_object( $last_order ) ? $last_order->id : null,
'last_order_id' => is_object( $last_order ) ? $last_order->get_id() : null,
'last_order_date' => is_object( $last_order ) ? $this->server->format_datetime( $last_order->post_date_gmt ) : null,
'orders_count' => wc_get_customer_order_count( $customer->ID ),
'total_spent' => wc_format_decimal( wc_get_customer_total_spent( $customer->ID ), 2 ),
@ -611,43 +611,43 @@ class WC_API_Customers extends WC_API_Resource {
*/
public function add_customer_data( $order_data, $order ) {
if ( 0 == $order->customer_user ) {
if ( 0 == $order->get_user_id() ) {
// add customer data from order
$order_data['customer'] = array(
'id' => 0,
'email' => $order->billing_email,
'first_name' => $order->billing_first_name,
'last_name' => $order->billing_last_name,
'email' => $order->get_billing_email(),
'first_name' => $order->get_billing_first_name(),
'last_name' => $order->get_billing_last_name(),
'billing_address' => array(
'first_name' => $order->billing_first_name,
'last_name' => $order->billing_last_name,
'company' => $order->billing_company,
'address_1' => $order->billing_address_1,
'address_2' => $order->billing_address_2,
'city' => $order->billing_city,
'state' => $order->billing_state,
'postcode' => $order->billing_postcode,
'country' => $order->billing_country,
'email' => $order->billing_email,
'phone' => $order->billing_phone,
'first_name' => $order->get_billing_first_name(),
'last_name' => $order->get_billing_last_name(),
'company' => $order->get_billing_company(),
'address_1' => $order->get_billing_address_1(),
'address_2' => $order->get_billing_address_2(),
'city' => $order->get_billing_city(),
'state' => $order->get_billing_state(),
'postcode' => $order->get_billing_postcode(),
'country' => $order->get_billing_country(),
'email' => $order->get_billing_email(),
'phone' => $order->get_billing_phone(),
),
'shipping_address' => array(
'first_name' => $order->shipping_first_name,
'last_name' => $order->shipping_last_name,
'company' => $order->shipping_company,
'address_1' => $order->shipping_address_1,
'address_2' => $order->shipping_address_2,
'city' => $order->shipping_city,
'state' => $order->shipping_state,
'postcode' => $order->shipping_postcode,
'country' => $order->shipping_country,
'first_name' => $order->get_shipping_first_name(),
'last_name' => $order->get_shipping_last_name(),
'company' => $order->get_shipping_company(),
'address_1' => $order->get_shipping_address_1(),
'address_2' => $order->get_shipping_address_2(),
'city' => $order->get_shipping_city(),
'state' => $order->get_shipping_state(),
'postcode' => $order->get_shipping_postcode(),
'country' => $order->get_shipping_country(),
),
);
} else {
$order_data['customer'] = current( $this->get_customer( $order->customer_user ) );
$order_data['customer'] = current( $this->get_customer( $order->get_user_id() ) );
}
return $order_data;

View File

@ -159,14 +159,14 @@ class WC_API_Orders extends WC_API_Resource {
}
$order_data = array(
'id' => $order->id,
'id' => $order->get_id(),
'order_number' => $order->get_order_number(),
'order_key' => $order->order_key,
'order_key' => $order->get_order_key(),
'created_at' => $this->server->format_datetime( $order_post->post_date_gmt ),
'updated_at' => $this->server->format_datetime( $order_post->post_modified_gmt ),
'completed_at' => $this->server->format_datetime( $order->completed_date, true ),
'status' => $order->get_status(),
'currency' => $order->get_order_currency(),
'currency' => $order->get_currency(),
'total' => wc_format_decimal( $order->get_total(), $dp ),
'subtotal' => wc_format_decimal( $order->get_subtotal(), $dp ),
'total_line_items_quantity' => $order->get_item_count(),
@ -177,37 +177,37 @@ class WC_API_Orders extends WC_API_Resource {
'total_discount' => wc_format_decimal( $order->get_total_discount(), $dp ),
'shipping_methods' => $order->get_shipping_method(),
'payment_details' => array(
'method_id' => $order->payment_method,
'method_title' => $order->payment_method_title,
'paid' => isset( $order->paid_date ),
'method_id' => $order->get_payment_method(),
'method_title' => $order->get_payment_method_title(),
'paid' => 0 < $order->get_date_paid(),
),
'billing_address' => array(
'first_name' => $order->billing_first_name,
'last_name' => $order->billing_last_name,
'company' => $order->billing_company,
'address_1' => $order->billing_address_1,
'address_2' => $order->billing_address_2,
'city' => $order->billing_city,
'state' => $order->billing_state,
'postcode' => $order->billing_postcode,
'country' => $order->billing_country,
'email' => $order->billing_email,
'phone' => $order->billing_phone,
'first_name' => $order->get_billing_first_name(),
'last_name' => $order->get_billing_last_name(),
'company' => $order->get_billing_company(),
'address_1' => $order->get_billing_address_1(),
'address_2' => $order->get_billing_address_2(),
'city' => $order->get_billing_city(),
'state' => $order->get_billing_state(),
'postcode' => $order->get_billing_postcode(),
'country' => $order->get_billing_country(),
'email' => $order->get_billing_email(),
'phone' => $order->get_billing_phone(),
),
'shipping_address' => array(
'first_name' => $order->shipping_first_name,
'last_name' => $order->shipping_last_name,
'company' => $order->shipping_company,
'address_1' => $order->shipping_address_1,
'address_2' => $order->shipping_address_2,
'city' => $order->shipping_city,
'state' => $order->shipping_state,
'postcode' => $order->shipping_postcode,
'country' => $order->shipping_country,
'first_name' => $order->get_shipping_first_name(),
'last_name' => $order->get_shipping_last_name(),
'company' => $order->get_shipping_company(),
'address_1' => $order->get_shipping_address_1(),
'address_2' => $order->get_shipping_address_2(),
'city' => $order->get_shipping_city(),
'state' => $order->get_shipping_state(),
'postcode' => $order->get_shipping_postcode(),
'country' => $order->get_shipping_country(),
),
'note' => $order->customer_note,
'customer_ip' => $order->customer_ip_address,
'customer_user_agent' => $order->customer_user_agent,
'note' => $order->get_customer_note(),
'customer_ip' => $order->get_customer_ip_address(),
'customer_user_agent' => $order->get_user_agent(),
'customer_id' => $order->get_user_id(),
'view_order_url' => $order->get_view_order_url(),
'line_items' => array(),
@ -474,7 +474,7 @@ class WC_API_Orders extends WC_API_Resource {
// set is vat exempt
if ( isset( $data['is_vat_exempt'] ) ) {
update_post_meta( $order->id, '_is_vat_exempt', $data['is_vat_exempt'] ? 'yes' : 'no' );
update_post_meta( $order->get_id(), '_is_vat_exempt', $data['is_vat_exempt'] ? 'yes' : 'no' );
}
// calculate totals and set them
@ -488,8 +488,8 @@ class WC_API_Orders extends WC_API_Resource {
throw new WC_API_Exception( 'woocommerce_invalid_payment_details', __( 'Payment method ID and title are required', 'woocommerce' ), 400 );
}
update_post_meta( $order->id, '_payment_method', $data['payment_details']['method_id'] );
update_post_meta( $order->id, '_payment_method_title', $data['payment_details']['method_title'] );
update_post_meta( $order->get_id(), '_payment_method', $data['payment_details']['method_id'] );
update_post_meta( $order->get_id(), '_payment_method_title', $data['payment_details']['method_title'] );
// mark as paid if set
if ( isset( $data['payment_details']['paid'] ) && true === $data['payment_details']['paid'] ) {
@ -504,24 +504,24 @@ class WC_API_Orders extends WC_API_Resource {
throw new WC_API_Exception( 'woocommerce_invalid_order_currency', __( 'Provided order currency is invalid', 'woocommerce'), 400 );
}
update_post_meta( $order->id, '_order_currency', $data['currency'] );
update_post_meta( $order->get_id(), '_order_currency', $data['currency'] );
}
// set order meta
if ( isset( $data['order_meta'] ) && is_array( $data['order_meta'] ) ) {
$this->set_order_meta( $order->id, $data['order_meta'] );
$this->set_order_meta( $order->get_id(), $data['order_meta'] );
}
// HTTP 201 Created
$this->server->send_status( 201 );
wc_delete_shop_order_transients( $order->id );
wc_delete_shop_order_transients( $order->get_id() );
do_action( 'woocommerce_api_create_order', $order->id, $data, $this );
do_action( 'woocommerce_api_create_order', $order->get_id(), $data, $this );
wc_transaction_query( 'commit' );
return $this->get_order( $order->id );
return $this->get_order( $order->get_id() );
} catch ( WC_API_Exception $e ) {
@ -575,7 +575,7 @@ class WC_API_Orders extends WC_API_Resource {
throw new WC_API_Exception( 'woocommerce_api_invalid_order_id', __( 'Order ID is invalid', 'woocommerce' ), 400 );
}
$order_args = array( 'order_id' => $order->id );
$order_args = array( 'order_id' => $order->get_id() );
// Customer note.
if ( isset( $data['note'] ) ) {
@ -589,7 +589,7 @@ class WC_API_Orders extends WC_API_Resource {
throw new WC_API_Exception( 'woocommerce_api_invalid_customer_id', __( 'Customer ID is invalid', 'woocommerce' ), 400 );
}
update_post_meta( $order->id, '_customer_user', $data['customer_id'] );
update_post_meta( $order->get_id(), '_customer_user', $data['customer_id'] );
}
// Billing/shipping address.
@ -633,12 +633,12 @@ class WC_API_Orders extends WC_API_Resource {
// Method ID.
if ( isset( $data['payment_details']['method_id'] ) ) {
update_post_meta( $order->id, '_payment_method', $data['payment_details']['method_id'] );
update_post_meta( $order->get_id(), '_payment_method', $data['payment_details']['method_id'] );
}
// Method title.
if ( isset( $data['payment_details']['method_title'] ) ) {
update_post_meta( $order->id, '_payment_method_title', $data['payment_details']['method_title'] );
update_post_meta( $order->get_id(), '_payment_method_title', $data['payment_details']['method_title'] );
}
// Mark as paid if set.
@ -653,7 +653,7 @@ class WC_API_Orders extends WC_API_Resource {
throw new WC_API_Exception( 'woocommerce_invalid_order_currency', __( 'Provided order currency is invalid', 'woocommerce' ), 400 );
}
update_post_meta( $order->id, '_order_currency', $data['currency'] );
update_post_meta( $order->get_id(), '_order_currency', $data['currency'] );
}
// If items have changed, recalculate order totals.
@ -663,7 +663,7 @@ class WC_API_Orders extends WC_API_Resource {
// Update order meta.
if ( isset( $data['order_meta'] ) && is_array( $data['order_meta'] ) ) {
$this->set_order_meta( $order->id, $data['order_meta'] );
$this->set_order_meta( $order->get_id(), $data['order_meta'] );
}
// Update the order post to set customer note/modified date.
@ -674,9 +674,9 @@ class WC_API_Orders extends WC_API_Resource {
$order->update_status( $data['status'], isset( $data['status_note'] ) ? $data['status_note'] : '', true );
}
wc_delete_shop_order_transients( $order->id );
wc_delete_shop_order_transients( $order->get_id() );
do_action( 'woocommerce_api_edit_order', $order->id, $data, $this );
do_action( 'woocommerce_api_edit_order', $order->get_id(), $data, $this );
return $this->get_order( $id );
} catch ( WC_API_Exception $e ) {
@ -877,7 +877,7 @@ class WC_API_Orders extends WC_API_Resource {
$result = $wpdb->get_row(
$wpdb->prepare( "SELECT * FROM {$wpdb->prefix}woocommerce_order_items WHERE order_item_id = %d AND order_id = %d",
absint( $item['id'] ),
absint( $order->id )
absint( $order->get_id() )
) );
if ( is_null( $result ) ) {
@ -1366,7 +1366,7 @@ class WC_API_Orders extends WC_API_Resource {
do_action( 'woocommerce_api_create_order_note', $note_id, $order_id, $this );
return $this->get_order_note( $order->id, $note_id );
return $this->get_order_note( $order->get_id(), $note_id );
} catch ( WC_API_Exception $e ) {
return new WP_Error( $e->getErrorCode(), $e->getMessage(), array( 'status' => $e->getCode() ) );
}
@ -1413,11 +1413,11 @@ class WC_API_Orders extends WC_API_Resource {
}
// Ensure note ID is associated with given order
if ( $note->comment_post_ID != $order->id ) {
if ( $note->comment_post_ID != $order->get_id() ) {
throw new WC_API_Exception( 'woocommerce_api_invalid_order_note_id', __( 'The order note ID provided is not associated with the order', 'woocommerce' ), 400 );
}
$data = apply_filters( 'woocommerce_api_edit_order_note_data', $data, $note->comment_ID, $order->id, $this );
$data = apply_filters( 'woocommerce_api_edit_order_note_data', $data, $note->comment_ID, $order->get_id(), $this );
// Note content
if ( isset( $data['note'] ) ) {
@ -1436,9 +1436,9 @@ class WC_API_Orders extends WC_API_Resource {
update_comment_meta( $note->comment_ID, 'is_customer_note', true === $data['customer_note'] ? 1 : 0 );
}
do_action( 'woocommerce_api_edit_order_note', $note->comment_ID, $order->id, $this );
do_action( 'woocommerce_api_edit_order_note', $note->comment_ID, $order->get_id(), $this );
return $this->get_order_note( $order->id, $note->comment_ID );
return $this->get_order_note( $order->get_id(), $note->comment_ID );
} catch ( WC_API_Exception $e ) {
return new WP_Error( $e->getErrorCode(), $e->getMessage(), array( 'status' => $e->getCode() ) );
}
@ -1659,8 +1659,8 @@ class WC_API_Orders extends WC_API_Resource {
$order = wc_get_order( $order_id );
if ( isset( $payment_gateways[ $order->payment_method ] ) && $payment_gateways[ $order->payment_method ]->supports( 'refunds' ) ) {
$result = $payment_gateways[ $order->payment_method ]->process_refund( $order_id, $refund->get_refund_amount(), $refund->get_refund_reason() );
if ( isset( $payment_gateways[ $order->get_payment_method() ] ) && $payment_gateways[ $order->get_payment_method() ]->supports( 'refunds' ) ) {
$result = $payment_gateways[ $order->get_payment_method() ]->process_refund( $order_id, $refund->get_refund_amount(), $refund->get_refund_reason() );
if ( is_wp_error( $result ) ) {
return $result;

View File

@ -1062,7 +1062,7 @@ class WC_AJAX {
$product = wc_get_product( $product_id );
$files = $product->get_files();
if ( ! $order->billing_email ) {
if ( ! $order->get_billing_email() ) {
die();
}
@ -1148,64 +1148,16 @@ class WC_AJAX {
die();
}
$_product = wc_get_product( $post->ID );
$product = wc_get_product( $post->ID );
$order = wc_get_order( $order_id );
$order_taxes = $order->get_taxes();
$class = 'new_row';
$item_id = $order->add_product( $product );
$item = apply_filters( 'woocommerce_ajax_order_item', $order->get_item( $item_id ), $item_id );
// Set values
$item = array();
$item['product_id'] = $_product->id;
$item['variation_id'] = isset( $_product->variation_id ) ? $_product->variation_id : '';
$item['variation_data'] = $item['variation_id'] ? $_product->get_variation_attributes() : '';
$item['name'] = $_product->get_title();
$item['tax_class'] = $_product->get_tax_class();
$item['qty'] = 1;
$item['line_subtotal'] = wc_format_decimal( $_product->get_price_excluding_tax() );
$item['line_subtotal_tax'] = '';
$item['line_total'] = wc_format_decimal( $_product->get_price_excluding_tax() );
$item['line_tax'] = '';
$item['type'] = 'line_item';
// Add line item
$item_id = wc_add_order_item( $order_id, array(
'order_item_name' => $item['name'],
'order_item_type' => 'line_item'
) );
// Add line item meta
if ( $item_id ) {
wc_add_order_item_meta( $item_id, '_qty', $item['qty'] );
wc_add_order_item_meta( $item_id, '_tax_class', $item['tax_class'] );
wc_add_order_item_meta( $item_id, '_product_id', $item['product_id'] );
wc_add_order_item_meta( $item_id, '_variation_id', $item['variation_id'] );
wc_add_order_item_meta( $item_id, '_line_subtotal', $item['line_subtotal'] );
wc_add_order_item_meta( $item_id, '_line_subtotal_tax', $item['line_subtotal_tax'] );
wc_add_order_item_meta( $item_id, '_line_total', $item['line_total'] );
wc_add_order_item_meta( $item_id, '_line_tax', $item['line_tax'] );
// Since 2.2
wc_add_order_item_meta( $item_id, '_line_tax_data', array( 'total' => array(), 'subtotal' => array() ) );
// Store variation data in meta
if ( $item['variation_data'] && is_array( $item['variation_data'] ) ) {
foreach ( $item['variation_data'] as $key => $value ) {
wc_add_order_item_meta( $item_id, str_replace( 'attribute_', '', $key ), $value );
}
}
do_action( 'woocommerce_ajax_add_order_item_meta', $item_id, $item );
}
$item['item_meta'] = $order->get_item_meta( $item_id );
$item['item_meta_array'] = $order->get_item_meta_array( $item_id );
$item = $order->expand_item_meta( $item );
$item = apply_filters( 'woocommerce_ajax_order_item', $item, $item_id );
do_action( 'woocommerce_ajax_add_order_item_meta', $item_id, $item );
include( 'admin/meta-boxes/views/html-order-item.php' );
// Quit out
die();
}
@ -1256,11 +1208,11 @@ class WC_AJAX {
$order = wc_get_order( $order_id );
$order_taxes = $order->get_taxes();
$shipping_methods = WC()->shipping() ? WC()->shipping->load_shipping_methods() : array();
$item = array();
// Add new shipping
$shipping = new WC_Shipping_Rate();
$item_id = $order->add_shipping( $shipping );
$shipping = new WC_Shipping_Rate();
$item_id = $order->add_shipping( $shipping );
$item = $order->get_item( $item_id );
include( 'admin/meta-boxes/views/html-order-shipping.php' );
@ -2222,8 +2174,8 @@ class WC_AJAX {
if ( WC()->payment_gateways() ) {
$payment_gateways = WC()->payment_gateways->payment_gateways();
}
if ( isset( $payment_gateways[ $order->payment_method ] ) && $payment_gateways[ $order->payment_method ]->supports( 'refunds' ) ) {
$result = $payment_gateways[ $order->payment_method ]->process_refund( $order_id, $refund_amount, $refund_reason );
if ( isset( $payment_gateways[ $order->get_payment_method() ] ) && $payment_gateways[ $order->get_payment_method() ]->supports( 'refunds' ) ) {
$result = $payment_gateways[ $order->get_payment_method() ]->process_refund( $order_id, $refund_amount, $refund_reason );
do_action( 'woocommerce_refund_processed', $refund, $result );

View File

@ -164,7 +164,6 @@ class WC_Checkout {
* 527 - Cannot create shipping item.
* 528 - Cannot create tax item.
* 529 - Cannot create coupon item.
* @access public
* @throws Exception
* @return int|WP_ERROR
*/
@ -180,16 +179,9 @@ class WC_Checkout {
// Start transaction if available
wc_transaction_query( 'start' );
$order_data = array(
'status' => apply_filters( 'woocommerce_default_order_status', 'pending' ),
'customer_id' => $this->customer_id,
'customer_note' => isset( $this->posted['order_comments'] ) ? $this->posted['order_comments'] : '',
'cart_hash' => md5( json_encode( wc_clean( WC()->cart->get_cart_for_session() ) ) . WC()->cart->total ),
'created_via' => 'checkout',
);
// Insert or update the post data
$order_id = absint( WC()->session->order_awaiting_payment );
$order_id = absint( WC()->session->order_awaiting_payment );
$cart_hash = md5( json_encode( wc_clean( WC()->cart->get_cart_for_session() ) ) . WC()->cart->total );
/**
* If there is an order pending payment, we can resume it here so
@ -197,149 +189,144 @@ class WC_Checkout {
* different items or cost, create a new order. We use a hash to
* detect changes which is based on cart items + order total.
*/
if ( $order_id && $order_data['cart_hash'] === get_post_meta( $order_id, '_cart_hash', true ) && ( $order = wc_get_order( $order_id ) ) && $order->has_status( array( 'pending', 'failed' ) ) ) {
$order_data['order_id'] = $order_id;
$order = wc_update_order( $order_data );
if ( is_wp_error( $order ) ) {
throw new Exception( sprintf( __( 'Error %d: Unable to create order. Please try again.', 'woocommerce' ), 522 ) );
} else {
$order->remove_order_items();
do_action( 'woocommerce_resume_order', $order_id );
}
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 );
// Remove all items - we will re-add them later.
$order->remove_order_items();
/**
* Not resuming - lets create a new order object.
*/
} else {
$order = new WC_Order();
}
$order = wc_create_order( $order_data );
$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 );
if ( is_wp_error( $order ) ) {
throw new Exception( sprintf( __( 'Error %d: Unable to create order. Please try again.', 'woocommerce' ), 520 ) );
} elseif ( false === $order ) {
throw new Exception( sprintf( __( 'Error %d: Unable to create order. Please try again.', 'woocommerce' ), 521 ) );
} else {
$order_id = $order->id;
do_action( 'woocommerce_new_order', $order_id );
// 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' ) );
}
}
}
// Store the line items to the new/resumed order
// Add line items.
foreach ( WC()->cart->get_cart() as $cart_item_key => $values ) {
$item_id = $order->add_product(
$values['data'],
$values['quantity'],
array(
'variation' => $values['variation'],
'totals' => array(
'subtotal' => $values['line_subtotal'],
'subtotal_tax' => $values['line_subtotal_tax'],
'total' => $values['line_total'],
'tax' => $values['line_tax'],
'tax_data' => $values['line_tax_data'] // Since 2.2
)
)
);
$product = $values['data'];
$item = new WC_Order_Item_Product( array(
'qty' => $values['quantity'],
'name' => $product ? $product->get_title() : '',
'tax_class' => $product ? $product->get_tax_class() : '',
'product_id' => $product ? $product->get_id() : '',
'variation_id' => $product && isset( $product->variation_id ) ? $product->variation_id : 0,
'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'],
) );
if ( ! $item_id ) {
throw new Exception( sprintf( __( 'Error %d: Unable to create order. Please try again.', 'woocommerce' ), 525 ) );
// Handle backorders @todo improve how these are handled/stored
if ( $product->backorders_require_notification() && $product->is_on_backorder( $args['qty'] ) ) {
$item->add_meta_data( apply_filters( 'woocommerce_backordered_item_meta_name', __( 'Backordered', 'woocommerce' ) ), $values['quantity'] - max( 0, $product->get_total_stock() ), true );
}
// Allow plugins to add order item meta
do_action( 'woocommerce_add_order_item_meta', $item_id, $values, $cart_item_key );
// Set this to pass to legacy actions @todo remove in future release
$item->legacy_values = $values;
$item->legacy_cart_item_key = $cart_item_key;
$order->add_item( $item );
}
// Store fees
// Add fees
foreach ( WC()->cart->get_fees() as $fee_key => $fee ) {
$item_id = $order->add_fee( $fee );
$item = new WC_Order_Item_Fee( array(
'name' => $fee->name,
'tax_class' => $fee->taxable ? $fee->tax_class : 0,
'total' => $fee->amount,
'total_tax' => $fee->tax,
'taxes' => array(
'total' => $fee->tax_data,
),
) );
if ( ! $item_id ) {
throw new Exception( sprintf( __( 'Error %d: Unable to create order. Please try again.', 'woocommerce' ), 526 ) );
}
// Set this to pass to legacy actions @todo remove in future release
$item->legacy_fee = $fee;
$item->legacy_fee_key = $fee_key;
// Allow plugins to add order item meta to fees
do_action( 'woocommerce_add_order_fee_meta', $order_id, $item_id, $fee, $fee_key );
$order->add_item( $item );
}
// Store shipping for all packages
foreach ( WC()->shipping->get_packages() as $package_key => $package ) {
if ( isset( $package['rates'][ $this->shipping_methods[ $package_key ] ] ) ) {
$item_id = $order->add_shipping( $package['rates'][ $this->shipping_methods[ $package_key ] ] );
$shipping_rate = $package['rates'][ $this->shipping_methods[ $package_key ] ];
$item = new WC_Order_Item_Shipping( array(
'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(),
) );
if ( ! $item_id ) {
throw new Exception( sprintf( __( 'Error %d: Unable to create order. Please try again.', 'woocommerce' ), 527 ) );
}
// Set this to pass to legacy actions @todo remove in future release
$item->legacy_package_key = $package_key;
// Allows plugins to add order item meta to shipping
do_action( 'woocommerce_add_shipping_order_item', $order_id, $item_id, $package_key );
$order->add_item( $item );
}
}
// Store tax rows
foreach ( array_keys( WC()->cart->taxes + WC()->cart->shipping_taxes ) as $tax_rate_id ) {
if ( $tax_rate_id && ! $order->add_tax( $tax_rate_id, WC()->cart->get_tax_amount( $tax_rate_id ), WC()->cart->get_shipping_tax_amount( $tax_rate_id ) ) && apply_filters( 'woocommerce_cart_remove_taxes_zero_rate_id', 'zero-rated' ) !== $tax_rate_id ) {
throw new Exception( sprintf( __( 'Error %d: Unable to create order. Please try again.', 'woocommerce' ), 528 ) );
if ( $tax_rate_id && $tax_rate_id !== apply_filters( 'woocommerce_cart_remove_taxes_zero_rate_id', 'zero-rated' ) ) {
$order->add_item( new WC_Order_Item_Tax( array(
'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 ),
) ) );
}
}
// Store coupons
foreach ( WC()->cart->get_coupons() as $code => $coupon ) {
if ( ! $order->add_coupon( $code, WC()->cart->get_coupon_discount_amount( $code ), WC()->cart->get_coupon_discount_tax_amount( $code ) ) ) {
throw new Exception( sprintf( __( 'Error %d: Unable to create order. Please try again.', 'woocommerce' ), 529 ) );
}
$item = new WC_Order_Item_Coupon( array(
'code' => $code,
'discount' => WC()->cart->get_coupon_discount_amount( $code ),
'discount_tax' => WC()->cart->get_coupon_discount_tax_amount( $code ),
) );
$order->add_item( $item );
}
// Billing address
$billing_address = array();
if ( $this->checkout_fields['billing'] ) {
foreach ( array_keys( $this->checkout_fields['billing'] ) as $field ) {
$field_name = str_replace( 'billing_', '', $field );
$billing_address[ $field_name ] = $this->get_posted_address_data( $field_name );
}
}
// Shipping address.
$shipping_address = array();
if ( $this->checkout_fields['shipping'] ) {
foreach ( array_keys( $this->checkout_fields['shipping'] ) as $field ) {
$field_name = str_replace( 'shipping_', '', $field );
$shipping_address[ $field_name ] = $this->get_posted_address_data( $field_name, 'shipping' );
}
}
$order->set_address( $billing_address, 'billing' );
$order->set_address( $shipping_address, 'shipping' );
$order->set_payment_method( $this->payment_method );
$order->set_total( WC()->cart->shipping_total, 'shipping' );
$order->set_total( WC()->cart->get_cart_discount_total(), 'cart_discount' );
$order->set_total( WC()->cart->get_cart_discount_tax_total(), 'cart_discount_tax' );
$order->set_total( WC()->cart->tax_total, 'tax' );
$order->set_total( WC()->cart->shipping_tax_total, 'shipping_tax' );
$order->set_total( WC()->cart->total );
// Save the order
$order_id = $order->save();
$customer = new WC_Customer( $this->customer_id );
// Update user meta
if ( $this->customer_id ) {
if ( apply_filters( 'woocommerce_checkout_update_customer_data', true, $this ) ) {
foreach ( $billing_address as $key => $value ) {
if ( is_callable( array( $customer, "set_billing_{$key}" ) ) ) {
$customer->{"set_billing_{$key}"}( $value );
}
}
if ( WC()->cart->needs_shipping() ) {
foreach ( $shipping_address as $key => $value ) {
if ( is_callable( array( $customer, "set_shipping_{$key}" ) ) ) {
$customer->{"set_shipping_{$key}"}( $value );
}
}
}
}
$this->update_customer_data();
$customer->save();
do_action( 'woocommerce_checkout_update_user_meta', $this->customer_id, $this->posted );
}
// Let plugins add meta
// Let plugins add their own meta data
do_action( 'woocommerce_checkout_update_order_meta', $order_id, $this->posted );
// If we got here, the order was created without problems!
@ -354,6 +341,37 @@ class WC_Checkout {
return $order_id;
}
/**
* 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 );
}
}
/**
* Process the checkout after the confirm order button is pressed.
*/

View File

@ -318,7 +318,7 @@ class WC_Emails {
'@type' => 'Offer',
'itemOffered' => $item_offered,
'price' => $order->get_line_subtotal( $item ),
'priceCurrency' => $order->get_order_currency(),
'priceCurrency' => $order->get_currency(),
'eligibleQuantity' => (object) array(
'@type' => 'QuantitativeValue',
'value' => apply_filters( 'woocommerce_email_order_item_quantity', $item['qty'], $item )
@ -337,7 +337,7 @@ class WC_Emails {
'name' => get_bloginfo( 'name' ),
),
'orderNumber' => strval( $order->get_order_number() ),
'priceCurrency' => $order->get_order_currency(),
'priceCurrency' => $order->get_currency(),
'price' => $order->get_total(),
'acceptedOffer' => $accepted_offers,
'url' => $order->get_view_order_url(),
@ -370,7 +370,7 @@ class WC_Emails {
if ( $sent_to_admin ) {
$markup['potentialAction'] = (object) array(
'@type' => 'ViewAction',
'target' => admin_url( 'post.php?post=' . absint( $order->id ) . '&action=edit' ),
'target' => admin_url( 'post.php?post=' . absint( $order->get_id() ) . '&action=edit' ),
);
}
@ -405,7 +405,7 @@ class WC_Emails {
$fields[ $key ] = array(
'label' => wptexturize( $key ),
'value' => wptexturize( get_post_meta( $order->id, $field, true ) )
'value' => wptexturize( get_post_meta( $order->get_id(), $field, true ) )
);
}
}
@ -451,24 +451,24 @@ class WC_Emails {
public function customer_details( $order, $sent_to_admin = false, $plain_text = false ) {
$fields = array();
if ( $order->customer_note ) {
if ( $order->get_customer_note() ) {
$fields['customer_note'] = array(
'label' => __( 'Note', 'woocommerce' ),
'value' => wptexturize( $order->customer_note )
'value' => wptexturize( $order->get_customer_note() )
);
}
if ( $order->billing_email ) {
if ( $order->get_billing_email() ) {
$fields['billing_email'] = array(
'label' => __( 'Email', 'woocommerce' ),
'value' => wptexturize( $order->billing_email )
'value' => wptexturize( $order->get_billing_email() )
);
}
if ( $order->billing_phone ) {
if ( $order->get_billing_phone() ) {
$fields['billing_phone'] = array(
'label' => __( 'Tel', 'woocommerce' ),
'value' => wptexturize( $order->billing_phone )
'value' => wptexturize( $order->get_billing_phone() )
);
}

View File

@ -288,22 +288,22 @@ class WC_Form_Handler {
$order_id = absint( $wp->query_vars['order-pay'] );
$order = wc_get_order( $order_id );
if ( $order->id == $order_id && $order->order_key == $order_key && $order->needs_payment() ) {
if ( $order->get_id() == $order_id && $order->get_order_key() == $order_key && $order->needs_payment() ) {
do_action( 'woocommerce_before_pay_action', $order );
// Set customer location to order location
if ( $order->billing_country ) {
WC()->customer->set_country( $order->billing_country );
if ( $order->get_billing_country() ) {
WC()->customer->set_country( $order->get_billing_country() );
}
if ( $order->billing_state ) {
WC()->customer->set_state( $order->billing_state );
if ( $order->get_billing_state() ) {
WC()->customer->set_state( $order->get_billing_state() );
}
if ( $order->billing_postcode ) {
WC()->customer->set_postcode( $order->billing_postcode );
if ( $order->get_billing_postcode() ) {
WC()->customer->set_postcode( $order->get_billing_postcode() );
}
if ( $order->billing_city ) {
WC()->customer->set_city( $order->billing_city );
if ( $order->get_billing_city() ) {
WC()->customer->set_city( $order->get_billing_city() );
}
WC()->customer->save();
@ -598,7 +598,7 @@ class WC_Form_Handler {
// Load the previous order - Stop if the order does not exist
$order = wc_get_order( absint( $_GET['order_again'] ) );
if ( empty( $order->id ) ) {
if ( empty( $order->get_id() ) ) {
return;
}
@ -608,7 +608,7 @@ class WC_Form_Handler {
// Make sure the user is allowed to order again. By default it check if the
// previous order belonged to the current user.
if ( ! current_user_can( 'order_again', $order->id ) ) {
if ( ! current_user_can( 'order_again', $order->get_id() ) ) {
return;
}
@ -637,7 +637,7 @@ class WC_Form_Handler {
WC()->cart->add_to_cart( $product_id, $quantity, $variation_id, $variations, $cart_item_data );
}
do_action( 'woocommerce_ordered_again', $order->id );
do_action( 'woocommerce_ordered_again', $order->get_id() );
// Redirect to cart
wc_add_notice( __( 'The cart has been filled with the items from your previous order.', 'woocommerce' ) );
@ -660,7 +660,7 @@ class WC_Form_Handler {
if ( $order->has_status( 'cancelled' ) ) {
// Already cancelled - take no action
} elseif ( $user_can_cancel && $order_can_cancel && $order->id === $order_id && $order->order_key === $order_key ) {
} elseif ( $user_can_cancel && $order_can_cancel && $order->get_id() === $order_id && $order->get_order_key() === $order_key ) {
// Cancel the order + restore stock
$order->cancel_order( __('Order cancelled by customer.', 'woocommerce' ) );
@ -668,7 +668,7 @@ class WC_Form_Handler {
// Message
wc_add_notice( apply_filters( 'woocommerce_order_cancelled_notice', __( 'Your order was cancelled.', 'woocommerce' ) ), apply_filters( 'woocommerce_order_cancelled_notice_type', 'notice' ) );
do_action( 'woocommerce_cancelled_order', $order->id );
do_action( 'woocommerce_cancelled_order', $order->get_id() );
} elseif ( $user_can_cancel && ! $order_can_cancel ) {
wc_add_notice( __( 'Your order can no longer be cancelled. Please contact us if you need assistance.', 'woocommerce' ), 'error' );

View File

@ -205,7 +205,7 @@ class WC_Frontend_Scripts {
}
if ( 'geolocation_ajax' === get_option( 'woocommerce_default_customer_address' ) ) {
// Exclude common bots from geolocation by user agent.
$ua = isset( $_SERVER['HTTP_USER_AGENT'] ) ? strtolower( $_SERVER['HTTP_USER_AGENT'] ) : '';
$ua = wc_get_user_agent();
if ( ! strstr( $ua, 'bot' ) && ! strstr( $ua, 'spider' ) && ! strstr( $ua, 'crawl' ) ) {
self::enqueue_script( 'wc-geolocation', $frontend_script_path . 'geolocation' . $suffix . '.js', array( 'jquery' ) );

View File

@ -306,7 +306,7 @@ class WC_Order_Item_Product extends WC_Order_Item {
*/
public function set_variation( $data ) {
foreach ( $data as $key => $value ) {
$this->_meta_data[ str_replace( 'attribute_', '', $key ) ] = $value;
$this->add_meta_data( str_replace( 'attribute_', '', $key ), $value, true );
}
}

View File

@ -316,7 +316,9 @@ class WC_Order_Item extends WC_Data implements ArrayAccess {
continue;
}
$attribute_key = urldecode( str_replace( 'attribute_', '', $meta->key ) );
$meta->key = rawurldecode( $meta->key );
$meta->value = rawurldecode( $meta->value );
$attribute_key = str_replace( 'attribute_', '', $meta->key );
$display_key = wc_attribute_label( $attribute_key, is_callable( array( $this, 'get_product' ) ) ? $this->get_product() : false );
$display_value = $meta->value;
@ -329,9 +331,9 @@ class WC_Order_Item extends WC_Data implements ArrayAccess {
$formatted_meta[ $meta->meta_id ] = (object) array(
'key' => $meta->key,
'value' => $meta->key,
'value' => $meta->value,
'display_key' => apply_filters( 'woocommerce_order_item_display_meta_key', $display_key ),
'display_value' => apply_filters( 'woocommerce_order_item_display_meta_value', $display_value ),
'display_value' => apply_filters( 'woocommerce_order_item_display_meta_value', wpautop( make_clickable( $display_value ) ) ),
);
}

View File

@ -585,7 +585,7 @@ class WC_CLI_Customer extends WC_CLI_Command {
'last_name' => $user->last_name,
'username' => $user->user_login,
'role' => $user->roles[0],
'last_order_id' => is_object( $last_order ) ? $last_order->id : null,
'last_order_id' => is_object( $last_order ) ? $last_order->get_id() : null,
'last_order_date' => is_object( $last_order ) ? $this->format_datetime( $last_order->post_date_gmt ) : null,
'orders_count' => wc_get_customer_order_count( $user->ID ),
'total_spent' => wc_format_decimal( wc_get_customer_total_spent( $user->ID ), 2 ),

View File

@ -151,8 +151,8 @@ class WC_CLI_Order extends WC_CLI_Command {
throw new WC_CLI_Exception( 'woocommerce_invalid_payment_details', __( 'Payment method ID and title are required', 'woocommerce' ) );
}
update_post_meta( $order->id, '_payment_method', $data['payment_details']['method_id'] );
update_post_meta( $order->id, '_payment_method_title', $data['payment_details']['method_title'] );
update_post_meta( $order->get_id(), '_payment_method', $data['payment_details']['method_id'] );
update_post_meta( $order->get_id(), '_payment_method_title', $data['payment_details']['method_title'] );
// Mark as paid if set.
if ( isset( $data['payment_details']['paid'] ) && $this->is_true( $data['payment_details']['paid'] ) ) {
@ -166,24 +166,24 @@ class WC_CLI_Order extends WC_CLI_Command {
throw new WC_CLI_Exception( 'woocommerce_invalid_order_currency', __( 'Provided order currency is invalid', 'woocommerce') );
}
update_post_meta( $order->id, '_order_currency', $data['currency'] );
update_post_meta( $order->get_id(), '_order_currency', $data['currency'] );
}
// Set order meta.
if ( isset( $data['order_meta'] ) && is_array( $data['order_meta'] ) ) {
$this->set_order_meta( $order->id, $data['order_meta'] );
$this->set_order_meta( $order->get_id(), $data['order_meta'] );
}
wc_delete_shop_order_transients( $order->id );
wc_delete_shop_order_transients( $order->get_id() );
do_action( 'woocommerce_cli_create_order', $order->id, $data );
do_action( 'woocommerce_cli_create_order', $order->get_id(), $data );
wc_transaction_query( 'commit' );
if ( $porcelain ) {
WP_CLI::line( $order->id );
WP_CLI::line( $order->get_id() );
} else {
WP_CLI::success( "Created order {$order->id}." );
WP_CLI::success( "Created order {$order->get_id()}." );
}
} catch ( WC_CLI_Exception $e ) {
wc_transaction_query( 'rollback' );
@ -429,7 +429,7 @@ class WC_CLI_Order extends WC_CLI_Command {
throw new WC_CLI_Exception( 'woocommerce_cli_invalid_order_id', __( 'Order ID is invalid', 'woocommerce' ) );
}
$order_args = array( 'order_id' => $order->id );
$order_args = array( 'order_id' => $order->get_id() );
// customer note
if ( isset( $data['note'] ) ) {
@ -450,7 +450,7 @@ class WC_CLI_Order extends WC_CLI_Command {
throw new WC_CLI_Exception( 'woocommerce_cli_invalid_customer_id', __( 'Customer ID is invalid', 'woocommerce' ) );
}
update_post_meta( $order->id, '_customer_user', $data['customer_id'] );
update_post_meta( $order->get_id(), '_customer_user', $data['customer_id'] );
}
// billing/shipping address
@ -500,12 +500,12 @@ class WC_CLI_Order extends WC_CLI_Command {
// method ID
if ( isset( $data['payment_details']['method_id'] ) ) {
update_post_meta( $order->id, '_payment_method', $data['payment_details']['method_id'] );
update_post_meta( $order->get_id(), '_payment_method', $data['payment_details']['method_id'] );
}
// method title
if ( isset( $data['payment_details']['method_title'] ) ) {
update_post_meta( $order->id, '_payment_method_title', $data['payment_details']['method_title'] );
update_post_meta( $order->get_id(), '_payment_method_title', $data['payment_details']['method_title'] );
}
// mark as paid if set
@ -521,13 +521,13 @@ class WC_CLI_Order extends WC_CLI_Command {
throw new WC_CLI_Exception( 'woocommerce_invalid_order_currency', __( 'Provided order currency is invalid', 'woocommerce' ) );
}
update_post_meta( $order->id, '_order_currency', $data['currency'] );
update_post_meta( $order->get_id(), '_order_currency', $data['currency'] );
}
// set order number
if ( isset( $data['order_number'] ) ) {
update_post_meta( $order->id, '_order_number', $data['order_number'] );
update_post_meta( $order->get_id(), '_order_number', $data['order_number'] );
}
// if items have changed, recalculate order totals
@ -537,17 +537,17 @@ class WC_CLI_Order extends WC_CLI_Command {
// update order meta
if ( isset( $data['order_meta'] ) && is_array( $data['order_meta'] ) ) {
$this->set_order_meta( $order->id, $data['order_meta'] );
$this->set_order_meta( $order->get_id(), $data['order_meta'] );
}
// update the order post to set customer note/modified date
wc_update_order( $order_args );
wc_delete_shop_order_transients( $order->id );
wc_delete_shop_order_transients( $order->get_id() );
do_action( 'woocommerce_cli_update_order', $order->id, $data );
do_action( 'woocommerce_cli_update_order', $order->get_id(), $data );
WP_CLI::success( "Updated order {$order->id}." );
WP_CLI::success( "Updated order {$order->get_id()}." );
} catch ( WC_CLI_Exception $e ) {
WP_CLI::error( $e->getMessage() );
@ -626,16 +626,16 @@ class WC_CLI_Order extends WC_CLI_Command {
* @return array
*/
protected function get_order_data( $order ) {
$order_post = get_post( $order->id );
$order_post = get_post( $order->get_id() );
$dp = wc_get_price_decimals();
$order_data = array(
'id' => $order->id,
'id' => $order->get_id(),
'order_number' => $order->get_order_number(),
'created_at' => $this->format_datetime( $order_post->post_date_gmt ),
'updated_at' => $this->format_datetime( $order_post->post_modified_gmt ),
'completed_at' => $this->format_datetime( $order->completed_date, true ),
'status' => $order->get_status(),
'currency' => $order->get_order_currency(),
'currency' => $order->get_currency(),
'total' => wc_format_decimal( $order->get_total(), $dp ),
'subtotal' => wc_format_decimal( $order->get_subtotal(), $dp ),
'total_line_items_quantity' => $order->get_item_count(),
@ -646,37 +646,37 @@ class WC_CLI_Order extends WC_CLI_Command {
'total_discount' => wc_format_decimal( $order->get_total_discount(), $dp ),
'shipping_methods' => $order->get_shipping_method(),
'payment_details' => array(
'method_id' => $order->payment_method,
'method_title' => $order->payment_method_title,
'paid' => isset( $order->paid_date ),
'method_id' => $order->get_payment_method(),
'method_title' => $order->get_payment_method_title(),
'paid' => 0 < $order->get_date_paid(),
),
'billing_address' => array(
'first_name' => $order->billing_first_name,
'last_name' => $order->billing_last_name,
'company' => $order->billing_company,
'address_1' => $order->billing_address_1,
'address_2' => $order->billing_address_2,
'city' => $order->billing_city,
'state' => $order->billing_state,
'postcode' => $order->billing_postcode,
'country' => $order->billing_country,
'email' => $order->billing_email,
'phone' => $order->billing_phone,
'first_name' => $order->get_billing_first_name(),
'last_name' => $order->get_billing_last_name(),
'company' => $order->get_billing_company(),
'address_1' => $order->get_billing_address_1(),
'address_2' => $order->get_billing_address_2(),
'city' => $order->get_billing_city(),
'state' => $order->get_billing_state(),
'postcode' => $order->get_billing_postcode(),
'country' => $order->get_billing_country(),
'email' => $order->get_billing_email(),
'phone' => $order->get_billing_phone(),
),
'shipping_address' => array(
'first_name' => $order->shipping_first_name,
'last_name' => $order->shipping_last_name,
'company' => $order->shipping_company,
'address_1' => $order->shipping_address_1,
'address_2' => $order->shipping_address_2,
'city' => $order->shipping_city,
'state' => $order->shipping_state,
'postcode' => $order->shipping_postcode,
'country' => $order->shipping_country,
'first_name' => $order->get_shipping_first_name(),
'last_name' => $order->get_shipping_last_name(),
'company' => $order->get_shipping_company(),
'address_1' => $order->get_shipping_address_1(),
'address_2' => $order->get_shipping_address_2(),
'city' => $order->get_shipping_city(),
'state' => $order->get_shipping_state(),
'postcode' => $order->get_shipping_postcode(),
'country' => $order->get_shipping_country(),
),
'note' => $order->customer_note,
'customer_ip' => $order->customer_ip_address,
'customer_user_agent' => $order->customer_user_agent,
'note' => $order->get_customer_note(),
'customer_ip' => $order->get_customer_ip_address(),
'customer_user_agent' => $order->get_user_agent(),
'customer_id' => $order->get_user_id(),
'view_order_url' => $order->get_view_order_url(),
'line_items' => array(),
@ -884,7 +884,7 @@ class WC_CLI_Order extends WC_CLI_Command {
$result = $wpdb->get_row(
$wpdb->prepare( "SELECT * FROM {$wpdb->prefix}woocommerce_order_items WHERE order_item_id = %d AND order_id = %d",
absint( $item['id'] ),
absint( $order->id )
absint( $order->get_id() )
) );
if ( is_null( $result ) ) {

View File

@ -52,7 +52,7 @@ class WC_Email_Cancelled_Order extends WC_Email {
$this->object = wc_get_order( $order_id );
$this->find['order-date'] = '{order_date}';
$this->find['order-number'] = '{order_number}';
$this->replace['order-date'] = date_i18n( wc_date_format(), strtotime( $this->object->order_date ) );
$this->replace['order-date'] = date_i18n( wc_date_format(), $this->object->get_date_created() );
$this->replace['order-number'] = $this->object->get_order_number();
}

View File

@ -55,12 +55,12 @@ class WC_Email_Customer_Completed_Order extends WC_Email {
if ( $order_id ) {
$this->object = wc_get_order( $order_id );
$this->recipient = $this->object->billing_email;
$this->recipient = $this->object->get_billing_email();
$this->find['order-date'] = '{order_date}';
$this->find['order-number'] = '{order_number}';
$this->replace['order-date'] = date_i18n( wc_date_format(), strtotime( $this->object->order_date ) );
$this->replace['order-date'] = date_i18n( wc_date_format(), $this->object->get_date_created() );
$this->replace['order-number'] = $this->object->get_order_number();
}

View File

@ -73,12 +73,12 @@ class WC_Email_Customer_Invoice extends WC_Email {
if ( $order ) {
$this->object = $order;
$this->recipient = $this->object->billing_email;
$this->recipient = $this->object->get_billing_email();
$this->find['order-date'] = '{order_date}';
$this->find['order-number'] = '{order_number}';
$this->replace['order-date'] = date_i18n( wc_date_format(), strtotime( $this->object->order_date ) );
$this->replace['order-date'] = date_i18n( wc_date_format(), $this->object->get_date_created() );
$this->replace['order-number'] = $this->object->get_order_number();
}

View File

@ -68,13 +68,13 @@ class WC_Email_Customer_Note extends WC_Email {
extract( $args );
if ( $order_id && ( $this->object = wc_get_order( $order_id ) ) ) {
$this->recipient = $this->object->billing_email;
$this->recipient = $this->object->get_billing_email();
$this->customer_note = $customer_note;
$this->find['order-date'] = '{order_date}';
$this->find['order-number'] = '{order_number}';
$this->replace['order-date'] = date_i18n( wc_date_format(), strtotime( $this->object->order_date ) );
$this->replace['order-date'] = date_i18n( wc_date_format(), $this->object->get_date_created() );
$this->replace['order-number'] = $this->object->get_order_number();
} else {
return;

View File

@ -49,12 +49,12 @@ class WC_Email_Customer_On_Hold_Order extends WC_Email {
if ( $order_id ) {
$this->object = wc_get_order( $order_id );
$this->recipient = $this->object->billing_email;
$this->recipient = $this->object->get_billing_email();
$this->find['order-date'] = '{order_date}';
$this->find['order-number'] = '{order_number}';
$this->replace['order-date'] = date_i18n( wc_date_format(), strtotime( $this->object->order_date ) );
$this->replace['order-date'] = date_i18n( wc_date_format(), $this->object->get_date_created() );
$this->replace['order-number'] = $this->object->get_order_number();
}

View File

@ -48,12 +48,12 @@ class WC_Email_Customer_Processing_Order extends WC_Email {
if ( $order_id ) {
$this->object = wc_get_order( $order_id );
$this->recipient = $this->object->billing_email;
$this->recipient = $this->object->get_billing_email();
$this->find['order-date'] = '{order_date}';
$this->find['order-number'] = '{order_number}';
$this->replace['order-date'] = date_i18n( wc_date_format(), strtotime( $this->object->order_date ) );
$this->replace['order-date'] = date_i18n( wc_date_format(), $this->object->get_date_created() );
$this->replace['order-number'] = $this->object->get_order_number();
}

View File

@ -112,12 +112,12 @@ class WC_Email_Customer_Refunded_Order extends WC_Email {
if ( $order_id ) {
$this->object = wc_get_order( $order_id );
$this->recipient = $this->object->billing_email;
$this->recipient = $this->object->get_billing_email();
$this->find['order-date'] = '{order_date}';
$this->find['order-number'] = '{order_number}';
$this->replace['order-date'] = date_i18n( wc_date_format(), strtotime( $this->object->order_date ) );
$this->replace['order-date'] = date_i18n( wc_date_format(), $this->object->get_date_created() );
$this->replace['order-number'] = $this->object->get_order_number();
}

View File

@ -52,7 +52,7 @@ class WC_Email_Failed_Order extends WC_Email {
$this->object = wc_get_order( $order_id );
$this->find['order-date'] = '{order_date}';
$this->find['order-number'] = '{order_number}';
$this->replace['order-date'] = date_i18n( wc_date_format(), strtotime( $this->object->order_date ) );
$this->replace['order-date'] = date_i18n( wc_date_format(), $this->object->get_date_created() );
$this->replace['order-number'] = $this->object->get_order_number();
}

View File

@ -56,7 +56,7 @@ class WC_Email_New_Order extends WC_Email {
$this->object = wc_get_order( $order_id );
$this->find['order-date'] = '{order_date}';
$this->find['order-number'] = '{order_number}';
$this->replace['order-date'] = date_i18n( wc_date_format(), strtotime( $this->object->order_date ) );
$this->replace['order-date'] = date_i18n( wc_date_format(), $this->object->get_date_created() );
$this->replace['order-number'] = $this->object->get_order_number();
}

View File

@ -246,11 +246,11 @@ class WC_Gateway_BACS extends WC_Payment_Gateway {
*/
public function email_instructions( $order, $sent_to_admin, $plain_text = false ) {
if ( ! $sent_to_admin && 'bacs' === $order->payment_method && $order->has_status( 'on-hold' ) ) {
if ( ! $sent_to_admin && 'bacs' === $order->get_payment_method() && $order->has_status( 'on-hold' ) ) {
if ( $this->instructions ) {
echo wpautop( wptexturize( $this->instructions ) ) . PHP_EOL;
}
$this->bank_details( $order->id );
$this->bank_details( $order->get_id() );
}
}
@ -270,7 +270,7 @@ class WC_Gateway_BACS extends WC_Payment_Gateway {
$order = wc_get_order( $order_id );
// Get the order country and country $locale
$country = $order->billing_country;
$country = $order->get_billing_country();
$locale = $this->get_country_locale();
// Get sortcode label in the $locale array and use appropriate one
@ -337,7 +337,7 @@ class WC_Gateway_BACS extends WC_Payment_Gateway {
$order->update_status( 'on-hold', __( 'Awaiting BACS payment', 'woocommerce' ) );
// Reduce stock levels
$order->reduce_order_stock();
wc_reduce_stock_levels( $order_id );
// Remove cart
WC()->cart->empty_cart();

View File

@ -97,7 +97,7 @@ class WC_Gateway_Cheque extends WC_Payment_Gateway {
* @param bool $plain_text
*/
public function email_instructions( $order, $sent_to_admin, $plain_text = false ) {
if ( $this->instructions && ! $sent_to_admin && 'cheque' === $order->payment_method && $order->has_status( 'on-hold' ) ) {
if ( $this->instructions && ! $sent_to_admin && 'cheque' === $order->get_payment_method() && $order->has_status( 'on-hold' ) ) {
echo wpautop( wptexturize( $this->instructions ) ) . PHP_EOL;
}
}
@ -116,7 +116,7 @@ class WC_Gateway_Cheque extends WC_Payment_Gateway {
$order->update_status( 'on-hold', _x( 'Awaiting check payment', 'Check payment method', 'woocommerce' ) );
// Reduce stock levels
$order->reduce_order_stock();
wc_reduce_stock_levels( $order_id );
// Remove cart
WC()->cart->empty_cart();

View File

@ -203,7 +203,7 @@ class WC_Gateway_COD extends WC_Payment_Gateway {
$order->update_status( apply_filters( 'woocommerce_cod_process_payment_order_status', $order->has_downloadable_item() ? 'on-hold' : 'processing', $order ), __( 'Payment to be made upon delivery.', 'woocommerce' ) );
// Reduce stock levels
$order->reduce_order_stock();
wc_reduce_stock_levels( $order_id );
// Remove cart
WC()->cart->empty_cart();
@ -233,7 +233,7 @@ class WC_Gateway_COD extends WC_Payment_Gateway {
* @param bool $plain_text
*/
public function email_instructions( $order, $sent_to_admin, $plain_text = false ) {
if ( $this->instructions && ! $sent_to_admin && 'cod' === $order->payment_method ) {
if ( $this->instructions && ! $sent_to_admin && 'cod' === $order->get_payment_method() ) {
echo wpautop( wptexturize( $this->instructions ) ) . PHP_EOL;
}
}

View File

@ -315,7 +315,7 @@ class WC_Gateway_Paypal extends WC_Payment_Gateway {
public function capture_payment( $order_id ) {
$order = wc_get_order( $order_id );
if ( 'paypal' === $order->payment_method && 'pending' === get_post_meta( $order->id, '_paypal_status', true ) && $order->get_transaction_id() ) {
if ( 'paypal' === $order->get_payment_method() && 'pending' === get_post_meta( $order->get_id(), '_paypal_status', true ) && $order->get_transaction_id() ) {
$this->init_api();
$result = WC_Gateway_Paypal_API_Handler::do_capture( $order );
@ -331,8 +331,8 @@ class WC_Gateway_Paypal extends WC_Payment_Gateway {
switch ( $result->PAYMENTSTATUS ) {
case 'Completed' :
$order->add_order_note( sprintf( __( 'Payment of %s was captured - Auth ID: %s, Transaction ID: %s', 'woocommerce' ), $result->AMT, $result->AUTHORIZATIONID, $result->TRANSACTIONID ) );
update_post_meta( $order->id, '_paypal_status', $result->PAYMENTSTATUS );
update_post_meta( $order->id, '_transaction_id', $result->TRANSACTIONID );
update_post_meta( $order->get_id(), '_paypal_status', $result->PAYMENTSTATUS );
update_post_meta( $order->get_id(), '_transaction_id', $result->TRANSACTIONID );
break;
default :
$order->add_order_note( sprintf( __( 'Payment could not captured - Auth ID: %s, Status: %s', 'woocommerce' ), $result->AUTHORIZATIONID, $result->PAYMENTSTATUS ) );

View File

@ -38,7 +38,7 @@ class WC_Gateway_Paypal_API_Handler {
'METHOD' => 'DoCapture',
'AUTHORIZATIONID' => $order->get_transaction_id(),
'AMT' => number_format( is_null( $amount ) ? $order->get_total() : $amount, 2, '.', '' ),
'CURRENCYCODE' => $order->get_order_currency(),
'CURRENCYCODE' => $order->get_currency(),
'COMPLETETYPE' => 'Complete',
);
return apply_filters( 'woocommerce_paypal_capture_request', $request, $order, $amount );
@ -64,7 +64,7 @@ class WC_Gateway_Paypal_API_Handler {
);
if ( ! is_null( $amount ) ) {
$request['AMT'] = number_format( $amount, 2, '.', '' );
$request['CURRENCYCODE'] = $order->get_order_currency();
$request['CURRENCYCODE'] = $order->get_currency();
$request['REFUNDTYPE'] = 'Partial';
}
return apply_filters( 'woocommerce_paypal_refund_request', $request, $order, $amount, $reason );

View File

@ -57,7 +57,7 @@ class WC_Gateway_Paypal_IPN_Handler extends WC_Gateway_Paypal_Response {
$posted['payment_status'] = 'completed';
}
WC_Gateway_Paypal::log( 'Found order #' . $order->id );
WC_Gateway_Paypal::log( 'Found order #' . $order->get_id() );
WC_Gateway_Paypal::log( 'Payment status: ' . $posted['payment_status'] );
if ( method_exists( $this, 'payment_status_' . $posted['payment_status'] ) ) {
@ -126,8 +126,8 @@ class WC_Gateway_Paypal_IPN_Handler extends WC_Gateway_Paypal_Response {
* @param string $currency
*/
protected function validate_currency( $order, $currency ) {
if ( $order->get_order_currency() != $currency ) {
WC_Gateway_Paypal::log( 'Payment error: Currencies do not match (sent "' . $order->get_order_currency() . '" | returned "' . $currency . '")' );
if ( $order->get_currency() != $currency ) {
WC_Gateway_Paypal::log( 'Payment error: Currencies do not match (sent "' . $order->get_currency() . '" | returned "' . $currency . '")' );
// Put this order on-hold for manual checking.
$order->update_status( 'on-hold', sprintf( __( 'Validation error: PayPal currencies do not match (code %s).', 'woocommerce' ), $currency ) );
@ -173,7 +173,7 @@ class WC_Gateway_Paypal_IPN_Handler extends WC_Gateway_Paypal_Response {
*/
protected function payment_status_completed( $order, $posted ) {
if ( $order->has_status( array( 'processing', 'completed' ) ) ) {
WC_Gateway_Paypal::log( 'Aborting, Order #' . $order->id . ' is already complete.' );
WC_Gateway_Paypal::log( 'Aborting, Order #' . $order->get_id() . ' is already complete.' );
exit;
}
@ -188,7 +188,7 @@ class WC_Gateway_Paypal_IPN_Handler extends WC_Gateway_Paypal_Response {
if ( ! empty( $posted['mc_fee'] ) ) {
// Log paypal transaction fee.
update_post_meta( $order->id, 'PayPal Transaction Fee', wc_clean( $posted['mc_fee'] ) );
update_post_meta( $order->get_id(), 'PayPal Transaction Fee', wc_clean( $posted['mc_fee'] ) );
}
} else {
@ -258,7 +258,7 @@ class WC_Gateway_Paypal_IPN_Handler extends WC_Gateway_Paypal_Response {
$order->update_status( 'refunded', sprintf( __( 'Payment %s via IPN.', 'woocommerce' ), strtolower( $posted['payment_status'] ) ) );
$this->send_ipn_email_notification(
sprintf( __( 'Payment for order %s refunded', 'woocommerce' ), '<a class="link" href="' . esc_url( admin_url( 'post.php?post=' . $order->id . '&action=edit' ) ) . '">' . $order->get_order_number() . '</a>' ),
sprintf( __( 'Payment for order %s refunded', 'woocommerce' ), '<a class="link" href="' . esc_url( admin_url( 'post.php?post=' . $order->get_id() . '&action=edit' ) ) . '">' . $order->get_order_number() . '</a>' ),
sprintf( __( 'Order #%s has been marked as refunded - PayPal reason code: %s', 'woocommerce' ), $order->get_order_number(), $posted['reason_code'] )
);
}
@ -273,7 +273,7 @@ class WC_Gateway_Paypal_IPN_Handler extends WC_Gateway_Paypal_Response {
$order->update_status( 'on-hold', sprintf( __( 'Payment %s via IPN.', 'woocommerce' ), wc_clean( $posted['payment_status'] ) ) );
$this->send_ipn_email_notification(
sprintf( __( 'Payment for order %s reversed', 'woocommerce' ), '<a class="link" href="' . esc_url( admin_url( 'post.php?post=' . $order->id . '&action=edit' ) ) . '">' . $order->get_order_number() . '</a>' ),
sprintf( __( 'Payment for order %s reversed', 'woocommerce' ), '<a class="link" href="' . esc_url( admin_url( 'post.php?post=' . $order->get_id() . '&action=edit' ) ) . '">' . $order->get_order_number() . '</a>' ),
sprintf( __( 'Order #%s has been marked on-hold due to a reversal - PayPal reason code: %s', 'woocommerce' ), $order->get_order_number(), wc_clean( $posted['reason_code'] ) )
);
}
@ -286,7 +286,7 @@ class WC_Gateway_Paypal_IPN_Handler extends WC_Gateway_Paypal_Response {
protected function payment_status_canceled_reversal( $order, $posted ) {
$this->send_ipn_email_notification(
sprintf( __( 'Reversal cancelled for order #%s', 'woocommerce' ), $order->get_order_number() ),
sprintf( __( 'Order #%s has had a reversal cancelled. Please check the status of payment and update the order status accordingly here: %s', 'woocommerce' ), $order->get_order_number(), esc_url( admin_url( 'post.php?post=' . $order->id . '&action=edit' ) ) )
sprintf( __( 'Order #%s has had a reversal cancelled. Please check the status of payment and update the order status accordingly here: %s', 'woocommerce' ), $order->get_order_number(), esc_url( admin_url( 'post.php?post=' . $order->get_id() . '&action=edit' ) ) )
);
}
@ -297,22 +297,22 @@ class WC_Gateway_Paypal_IPN_Handler extends WC_Gateway_Paypal_Response {
*/
protected function save_paypal_meta_data( $order, $posted ) {
if ( ! empty( $posted['payer_email'] ) ) {
update_post_meta( $order->id, 'Payer PayPal address', wc_clean( $posted['payer_email'] ) );
update_post_meta( $order->get_id(), 'Payer PayPal address', wc_clean( $posted['payer_email'] ) );
}
if ( ! empty( $posted['first_name'] ) ) {
update_post_meta( $order->id, 'Payer first name', wc_clean( $posted['first_name'] ) );
update_post_meta( $order->get_id(), 'Payer first name', wc_clean( $posted['first_name'] ) );
}
if ( ! empty( $posted['last_name'] ) ) {
update_post_meta( $order->id, 'Payer last name', wc_clean( $posted['last_name'] ) );
update_post_meta( $order->get_id(), 'Payer last name', wc_clean( $posted['last_name'] ) );
}
if ( ! empty( $posted['payment_type'] ) ) {
update_post_meta( $order->id, 'Payment type', wc_clean( $posted['payment_type'] ) );
update_post_meta( $order->get_id(), 'Payment type', wc_clean( $posted['payment_type'] ) );
}
if ( ! empty( $posted['txn_id'] ) ) {
update_post_meta( $order->id, '_transaction_id', wc_clean( $posted['txn_id'] ) );
update_post_meta( $order->get_id(), '_transaction_id', wc_clean( $posted['txn_id'] ) );
}
if ( ! empty( $posted['payment_status'] ) ) {
update_post_meta( $order->id, '_paypal_status', wc_clean( $posted['payment_status'] ) );
update_post_meta( $order->get_id(), '_paypal_status', wc_clean( $posted['payment_status'] ) );
}
}

View File

@ -90,8 +90,8 @@ class WC_Gateway_Paypal_PDT_Handler extends WC_Gateway_Paypal_Response {
WC_Gateway_Paypal::log( 'PDT Transaction Result: ' . print_r( $transaction_result, true ) );
update_post_meta( $order->id, '_paypal_status', $status );
update_post_meta( $order->id, '_transaction_id', $transaction );
update_post_meta( $order->get_id(), '_paypal_status', $status );
update_post_meta( $order->get_id(), '_transaction_id', $transaction );
if ( $transaction_result ) {
if ( 'completed' === $status ) {
@ -103,19 +103,19 @@ class WC_Gateway_Paypal_PDT_Handler extends WC_Gateway_Paypal_Response {
// Log paypal transaction fee and other meta data.
if ( ! empty( $transaction_result['mc_fee'] ) ) {
update_post_meta( $order->id, 'PayPal Transaction Fee', $transaction_result['mc_fee'] );
update_post_meta( $order->get_id(), 'PayPal Transaction Fee', $transaction_result['mc_fee'] );
}
if ( ! empty( $transaction_result['payer_email'] ) ) {
update_post_meta( $order->id, 'Payer PayPal address', $transaction_result['payer_email'] );
update_post_meta( $order->get_id(), 'Payer PayPal address', $transaction_result['payer_email'] );
}
if ( ! empty( $transaction_result['first_name'] ) ) {
update_post_meta( $order->id, 'Payer first name', $transaction_result['first_name'] );
update_post_meta( $order->get_id(), 'Payer first name', $transaction_result['first_name'] );
}
if ( ! empty( $transaction_result['last_name'] ) ) {
update_post_meta( $order->id, 'Payer last name', $transaction_result['last_name'] );
update_post_meta( $order->get_id(), 'Payer last name', $transaction_result['last_name'] );
}
if ( ! empty( $transaction_result['payment_type'] ) ) {
update_post_meta( $order->id, 'Payment type', $transaction_result['payment_type'] );
update_post_meta( $order->get_id(), 'Payment type', $transaction_result['payment_type'] );
}
}
} else {

View File

@ -77,18 +77,18 @@ class WC_Gateway_Paypal_Request {
'paymentaction' => $this->gateway->get_option( 'paymentaction' ),
'bn' => 'WooThemes_Cart',
'invoice' => $this->gateway->get_option( 'invoice_prefix' ) . $order->get_order_number(),
'custom' => json_encode( array( 'order_id' => $order->id, 'order_key' => $order->order_key ) ),
'custom' => json_encode( array( 'order_id' => $order->get_id(), 'order_key' => $order->get_order_key() ) ),
'notify_url' => $this->notify_url,
'first_name' => $order->billing_first_name,
'last_name' => $order->billing_last_name,
'company' => $order->billing_company,
'address1' => $order->billing_address_1,
'address2' => $order->billing_address_2,
'city' => $order->billing_city,
'state' => $this->get_paypal_state( $order->billing_country, $order->billing_state ),
'zip' => $order->billing_postcode,
'country' => $order->billing_country,
'email' => $order->billing_email
'first_name' => $order->get_billing_first_name(),
'last_name' => $order->get_billing_last_name(),
'company' => $order->get_billing_company(),
'address1' => $order->get_billing_address_1(),
'address2' => $order->get_billing_address_2(),
'city' => $order->get_billing_city(),
'state' => $this->get_paypal_state( $order->get_billing_country(), $order->get_billing_state() ),
'zip' => $order->get_billing_postcode(),
'country' => $order->get_billing_country(),
'email' => $order->get_billing_email()
),
$this->get_phone_number_args( $order ),
$this->get_shipping_args( $order ),
@ -102,8 +102,8 @@ class WC_Gateway_Paypal_Request {
* @return array
*/
protected function get_phone_number_args( $order ) {
if ( in_array( $order->billing_country, array( 'US','CA' ) ) ) {
$phone_number = str_replace( array( '(', '-', ' ', ')', '.' ), '', $order->billing_phone );
if ( in_array( $order->get_billing_country(), array( 'US','CA' ) ) ) {
$phone_number = str_replace( array( '(', '-', ' ', ')', '.' ), '', $order->get_billing_phone() );
$phone_number = ltrim( $phone_number, '+1' );
$phone_args = array(
'night_phone_a' => substr( $phone_number, 0, 3 ),
@ -115,8 +115,8 @@ class WC_Gateway_Paypal_Request {
);
} else {
$phone_args = array(
'night_phone_b' => $order->billing_phone,
'day_phone_b' => $order->billing_phone
'night_phone_b' => $order->get_billing_phone(),
'day_phone_b' => $order->get_billing_phone()
);
}
return $phone_args;
@ -135,15 +135,15 @@ class WC_Gateway_Paypal_Request {
$shipping_args['no_shipping'] = 0;
// If we are sending shipping, send shipping address instead of billing
$shipping_args['first_name'] = $order->shipping_first_name;
$shipping_args['last_name'] = $order->shipping_last_name;
$shipping_args['company'] = $order->shipping_company;
$shipping_args['address1'] = $order->shipping_address_1;
$shipping_args['address2'] = $order->shipping_address_2;
$shipping_args['city'] = $order->shipping_city;
$shipping_args['state'] = $this->get_paypal_state( $order->shipping_country, $order->shipping_state );
$shipping_args['country'] = $order->shipping_country;
$shipping_args['zip'] = $order->shipping_postcode;
$shipping_args['first_name'] = $order->get_shipping_first_name();
$shipping_args['last_name'] = $order->get_shipping_last_name();
$shipping_args['company'] = $order->get_shipping_company();
$shipping_args['address1'] = $order->get_shipping_address_1();
$shipping_args['address2'] = $order->get_shipping_address_2();
$shipping_args['city'] = $order->get_shipping_city();
$shipping_args['state'] = $this->get_paypal_state( $order->get_shipping_country(), $order->get_shipping_state() );
$shipping_args['country'] = $order->get_shipping_country();
$shipping_args['zip'] = $order->get_shipping_postcode();
} else {
$shipping_args['no_shipping'] = 1;
}
@ -356,7 +356,7 @@ class WC_Gateway_Paypal_Request {
protected function round( $price, $order ) {
$precision = 2;
if ( ! $this->currency_has_decimals( $order->get_order_currency() ) ) {
if ( ! $this->currency_has_decimals( $order->get_currency() ) ) {
$precision = 0;
}
@ -372,7 +372,7 @@ class WC_Gateway_Paypal_Request {
protected function number_format( $price, $order ) {
$decimals = 2;
if ( ! $this->currency_has_decimals( $order->get_order_currency() ) ) {
if ( ! $this->currency_has_decimals( $order->get_currency() ) ) {
$decimals = 0;
}

View File

@ -40,7 +40,7 @@ abstract class WC_Gateway_Paypal_Response {
$order = wc_get_order( $order_id );
}
if ( ! $order || $order->order_key !== $order_key ) {
if ( ! $order || $order->get_order_key() !== $order_key ) {
WC_Gateway_Paypal::log( 'Error: Order Keys do not match.' );
return false;
}
@ -66,7 +66,7 @@ abstract class WC_Gateway_Paypal_Response {
*/
protected function payment_on_hold( $order, $reason = '' ) {
$order->update_status( 'on-hold', $reason );
$order->reduce_order_stock();
wc_reduce_stock_levels( $order_id );
WC()->cart->empty_cart();
}
}

View File

@ -103,13 +103,13 @@ class WC_Addons_Gateway_Simplify_Commerce extends WC_Gateway_Simplify_Commerce {
// Create customer
$customer = Simplify_Customer::createCustomer( array(
'token' => $cart_token,
'email' => $order->billing_email,
'email' => $order->get_billing_email(),
'name' => trim( $order->get_formatted_billing_full_name() ),
'reference' => $order->id
'reference' => $order->get_id()
) );
if ( is_object( $customer ) && '' != $customer->id ) {
$this->save_subscription_meta( $order->id, $customer->id );
$this->save_subscription_meta( $order->get_id(), $customer->id );
} else {
$error_msg = __( 'Error creating user in Simplify Commerce.', 'woocommerce' );
@ -175,10 +175,10 @@ class WC_Addons_Gateway_Simplify_Commerce extends WC_Gateway_Simplify_Commerce {
* @return array
*/
protected function process_pre_order( $order, $cart_token = '' ) {
if ( WC_Pre_Orders_Order::order_requires_payment_tokenization( $order->id ) ) {
if ( WC_Pre_Orders_Order::order_requires_payment_tokenization( $order->get_id() ) ) {
try {
if ( $order->order_total * 100 < 50 ) {
if ( $order->get_total() * 100 < 50 ) {
$error_msg = __( 'Sorry, the minimum allowed order total is 0.50 to use this payment method.', 'woocommerce' );
throw new Simplify_ApiException( $error_msg );
@ -197,16 +197,16 @@ class WC_Addons_Gateway_Simplify_Commerce extends WC_Gateway_Simplify_Commerce {
// Create customer
$customer = Simplify_Customer::createCustomer( array(
'token' => $cart_token,
'email' => $order->billing_email,
'email' => $order->get_billing_email(),
'name' => trim( $order->get_formatted_billing_full_name() ),
'reference' => $order->id
'reference' => $order->get_id()
) );
if ( is_object( $customer ) && '' != $customer->id ) {
$customer_id = wc_clean( $customer->id );
// Store the customer ID in the order
update_post_meta( $order->id, '_simplify_customer_id', $customer_id );
update_post_meta( $order->get_id(), '_simplify_customer_id', $customer_id );
} else {
$error_msg = __( 'Error creating user in Simplify Commerce.', 'woocommerce' );
@ -214,7 +214,7 @@ class WC_Addons_Gateway_Simplify_Commerce extends WC_Gateway_Simplify_Commerce {
}
// Reduce stock levels
$order->reduce_order_stock();
wc_reduce_stock_levels( $order_id );
// Remove cart
WC()->cart->empty_cart();
@ -259,11 +259,11 @@ class WC_Addons_Gateway_Simplify_Commerce extends WC_Gateway_Simplify_Commerce {
$order = wc_get_order( $order_id );
// Processing subscription
if ( 'standard' == $this->mode && ( $this->order_contains_subscription( $order->id ) || ( function_exists( 'wcs_is_subscription' ) && wcs_is_subscription( $order_id ) ) ) ) {
if ( 'standard' == $this->mode && ( $this->order_contains_subscription( $order->get_id() ) || ( function_exists( 'wcs_is_subscription' ) && wcs_is_subscription( $order_id ) ) ) ) {
return $this->process_subscription( $order, $cart_token );
// Processing pre-order
} elseif ( 'standard' == $this->mode && $this->order_contains_pre_order( $order->id ) ) {
} elseif ( 'standard' == $this->mode && $this->order_contains_pre_order( $order->get_id() ) ) {
return $this->process_pre_order( $order, $cart_token );
// Processing regular product
@ -292,7 +292,7 @@ class WC_Addons_Gateway_Simplify_Commerce extends WC_Gateway_Simplify_Commerce {
return new WP_Error( 'simplify_error', __( 'Sorry, the minimum allowed order total is 0.50 to use this payment method.', 'woocommerce' ) );
}
$customer_id = get_post_meta( $order->id, '_simplify_customer_id', true );
$customer_id = get_post_meta( $order->get_id(), '_simplify_customer_id', true );
if ( ! $customer_id ) {
return new WP_Error( 'simplify_error', __( 'Customer not found', 'woocommerce' ) );
@ -305,7 +305,7 @@ class WC_Addons_Gateway_Simplify_Commerce extends WC_Gateway_Simplify_Commerce {
'customer' => $customer_id,
'description' => sprintf( __( '%s - Order #%s', 'woocommerce' ), esc_html( get_bloginfo( 'name', 'display' ) ), $order->get_order_number() ),
'currency' => strtoupper( get_woocommerce_currency() ),
'reference' => $order->id
'reference' => $order->get_id()
) );
} catch ( Exception $e ) {
@ -361,7 +361,7 @@ class WC_Addons_Gateway_Simplify_Commerce extends WC_Gateway_Simplify_Commerce {
* @param WC_Order $renewal_order The order which recorded the successful payment (to make up for the failed automatic payment).
*/
public function update_failing_payment_method( $subscription, $renewal_order ) {
update_post_meta( $subscription->id, '_simplify_customer_id', get_post_meta( $renewal_order->id, '_simplify_customer_id', true ) );
update_post_meta( $subscription->id, '_simplify_customer_id', get_post_meta( $renewal_order->get_id(), '_simplify_customer_id', true ) );
}
/**
@ -413,7 +413,7 @@ class WC_Addons_Gateway_Simplify_Commerce extends WC_Gateway_Simplify_Commerce {
* @return void
*/
public function delete_resubscribe_meta( $resubscribe_order ) {
delete_post_meta( $resubscribe_order->id, '_simplify_customer_id' );
delete_post_meta( $resubscribe_order->get_id(), '_simplify_customer_id' );
}
/**
@ -429,7 +429,7 @@ class WC_Addons_Gateway_Simplify_Commerce extends WC_Gateway_Simplify_Commerce {
$order_item = array_shift( $order_items );
$pre_order_name = sprintf( __( '%s - Pre-order for "%s"', 'woocommerce' ), esc_html( get_bloginfo( 'name', 'display' ) ), $order_item['name'] ) . ' ' . sprintf( __( '(Order #%s)', 'woocommerce' ), $order->get_order_number() );
$customer_id = get_post_meta( $order->id, '_simplify_customer_id', true );
$customer_id = get_post_meta( $order->get_id(), '_simplify_customer_id', true );
if ( ! $customer_id ) {
return new WP_Error( 'simplify_error', __( 'Customer not found', 'woocommerce' ) );
@ -437,11 +437,11 @@ class WC_Addons_Gateway_Simplify_Commerce extends WC_Gateway_Simplify_Commerce {
// Charge the customer
$payment = Simplify_Payment::createPayment( array(
'amount' => $order->order_total * 100, // In cents.
'amount' => $order->get_total() * 100, // In cents.
'customer' => $customer_id,
'description' => trim( substr( $pre_order_name, 0, 1024 ) ),
'currency' => strtoupper( get_woocommerce_currency() ),
'reference' => $order->id
'reference' => $order->get_id()
) );
if ( 'APPROVED' == $payment->paymentStatus ) {
@ -484,12 +484,12 @@ class WC_Addons_Gateway_Simplify_Commerce extends WC_Gateway_Simplify_Commerce {
$amount = absint( $_REQUEST['amount'] );
$order_id = absint( $_REQUEST['reference'] );
$order = wc_get_order( $order_id );
$order_total = absint( $order->order_total * 100 );
$order_total = absint( $order->get_total() * 100 );
if ( $amount === $order_total ) {
if ( $this->order_contains_subscription( $order->id ) ) {
if ( $this->order_contains_subscription( $order->get_id() ) ) {
$response = $this->process_subscription( $order, $cart_token );
} elseif ( $this->order_contains_pre_order( $order->id ) ) {
} elseif ( $this->order_contains_pre_order( $order->get_id() ) ) {
$response = $this->process_pre_order( $order, $cart_token );
} else {
$response = parent::process_standard_payments( $order, $cart_token );

View File

@ -392,7 +392,7 @@ class WC_Gateway_Simplify_Commerce extends WC_Payment_Gateway_CC {
// Are we saving a new payment method?
if ( is_user_logged_in() && isset( $_POST['wc-simplify_commerce-new-payment-method'] ) && true === (bool) $_POST['wc-simplify_commerce-new-payment-method'] ) {
$customer_info = array(
'email' => $order->billing_email,
'email' => $order->get_billing_email(),
'name' => trim( $order->get_formatted_billing_full_name() ),
);
$token = $this->save_token( $customer_token, $cart_token, $customer_info );
@ -499,7 +499,7 @@ class WC_Gateway_Simplify_Commerce extends WC_Payment_Gateway_CC {
'amount' => $amount * 100, // In cents.
'description' => sprintf( __( '%s - Order #%s', 'woocommerce' ), esc_html( get_bloginfo( 'name', 'display' ) ), $order->get_order_number() ),
'currency' => strtoupper( get_woocommerce_currency() ),
'reference' => $order->id
'reference' => $order->get_id()
);
$data = array_merge( $data, $token );
@ -608,20 +608,20 @@ class WC_Gateway_Simplify_Commerce extends WC_Payment_Gateway_CC {
protected function get_hosted_payments_args( $order ) {
$args = apply_filters( 'woocommerce_simplify_commerce_hosted_args', array(
'sc-key' => $this->public_key,
'amount' => $order->order_total * 100,
'reference' => $order->id,
'amount' => $order->get_total() * 100,
'reference' => $order->get_id(),
'name' => esc_html( get_bloginfo( 'name', 'display' ) ),
'description' => sprintf( __( 'Order #%s', 'woocommerce' ), $order->get_order_number() ),
'receipt' => 'false',
'color' => $this->modal_color,
'redirect-url' => WC()->api_request_url( 'WC_Gateway_Simplify_Commerce' ),
'address' => $order->billing_address_1 . ' ' . $order->billing_address_2,
'address-city' => $order->billing_city,
'address-state' => $order->billing_state,
'address-zip' => $order->billing_postcode,
'address-country' => $order->billing_country,
'address' => $order->get_billing_address_1() . ' ' . $order->get_billing_address_2(),
'address-city' => $order->get_billing_city(),
'address-state' => $order->get_billing_state(),
'address-zip' => $order->get_billing_postcode(),
'address-country' => $order->get_billing_country(),
'operation' => 'create.token',
), $order->id );
), $order->get_id() );
return $args;
}

View File

@ -90,19 +90,19 @@ class WC_Shortcode_Checkout {
return;
}
if ( $order->id == $order_id && $order->order_key == $order_key ) {
if ( $order->get_id() == $order_id && $order->get_order_key() == $order_key ) {
if ( $order->needs_payment() ) {
// Set customer location to order location
if ( $order->billing_country ) {
WC()->customer->set_country( $order->billing_country );
if ( $order->get_billing_country() ) {
WC()->customer->set_country( $order->get_billing_country() );
}
if ( $order->billing_state ) {
WC()->customer->set_state( $order->billing_state );
if ( $order->get_billing_state() ) {
WC()->customer->set_state( $order->get_billing_state() );
}
if ( $order->billing_postcode ) {
WC()->customer->set_postcode( $order->billing_postcode );
if ( $order->get_billing_postcode() ) {
WC()->customer->set_postcode( $order->get_billing_postcode() );
}
WC()->customer->save();
@ -133,7 +133,7 @@ class WC_Shortcode_Checkout {
$order_key = isset( $_GET['key'] ) ? wc_clean( $_GET['key'] ) : '';
$order = wc_get_order( $order_id );
if ( $order->id == $order_id && $order->order_key == $order_key ) {
if ( $order->get_id() == $order_id && $order->get_order_key() == $order_key ) {
if ( $order->needs_payment() ) {
@ -151,17 +151,17 @@ class WC_Shortcode_Checkout {
<?php _e( 'Total:', 'woocommerce' ); ?>
<strong><?php echo $order->get_formatted_order_total(); ?></strong>
</li>
<?php if ($order->payment_method_title) : ?>
<?php if ($order->get_payment_method_title()) : ?>
<li class="method">
<?php _e( 'Payment Method:', 'woocommerce' ); ?>
<strong><?php
echo $order->payment_method_title;
echo $order->get_payment_method_title();
?></strong>
</li>
<?php endif; ?>
</ul>
<?php do_action( 'woocommerce_receipt_' . $order->payment_method, $order_id ); ?>
<?php do_action( 'woocommerce_receipt_' . $order->get_payment_method(), $order_id ); ?>
<div class="clear"></div>
<?php
@ -200,7 +200,7 @@ class WC_Shortcode_Checkout {
if ( $order_id > 0 ) {
$order = wc_get_order( $order_id );
if ( $order->order_key != $order_key ) {
if ( $order->get_order_key() != $order_key ) {
$order = false;
}
}

View File

@ -55,10 +55,10 @@ class WC_Shortcode_Order_Tracking {
$order = wc_get_order( apply_filters( 'woocommerce_shortcode_order_tracking_order_id', $order_id ) );
if ( $order && $order->id && $order_email ) {
if ( $order && $order->get_id() && $order_email ) {
if ( strtolower( $order->billing_email ) == strtolower( $order_email ) ) {
do_action( 'woocommerce_track_order', $order->id );
if ( strtolower( $order->get_billing_email() ) == strtolower( $order_email ) ) {
do_action( 'woocommerce_track_order', $order->get_id() );
wc_get_template( 'order/tracking.php', array(
'order' => $order
) );

View File

@ -108,8 +108,7 @@ function wc_attribute_label( $name, $product = '' ) {
global $wpdb;
if ( taxonomy_is_product_attribute( $name ) ) {
$name = wc_sanitize_taxonomy_name( str_replace( 'pa_', '', $name ) );
$name = wc_sanitize_taxonomy_name( str_replace( 'pa_', '', $name ) );
$label = $wpdb->get_var( $wpdb->prepare( "SELECT attribute_label FROM {$wpdb->prefix}woocommerce_attribute_taxonomies WHERE attribute_name = %s;", $name ) );
if ( ! $label ) {

View File

@ -162,7 +162,7 @@ function wc_clear_cart_after_payment() {
if ( $order_id > 0 ) {
$order = wc_get_order( $order_id );
if ( $order->order_key === $order_key ) {
if ( $order->get_order_key() === $order_key ) {
WC()->cart->empty_cart();
}
}
@ -171,7 +171,7 @@ function wc_clear_cart_after_payment() {
if ( WC()->session->order_awaiting_payment > 0 ) {
$order = wc_get_order( WC()->session->order_awaiting_payment );
if ( $order && $order->id > 0 ) {
if ( $order && $order->get_id() > 0 ) {
// If the order has not failed, or is not pending, the order must have gone through
if ( ! $order->has_status( array( 'failed', 'pending', 'cancelled' ) ) ) {
WC()->cart->empty_cart();

View File

@ -54,76 +54,55 @@ add_filter( 'woocommerce_short_description', 'do_shortcode', 11 ); // AFTER wpau
* Returns a new order object on success which can then be used to add additional data.
*
* @param array $args
*
* @return WC_Order|WP_Error WC_Order on success, WP_Error on failure.
* @return WC_Order
*/
function wc_create_order( $args = array() ) {
$default_args = array(
'status' => '',
'status' => null,
'customer_id' => null,
'customer_note' => null,
'parent' => null,
'created_via' => null,
'cart_hash' => null,
'order_id' => 0,
'created_via' => '',
'cart_hash' => '',
'parent' => 0,
);
$args = wp_parse_args( $args, $default_args );
$order_data = array();
$args = wp_parse_args( $args, $default_args );
$order = new WC_Order( $args['order_id'] );
if ( $args['order_id'] > 0 ) {
$updating = true;
$order_data['ID'] = $args['order_id'];
} else {
$updating = false;
$order_data['post_type'] = 'shop_order';
$order_data['post_status'] = 'wc-' . apply_filters( 'woocommerce_default_order_status', 'pending' );
$order_data['ping_status'] = 'closed';
$order_data['post_author'] = 1;
$order_data['post_password'] = uniqid( 'order_' );
$order_data['post_title'] = sprintf( __( 'Order &ndash; %s', 'woocommerce' ), strftime( _x( '%b %d, %Y @ %I:%M %p', 'Order date parsed by strftime', 'woocommerce' ) ) );
$order_data['post_parent'] = absint( $args['parent'] );
// Update props that were set (not null)
if ( ! is_null( $args['parent'] ) ) {
$order->set_parent_id( absint( $args['parent'] ) );
}
if ( $args['status'] ) {
if ( ! in_array( 'wc-' . $args['status'], array_keys( wc_get_order_statuses() ) ) ) {
return new WP_Error( 'woocommerce_invalid_order_status', __( 'Invalid order status', 'woocommerce' ) );
}
$order_data['post_status'] = 'wc-' . $args['status'];
if ( ! is_null( $args['status'] ) ) {
$order->set_status( $args['status'] );
}
if ( ! is_null( $args['customer_note'] ) ) {
$order_data['post_excerpt'] = $args['customer_note'];
$order->set_customer_note( $args['customer_note'] );
}
if ( $updating ) {
$order_id = wp_update_post( $order_data );
} else {
$order_id = wp_insert_post( apply_filters( 'woocommerce_new_order_data', $order_data ), true );
if ( ! is_null( $args['customer_id'] ) ) {
$order->set_customer_id( is_numeric( $args['customer_id'] ) ? absint( $args['customer_id'] ) : 0 );
}
if ( is_wp_error( $order_id ) ) {
return $order_id;
if ( ! is_null( $args['created_via'] ) ) {
$order->set_created_via( sanitize_text_field( $args['created_via'] ) );
}
if ( ! $updating ) {
update_post_meta( $order_id, '_order_key', 'wc_' . apply_filters( 'woocommerce_generate_order_key', uniqid( 'order_' ) ) );
update_post_meta( $order_id, '_order_currency', get_woocommerce_currency() );
update_post_meta( $order_id, '_prices_include_tax', get_option( 'woocommerce_prices_include_tax' ) );
update_post_meta( $order_id, '_customer_ip_address', WC_Geolocation::get_ip_address() );
update_post_meta( $order_id, '_customer_user_agent', isset( $_SERVER['HTTP_USER_AGENT'] ) ? $_SERVER['HTTP_USER_AGENT'] : '' );
update_post_meta( $order_id, '_customer_user', 0 );
update_post_meta( $order_id, '_created_via', sanitize_text_field( $args['created_via'] ) );
update_post_meta( $order_id, '_cart_hash', sanitize_text_field( $args['cart_hash'] ) );
if ( ! is_null( $args['cart_hash'] ) ) {
$order->set_cart_hash( sanitize_text_field( $args['cart_hash'] ) );
}
if ( is_numeric( $args['customer_id'] ) ) {
update_post_meta( $order_id, '_customer_user', $args['customer_id'] );
}
// Update other order props set automatically
$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->save();
update_post_meta( $order_id, '_order_version', WC_VERSION );
return wc_get_order( $order_id );
return $order;
}
/**
@ -980,7 +959,7 @@ function wc_get_customer_default_location() {
case 'geolocation_ajax' :
case 'geolocation' :
// Exclude common bots from geolocation by user agent.
$ua = isset( $_SERVER['HTTP_USER_AGENT'] ) ? strtolower( $_SERVER['HTTP_USER_AGENT'] ) : '';
$ua = wc_get_user_agent();
if ( ! strstr( $ua, 'bot' ) && ! strstr( $ua, 'spider' ) && ! strstr( $ua, 'crawl' ) ) {
$location = WC_Geolocation::geolocate_ip( '', true, false );
@ -1002,6 +981,15 @@ function wc_get_customer_default_location() {
return apply_filters( 'woocommerce_customer_default_location_array', $location );
}
/**
* Get user agent string.
* @since 2.7.0
* @return string
*/
function wc_get_user_agent() {
return isset( $_SERVER['HTTP_USER_AGENT'] ) ? strtolower( $_SERVER['HTTP_USER_AGENT'] ) : '';
}
// This function can be removed when WP 3.9.2 or greater is required.
if ( ! function_exists( 'hash_equals' ) ) :
/**

View File

@ -412,7 +412,7 @@ function wc_register_order_type( $type, $args = array() ) {
function wc_downloadable_file_permission( $download_id, $product_id, $order, $qty = 1 ) {
global $wpdb;
$user_email = sanitize_email( $order->billing_email );
$user_email = sanitize_email( $order->get_billing_email() );
$limit = trim( get_post_meta( $product_id, '_download_limit', true ) );
$expiry = trim( get_post_meta( $product_id, '_download_expiry', true ) );
@ -429,10 +429,10 @@ function wc_downloadable_file_permission( $download_id, $product_id, $order, $qt
$data = apply_filters( 'woocommerce_downloadable_file_permission_data', array(
'download_id' => $download_id,
'product_id' => $product_id,
'user_id' => absint( $order->user_id ),
'user_id' => absint( $order->get_user_id() ),
'user_email' => $user_email,
'order_id' => $order->id,
'order_key' => $order->order_key,
'order_id' => $order->get_id(),
'order_key' => $order->get_order_key(),
'downloads_remaining' => $limit,
'access_granted' => current_time( 'mysql' ),
'download_count' => 0
@ -962,7 +962,7 @@ function wc_get_payment_gateway_by_order( $order ) {
$order = wc_get_order( $order_id );
}
return isset( $payment_gateways[ $order->payment_method ] ) ? $payment_gateways[ $order->payment_method ] : false;
return isset( $payment_gateways[ $order->get_payment_method() ] ) ? $payment_gateways[ $order->get_payment_method() ] : false;
}
/**

View File

@ -2327,10 +2327,11 @@ if ( ! function_exists( 'wc_get_email_order_items' ) ) {
ob_start();
$defaults = array(
'show_sku' => false,
'show_image' => false,
'image_size' => array( 32, 32 ),
'plain_text' => false
'show_sku' => false,
'show_image' => false,
'image_size' => array( 32, 32 ),
'plain_text' => false,
'sent_to_admin' => false,
);
$args = wp_parse_args( $args, $defaults );
@ -2344,6 +2345,8 @@ if ( ! function_exists( 'wc_get_email_order_items' ) ) {
'show_purchase_note' => $order->is_paid(),
'show_image' => $args['show_image'],
'image_size' => $args['image_size'],
'plain_text' => $args['plain_text'],
'sent_to_admin' => $args['sent_to_admin'],
) );
return apply_filters( 'woocommerce_email_order_items_table', ob_get_clean(), $order );

View File

@ -183,7 +183,7 @@ function wc_paying_customer( $order_id ) {
update_user_meta( $customer_id, 'paying_customer', 1 );
$old_spent = absint( get_user_meta( $customer_id, '_money_spent', true ) );
update_user_meta( $customer_id, '_money_spent', $old_spent + $order->order_total );
update_user_meta( $customer_id, '_money_spent', $old_spent + $order->get_total( true ) );
}
if ( $customer_id > 0 && 'shop_order' === $order->get_type() ) {
$old_count = absint( get_user_meta( $customer_id, '_order_count', true ) );
@ -259,7 +259,7 @@ function wc_customer_has_capability( $allcaps, $caps, $args ) {
$user_id = $args[1];
$order = wc_get_order( $args[2] );
if ( $order && $user_id == $order->user_id ) {
if ( $order && $user_id == $order->get_user_id() ) {
$allcaps['view_order'] = true;
}
break;
@ -275,7 +275,7 @@ function wc_customer_has_capability( $allcaps, $caps, $args ) {
}
$order = wc_get_order( $order_id );
if ( $user_id == $order->user_id || empty( $order->user_id ) ) {
if ( $user_id == $order->get_user_id() || empty( $order->get_user_id() ) ) {
$allcaps['pay_for_order'] = true;
}
break;
@ -283,7 +283,7 @@ function wc_customer_has_capability( $allcaps, $caps, $args ) {
$user_id = $args[1];
$order = wc_get_order( $args[2] );
if ( $user_id == $order->user_id ) {
if ( $user_id == $order->get_user_id() ) {
$allcaps['order_again'] = true;
}
break;
@ -291,7 +291,7 @@ function wc_customer_has_capability( $allcaps, $caps, $args ) {
$user_id = $args[1];
$order = wc_get_order( $args[2] );
if ( $user_id == $order->user_id ) {
if ( $user_id == $order->get_user_id() ) {
$allcaps['cancel_order'] = true;
}
break;
@ -402,7 +402,7 @@ function wc_get_customer_available_downloads( $customer_id ) {
if ( $results ) {
foreach ( $results as $result ) {
if ( ! $order || $order->id != $result->order_id ) {
if ( ! $order || $order->get_id() != $result->order_id ) {
// new order
$order = wc_get_order( $result->order_id );
$_product = null;
@ -455,8 +455,8 @@ function wc_get_customer_available_downloads( $customer_id ) {
'download_id' => $result->download_id,
'product_id' => $product_id,
'download_name' => $download_name,
'order_id' => $order->id,
'order_key' => $order->order_key,
'order_id' => $order->get_id(),
'order_key' => $order->get_order_key(),
'downloads_remaining' => $result->downloads_remaining,
'access_expires' => $result->access_expires,
'file' => $download_file

View File

@ -44,16 +44,16 @@ if ( $order ) : ?>
</li>
<li class="date">
<?php _e( 'Date:', 'woocommerce' ); ?>
<strong><?php echo date_i18n( get_option( 'date_format' ), strtotime( $order->order_date ) ); ?></strong>
<strong><?php echo date_i18n( get_option( 'date_format' ), $order->get_date_created() ); ?></strong>
</li>
<li class="total">
<?php _e( 'Total:', 'woocommerce' ); ?>
<strong><?php echo $order->get_formatted_order_total(); ?></strong>
</li>
<?php if ( $order->payment_method_title ) : ?>
<?php if ( $order->get_payment_method_title() ) : ?>
<li class="method">
<?php _e( 'Payment Method:', 'woocommerce' ); ?>
<strong><?php echo $order->payment_method_title; ?></strong>
<strong><?php echo $order->get_payment_method_title(); ?></strong>
</li>
<?php endif; ?>
</ul>
@ -61,8 +61,8 @@ if ( $order ) : ?>
<?php endif; ?>
<?php do_action( 'woocommerce_thankyou_' . $order->payment_method, $order->id ); ?>
<?php do_action( 'woocommerce_thankyou', $order->id ); ?>
<?php do_action( 'woocommerce_thankyou_' . $order->get_payment_method(), $order->get_id() ); ?>
<?php do_action( 'woocommerce_thankyou', $order->get_id() ); ?>
<?php else : ?>

View File

@ -25,7 +25,7 @@ do_action( 'woocommerce_email_before_order_table', $order, $sent_to_admin, $plai
<?php if ( ! $sent_to_admin ) : ?>
<h2><?php printf( __( 'Order #%s', 'woocommerce' ), $order->get_order_number() ); ?></h2>
<?php else : ?>
<h2><a class="link" href="<?php echo esc_url( admin_url( 'post.php?post=' . $order->id . '&action=edit' ) ); ?>"><?php printf( __( 'Order #%s', 'woocommerce'), $order->get_order_number() ); ?></a> (<?php printf( '<time datetime="%s">%s</time>', date_i18n( 'c', strtotime( $order->order_date ) ), date_i18n( wc_date_format(), strtotime( $order->order_date ) ) ); ?>)</h2>
<h2><a class="link" href="<?php echo esc_url( admin_url( 'post.php?post=' . $order->get_id() . '&action=edit' ) ); ?>"><?php printf( __( 'Order #%s', 'woocommerce'), $order->get_order_number() ); ?></a> (<?php printf( '<time datetime="%s">%s</time>', date_i18n( 'c', $order->get_date_created() ), date_i18n( wc_date_format(), $order->get_date_created() ) ); ?>)</h2>
<?php endif; ?>
<table class="td" cellspacing="0" cellpadding="6" style="width: 100%; font-family: 'Helvetica Neue', Helvetica, Roboto, Arial, sans-serif;" border="1">
@ -37,7 +37,7 @@ do_action( 'woocommerce_email_before_order_table', $order, $sent_to_admin, $plai
</tr>
</thead>
<tbody>
<?php echo $order->email_order_items_table( array(
<?php echo wc_get_email_order_items( $order, array(
'show_sku' => $sent_to_admin,
'show_image' => false,
'image_size' => array( 32, 32 ),

View File

@ -10,49 +10,43 @@
* happen. When this occurs the version of the template file will be bumped and
* the readme will list any important changes.
*
* @see https://docs.woocommerce.com/document/template-structure/
* @see https://docs.woothemes.com/document/template-structure/
* @author WooThemes
* @package WooCommerce/Templates/Emails
* @version 2.1.2
* @version 2.7.0
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
exit;
}
foreach ( $items as $item_id => $item ) :
$_product = apply_filters( 'woocommerce_order_item_product', $order->get_product_from_item( $item ), $item );
$item_meta = new WC_Order_Item_Meta( $item, $_product );
if ( apply_filters( 'woocommerce_order_item_visible', true, $item ) ) {
$product = $item->get_product();
?>
<tr class="<?php echo esc_attr( apply_filters( 'woocommerce_order_item_class', 'order_item', $item, $order ) ); ?>">
<td class="td" style="text-align:left; vertical-align:middle; border: 1px solid #eee; font-family: 'Helvetica Neue', Helvetica, Roboto, Arial, sans-serif; word-wrap:break-word;"><?php
// Show title/image etc
if ( $show_image ) {
echo apply_filters( 'woocommerce_order_item_thumbnail', '<div style="margin-bottom: 5px"><img src="' . ( $_product->get_image_id() ? current( wp_get_attachment_image_src( $_product->get_image_id(), 'thumbnail') ) : wc_placeholder_img_src() ) .'" alt="' . esc_attr__( 'Product Image', 'woocommerce' ) . '" height="' . esc_attr( $image_size[1] ) . '" width="' . esc_attr( $image_size[0] ) . '" style="vertical-align:middle; margin-right: 10px;" /></div>', $item );
echo apply_filters( 'woocommerce_order_item_thumbnail', '<div style="margin-bottom: 5px"><img src="' . ( $product->get_image_id() ? current( wp_get_attachment_image_src( $product->get_image_id(), 'thumbnail') ) : wc_placeholder_img_src() ) .'" alt="' . esc_attr__( 'Product Image', 'woocommerce' ) . '" height="' . esc_attr( $image_size[1] ) . '" width="' . esc_attr( $image_size[0] ) . '" style="vertical-align:middle; margin-right: 10px;" /></div>', $item );
}
// Product name
echo apply_filters( 'woocommerce_order_item_name', $item['name'], $item, false );
// SKU
if ( $show_sku && is_object( $_product ) && $_product->get_sku() ) {
echo ' (#' . $_product->get_sku() . ')';
if ( $show_sku && is_object( $product ) && $product->get_sku() ) {
echo ' (#' . $product->get_sku() . ')';
}
// allow other plugins to add additional product information here
do_action( 'woocommerce_order_item_meta_start', $item_id, $item, $order, $plain_text );
// Variation
if ( ! empty( $item_meta->meta ) ) {
echo '<br/><small>' . nl2br( $item_meta->display( true, true, '_', "\n" ) ) . '</small>';
}
wc_display_item_meta( $item );
// File URLs
if ( $show_download_links ) {
$order->display_item_downloads( $item );
wc_display_item_downloads( $item );
}
// allow other plugins to add additional product information here
@ -65,7 +59,7 @@ foreach ( $items as $item_id => $item ) :
<?php
}
if ( $show_purchase_note && is_object( $_product ) && ( $purchase_note = get_post_meta( $_product->id, '_purchase_note', true ) ) ) : ?>
if ( $show_purchase_note && is_object( $product ) && ( $purchase_note = get_post_meta( $product->id, '_purchase_note', true ) ) ) : ?>
<tr>
<td colspan="3" style="text-align:left; vertical-align:middle; border: 1px solid #eee; font-family: 'Helvetica Neue', Helvetica, Roboto, Arial, sans-serif;"><?php echo wpautop( do_shortcode( wp_kses_post( $purchase_note ) ) ); ?></td>
</tr>

View File

@ -22,7 +22,7 @@ if ( ! defined( 'ABSPATH' ) ) {
echo "= " . $email_heading . " =\n\n";
echo sprintf( __( 'The order #%d from %s has been cancelled. The order was as follows:', 'woocommerce' ), $order->id, $order->get_formatted_billing_full_name() ) . "\n\n";
echo sprintf( __( 'The order #%d from %s has been cancelled. The order was as follows:', 'woocommerce' ), $order->get_id(), $order->get_formatted_billing_full_name() ) . "\n\n";
echo "=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\n\n";

View File

@ -22,7 +22,7 @@ if ( ! defined( 'ABSPATH' ) ) {
echo "= " . $email_heading . " =\n\n";
echo sprintf( __( 'Payment for order #%d from %s has failed. The order was as follows:', 'woocommerce' ), $order->id, $order->get_formatted_billing_full_name() ) . "\n\n";
echo sprintf( __( 'Payment for order #%d from %s has failed. The order was as follows:', 'woocommerce' ), $order->get_id(), $order->get_formatted_billing_full_name() ) . "\n\n";
echo "=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\n\n";

View File

@ -23,12 +23,13 @@ if ( ! defined( 'ABSPATH' ) ) {
do_action( 'woocommerce_email_before_order_table', $order, $sent_to_admin, $plain_text, $email );
echo strtoupper( sprintf( __( 'Order number: %s', 'woocommerce' ), $order->get_order_number() ) ) . "\n";
echo date_i18n( __( 'jS F Y', 'woocommerce' ), strtotime( $order->order_date ) ) . "\n";
echo "\n" . $order->email_order_items_table( array(
'show_sku' => $sent_to_admin,
'show_image' => false,
'image_size' => array( 32, 32 ),
'plain_text' => true
echo date_i18n( __( 'jS F Y', 'woocommerce' ), $order->get_date_created() ) . "\n";
echo "\n" . wc_get_email_order_items( $order, array(
'show_sku' => $sent_to_admin,
'show_image' => false,
'image_size' => array( 32, 32 ),
'plain_text' => true,
'sent_to_admin' => $sent_to_admin
) );
echo "==========\n\n";
@ -40,7 +41,7 @@ if ( $totals = $order->get_order_item_totals() ) {
}
if ( $sent_to_admin ) {
echo "\n" . sprintf( __( 'View order: %s', 'woocommerce'), admin_url( 'post.php?post=' . $order->id . '&action=edit' ) ) . "\n";
echo "\n" . sprintf( __( 'View order: %s', 'woocommerce'), admin_url( 'post.php?post=' . $order->get_id() . '&action=edit' ) ) . "\n";
}
do_action( 'woocommerce_email_after_order_table', $order, $sent_to_admin, $plain_text, $email );

View File

@ -13,7 +13,7 @@
* @see https://docs.woocommerce.com/document/template-structure/
* @author WooThemes
* @package WooCommerce/Templates/Emails/Plain
* @version 2.1.2
* @version 2.7.0
*/
if ( ! defined( 'ABSPATH' ) ) {
@ -21,59 +21,38 @@ if ( ! defined( 'ABSPATH' ) ) {
}
foreach ( $items as $item_id => $item ) :
$_product = apply_filters( 'woocommerce_order_item_product', $order->get_product_from_item( $item ), $item );
$item_meta = new WC_Order_Item_Meta( $item, $_product );
if ( apply_filters( 'woocommerce_order_item_visible', true, $item ) ) {
// Title
echo apply_filters( 'woocommerce_order_item_name', $item['name'], $item, false );
// SKU
if ( $show_sku && $_product->get_sku() ) {
echo ' (#' . $_product->get_sku() . ')';
$product = $item->get_product();
echo apply_filters( 'woocommerce_order_item_name', $item->get_name(), $item, false );
if ( $show_sku && $product->get_sku() ) {
echo ' (#' . $product->get_sku() . ')';
}
echo ' X ' . apply_filters( 'woocommerce_email_order_item_quantity', $item['qty'], $item );
echo ' = ' . $order->get_formatted_line_subtotal( $item ) . "\n";
// allow other plugins to add additional product information here
do_action( 'woocommerce_order_item_meta_start', $item_id, $item, $order, $plain_text );
// Variation
echo ( $item_meta_content = $item_meta->display( true, true ) ) ? "\n" . $item_meta_content : '';
// Quantity
echo "\n" . sprintf( __( 'Quantity: %s', 'woocommerce' ), apply_filters( 'woocommerce_email_order_item_quantity', $item['qty'], $item ) );
// Cost
echo "\n" . sprintf( __( 'Cost: %s', 'woocommerce' ), $order->get_formatted_line_subtotal( $item ) );
// Download URLs
if ( $show_download_links && $_product->exists() && $_product->is_downloadable() ) {
$download_files = $order->get_item_downloads( $item );
$i = 0;
foreach ( $download_files as $download_id => $file ) {
$i++;
if ( count( $download_files ) > 1 ) {
$prefix = sprintf( __( 'Download %d', 'woocommerce' ), $i );
} elseif ( $i == 1 ) {
$prefix = __( 'Download', 'woocommerce' );
}
echo "\n" . $prefix . '(' . esc_html( $file['name'] ) . '): ' . esc_url( $file['download_url'] );
}
echo strip_tags( wc_display_item_meta( $item, array(
'before' => "\n- ",
'separator' => "\n- ",
'after' => "",
'echo' => false,
'autop' => false,
) ) );
if ( $show_download_links ) {
echo strip_tags( wc_display_item_downloads( $item, array(
'before' => "\n- ",
'separator' => "\n- ",
'after' => "",
'echo' => false,
'show_url' => true,
) ) );
}
// allow other plugins to add additional product information here
do_action( 'woocommerce_order_item_meta_end', $item_id, $item, $order, $plain_text );
}
// Note
if ( $show_purchase_note && ( $purchase_note = get_post_meta( $_product->id, '_purchase_note', true ) ) ) {
if ( $show_purchase_note && ( $purchase_note = get_post_meta( $product->id, '_purchase_note', true ) ) ) {
echo "\n" . do_shortcode( wp_kses_post( $purchase_note ) );
}
echo "\n\n";
endforeach;

View File

@ -56,7 +56,7 @@ if ( $customer_orders ) : ?>
</a>
<?php elseif ( 'order-date' === $column_id ) : ?>
<time datetime="<?php echo date( 'Y-m-d', strtotime( $order->order_date ) ); ?>" title="<?php echo esc_attr( strtotime( $order->order_date ) ); ?>"><?php echo date_i18n( get_option( 'date_format' ), strtotime( $order->order_date ) ); ?></time>
<time datetime="<?php echo date( 'Y-m-d', $order->get_date_created() ); ?>" title="<?php echo esc_attr( $order->get_date_created() ); ?>"><?php echo date_i18n( get_option( 'date_format' ), $order->get_date_created() ); ?></time>
<?php elseif ( 'order-status' === $column_id ) : ?>
<?php echo wc_get_order_status_name( $order->get_status() ); ?>

View File

@ -52,7 +52,7 @@ do_action( 'woocommerce_before_account_orders', $has_orders ); ?>
</a>
<?php elseif ( 'order-date' === $column_id ) : ?>
<time datetime="<?php echo date( 'Y-m-d', strtotime( $order->order_date ) ); ?>" title="<?php echo esc_attr( strtotime( $order->order_date ) ); ?>"><?php echo date_i18n( get_option( 'date_format' ), strtotime( $order->order_date ) ); ?></time>
<time datetime="<?php echo date( 'Y-m-d', $order->get_date_created() ); ?>" title="<?php echo esc_attr( $order->get_date_created() ); ?>"><?php echo date_i18n( get_option( 'date_format' ), $order->get_date_created() ); ?></time>
<?php elseif ( 'order-status' === $column_id ) : ?>
<?php echo wc_get_order_status_name( $order->get_status() ); ?>

View File

@ -27,7 +27,7 @@ if ( ! defined( 'ABSPATH' ) ) {
printf(
__( 'Order #%1$s was placed on %2$s and is currently %3$s.', 'woocommerce' ),
'<mark class="order-number">' . $order->get_order_number() . '</mark>',
'<mark class="order-date">' . date_i18n( get_option( 'date_format' ), strtotime( $order->order_date ) ) . '</mark>',
'<mark class="order-date">' . date_i18n( get_option( 'date_format' ), $order->get_date_created() ) . '</mark>',
'<mark class="order-status">' . wc_get_order_status_name( $order->get_status() ) . '</mark>'
);
?></p>

View File

@ -22,5 +22,5 @@ if ( ! defined( 'ABSPATH' ) ) {
?>
<p class="order-again">
<a href="<?php echo esc_url( wp_nonce_url( add_query_arg( 'order_again', $order->id ) , 'woocommerce-order_again' ) ); ?>" class="button"><?php _e( 'Order Again', 'woocommerce' ); ?></a>
<a href="<?php echo esc_url( wp_nonce_url( add_query_arg( 'order_again', $order->get_id() ) , 'woocommerce-order_again' ) ); ?>" class="button"><?php _e( 'Order Again', 'woocommerce' ); ?></a>
</p>

View File

@ -23,24 +23,24 @@ if ( ! defined( 'ABSPATH' ) ) {
<header><h2><?php _e( 'Customer Details', 'woocommerce' ); ?></h2></header>
<table class="shop_table customer_details">
<?php if ( $order->customer_note ) : ?>
<?php if ( $order->get_customer_note() ) : ?>
<tr>
<th><?php _e( 'Note:', 'woocommerce' ); ?></th>
<td><?php echo wptexturize( $order->customer_note ); ?></td>
<td><?php echo wptexturize( $order->get_customer_note() ); ?></td>
</tr>
<?php endif; ?>
<?php if ( $order->billing_email ) : ?>
<?php if ( $order->get_billing_email() ) : ?>
<tr>
<th><?php _e( 'Email:', 'woocommerce' ); ?></th>
<td><?php echo esc_html( $order->billing_email ); ?></td>
<td><?php echo esc_html( $order->get_billing_email() ); ?></td>
</tr>
<?php endif; ?>
<?php if ( $order->billing_phone ) : ?>
<?php if ( $order->get_billing_phone() ) : ?>
<tr>
<th><?php _e( 'Telephone:', 'woocommerce' ); ?></th>
<td><?php echo esc_html( $order->billing_phone ); ?></td>
<td><?php echo esc_html( $order->get_billing_phone() ); ?></td>
</tr>
<?php endif; ?>

View File

@ -13,7 +13,7 @@
* @see https://docs.woocommerce.com/document/template-structure/
* @author WooThemes
* @package WooCommerce/Templates
* @version 2.5.0
* @version 2.7.0
*/
if ( ! defined( 'ABSPATH' ) ) {
@ -35,8 +35,8 @@ if ( ! apply_filters( 'woocommerce_order_item_visible', true, $item ) ) {
do_action( 'woocommerce_order_item_meta_start', $item_id, $item, $order );
$order->display_item_meta( $item );
$order->display_item_downloads( $item );
wc_display_item_meta( $item );
wc_display_item_downloads( $item );
do_action( 'woocommerce_order_item_meta_end', $item_id, $item, $order );
?>

View File

@ -25,7 +25,7 @@ if ( ! defined( 'ABSPATH' ) ) {
echo wp_kses_post( apply_filters( 'woocommerce_order_tracking_status', sprintf(
__( 'Order #%1$s was placed on %2$s and is currently %3$s.', 'woocommerce' ),
'<mark class="order-number">' . $order->get_order_number() . '</mark>',
'<mark class="order-date">' . date_i18n( get_option( 'date_format' ), strtotime( $order->order_date ) ) . '</mark>',
'<mark class="order-date">' . date_i18n( get_option( 'date_format' ), $order->get_date_created() ) . '</mark>',
'<mark class="order-status">' . wc_get_order_status_name( $order->get_status() ) . '</mark>'
) ) );
?></p>
@ -50,4 +50,4 @@ if ( ! defined( 'ABSPATH' ) ) {
</ol>
<?php endif; ?>
<?php do_action( 'woocommerce_view_order', $order->id ); ?>
<?php do_action( 'woocommerce_view_order', $order->get_id() ); ?>