Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $OrderOBJ = wc_get_order(2343);
- $item = new WC_Order_Item_Shipping();
- $new_ship_price = 10;
- $shippingItem = $OrderOBJ->get_items('shipping');
- $item->set_method_title( "Amazon shipping rate" );
- $item->set_method_id( "amazon_flat_rate:17" );
- $item->set_total( $new_ship_price );
- $OrderOBJ->update_item( $item );
- $OrderOBJ->calculate_totals();
- $OrderOBJ->save()
- $order_id = 2343;
- $order = wc_get_order($order_id);
- $cost = 10;
- $items = (array) $order->get_items('shipping');
- $country = $order->get_shipping_country();
- // Set the array for tax calculations
- $calculate_tax_for = array(
- 'country' => $country_code,
- 'state' => '', // Can be set (optional)
- 'postcode' => '', // Can be set (optional)
- 'city' => '', // Can be set (optional)
- );
- if ( sizeof( $items ) == 0 ) {
- $item = new WC_Order_Item_Shipping();
- $items = array($item);
- $new_item = true;
- }
- // Loop through shipping items
- foreach ( $items as $item ) {
- $item->set_method_title( __("Amazon shipping rate") );
- $item->set_method_id( "amazon_flat_rate:17" ); // set an existing Shipping method rate ID
- $item->set_total( $cost ); // (optional)
- $item->calculate_taxes( $calculate_tax_for ); // Calculate taxes
- if( isset($new_item) && $new_item ) {
- $order->add_item( $item );
- } else {
- $item->save()
- }
- }
- $order->calculate_totals();
- $order->save();
- $order_id = 2343;
- $order = wc_get_order($order_id);
- $items = (array) $order->get_items('shipping');
- if ( sizeof( $items ) > 0 ) {
- // Loop through shipping items
- foreach ( $items as $item_id => $item ) {
- $order->remove_item( $item_id );
- }
- $order->calculate_totals();
- $order->save();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement