Skip to content

Commit

Permalink
Order functions woocommerce to wc refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
coenjacobs committed Nov 25, 2013
1 parent c1a439e commit f7df17d
Show file tree
Hide file tree
Showing 14 changed files with 146 additions and 109 deletions.
4 changes: 2 additions & 2 deletions assets/js/admin/meta-boxes.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
};

Expand Down
2 changes: 1 addition & 1 deletion includes/admin/class-wc-admin-menus.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ public function menu_highlight() {

$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>" ;
}

Expand Down
2 changes: 1 addition & 1 deletion includes/admin/post-types/class-wc-admin-cpt-product.php
Original file line number Diff line number Diff line change
Expand Up @@ -999,7 +999,7 @@ public function process_product_file_download_paths( $product_id, $variation_id,
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 );
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public static function save( $post_id, $post ) {
} 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 {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,31 +132,31 @@ public static function save( $post_id, $post ) {
);

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 ] );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,25 +194,25 @@ public static function save( $post_id, $post ) {
}

// 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 ] );
}
Expand Down Expand Up @@ -249,18 +249,18 @@ public static function save( $post_id, $post ) {
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 ] );
}
Expand Down Expand Up @@ -293,14 +293,14 @@ public static function save( $post_id, $post ) {
$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;
Expand All @@ -321,8 +321,8 @@ public static function save( $post_id, $post ) {
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;
}
Expand All @@ -334,7 +334,7 @@ public static function save( $post_id, $post ) {
$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' );
Expand Down
44 changes: 22 additions & 22 deletions includes/class-wc-ajax.php
Original file line number Diff line number Diff line change
Expand Up @@ -767,7 +767,7 @@ public function grant_access_to_download() {

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 ) );
Expand Down Expand Up @@ -856,21 +856,21 @@ public function ajax_add_order_item() {
$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 );
Expand All @@ -894,16 +894,16 @@ public function ajax_add_order_fee() {
$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' );
Expand All @@ -924,7 +924,7 @@ public function ajax_remove_order_item() {

if ( sizeof( $order_item_ids ) > 0 ) {
foreach( $order_item_ids as $id ) {
woocommerce_delete_order_item( absint( $id ) );
wc_delete_order_item( absint( $id ) );
}
}

Expand Down Expand Up @@ -1034,7 +1034,7 @@ public function add_order_item_meta() {

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 ) {

Expand Down Expand Up @@ -1200,18 +1200,18 @@ public function calc_line_taxes() {
$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' );
Expand Down
Loading

0 comments on commit f7df17d

Please sign in to comment.