public function log_shipment_response($order_id, $response) { if (strpos($order_id, '_') !== false) { $parts = explode('_', $order_id); $order_id = $parts[0]; } if (get_post_type($order_id) != 'order_shipment') { return; } $order = WC_MS_Compatibility::wc_get_order($order_id); if ($order) { //Store the values of shipped order which we are getting from ShippingEasy. $tracking_number = $response['shipment']['tracking_number']; $carrier_key = $response['shipment']['carrier_key']; $carrier_service_key = $response['shipment']['carrier_service_key']; $shipment_cost_cents = $response['shipment']['shipment_cost']; $shipment_cost = $shipment_cost_cents / 100; $comment_update = 'Shipping Tracking Number: ' . $tracking_number . '<br/> Carrier Key: ' . $carrier_key . '<br/> Carrier Service Key: ' . $carrier_service_key . '<br/> Cost: ' . $shipment_cost; $order->add_order_note($comment_update); } }
<?php $shipments = WC_MS_Order_Shipment::get_by_order($post->ID); foreach ($shipments as $shipment_id) { $shipment = WC_MS_Compatibility::wc_get_order($shipment_id); ?> <div class="wc-shipment" id="wc-shipment-<?php echo $shipment_id; ?> "> <div class="address"> <strong><?php _e('<strong>Ship To:</strong><br/>', 'wc_shipping_multiple_address'); ?> </strong> <?php echo $shipment->get_formatted_shipping_address(); ?> <br/> (<a href="#" class="edit-shipment-address">Edit</a>) </div> <div class="edit_shipping_address" style="display:none;"> <?php $shipFields = WC()->countries->get_address_fields($shipment->shipping_country, 'shipping_'); if ($shipFields) { foreach ($shipFields as $key => $field) { if (!isset($field['type'])) { $field['type'] = 'text'; }
function list_order_item_addresses($order_id) { global $woocommerce; if (false == apply_filters('wcms_list_order_item_addresses', true, $order_id)) { return; } if ($order_id instanceof WC_Order) { $order = $order_id; $order_id = $order->id; } else { $order = WC_MS_Compatibility::wc_get_order($order_id); } $methods = get_post_meta($order_id, '_shipping_methods', true); $shipping_methods = $order->get_shipping_methods(); $packages = get_post_meta($order_id, '_wcms_packages', true); $multiship = get_post_meta($order_id, '_multiple_shipping', true); if (!$packages || count($packages) == 1) { return; } // load the address fields $this->load_cart_files(); $cart = new WC_Cart(); echo '<p><strong>' . __('This order ships to multiple addresses.', 'wc_shipping_multiple_address') . '</strong></p>'; echo '<table class="shop_table shipping_packages" cellspacing="0" cellpadding="6" style="width: 100%; border: 1px solid #eee;" border="1" bordercolor="#eee">'; echo '<thead><tr>'; echo '<th scope="col" style="text-align:left; border: 1px solid #eee;">' . __('Products', 'woocommerce') . '</th>'; echo '<th scope="col" style="text-align:left; border: 1px solid #eee;">' . __('Address', 'woocommerce') . '</th>'; echo '<th scope="col" style="text-align:left; border: 1px solid #eee;">' . __('Notes', 'woocommerce') . '</th>'; echo '</tr></thead><tbody>'; foreach ($packages as $x => $package) { $products = $package['contents']; $method = $methods[$x]['label']; foreach ($shipping_methods as $ship_method) { if ($ship_method['method_id'] == $method) { $method = $ship_method['name']; break; } } $address = ''; if (!empty($package['full_address'])) { $address = wcms_get_formatted_address($package['full_address']); } ?> <tr> <td style="text-align:left; vertical-align:middle; border: 1px solid #eee;"><ul> <?php foreach ($products as $i => $product) { ?> <li><?php echo get_the_title($product['data']->id) . ' × ' . $product['quantity'] . '<br />' . $cart->get_item_data($product, true); ?> </li> <?php } ?> </ul></td> <td style="text-align:left; vertical-align:middle; border: 1px solid #eee;"> <?php echo $address; ?> <br/> <em>(<?php echo $method; ?> )</em> </td> <td style="text-align:left; vertical-align:middle; border: 1px solid #eee;"> <?php if (!empty($package['note'])) { echo $package['note']; } else { echo '–'; } if (!empty($package['date'])) { echo '<p>' . sprintf(__('Delivery date: %s', 'wc_shipping_multiple_address'), $package['date']) . '</p>'; } ?> </td> </tr> <?php } echo '</table>'; }
public function calculate_taxes($cart = null, $packages = null, $return_packages = false) { global $woocommerce; if (get_option('woocommerce_calc_taxes', 0) != 'yes') { if ($return_packages) { return $packages; } return; } $default_shipping_location = array($woocommerce->customer->get_shipping_country(), $woocommerce->customer->get_shipping_state(), $woocommerce->customer->get_shipping_postcode()); $merge = false; if (!is_object($cart)) { $cart = $woocommerce->cart; $merge = true; } if (isset($_POST['action']) && $_POST['action'] == 'woocommerce_update_shipping_method') { return $cart; } if (!$packages) { $packages = $cart->get_shipping_packages(); } if (count($packages) < 2) { return; } // clear the taxes arrays remove tax totals from the grand total $old_taxes = $cart->taxes; $old_tax_total = $cart->tax_total; $old_shipping_taxes = $cart->shipping_taxes; $old_shipping_tax_total = $cart->shipping_tax_total; $old_total = $cart->total; $cart_total_without_taxes = $old_total - ($old_tax_total + $old_shipping_tax_total); // deduct taxes from the subtotal $cart->subtotal -= $old_tax_total; $item_taxes = array(); $cart_taxes = array(); foreach ($packages as $idx => $package) { if (isset($package['destination']) && !$this->wcms->is_address_empty($package['destination'])) { $woocommerce->customer->calculated_shipping(true); $woocommerce->customer->set_shipping_location($package['destination']['country'], $package['destination']['state'], $package['destination']['postcode']); } $tax_rates = array(); $shop_tax_rates = array(); /** * Calculate subtotals for items. This is done first so that discount logic can use the values. */ foreach ($package['contents'] as $cart_item_key => $values) { $_product = $values['data']; // Prices $line_price = $_product->get_price() * $values['quantity']; $line_subtotal = 0; $line_subtotal_tax = 0; if (!$_product->is_taxable()) { $line_subtotal = $line_price; } elseif ($cart->prices_include_tax) { // Get base tax rates if (empty($shop_tax_rates[$_product->tax_class])) { $shop_tax_rates[$_product->tax_class] = $cart->tax->get_shop_base_rate($_product->tax_class); } // Get item tax rates if (empty($tax_rates[$_product->get_tax_class()])) { $tax_rates[$_product->get_tax_class()] = $cart->tax->get_rates($_product->get_tax_class()); } $base_tax_rates = $shop_tax_rates[$_product->tax_class]; $item_tax_rates = $tax_rates[$_product->get_tax_class()]; /** * ADJUST TAX - Calculations when base tax is not equal to the item tax */ if ($item_tax_rates !== $base_tax_rates) { // Work out a new base price without the shop's base tax $taxes = $cart->tax->calc_tax($line_price, $base_tax_rates, true, true); // Now we have a new item price (excluding TAX) $line_subtotal = $line_price - array_sum($taxes); // Now add modifed taxes $tax_result = $cart->tax->calc_tax($line_subtotal, $item_tax_rates); $line_subtotal_tax = array_sum($tax_result); /** * Regular tax calculation (customer inside base and the tax class is unmodified */ } else { // Calc tax normally $taxes = $cart->tax->calc_tax($line_price, $item_tax_rates, true); $line_subtotal_tax = array_sum($taxes); $line_subtotal = $line_price - array_sum($taxes); } /** * Prices exclude tax * * This calculation is simpler - work with the base, untaxed price. */ } else { // Get item tax rates if (empty($tax_rates[$_product->get_tax_class()])) { $tax_rates[$_product->get_tax_class()] = WC_MS_Compatibility::get_tax_rates($_product->get_tax_class()); } $item_tax_rates = $tax_rates[$_product->get_tax_class()]; // Base tax for line before discount - we will store this in the order data $taxes = WC_MS_Compatibility::calc_tax($line_price, $item_tax_rates); $line_subtotal_tax = array_sum($taxes); $line_subtotal = $line_price; } // Add to main subtotal $cart->subtotal += $line_subtotal_tax; } /** * Calculate totals for items */ foreach ($package['contents'] as $cart_item_key => $values) { $_product = $values['data']; // Prices $base_price = $_product->get_price(); $line_price = $_product->get_price() * $values['quantity']; // Tax data $taxes = array(); $discounted_taxes = array(); if (!$_product->is_taxable()) { // Discounted Price (price with any pre-tax discounts applied) $discounted_price = $cart->get_discounted_price($values, $base_price, true); $line_subtotal_tax = 0; $line_subtotal = $line_price; $line_tax = 0; $line_total = WC_MS_Compatibility::round_tax($discounted_price * $values['quantity']); /** * Prices include tax */ } elseif ($cart->prices_include_tax) { $base_tax_rates = $shop_tax_rates[$_product->tax_class]; $item_tax_rates = $tax_rates[$_product->get_tax_class()]; /** * ADJUST TAX - Calculations when base tax is not equal to the item tax */ if ($item_tax_rates !== $base_tax_rates) { // Work out a new base price without the shop's base tax $taxes = $cart->tax->calc_tax($line_price, $base_tax_rates, true, true); // Now we have a new item price (excluding TAX) $line_subtotal = woocommerce_round_tax_total($line_price - array_sum($taxes)); // Now add modifed taxes $taxes = $cart->tax->calc_tax($line_subtotal, $item_tax_rates); $line_subtotal_tax = array_sum($taxes); // Adjusted price (this is the price including the new tax rate) $adjusted_price = ($line_subtotal + $line_subtotal_tax) / $values['quantity']; // Apply discounts $discounted_price = $cart->get_discounted_price($values, $adjusted_price, true); $discounted_taxes = $cart->tax->calc_tax($discounted_price * $values['quantity'], $item_tax_rates, true); $line_tax = array_sum($discounted_taxes); $line_total = $discounted_price * $values['quantity'] - $line_tax; /** * Regular tax calculation (customer inside base and the tax class is unmodified */ } else { // Work out a new base price without the shop's base tax $taxes = $cart->tax->calc_tax($line_price, $item_tax_rates, true); // Now we have a new item price (excluding TAX) $line_subtotal = $line_price - array_sum($taxes); $line_subtotal_tax = array_sum($taxes); // Calc prices and tax (discounted) $discounted_price = $cart->get_discounted_price($values, $base_price, true); $discounted_taxes = $cart->tax->calc_tax($discounted_price * $values['quantity'], $item_tax_rates, true); $line_tax = array_sum($discounted_taxes); $line_total = $discounted_price * $values['quantity'] - $line_tax; } // Tax rows - merge the totals we just got foreach (array_keys($cart_taxes + $discounted_taxes) as $key) { $cart_taxes[$key] = (isset($discounted_taxes[$key]) ? $discounted_taxes[$key] : 0) + (isset($cart_taxes[$key]) ? $cart_taxes[$key] : 0); } /** * Prices exclude tax */ } else { $item_tax_rates = $tax_rates[$_product->get_tax_class()]; // Work out a new base price without the shop's base tax $taxes = WC_MS_Compatibility::calc_tax($line_price, $item_tax_rates); // Now we have the item price (excluding TAX) $line_subtotal = $line_price; $line_subtotal_tax = array_sum($taxes); // Now calc product rates $discounted_price = $cart->get_discounted_price($values, $base_price, true); $discounted_taxes = WC_MS_Compatibility::calc_tax($discounted_price * $values['quantity'], $item_tax_rates); $discounted_tax_amount = array_sum($discounted_taxes); $line_tax = $discounted_tax_amount; $line_total = $discounted_price * $values['quantity']; // Tax rows - merge the totals we just got foreach (array_keys($cart_taxes + $discounted_taxes) as $key) { $cart_taxes[$key] = (isset($discounted_taxes[$key]) ? $discounted_taxes[$key] : 0) + (isset($cart_taxes[$key]) ? $cart_taxes[$key] : 0); } } // Store costs + taxes for lines if (!isset($item_taxes[$cart_item_key])) { $item_taxes[$cart_item_key]['line_total'] = $line_total; $item_taxes[$cart_item_key]['line_tax'] = $line_tax; $item_taxes[$cart_item_key]['line_subtotal'] = $line_subtotal; $item_taxes[$cart_item_key]['line_subtotal_tax'] = $line_subtotal_tax; $item_taxes[$cart_item_key]['line_tax_data'] = array('total' => $discounted_taxes, 'subtotal' => $taxes); } else { $item_taxes[$cart_item_key]['line_total'] += $line_total; $item_taxes[$cart_item_key]['line_tax'] += $line_tax; $item_taxes[$cart_item_key]['line_subtotal'] += $line_subtotal; $item_taxes[$cart_item_key]['line_subtotal_tax'] += $line_subtotal_tax; $item_taxes[$cart_item_key]['line_tax_data']['total'] += $discounted_taxes; $item_taxes[$cart_item_key]['line_tax_data']['subtotal'] += $taxes; } $packages[$idx]['contents'][$cart_item_key]['line_total'] = $line_total; $packages[$idx]['contents'][$cart_item_key]['line_tax'] = $line_tax; $packages[$idx]['contents'][$cart_item_key]['line_subtotal'] = $line_subtotal; $packages[$idx]['contents'][$cart_item_key]['line_subtotal_tax'] = $line_subtotal_tax; $packages[$idx]['contents'][$cart_item_key]['line_tax_data'] = array('total' => $discounted_taxes, 'subtotal' => $taxes); } } foreach ($item_taxes as $cart_item_key => $taxes) { if (!isset($cart->cart_contents[$cart_item_key])) { continue; } $product_id = $cart->cart_contents[$cart_item_key]['product_id']; $woocommerce->cart->recurring_cart_contents = array(); $cart->cart_contents[$cart_item_key]['line_total'] = $taxes['line_total']; $cart->cart_contents[$cart_item_key]['line_tax'] = $taxes['line_tax']; $cart->cart_contents[$cart_item_key]['line_subtotal'] = $taxes['line_subtotal']; $cart->cart_contents[$cart_item_key]['line_subtotal_tax'] = $taxes['line_subtotal_tax']; $cart->cart_contents[$cart_item_key]['line_tax_data'] = $taxes['line_tax_data']; // Set recurring taxes for subscription products if (class_exists('WC_Subscriptions_Product') && WC_Subscriptions_Product::is_subscription($product_id)) { $woocommerce->cart->recurring_cart_contents[$product_id]['recurring_line_total'] = $taxes['line_total']; $woocommerce->cart->recurring_cart_contents[$product_id]['recurring_line_tax'] = $taxes['line_tax']; $woocommerce->cart->recurring_cart_contents[$product_id]['recurring_line_subtotal'] = $taxes['line_subtotal']; $woocommerce->cart->recurring_cart_contents[$product_id]['recurring_line_subtotal_tax'] = $taxes['line_subtotal_tax']; } } // Total up/round taxes and shipping taxes if ($cart->round_at_subtotal) { $cart->tax_total = WC_MS_Compatibility::get_tax_total($cart_taxes); $cart->taxes = array_map('WC_MS_Compatibility::round_tax', $cart_taxes); } else { $cart->tax_total = array_sum($cart_taxes); $cart->taxes = array_map('WC_MS_Compatibility::round_tax', $cart_taxes); } if ($merge) { $woocommerce->cart = $cart; } // Setting an empty default customer shipping location prevents // subtotal calculation from applying the incorrect taxes based // on the shipping address. But do not remove the shipping country // to satisfy the validation done on WC_Checkout $woocommerce->customer->calculated_shipping(false); $woocommerce->customer->set_shipping_location($woocommerce->customer->get_shipping_country(), '', ''); if ($return_packages) { return $packages; } // store the modified packages array wcms_session_set('wcms_packages', $packages); return $cart; }
function show_multiple_addresses_line($column) { global $post, $woocommerce, $the_order; if (empty($the_order) || $the_order->id != $post->ID) { $the_order = WC_MS_Compatibility::wc_get_order($post->ID); } if ($column == 'shipping_address') { $packages = get_post_meta($post->ID, '_wcms_packages', true); if (!$the_order->get_formatted_shipping_address() && count($packages) > 1) { _e('Ships to multiple addresses ', 'woocommerce'); } } }
public static function send_package_email($order_id, $package_index) { global $woocommerce; $settings = get_option('woocommerce_multiple_shipping_settings', array()); $order = WC_MS_Compatibility::wc_get_order($order_id); $subject = isset($settings['email_subject']) && !empty($settings['email_subject']) ? $settings['email_subject'] : __('Part of your order has been shipped', 'wc_shipping_multiple_address'); $message = isset($settings['email_message']) && !empty($settings['email_message']) ? $settings['email_message'] : false; if (!$message) { $message = self::get_default_email_body(); } $mailer = $woocommerce->mailer(); $message = $mailer->wrap_message($subject, $message); $ts = strtotime($order->order_date); $order_date = date(get_option('date_format'), $ts); $order_time = date(get_option('time_format'), $ts); $search = array('{order_id}', '{order_date}', '{order_time}', '{customer_first_name}', '{customer_last_name}', '{products_table}', '{addresses_table}'); $replacements = array($order->get_order_number(), $order_date, $order_time, $order->billing_first_name, $order->billing_last_name, self::render_products_table($order, $package_index), self::render_addresses_table($order, $package_index)); $message = str_replace($search, $replacements, $message); $mailer->send($order->billing_email, $subject, $message); }
function generate_ms_product_select_html($key, $data) { global $woocommerce; $settings = get_option('woocommerce_multiple_shipping_settings', array()); $html = ''; $data['title'] = isset($data['title']) ? $data['title'] : ''; $data['desc_tip'] = isset($data['desc_tip']) ? $data['desc_tip'] : false; $data['description'] = isset($data['description']) ? $data['description'] : ''; // Description handling if ($data['desc_tip'] === true) { $description = ''; $tip = $data['description']; } elseif (!empty($data['desc_tip'])) { $description = $data['description']; $tip = $data['desc_tip']; } elseif (!empty($data['description'])) { $description = $data['description']; $tip = ''; } else { $description = $tip = ''; } // Custom attribute handling $custom_attributes = array(); if (!isset($settings['excluded_products'])) { $settings['excluded_products'] = array(); } if (WC_MS_Compatibility::is_wc_version_gte('2.3')) { $product_ids = array_filter(array_map('absint', $settings['excluded_products'])); $json_ids = array(); foreach ($product_ids as $product_id) { $product = wc_get_product($product_id); $json_ids[$product_id] = wp_kses_post($product->get_formatted_name()); } $html .= '<tr valign="top">' . "\n"; $html .= '<th scope="row" class="titledesc">'; $html .= '<label for="' . esc_attr($this->plugin_id . $this->id . '_' . $key) . '">' . wp_kses_post($data['title']) . '</label>'; if ($tip) { $html .= '<img class="help_tip" data-tip="' . esc_attr($tip) . '" src="' . $woocommerce->plugin_url() . '/assets/images/help.png" height="16" width="16" />'; } $html .= '</th>' . "\n"; $html .= '<td class="forminp">' . "\n"; $html .= '<fieldset><legend class="screen-reader-text"><span>' . wp_kses_post($data['title']) . '</span></legend>' . "\n"; $html .= '<input type="hidden" data-multiple="true" id="' . esc_attr($this->plugin_id . $this->id . '_' . $key) . '" name="' . esc_attr($this->plugin_id . $this->id . '_' . $key) . '[]" class="wcms-product-search" data-placeholder="' . __('Search for a product…', 'woocommerce') . '" style="width: 400px" value="' . implode(',', array_keys($json_ids)) . '" data-selected="' . esc_attr(json_encode($json_ids)) . '" >'; if ($description) { $html .= ' <p class="description">' . wp_kses_post($description) . '</p>' . "\n"; } $html .= '</fieldset>'; $html .= '</td>' . "\n"; $html .= '</tr>' . "\n"; } else { $html .= '<tr valign="top">' . "\n"; $html .= '<th scope="row" class="titledesc">'; $html .= '<label for="' . esc_attr($this->plugin_id . $this->id . '_' . $key) . '">' . wp_kses_post($data['title']) . '</label>'; if ($tip) { $html .= '<img class="help_tip" data-tip="' . esc_attr($tip) . '" src="' . $woocommerce->plugin_url() . '/assets/images/help.png" height="16" width="16" />'; } $html .= '</th>' . "\n"; $html .= '<td class="forminp">' . "\n"; $html .= '<fieldset><legend class="screen-reader-text"><span>' . wp_kses_post($data['title']) . '</span></legend>' . "\n"; $html .= '<select multiple="multiple" id="' . esc_attr($this->plugin_id . $this->id . '_' . $key) . '" name="' . esc_attr($this->plugin_id . $this->id . '_' . $key) . '[]" class="wcms-product-search" data-placeholder="' . __('Search for a product…', 'woocommerce') . '" style="width: 400px"><option></option>'; if (!empty($settings['excluded_products'])) { foreach ($settings['excluded_products'] as $pid) { $html .= '<option value="' . $pid . '" selected>#' . $pid . ' - ' . get_the_title($pid) . '</option>'; } } $html .= '</select>'; if ($description) { $html .= ' <p class="description">' . wp_kses_post($description) . '</p>' . "\n"; } $html .= '</fieldset>'; $html .= '</td>' . "\n"; $html .= '</tr>' . "\n"; } return $html; }
<?php if (empty($addresses)) { echo '<p>' . __('No address on file. Please add one below.', 'wc_shipping_multiple_address') . '</p>'; } else { /* @var $woocommerce Woocommerce */ echo '<div class="address-container">'; foreach ($addresses as $idx => $address) { WC_MS_Compatibility::wc_get_template('address-block.php', array('idx' => $idx, 'address' => $address, 'woocommerce' => $woocommerce, 'checkout' => $checkout, 'shipFields' => $shipFields), 'multi-shipping', dirname(WC_Ship_Multiple::FILE) . '/templates/'); } echo '<div class="clear"></div>'; echo '</div>'; } ?> <hr /> <?php $address_id = '-1'; $address = array(); if (isset($_GET['edit'])) { $address_id = intval($_GET['edit']); $address = $addresses[$address_id]; ?> <h2><?php _e('Edit address', 'wc_shipping_multiple_address'); ?> </h2> <?php } else { ?>
<div class="addresses"> <header class="title"> <h3><?php _e('Other Shipping Addresses', 'wc_shipping_multiple_address'); ?> </h3> <a href="<?php echo add_query_arg('action', 'add', $form_url); ?> " class="edit"><?php _e('Add Address', 'woocommerce'); ?> </a> </header> <?php if (empty($addresses)) { echo '<i>' . __('No shipping addresses set up yet.', 'wc_shipping_multiple_address') . '</i> '; echo '<a href="' . add_query_arg('action', 'add', $form_url) . '">' . __('Set up shipping addresses', 'wc_shipping_multiple_address') . '</a>'; } else { foreach ($addresses as $idx => $address) { WC_MS_Compatibility::wc_get_template('address-block.php', array('address' => $address, 'idx' => $idx), 'multi-shipping', dirname(WC_Ship_Multiple::FILE) . '/templates/'); } echo '<div class="clear: both;"></div>'; } ?> </div>
/** * Create a new Order Shipment * * @param array $args * @return int|WP_Error */ public function create_shipment($args) { $default_args = array('status' => '', 'customer_id' => null, 'customer_note' => null, 'created_via' => '', 'parent' => 0); $args = wp_parse_args($args, $default_args); $shipment_data = array(); if (empty($args['parent'])) { return new WP_Error('create_shipment', __('Cannot create a shipment without an Order ID', 'wc_shipping_multiple_address')); } $order_id = $args['parent']; $wc_order = WC_MS_Compatibility::wc_get_order($order_id); $updating = false; $shipment_data['post_type'] = 'order_shipment'; $shipment_data['post_status'] = 'wc-' . apply_filters('wc_ms_default_shipment_status', 'pending'); $shipment_data['ping_status'] = 'closed'; $shipment_data['post_author'] = 1; $shipment_data['post_password'] = $wc_order->post->post_password; $shipment_data['post_title'] = sprintf(__('Shipment – %s', 'wc_shipping_multiple_address'), strftime(_x('%b %d, %Y @ %I:%M %p', 'Order date parsed by strftime', 'wc_shipping_multiple_address'))); $shipment_data['post_parent'] = $order_id; if ($args['status']) { if (!in_array('wc-' . $args['status'], array_keys(wc_get_order_statuses()))) { return new WP_Error('woocommerce_invalid_order_status', __('Invalid shipment status', 'wc_shipping_multiple_address')); } $shipment_data['post_status'] = 'wc-' . $args['status']; } if (!is_null($args['customer_note'])) { $shipment_data['post_excerpt'] = $args['customer_note']; } $shipment_id = wp_insert_post(apply_filters('wc_ms_new_shipment_data', $shipment_data), true); if (is_wp_error($shipment_id)) { return $shipment_id; } update_post_meta($shipment_id, '_shipment_key', 'wc_' . apply_filters('wc_ms_generate_shipment_key', uniqid('shipment_'))); update_post_meta($shipment_id, '_created_via', sanitize_text_field($args['created_via'])); $shipment = WC_MS_Compatibility::wc_get_order($shipment_id); $shipment->add_order_note('Shipment for Order ' . $wc_order->get_order_number()); return $shipment_id; }