Order functions woocommerce to wc refactor

This commit is contained in:
Coen Jacobs 2013-11-25 14:54:52 +01:00
parent c1a439eb99
commit f7df17db1c
14 changed files with 146 additions and 109 deletions

View File

@ -499,7 +499,7 @@ jQuery( function($){
$.each( add_item_ids, function( index, value ) {
var data = {
action: 'woocommerce_add_order_item',
action: 'wc_add_order_item',
item_to_add: value,
order_id: woocommerce_admin_meta_boxes.post_id,
security: woocommerce_admin_meta_boxes.order_item_nonce
@ -558,7 +558,7 @@ jQuery( function($){
var data = {
order_item_id: $item.attr( 'data-order_item_id' ),
action: 'woocommerce_add_order_item_meta',
action: 'wc_add_order_item_meta',
security: woocommerce_admin_meta_boxes.order_item_nonce
};

View File

@ -127,7 +127,7 @@ class WC_Admin_Menus {
$menu_name = _x('Orders', 'Admin menu name', 'woocommerce');
$menu_name_count = '';
if ( $order_count = woocommerce_processing_order_count() ) {
if ( $order_count = wc_processing_order_count() ) {
$menu_name_count = " <span class='awaiting-mod update-plugins count-$order_count'><span class='processing-count'>" . number_format_i18n( $order_count ) . "</span></span>" ;
}

View File

@ -999,7 +999,7 @@ class WC_Admin_CPT_Product extends WC_Admin_CPT {
foreach ( $new_download_ids as $download_id ) {
// grant permission if it doesn't already exist
if ( ! $wpdb->get_var( $wpdb->prepare( "SELECT 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 ) ) ) {
woocommerce_downloadable_file_permission( $download_id, $product_id, $order );
wc_downloadable_file_permission( $download_id, $product_id, $order );
}
}
}

View File

@ -113,7 +113,7 @@ class WC_Meta_Box_Order_Actions {
} elseif ( $action == 'regenerate_download_permissions' ) {
delete_post_meta( $post_id, '_download_permissions_granted' );
woocommerce_downloadable_product_permissions( $post_id );
wc_downloadable_product_permissions( $post_id );
} else {

View File

@ -132,31 +132,31 @@ class WC_Meta_Box_Order_Items {
);
if ( isset( $order_item_qty[ $item_id ] ) )
woocommerce_update_order_item_meta( $item_id, '_qty', apply_filters( 'woocommerce_stock_amount', $order_item_qty[ $item_id ] ) );
wc_update_order_item_meta( $item_id, '_qty', apply_filters( 'woocommerce_stock_amount', $order_item_qty[ $item_id ] ) );
if ( isset( $order_item_tax_class[ $item_id ] ) )
woocommerce_update_order_item_meta( $item_id, '_tax_class', wc_clean( $order_item_tax_class[ $item_id ] ) );
wc_update_order_item_meta( $item_id, '_tax_class', wc_clean( $order_item_tax_class[ $item_id ] ) );
if ( isset( $line_subtotal[ $item_id ] ) ) {
woocommerce_update_order_item_meta( $item_id, '_line_subtotal', wc_format_decimal( $line_subtotal[ $item_id ] ) );
wc_update_order_item_meta( $item_id, '_line_subtotal', wc_format_decimal( $line_subtotal[ $item_id ] ) );
$subtotal += wc_format_decimal( $line_subtotal[ $item_id ] );
}
if ( isset( $line_subtotal_tax[ $item_id ] ) ) {
woocommerce_update_order_item_meta( $item_id, '_line_subtotal_tax', wc_format_decimal( $line_subtotal_tax[ $item_id ] ) );
wc_update_order_item_meta( $item_id, '_line_subtotal_tax', wc_format_decimal( $line_subtotal_tax[ $item_id ] ) );
$subtotal += wc_format_decimal( $line_subtotal_tax[ $item_id ] );
}
if ( isset( $line_total[ $item_id ] ) ) {
woocommerce_update_order_item_meta( $item_id, '_line_total', wc_format_decimal( $line_total[ $item_id ] ) );
wc_update_order_item_meta( $item_id, '_line_total', wc_format_decimal( $line_total[ $item_id ] ) );
$total += wc_format_decimal( $line_total[ $item_id ] );
}
if ( isset( $line_tax[ $item_id ] ) ) {
woocommerce_update_order_item_meta( $item_id, '_line_tax', wc_format_decimal( $line_tax[ $item_id ] ) );
wc_update_order_item_meta( $item_id, '_line_tax', wc_format_decimal( $line_tax[ $item_id ] ) );
$total += wc_format_decimal( $line_tax[ $item_id ] );
}

View File

@ -194,25 +194,25 @@ class WC_Meta_Box_Order_Totals {
}
// Add line item
$new_id = woocommerce_add_order_item( $post_id, array(
$new_id = wc_add_order_item( $post_id, array(
'order_item_name' => wc_clean( $code ),
'order_item_type' => 'tax'
) );
// Add line item meta
if ( $new_id ) {
woocommerce_update_order_item_meta( $new_id, 'rate_id', $rate_id );
woocommerce_update_order_item_meta( $new_id, 'label', $label );
woocommerce_update_order_item_meta( $new_id, 'compound', $compound );
wc_update_order_item_meta( $new_id, 'rate_id', $rate_id );
wc_update_order_item_meta( $new_id, 'label', $label );
wc_update_order_item_meta( $new_id, 'compound', $compound );
if ( isset( $order_taxes_amount[ $item_id ][ $new_key ] ) ) {
woocommerce_update_order_item_meta( $new_id, 'tax_amount', wc_format_decimal( $order_taxes_amount[ $item_id ][ $new_key ] ) );
wc_update_order_item_meta( $new_id, 'tax_amount', wc_format_decimal( $order_taxes_amount[ $item_id ][ $new_key ] ) );
$total_tax += wc_format_decimal( $order_taxes_amount[ $item_id ][ $new_key ] );
}
if ( isset( $order_taxes_shipping_amount[ $item_id ][ $new_key ] ) ) {
woocommerce_update_order_item_meta( $new_id, 'shipping_tax_amount', wc_format_decimal( $order_taxes_shipping_amount[ $item_id ][ $new_key ] ) );
wc_update_order_item_meta( $new_id, 'shipping_tax_amount', wc_format_decimal( $order_taxes_shipping_amount[ $item_id ][ $new_key ] ) );
$total_shipping_tax += wc_format_decimal( $order_taxes_shipping_amount[ $item_id ][ $new_key ] );
}
@ -249,18 +249,18 @@ class WC_Meta_Box_Order_Totals {
array( '%d' )
);
woocommerce_update_order_item_meta( $item_id, 'rate_id', $rate_id );
woocommerce_update_order_item_meta( $item_id, 'label', $label );
woocommerce_update_order_item_meta( $item_id, 'compound', $compound );
wc_update_order_item_meta( $item_id, 'rate_id', $rate_id );
wc_update_order_item_meta( $item_id, 'label', $label );
wc_update_order_item_meta( $item_id, 'compound', $compound );
if ( isset( $order_taxes_amount[ $item_id ] ) ) {
woocommerce_update_order_item_meta( $item_id, 'tax_amount', wc_format_decimal( $order_taxes_amount[ $item_id ] ) );
wc_update_order_item_meta( $item_id, 'tax_amount', wc_format_decimal( $order_taxes_amount[ $item_id ] ) );
$total_tax += wc_format_decimal( $order_taxes_amount[ $item_id ] );
}
if ( isset( $order_taxes_shipping_amount[ $item_id ] ) ) {
woocommerce_update_order_item_meta( $item_id, 'shipping_tax_amount', wc_format_decimal( $order_taxes_shipping_amount[ $item_id ] ) );
wc_update_order_item_meta( $item_id, 'shipping_tax_amount', wc_format_decimal( $order_taxes_shipping_amount[ $item_id ] ) );
$total_shipping_tax += wc_format_decimal( $order_taxes_shipping_amount[ $item_id ] );
}
@ -293,14 +293,14 @@ class WC_Meta_Box_Order_Totals {
$method_title = wc_clean( $shipping_method_title[ $item_id ][ $new_key ] );
$cost = wc_format_decimal( $shipping_cost[ $item_id ][ $new_key ] );
$new_id = woocommerce_add_order_item( $post_id, array(
$new_id = wc_add_order_item( $post_id, array(
'order_item_name' => $method_title,
'order_item_type' => 'shipping'
) );
if ( $new_id ) {
woocommerce_add_order_item_meta( $new_id, 'method_id', $method_id );
woocommerce_add_order_item_meta( $new_id, 'cost', $cost );
wc_add_order_item_meta( $new_id, 'method_id', $method_id );
wc_add_order_item_meta( $new_id, 'cost', $cost );
}
$order_shipping += $cost;
@ -321,8 +321,8 @@ class WC_Meta_Box_Order_Totals {
array( '%d' )
);
woocommerce_update_order_item_meta( $item_id, 'method_id', $method_id );
woocommerce_update_order_item_meta( $item_id, 'cost', $cost );
wc_update_order_item_meta( $item_id, 'method_id', $method_id );
wc_update_order_item_meta( $item_id, 'cost', $cost );
$order_shipping += $cost;
}
@ -334,7 +334,7 @@ class WC_Meta_Box_Order_Totals {
$delete_ids = $_POST['delete_order_item_id'];
foreach ( $delete_ids as $id )
woocommerce_delete_order_item( absint( $id ) );
wc_delete_order_item( absint( $id ) );
}
delete_post_meta( $post_id, '_shipping_method' );

View File

@ -767,7 +767,7 @@ class WC_AJAX {
if ( $files ) {
foreach ( $files as $download_id => $file ) {
if ( $inserted_id = woocommerce_downloadable_file_permission( $download_id, $product_id, $order ) ) {
if ( $inserted_id = wc_downloadable_file_permission( $download_id, $product_id, $order ) ) {
// insert complete - get inserted data
$download = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}woocommerce_downloadable_product_permissions WHERE permission_id = %d", $inserted_id ) );
@ -856,21 +856,21 @@ class WC_AJAX {
$item['line_tax'] = '';
// Add line item
$item_id = woocommerce_add_order_item( $order_id, array(
$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 ) {
woocommerce_add_order_item_meta( $item_id, '_qty', $item['qty'] );
woocommerce_add_order_item_meta( $item_id, '_tax_class', $item['tax_class'] );
woocommerce_add_order_item_meta( $item_id, '_product_id', $item['product_id'] );
woocommerce_add_order_item_meta( $item_id, '_variation_id', $item['variation_id'] );
woocommerce_add_order_item_meta( $item_id, '_line_subtotal', $item['line_subtotal'] );
woocommerce_add_order_item_meta( $item_id, '_line_subtotal_tax', $item['line_subtotal_tax'] );
woocommerce_add_order_item_meta( $item_id, '_line_total', $item['line_total'] );
woocommerce_add_order_item_meta( $item_id, '_line_tax', $item['line_tax'] );
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'] );
}
do_action( 'woocommerce_ajax_add_order_item_meta', $item_id, $item );
@ -894,16 +894,16 @@ class WC_AJAX {
$order = new WC_Order( $order_id );
// Add line item
$item_id = woocommerce_add_order_item( $order_id, array(
$item_id = wc_add_order_item( $order_id, array(
'order_item_name' => '',
'order_item_type' => 'fee'
) );
// Add line item meta
if ( $item_id ) {
woocommerce_add_order_item_meta( $item_id, '_tax_class', '' );
woocommerce_add_order_item_meta( $item_id, '_line_total', '' );
woocommerce_add_order_item_meta( $item_id, '_line_tax', '' );
wc_add_order_item_meta( $item_id, '_tax_class', '' );
wc_add_order_item_meta( $item_id, '_line_total', '' );
wc_add_order_item_meta( $item_id, '_line_tax', '' );
}
include( 'includes/admin/post-types/meta-boxes/views/html-order-fee.php' );
@ -924,7 +924,7 @@ class WC_AJAX {
if ( sizeof( $order_item_ids ) > 0 ) {
foreach( $order_item_ids as $id ) {
woocommerce_delete_order_item( absint( $id ) );
wc_delete_order_item( absint( $id ) );
}
}
@ -1034,7 +1034,7 @@ class WC_AJAX {
check_ajax_referer( 'order-item', 'security' );
$meta_id = woocommerce_add_order_item_meta( absint( $_POST['order_item_id'] ), __( 'Name', 'woocommerce' ), __( 'Value', 'woocommerce' ) );
$meta_id = wc_add_order_item_meta( absint( $_POST['order_item_id'] ), __( 'Name', 'woocommerce' ), __( 'Value', 'woocommerce' ) );
if ( $meta_id ) {
@ -1200,18 +1200,18 @@ class WC_AJAX {
$item['label'] = WC()->countries->tax_or_vat();
// Add line item
$item_id = woocommerce_add_order_item( $order_id, array(
$item_id = wc_add_order_item( $order_id, array(
'order_item_name' => $item['name'],
'order_item_type' => 'tax'
) );
// Add line item meta
if ( $item_id ) {
woocommerce_add_order_item_meta( $item_id, 'rate_id', $item['rate_id'] );
woocommerce_add_order_item_meta( $item_id, 'label', $item['label'] );
woocommerce_add_order_item_meta( $item_id, 'compound', $item['compound'] );
woocommerce_add_order_item_meta( $item_id, 'tax_amount', $item['tax_amount'] );
woocommerce_add_order_item_meta( $item_id, 'shipping_tax_amount', $item['shipping_tax_amount'] );
wc_add_order_item_meta( $item_id, 'rate_id', $item['rate_id'] );
wc_add_order_item_meta( $item_id, 'label', $item['label'] );
wc_add_order_item_meta( $item_id, 'compound', $item['compound'] );
wc_add_order_item_meta( $item_id, 'tax_amount', $item['tax_amount'] );
wc_add_order_item_meta( $item_id, 'shipping_tax_amount', $item['shipping_tax_amount'] );
}
include( 'includes/admin/post-types/meta-boxes/views/html-order-tax.php' );

View File

@ -258,30 +258,30 @@ class WC_Checkout {
$_product = $values['data'];
// Add line item
$item_id = woocommerce_add_order_item( $order_id, array(
$item_id = wc_add_order_item( $order_id, array(
'order_item_name' => $_product->get_title(),
'order_item_type' => 'line_item'
) );
// Add line item meta
if ( $item_id ) {
woocommerce_add_order_item_meta( $item_id, '_qty', apply_filters( 'woocommerce_stock_amount', $values['quantity'] ) );
woocommerce_add_order_item_meta( $item_id, '_tax_class', $_product->get_tax_class() );
woocommerce_add_order_item_meta( $item_id, '_product_id', $values['product_id'] );
woocommerce_add_order_item_meta( $item_id, '_variation_id', $values['variation_id'] );
woocommerce_add_order_item_meta( $item_id, '_line_subtotal', wc_format_decimal( $values['line_subtotal'] ) );
woocommerce_add_order_item_meta( $item_id, '_line_total', wc_format_decimal( $values['line_total'] ) );
woocommerce_add_order_item_meta( $item_id, '_line_tax', wc_format_decimal( $values['line_tax'] ) );
woocommerce_add_order_item_meta( $item_id, '_line_subtotal_tax', wc_format_decimal( $values['line_subtotal_tax'] ) );
wc_add_order_item_meta( $item_id, '_qty', apply_filters( 'woocommerce_stock_amount', $values['quantity'] ) );
wc_add_order_item_meta( $item_id, '_tax_class', $_product->get_tax_class() );
wc_add_order_item_meta( $item_id, '_product_id', $values['product_id'] );
wc_add_order_item_meta( $item_id, '_variation_id', $values['variation_id'] );
wc_add_order_item_meta( $item_id, '_line_subtotal', wc_format_decimal( $values['line_subtotal'] ) );
wc_add_order_item_meta( $item_id, '_line_total', wc_format_decimal( $values['line_total'] ) );
wc_add_order_item_meta( $item_id, '_line_tax', wc_format_decimal( $values['line_tax'] ) );
wc_add_order_item_meta( $item_id, '_line_subtotal_tax', wc_format_decimal( $values['line_subtotal_tax'] ) );
// Store variation data in meta so admin can view it
if ( $values['variation'] && is_array( $values['variation'] ) )
foreach ( $values['variation'] as $key => $value )
woocommerce_add_order_item_meta( $item_id, esc_attr( str_replace( 'attribute_', '', $key ) ), $value );
wc_add_order_item_meta( $item_id, esc_attr( str_replace( 'attribute_', '', $key ) ), $value );
// Add line item meta for backorder status
if ( $_product->backorders_require_notification() && $_product->is_on_backorder( $values['quantity'] ) )
woocommerce_add_order_item_meta( $item_id, apply_filters( 'woocommerce_backordered_item_meta_name', __( 'Backordered', 'woocommerce' ), $cart_item_key, $order_id ), $values['quantity'] - max( 0, $_product->get_total_stock() ) );
wc_add_order_item_meta( $item_id, apply_filters( 'woocommerce_backordered_item_meta_name', __( 'Backordered', 'woocommerce' ), $cart_item_key, $order_id ), $values['quantity'] - max( 0, $_product->get_total_stock() ) );
// Allow plugins to add order item meta
do_action( 'woocommerce_add_order_item_meta', $item_id, $values, $cart_item_key );
@ -290,18 +290,18 @@ class WC_Checkout {
// Store fees
foreach ( WC()->cart->get_fees() as $fee ) {
$item_id = woocommerce_add_order_item( $order_id, array(
$item_id = wc_add_order_item( $order_id, array(
'order_item_name' => $fee->name,
'order_item_type' => 'fee'
) );
if ( $fee->taxable )
woocommerce_add_order_item_meta( $item_id, '_tax_class', $fee->tax_class );
wc_add_order_item_meta( $item_id, '_tax_class', $fee->tax_class );
else
woocommerce_add_order_item_meta( $item_id, '_tax_class', '0' );
wc_add_order_item_meta( $item_id, '_tax_class', '0' );
woocommerce_add_order_item_meta( $item_id, '_line_total', wc_format_decimal( $fee->amount ) );
woocommerce_add_order_item_meta( $item_id, '_line_tax', wc_format_decimal( $fee->tax ) );
wc_add_order_item_meta( $item_id, '_line_total', wc_format_decimal( $fee->amount ) );
wc_add_order_item_meta( $item_id, '_line_tax', wc_format_decimal( $fee->tax ) );
}
// Store shipping for all packages
@ -312,14 +312,14 @@ class WC_Checkout {
$method = $package['rates'][ $this->shipping_methods[ $i ] ];
$item_id = woocommerce_add_order_item( $order_id, array(
$item_id = wc_add_order_item( $order_id, array(
'order_item_name' => $method->label,
'order_item_type' => 'shipping'
) );
if ( $item_id ) {
woocommerce_add_order_item_meta( $item_id, 'method_id', $method->id );
woocommerce_add_order_item_meta( $item_id, 'cost', wc_format_decimal( $method->cost ) );
wc_add_order_item_meta( $item_id, 'method_id', $method->id );
wc_add_order_item_meta( $item_id, 'cost', wc_format_decimal( $method->cost ) );
}
}
}
@ -327,18 +327,18 @@ class WC_Checkout {
// Store tax rows
foreach ( array_keys( WC()->cart->taxes + WC()->cart->shipping_taxes ) as $key ) {
$item_id = woocommerce_add_order_item( $order_id, array(
$item_id = wc_add_order_item( $order_id, array(
'order_item_name' => WC()->cart->tax->get_rate_code( $key ),
'order_item_type' => 'tax'
) );
// Add line item meta
if ( $item_id ) {
woocommerce_add_order_item_meta( $item_id, 'rate_id', $key );
woocommerce_add_order_item_meta( $item_id, 'label', WC()->cart->tax->get_rate_label( $key ) );
woocommerce_add_order_item_meta( $item_id, 'compound', absint( WC()->cart->tax->is_compound( $key ) ? 1 : 0 ) );
woocommerce_add_order_item_meta( $item_id, 'tax_amount', wc_format_decimal( isset( WC()->cart->taxes[ $key ] ) ? WC()->cart->taxes[ $key ] : 0 ) );
woocommerce_add_order_item_meta( $item_id, 'shipping_tax_amount', wc_format_decimal( isset( WC()->cart->shipping_taxes[ $key ] ) ? WC()->cart->shipping_taxes[ $key ] : 0 ) );
wc_add_order_item_meta( $item_id, 'rate_id', $key );
wc_add_order_item_meta( $item_id, 'label', WC()->cart->tax->get_rate_label( $key ) );
wc_add_order_item_meta( $item_id, 'compound', absint( WC()->cart->tax->is_compound( $key ) ? 1 : 0 ) );
wc_add_order_item_meta( $item_id, 'tax_amount', wc_format_decimal( isset( WC()->cart->taxes[ $key ] ) ? WC()->cart->taxes[ $key ] : 0 ) );
wc_add_order_item_meta( $item_id, 'shipping_tax_amount', wc_format_decimal( isset( WC()->cart->shipping_taxes[ $key ] ) ? WC()->cart->shipping_taxes[ $key ] : 0 ) );
}
}
@ -346,14 +346,14 @@ class WC_Checkout {
if ( $applied_coupons = WC()->cart->get_coupons() ) {
foreach ( $applied_coupons as $code => $coupon ) {
$item_id = woocommerce_add_order_item( $order_id, array(
$item_id = wc_add_order_item( $order_id, array(
'order_item_name' => $code,
'order_item_type' => 'coupon'
) );
// Add line item meta
if ( $item_id ) {
woocommerce_add_order_item_meta( $item_id, 'discount_amount', isset( WC()->cart->coupon_discount_amounts[ $code ] ) ? WC()->cart->coupon_discount_amounts[ $code ] : 0 );
wc_add_order_item_meta( $item_id, 'discount_amount', isset( WC()->cart->coupon_discount_amounts[ $code ] ) ? WC()->cart->coupon_discount_amounts[ $code ] : 0 );
}
}
}

View File

@ -282,7 +282,7 @@ class WC_Post_types {
$menu_name = _x('Orders', 'Admin menu name', 'woocommerce' );
if ( $order_count = woocommerce_processing_order_count() ) {
if ( $order_count = wc_processing_order_count() ) {
$menu_name .= " <span class='awaiting-mod update-plugins count-$order_count'><span class='processing-count'>" . number_format_i18n( $order_count ) . "</span></span>" ;
}

View File

@ -863,7 +863,7 @@ class WC_Gateway_Paypal extends WC_Payment_Gateway {
if ( ! isset( $order->id ) ) {
// We have an invalid $order_id, probably because invoice_prefix has changed
$order_id = woocommerce_get_order_id_by_order_key( $order_key );
$order_id = wc_get_order_id_by_order_key( $order_key );
$order = new WC_Order( $order_id );
}

View File

@ -201,21 +201,21 @@ foreach ( $order_item_rows as $order_item_row ) {
$order_item['line_subtotal_tax'] = isset( $order_item['line_subtotal_tax'] ) ? $order_item['line_subtotal_tax'] : 0;
$order_item['line_subtotal'] = isset( $order_item['line_subtotal'] ) ? $order_item['line_subtotal'] : 0;
$item_id = woocommerce_add_order_item( $order_item_row->post_id, array(
$item_id = wc_add_order_item( $order_item_row->post_id, array(
'order_item_name' => $order_item['name'],
'order_item_type' => 'line_item'
) );
// Add line item meta
if ( $item_id ) {
woocommerce_add_order_item_meta( $item_id, '_qty', absint( $order_item['qty'] ) );
woocommerce_add_order_item_meta( $item_id, '_tax_class', $order_item['tax_class'] );
woocommerce_add_order_item_meta( $item_id, '_product_id', $order_item['id'] );
woocommerce_add_order_item_meta( $item_id, '_variation_id', $order_item['variation_id'] );
woocommerce_add_order_item_meta( $item_id, '_line_subtotal', wc_format_decimal( $order_item['line_subtotal'] ) );
woocommerce_add_order_item_meta( $item_id, '_line_subtotal_tax', wc_format_decimal( $order_item['line_subtotal_tax'] ) );
woocommerce_add_order_item_meta( $item_id, '_line_total', wc_format_decimal( $order_item['line_total'] ) );
woocommerce_add_order_item_meta( $item_id, '_line_tax', wc_format_decimal( $order_item['line_tax'] ) );
wc_add_order_item_meta( $item_id, '_qty', absint( $order_item['qty'] ) );
wc_add_order_item_meta( $item_id, '_tax_class', $order_item['tax_class'] );
wc_add_order_item_meta( $item_id, '_product_id', $order_item['id'] );
wc_add_order_item_meta( $item_id, '_variation_id', $order_item['variation_id'] );
wc_add_order_item_meta( $item_id, '_line_subtotal', wc_format_decimal( $order_item['line_subtotal'] ) );
wc_add_order_item_meta( $item_id, '_line_subtotal_tax', wc_format_decimal( $order_item['line_subtotal_tax'] ) );
wc_add_order_item_meta( $item_id, '_line_total', wc_format_decimal( $order_item['line_total'] ) );
wc_add_order_item_meta( $item_id, '_line_tax', wc_format_decimal( $order_item['line_tax'] ) );
$meta_rows = array();
@ -269,16 +269,16 @@ foreach ( $order_tax_rows as $order_tax_row ) {
if ( ! isset( $order_tax['label'] ) || ! isset( $order_tax['cart_tax'] ) || ! isset( $order_tax['shipping_tax'] ) )
continue;
$item_id = woocommerce_add_order_item( $order_tax_row->post_id, array(
$item_id = wc_add_order_item( $order_tax_row->post_id, array(
'order_item_name' => $order_tax['label'],
'order_item_type' => 'tax'
) );
// Add line item meta
if ( $item_id ) {
woocommerce_add_order_item_meta( $item_id, 'compound', absint( isset( $order_tax['compound'] ) ? $order_tax['compound'] : 0 ) );
woocommerce_add_order_item_meta( $item_id, 'tax_amount', wc_clean( $order_tax['cart_tax'] ) );
woocommerce_add_order_item_meta( $item_id, 'shipping_tax_amount', wc_clean( $order_tax['shipping_tax'] ) );
wc_add_order_item_meta( $item_id, 'compound', absint( isset( $order_tax['compound'] ) ? $order_tax['compound'] : 0 ) );
wc_add_order_item_meta( $item_id, 'tax_amount', wc_clean( $order_tax['cart_tax'] ) );
wc_add_order_item_meta( $item_id, 'shipping_tax_amount', wc_clean( $order_tax['shipping_tax'] ) );
}
// Delete from DB (rename)

View File

@ -211,6 +211,43 @@ if ( ! function_exists( 'woocommerce_format_hex' ) ) {
}
}
/**
* Order functions (soft deprecated)
*/
function woocommerce_get_order_id_by_order_key( $order_key ) {
wc_get_order_id_by_order_key( $order_key );
}
function woocommerce_downloadable_file_permission( $download_id, $product_id, $order ) {
wc_downloadable_file_permission( $download_id, $product_id, $order );
}
function woocommerce_downloadable_product_permissions( $order_id ) {
wc_downloadable_product_permissions( $order_id );
}
function woocommerce_add_order_item( $order_id, $item ) {
wc_add_order_item( $order_id, $item );
}
function woocommerce_delete_order_item( $item_id ) {
wc_delete_order_item( $item_id );
}
function woocommerce_update_order_item_meta( $item_id, $meta_key, $meta_value, $prev_value = '' ) {
wc_update_order_item_meta( $item_id, $meta_key, $meta_value, $prev_value );
}
function woocommerce_add_order_item_meta( $item_id, $meta_key, $meta_value, $unique = false ) {
wc_add_order_item_meta( $item_id, $meta_key, $meta_value, $unique );
}
function woocommerce_delete_order_item_meta( $item_id, $meta_key, $meta_value = '', $delete_all = false ) {
wc_delete_order_item_meta( $item_id, $meta_key, $meta_value, $delete_all );
}
function woocommerce_get_order_item_meta( $item_id, $key, $single = true ) {
wc_get_order_item_meta( $item_id, $key, $single );
}
function woocommerce_cancel_unpaid_orders() {
wc_cancel_unpaid_orders();
}
function woocommerce_processing_order_count() {
wc_processing_order_count();
}
/**
* Handle renamed filters
*/

View File

@ -19,7 +19,7 @@ if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
* @param string $order_key An order key has generated by
* @return int The ID of an order, or 0 if the order could not be found
*/
function woocommerce_get_order_id_by_order_key( $order_key ) {
function wc_get_order_id_by_order_key( $order_key ) {
global $wpdb;
// Faster than get_posts()
@ -37,7 +37,7 @@ function woocommerce_get_order_id_by_order_key( $order_key ) {
* @param WC_Order $order the order
* @return int insert id | bool false on failure
*/
function woocommerce_downloadable_file_permission( $download_id, $product_id, $order ) {
function wc_downloadable_file_permission( $download_id, $product_id, $order ) {
global $wpdb;
if ( $order->status == 'processing' && get_option( 'woocommerce_downloads_grant_access_after_payment' ) == 'no' )
@ -105,7 +105,7 @@ add_action('woocommerce_order_status_processing', 'woocommerce_downloadable_prod
* @param int $order_id
* @return void
*/
function woocommerce_downloadable_product_permissions( $order_id ) {
function wc_downloadable_product_permissions( $order_id ) {
if ( get_post_meta( $order_id, '_download_permissions_granted', true ) == 1 )
return; // Only do this once
@ -119,7 +119,7 @@ function woocommerce_downloadable_product_permissions( $order_id ) {
$downloads = get_post_meta( $_product->id, '_downloadable_files' ) ;
foreach ( $downloads[0] as $download_id => $download )
woocommerce_downloadable_file_permission( $download_id, $item['variation_id'] > 0 ? $item['variation_id'] : $item['product_id'], $order );
wc_downloadable_file_permission( $download_id, $item['variation_id'] > 0 ? $item['variation_id'] : $item['product_id'], $order );
}
}
}
@ -138,7 +138,7 @@ function woocommerce_downloadable_product_permissions( $order_id ) {
* @param array $data
* @return mixed
*/
function woocommerce_add_order_item( $order_id, $item ) {
function wc_add_order_item( $order_id, $item ) {
global $wpdb;
$order_id = absint( $order_id );
@ -173,13 +173,13 @@ function woocommerce_add_order_item( $order_id, $item ) {
}
/**
* woocommerce_delete_order_item function.
* Delete an item from the order it belongs to based on item id
*
* @access public
* @param int $item_id
* @return bool
*/
function woocommerce_delete_order_item( $item_id ) {
function wc_delete_order_item( $item_id ) {
global $wpdb;
$item_id = absint( $item_id );
@ -207,7 +207,7 @@ function woocommerce_delete_order_item( $item_id ) {
* @param string $prev_value (default: '')
* @return bool
*/
function woocommerce_update_order_item_meta( $item_id, $meta_key, $meta_value, $prev_value = '' ) {
function wc_update_order_item_meta( $item_id, $meta_key, $meta_value, $prev_value = '' ) {
return update_metadata( 'order_item', $item_id, $meta_key, $meta_value, $prev_value );
}
@ -221,7 +221,7 @@ function woocommerce_update_order_item_meta( $item_id, $meta_key, $meta_value, $
* @param bool $unique (default: false)
* @return bool
*/
function woocommerce_add_order_item_meta( $item_id, $meta_key, $meta_value, $unique = false ){
function wc_add_order_item_meta( $item_id, $meta_key, $meta_value, $unique = false ) {
return add_metadata( 'order_item', $item_id, $meta_key, $meta_value, $unique );
}
@ -235,7 +235,7 @@ function woocommerce_add_order_item_meta( $item_id, $meta_key, $meta_value, $uni
* @param bool $delete_all (default: false)
* @return bool
*/
function woocommerce_delete_order_item_meta( $item_id, $meta_key, $meta_value = '', $delete_all = false ) {
function wc_delete_order_item_meta( $item_id, $meta_key, $meta_value = '', $delete_all = false ) {
return delete_metadata( 'order_item', $item_id, $meta_key, $meta_value, $delete_all );
}
@ -248,17 +248,17 @@ function woocommerce_delete_order_item_meta( $item_id, $meta_key, $meta_value =
* @param bool $single (default: true)
* @return mixed
*/
function woocommerce_get_order_item_meta( $item_id, $key, $single = true ) {
function wc_get_order_item_meta( $item_id, $key, $single = true ) {
return get_metadata( 'order_item', $item_id, $key, $single );
}
/**
* woocommerce_cancel_unpaid_orders function.
* Cancel all unpaid orders after held duration to prevent stock lock for those products
*
* @access public
* @return void
*/
function woocommerce_cancel_unpaid_orders() {
function wc_cancel_unpaid_orders() {
global $wpdb;
$held_duration = get_option( 'woocommerce_hold_stock_minutes' );
@ -292,9 +292,9 @@ function woocommerce_cancel_unpaid_orders() {
}
wp_clear_scheduled_hook( 'woocommerce_cancel_unpaid_orders' );
wp_schedule_single_event( time() + ( absint( $held_duration ) * 60 ), 'woocommerce_cancel_unpaid_orders' );
wp_schedule_single_event( time() + ( absint( $held_duration ) * 60 ), 'wc_cancel_unpaid_orders' );
}
add_action( 'woocommerce_cancel_unpaid_orders', 'woocommerce_cancel_unpaid_orders' );
add_action( 'woocommerce_cancel_unpaid_orders', 'wc_cancel_unpaid_orders' );
/**
@ -303,7 +303,7 @@ add_action( 'woocommerce_cancel_unpaid_orders', 'woocommerce_cancel_unpaid_order
* @access public
* @return int
*/
function woocommerce_processing_order_count() {
function wc_processing_order_count() {
if ( false === ( $order_count = get_transient( 'woocommerce_processing_order_count' ) ) ) {
$order_statuses = get_terms( 'shop_order_status' );
$order_count = false;

View File

@ -582,7 +582,7 @@ Yes you can! Join in on our [GitHub repository](http://github.com/woothemes/wooc
* Tweak - Display tax/discount total for reference on orders
* Tweak - Humanised order email subjects/headings
* Tweak - Cleaned up the tax settings.
* Tweak - If a PayPal prefix is changed, IPN requests break for all existing orders - fixed. new woocommerce_get_order_id_by_order_key() function added. Thanks Brent.
* Tweak - If a PayPal prefix is changed, IPN requests break for all existing orders - fixed. new wc_get_order_id_by_order_key() function added. Thanks Brent.
* Tweak - On add to cart success, redirect back.
* Tweak - Prefix jquery plugins JS.
* Tweak - Made paypal use wc-api for IPN.