Get a formatted shipping address for the order.
public get_formatted_shipping_address ( ) : string | ||
return | string |
/** * Test: get_formatted_shipping_address */ function test_get_formatted_shipping_address() { $object = new WC_Order(); $object->set_shipping_first_name('Barney'); $object->set_shipping_last_name('Rubble'); $object->set_shipping_company('Bedrock Ltd.'); $object->set_shipping_address_1('34 Stonepants avenue'); $object->set_shipping_address_2('Rockville'); $object->set_shipping_city('Bedrock'); $object->set_shipping_state('Boulder'); $object->set_shipping_postcode('00001'); $object->set_shipping_country('US'); $this->assertEquals('Barney Rubble<br/>Bedrock Ltd.<br/>34 Stonepants avenue<br/>Rockville<br/>Bedrock, BOULDER 00001<br/>United States (US)', $object->get_formatted_shipping_address()); }
</tr> </thead> <tbody><?php foreach ($customer_orders as $customer_order) : $order = new WC_Order(); $order->populate( $customer_order ); $status = get_term_by('slug', $order->status, 'shop_order_status'); ?><tr class="order"> <td class="order-number" width="1%"> <a href="<?php echo esc_url( add_query_arg('order', $order->id, get_permalink(woocommerce_get_page_id('view_order'))) ); ?>"><?php echo $order->get_order_number(); ?></a> – <time title="<?php echo esc_attr( strtotime($order->order_date) ); ?>"><?php echo date_i18n(get_option('date_format'), strtotime($order->order_date)); ?></time> </td> <td class="order-shipto"><address><?php if ($order->get_formatted_shipping_address()) echo $order->get_formatted_shipping_address(); else echo '–'; ?></address></td> <td class="order-total" width="1%"><?php echo $order->get_formatted_order_total(); ?></td> <td class="order-status" style="text-align:left; white-space:nowrap;"> <?php echo ucfirst( __( $status->name, 'woocommerce' ) ); ?> <?php if (in_array($order->status, array('pending', 'failed'))) : ?> <a href="<?php echo esc_url( $order->get_cancel_order_url() ); ?>" class="cancel" title="<?php _e('Click to cancel this order', 'woocommerce'); ?>">(<?php _e('Cancel', 'woocommerce'); ?>)</a> <?php endif; ?> </td> <td class="order-actions" style="text-align:right; white-space:nowrap;"> <?php if (in_array($order->status, array('pending', 'failed'))) : ?> <a href="<?php echo esc_url( $order->get_checkout_payment_url() ); ?>" class="button btn theme pay"><?php _e('Pay', 'woocommerce'); ?></a> <?php endif; ?> <a href="<?php echo esc_url( add_query_arg('order', $order->id, get_permalink(woocommerce_get_page_id('view_order'))) ); ?>" class="btn button"><?php _e('View', 'woocommerce'); ?></a>
function sm_woo_get_packing_slip($purchase_ids, $purchase_id_arr) { if (!empty($purchase_ids) && !empty($purchase_id_arr)) { ?> <style type="text/css"> body { font-family:"Helvetica Neue", Helvetica, Arial, Verdana, sans-serif; } h1 span { font-size:0.75em; } h2 { color: #333; } .no-page-break { page-break-after: avoid; } #wrapper { margin:0 auto; width:95%; page-break-after: always; } #wrapper_last { margin:0 auto; width:95%; page-break-after: avoid; } .address{ width:98%; border-top:1px; border-right:1px; margin:1em auto; border-collapse:collapse; } .address_border{ border-bottom:1px; border-left:1px ; padding:.2em 1em; text-align:left; } table { width:98%; border-top:1px solid #e5eff8; border-right:1px solid #e5eff8; margin:1em auto; border-collapse:collapse; font-size:10pt; } td { border-bottom:1px solid #e5eff8; border-left:1px solid #e5eff8; padding:.3em 1em; text-align:center; } tr.odd td, tr.odd .column1 { background:#f4f9fe url(background.gif) no-repeat; } .column1 { background:#f4f9fe; } thead th { background:#f4f9fe; text-align:center; font:bold 1.2em/2em "Century Gothic","Trebuchet MS",Arial,Helvetica,sans-serif; } .datagrid { position: relative; top:-30pt; } .producthead{ text-align: left; } .pricehead{ text-align: right; } .sm_address_div{ position: relative; left:28pt; } .sm_email_span{ position: relative; left:10pt; } </style> <?php $counter = 0; foreach ($purchase_id_arr as $purchase_id_value) { $order = new WC_Order($purchase_id_value); $date_format = get_option('date_format'); if (is_plugin_active('woocommerce-sequential-order-numbers-pro/woocommerce-sequential-order-numbers.php')) { $purchase_display_id = isset($order->order_custom_fields['_order_number_formatted'][0]) ? $order->order_custom_fields['_order_number_formatted'][0] : $purchase_id_value; } else { $purchase_display_id = $purchase_id_value; } $counter++; if (count($purchase_id_arr) == $counter) { echo '<div id="wrapper_last">'; } else { echo '<div id="wrapper">'; } echo smart_manager_print_logo(); echo '<div style="margin-top:-0.8em;">'; echo '<h4 style="font:bold 1.2em/2em "Century Gothic","Trebuchet MS",Arial,Helvetica,sans-serif; position:relative; 12pt;"> ' . get_bloginfo('name') . '</h4>'; echo '<table class="address" style="position:relative; top:-22pt; left:-35pt;">'; echo '<tr><td class="address_border" colspan="2" valign="top" width="50%"><span style="position:relative; left:27pt; top:10pt;"> <b>Order # ' . $purchase_display_id . ' - ' . date($date_format, strtotime($order->order_date)) . '</b></span><br/></td></tr>'; echo '<tr><td class="address_border" width="35%" align="center"><br/><div class="sm_address_div">'; $formatted_billing_address = $order->get_formatted_billing_address(); if ($formatted_billing_address != '') { echo '<b>' . __('Billing Address', 'smart-manager') . '</b><p>'; echo $formatted_billing_address; echo '</p></td>'; } $formatted_shipping_address = $order->get_formatted_shipping_address(); if ($formatted_shipping_address != '') { echo '<td class="address_border" width="30%"><br/><div style="position:relative; top:3pt;"><b>' . __('Shipping Address', 'smart-manager') . '</b><p>'; echo $formatted_shipping_address; echo '</p></div></td>'; } echo '</tr>'; echo '<tr><td colspan="2" class="address_border"><span class="sm_email_span"><table class="address"><tr><td colspan="2" class="address_border" > <b>' . __('Email id', 'smart-manager') . ':</b> ' . $order->billing_email . '</td></tr> <tr><td class="address_border"><b>' . __('Tel', 'smart-manager') . ' :</b> ' . $order->billing_phone . '</td></tr></table> </span></td></tr>'; echo '</table>'; echo '<div class="datagrid"><table><tr class="column1"> <td class="producthead">' . __('Product', 'smart-manager') . '</td><td>' . __('SKU', 'smart-manager') . '</td> <td>' . __('Quantity', 'smart-manager') . '</td><td class="pricehead">' . __('Price', 'smart-manager') . '</td></tr>'; foreach ($order->get_items() as $item) { $_product = $order->get_product_from_item($item); $sku = $variation = ''; $sku = $_product->get_sku(); $formatted_variation = woocommerce_get_formatted_variation($_product->variation_data, true); $variation = !empty($formatted_variation) ? ' (' . $formatted_variation . ')' : ''; $item_total = $_product->get_price() * $item['item_meta']['_qty'][0]; $total_order += $item_total; echo '<tr><td class="producthead">'; echo $item['name'] . $variation; echo '</td><td>' . $sku . '</td><td>'; echo $item['item_meta']['_qty'][0]; echo '</td><td class="pricehead">'; echo woocommerce_price($item_total); echo '</td></tr>'; } echo '<tr><td colspan="2" rowspan="5" class="address_border" valign="top"><br/> <i>' . ($order->customer_note != '' ? __('Order Notes', 'smart-manager') . ' : ' . $order->customer_note : '') . '</i></td><td style="text-align:right;" class="address_border" valign="top"> <b>Subtotal </b></td><td class="pricehead">' . $order->get_subtotal_to_display() . '</td></tr>'; echo '<tr><td style="text-align:right;" class="address_border"><b>' . __('Shipping', 'smart-manager') . ' </b></td><td class="pricehead">' . $order->get_shipping_to_display() . '</td></tr>'; if ($order->cart_discount > 0) { echo '<tr><td style="text-align:right;" class="address_border">' . __('Cart Discount', 'smart-manager') . '</td><td style="text-align:right;">'; echo woocommerce_price($order->cart_discount); echo '</td></tr>'; } if ($order->order_discount > 0) { echo '<tr><td style="text-align:right;" class="address_border"><b>' . __('Order Discount', 'smart-manager') . ' </b></td>'; echo '<td class="pricehead">' . woocommerce_price($order->order_discount) . '</td></tr>'; } echo '<tr><td style="text-align:right;" class="address_border"><b>' . __('Tax', 'smart-manager') . ' </b></td><td class="pricehead">' . woocommerce_price($order->get_total_tax()) . '</td></tr>'; echo '<tr><td class="column1" style="text-align:right;"><b>' . __('Total', 'smart-manager') . ' </b></td><td class="column1" style="text-align:right;">' . woocommerce_price($order->order_total) . ' -via ' . $order->payment_method_title . '</td></tr>'; echo '</table></div></div></div>'; } } exit; }
/** * Get Orders to display in admin * * @return $orders */ function get_orders() { $user_id = get_current_user_id(); $orders = array(); $vendor_products = $this->get_vendor_products($user_id); $products = array(); foreach ($vendor_products as $_product) { $products[] = $_product->ID; } $_orders = $this->get_orders_for_vendor_products($products); $model_id = 0; if (!empty($_orders)) { foreach ($_orders as $order) { $order = new WC_Order($order->order_id); $valid_items = WCV_Queries::get_products_for_order($order->id); $valid = array(); $items = $order->get_items(); foreach ($items as $key => $value) { if (in_array($value['variation_id'], $valid_items) || in_array($value['product_id'], $valid_items)) { $valid[] = $value; } } $products = ''; foreach ($valid as $key => $item) { $item_meta = new WC_Order_Item_Meta($item['item_meta']); // $item_meta = $item_meta->display( false, true ); $item_meta = $item_meta->get_formatted(); $products .= '<strong>' . $item['qty'] . ' x ' . $item['name'] . '</strong><br />'; foreach ($item_meta as $key => $meta) { // Remove the sold by meta key for display if (strtolower($key) != 'sold by') { $products .= $meta['label'] . ' : ' . $meta['value'] . '<br />'; } } } $shippers = (array) get_post_meta($order->id, 'wc_pv_shipped', true); $shipped = in_array($user_id, $shippers) ? 'Yes' : 'No'; $sum = WCV_Queries::sum_for_orders(array($order->id), array('vendor_id' => get_current_user_id())); $total = $sum[0]->line_total; $comment_output = ''; // Need to fix how form is submitted for adding comments if at all possible. if ($this->can_view_comments) { $order_notes = $order->get_customer_order_notes(); $comment_output .= '<a href="#TB_inline?width=600&height=550&inlineId=order-comment-window-' . $model_id . '" class="thickbox">'; $comment_output .= sprintf(__('Comments (%s)', 'wcvendors'), count($order_notes)); $comment_output .= '</a>'; $comment_output .= '<div id="order-comment-window-' . $model_id . '" style="display:none;">'; $comment_output .= '<h3>' . __('Comments to Customer', 'wcvendors') . '</h3>'; if (!empty($order_notes)) { foreach ($order_notes as $order_note) { $last_added = human_time_diff(strtotime($order_note->comment_date_gmt), current_time('timestamp', 1)); $comment_output .= '<p>'; $comment_output .= $order_note->comment_content; $comment_output .= '<br />'; $comment_output .= sprintf(__('added %s ago', 'wcvendors'), $last_added); $comment_output .= '<br />'; $comment_output .= '</p>'; } } else { $comment_output .= '<p>' . __('No comments currently to customer.', 'wcvendors') . '</p>'; } if ($this->can_add_comments) { $comment_output .= wp_nonce_field('add-comment'); $comment_output .= ' <textarea name="comment_text" style="width:97%"></textarea> <input type="hidden" name="order_id" value="' . $order->id . '"> <input type="hidden" name="action" value="add_comment"> <input class="btn btn-large btn-block" type="submit" name="submit_comment" value="' . __('Add comment', 'wcvendors') . '">'; } $comment_output .= '</div>'; } $order_items = array(); $order_items['order_id'] = $order->id; $order_items['customer'] = $order->get_formatted_shipping_address(); $order_items['products'] = $products; $order_items['total'] = woocommerce_price($total); $order_items['date'] = date_i18n(wc_date_format(), strtotime($order->order_date)); // $order_items[ 'comments' ] = $comment_output; $order_items['status'] = $shipped; $orders[] = (object) $order_items; $model_id++; } } return $orders; }
$orderDate = isset($ourOrder->order_date) ? $ourOrder->order_date : '1'; $items = $ourOrder->get_items(); //$discounts = isset($ourOrder->get_total_discount()) ? $ourOrder->get_total_discount() : '1'; $authProfile = isset($ourOrder->wc_authorize_net_cim_customer_profile_id) ? $ourOrder->wc_authorize_net_cim_customer_profile_id : '1'; /* * The below foreach will pull the items array apart and process each item, finding its SKU and adding them to a comma separated list. */ foreach ($items as $item) { $id = ''; $id = isset($item['item_meta']['_variation_id']) ? $item['item_meta']['_variation_id'][0] : $item['item_meta']['_product_id'][0]; $item = new WC_Product($id); $skus[] = $item->get_sku(); } var_dump($skus); $orderItems = implode($skus, ","); $params = array('order_Id' => $orderID->ID, 'user_id' => $customerUser, 'subscription_id' => $subscriptionID, 'name' => $first . " " . $last, 'date' => date('Y-m-d', strtotime($orderDate)), 'email' => $customerEmail, 'products' => $orderItems, 'order_total' => $orderTotal, 'auth_profile' => $authProfile, 'address' => $ourOrder->get_formatted_shipping_address()); $wpdb->insert($wpdb->prefix . 'orders_archived', $params); /* * This is the scary part of the plugin. While active, the below few lines will delete the original orders from the many * tables found in both wordpress and woocommerce after saving the important information to the archived orders table. */ //if ($_GET['delete']) { if ($_POST['delete']) { wp_delete_post($orderID->ID); $wpdb->delete($wpdb->prefix . 'woocommerce_order_items', array("order_item_id" => $orderID->ID)); $wpdb->delete($wpdb->prefix . 'woocommerce_order_itemmeta', array("order_item_id" => $orderID->ID)); } } } ?>
/** * Get Orders to display in admin * * @return $orders */ function get_orders() { $user_id = get_current_user_id(); $orders = array(); $vendor_products = $this->get_vendor_products($user_id); $products = array(); foreach ($vendor_products as $_product) { $products[] = $_product->ID; } $_orders = $this->get_orders_for_vendor_products($products); $model_id = 0; if (!empty($_orders)) { foreach ($_orders as $order) { $order = new WC_Order($order->order_id); $valid_items = WCV_Queries::get_products_for_order($order->id); $valid = array(); $items = $order->get_items(); foreach ($items as $key => $item) { if (in_array($item['variation_id'], $valid_items) || in_array($item['product_id'], $valid_items)) { $valid[] = $item; } } $products = ''; foreach ($valid as $key => $item) { $wc_product = new WC_Product($item['product_id']); $products .= '<strong>' . $item['qty'] . ' x ' . $item['name'] . '</strong><br />'; if ($metadata = $order->has_meta($item['product_id'])) { $products .= '<table cellspacing="0" class="wcv_display_meta">'; foreach ($metadata as $meta) { // Skip hidden core fields if (in_array($meta['meta_key'], apply_filters('woocommerce_hidden_order_itemmeta', array('_qty', '_tax_class', '_product_id', '_variation_id', '_line_subtotal', '_line_subtotal_tax', '_line_total', '_line_tax', WC_Vendors::$pv_options->get_option('sold_by_label'))))) { 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'] = apply_filters('woocommerce_attribute_label', wc_attribute_label($meta['meta_key'], $wc_product), $meta['meta_key']); } $products .= '<tr><th>' . wp_kses_post(rawurldecode($meta['meta_key'])) . ':</th><td>' . wp_kses_post(wpautop(make_clickable(rawurldecode($meta['meta_value'])))) . '</td></tr>'; } $products .= '</table>'; } } $shippers = (array) get_post_meta($order->id, 'wc_pv_shipped', true); $shipped = in_array($user_id, $shippers) ? 'Yes' : 'No'; $sum = WCV_Queries::sum_for_orders(array($order->id), array('vendor_id' => get_current_user_id())); $total = $sum[0]->line_total; $comment_output = ''; // Need to fix how form is submitted for adding comments if at all possible. // if ( $this->can_view_comments) { // $order_notes = $order->get_customer_order_notes(); // $comment_output .= '<a href="#TB_inline?width=600&height=550&inlineId=order-comment-window-'.$model_id.'" class="thickbox">'; // $comment_output .= sprintf( __( 'Comments (%s)', 'wcvendors' ), count( $order_notes ) ); // $comment_output .= '</a>'; // $comment_output .= '<div id="order-comment-window-'.$model_id.'" style="display:none;">'; // $comment_output .= '<h3>'.__('Comments to Customer', 'wcvendors' ). '</h3>'; // if ( !empty( $order_notes ) ) { // foreach ($order_notes as $order_note) { // $last_added = human_time_diff( strtotime( $order_note->comment_date_gmt ), current_time( 'timestamp', 1 ) ); // $comment_output .= '<p>'; // $comment_output .= $order_note->comment_content; // $comment_output .= '<br />'; // $comment_output .= sprintf(__( 'added %s ago', 'wcvendors' ), $last_added ); // $comment_output .= '<br />'; // $comment_output .= '</p>'; // } // } else { // $comment_output .= '<p>'.__('No comments currently to customer.', 'wcvendors' ). '</p>'; // } // if ( $this->can_add_comments ) { // $comment_output .= wp_nonce_field( 'add-comment' ); // $comment_output .= ' // <textarea name="comment_text" style="width:97%"></textarea> // <input type="hidden" name="order_id" value="'. $order->id .'"> // <input type="hidden" name="action" value="add_comment"> // <input class="btn btn-large btn-block" type="submit" name="submit_comment" value="'.__( 'Add comment', 'wcvendors' ).'">'; // } // $comment_output .= '</div>'; // } $order_items = array(); $order_items['order_id'] = $order->id; $order_items['customer'] = $order->get_formatted_shipping_address(); $order_items['products'] = $products; $order_items['total'] = woocommerce_price($total); $order_items['date'] = date_i18n(wc_date_format(), strtotime($order->order_date)); // $order_items[ 'comments' ] = $comment_output; $order_items['status'] = $shipped; $orders[] = (object) $order_items; $model_id++; } } return $orders; }
} // See if product needs shipping $product = new WC_Product($value['product_id']); $needs_shipping = !$product->needs_shipping() || $product->is_downloadable('yes') ? false : true; } $shippers = (array) get_post_meta($order->id, 'wc_pv_shipped', true); $shipped = in_array($user_id, $shippers); ?> <tr> <td><?php echo $order->get_order_number(); ?> </td> <td><?php echo apply_filters('wcvendors_dashboard_google_maps_link', '<a target="_blank" href="' . esc_url('http://maps.google.com/maps?&q=' . urlencode(esc_html(preg_replace('#<br\\s*/?>#i', ', ', $order->get_formatted_shipping_address()))) . '&z=16') . '">' . esc_html(preg_replace('#<br\\s*/?>#i', ', ', $order->get_formatted_shipping_address())) . '</a>'); ?> </td> <td><?php $sum = WCV_Queries::sum_for_orders(array($order->id), array('vendor_id' => get_current_user_id())); $total = $sum[0]->line_total; $totals += $total; echo woocommerce_price($total); ?> </td> <td><?php echo $order->order_date; ?> </td> <td> <a href="#" class="view-items" id="<?php
function get_orders() { $user_id = get_current_user_id(); $orders = array(); $vendor_products = WCV_Queries::get_commission_products($user_id); $products = array(); foreach ($vendor_products as $_product) { $products[] = $_product->ID; } $_orders = WCV_Queries::get_orders_for_products($products); if (!empty($_orders)) { foreach ($_orders as $order) { $order = new WC_Order($order->order_id); $valid_items = WCV_Queries::get_products_for_order($order->id); $valid = array(); $items = $order->get_items(); foreach ($items as $key => $value) { if (in_array($value['variation_id'], $valid_items) || in_array($value['product_id'], $valid_items)) { $valid[] = $value; } } $products = ''; foreach ($valid as $key => $item) { $item_meta = new WC_Order_Item_Meta($item['item_meta']); // $item_meta = $item_meta->display( false, true ); $item_meta = $item_meta->get_formatted(); $products .= '<strong>' . $item['qty'] . ' x ' . $item['name'] . '</strong><br />'; foreach ($item_meta as $key => $meta) { // Remove the sold by meta key for display if (strtolower($key) != 'sold by') { $products .= $meta['label'] . ' : ' . $meta['value'] . '<br />'; } } } $shippers = (array) get_post_meta($order->id, 'wc_pv_shipped', true); $shipped = in_array($user_id, $shippers) ? 'Yes' : 'No'; $sum = WCV_Queries::sum_for_orders(array($order->id), array('vendor_id' => get_current_user_id())); $total = $sum[0]->line_total; $order_items = array(); $order_items['order_id'] = $order->id; $order_items['customer'] = $order->get_formatted_shipping_address(); $order_items['products'] = $products; $order_items['total'] = woocommerce_price($total); $order_items['date'] = date_i18n(wc_date_format(), strtotime($order->order_date)); $order_items['status'] = $shipped; $orders[] = (object) $order_items; } } return $orders; }
/** * Define our custom columns shown in admin. * @param string $column */ public function custom_columns($column) { global $post, $woocommerce, $the_order; if (empty($the_order) || $the_order->id != $post->ID) { $the_order = new WC_Order($post->ID); } switch ($column) { case 'order_status': printf('<mark class="%s tips" data-tip="%s">%s</mark>', sanitize_title($the_order->status), esc_html__($the_order->status, 'woocommerce'), esc_html__($the_order->status, 'woocommerce')); break; case 'order_date': if ('0000-00-00 00:00:00' == $post->post_date) { $t_time = $h_time = __('Unpublished', 'woocommerce'); } else { $t_time = get_the_time(__('Y/m/d g:i:s A', 'woocommerce'), $post); $gmt_time = strtotime($post->post_date_gmt . ' UTC'); $time_diff = current_time('timestamp', 1) - $gmt_time; $h_time = get_the_time(__('Y/m/d', 'woocommerce'), $post); } echo '<abbr title="' . esc_attr($t_time) . '">' . esc_html(apply_filters('post_date_column_time', $h_time, $post)) . '</abbr>'; break; case 'customer_message': if ($the_order->customer_message) { echo '<span class="note-on tips" data-tip="' . esc_attr($the_order->customer_message) . '">' . __('Yes', 'woocommerce') . '</span>'; } else { echo '<span class="na">–</span>'; } break; case 'billing_address': if ($the_order->get_formatted_billing_address()) { echo '<a target="_blank" href="' . esc_url('http://maps.google.com/maps?&q=' . urlencode($the_order->get_billing_address()) . '&z=16') . '">' . esc_html(preg_replace('#<br\\s*/?>#i', ', ', $the_order->get_formatted_billing_address())) . '</a>'; } else { echo '–'; } if ($the_order->payment_method_title) { echo '<small class="meta">' . __('Via', 'woocommerce') . ' ' . esc_html($the_order->payment_method_title) . '</small>'; } break; case 'order_items': printf('<a href="#" class="show_order_items">' . _n('%d item', '%d items', sizeof($the_order->get_items()), 'woocommerce') . '</a>', sizeof($the_order->get_items())); if (sizeof($the_order->get_items()) > 0) { echo '<table class="order_items" cellspacing="0">'; foreach ($the_order->get_items() as $item) { $_product = apply_filters('woocommerce_order_item_product', $the_order->get_product_from_item($item), $item); $item_meta = new WC_Order_Item_Meta($item['item_meta']); $item_meta_html = $item_meta->display(true, true); ?> <tr> <td class="qty"><?php echo absint($item['qty']); ?> </td> <td class="name"> <?php if (wc_product_sku_enabled() && $_product && $_product->get_sku()) { echo $_product->get_sku() . ' - '; } echo apply_filters('woocommerce_order_item_name', $item['name'], $item); ?> <?php if ($item_meta_html) { ?> <a class="tips" href="#" data-tip="<?php echo esc_attr($item_meta_html); ?> ">[?]</a> <?php } ?> </td> </tr> <?php } echo '</table>'; } else { echo '–'; } break; case 'shipping_address': if ($the_order->get_formatted_shipping_address()) { echo '<a target="_blank" href="' . esc_url('http://maps.google.com/maps?&q=' . urlencode($the_order->get_shipping_address()) . '&z=16') . '">' . esc_html(preg_replace('#<br\\s*/?>#i', ', ', $the_order->get_formatted_shipping_address())) . '</a>'; } else { echo '–'; } if ($the_order->get_shipping_method()) { echo '<small class="meta">' . __('Via', 'woocommerce') . ' ' . esc_html($the_order->get_shipping_method()) . '</small>'; } break; case 'order_notes': if ($post->comment_count) { // check the status of the post $post->post_status !== 'trash' ? $status = '' : ($status = 'post-trashed'); $latest_notes = get_comments(array('post_id' => $post->ID, 'number' => 1, 'status' => $status)); $latest_note = current($latest_notes); if ($post->comment_count == 1) { echo '<span class="note-on tips" data-tip="' . esc_attr($latest_note->comment_content) . '">' . __('Yes', 'woocommerce') . '</span>'; } else { $note_tip = isset($latest_note->comment_content) ? esc_attr($latest_note->comment_content . '<small style="display:block">' . sprintf(_n('plus %d other note', 'plus %d other notes', $post->comment_count - 1, 'woocommerce'), $post->comment_count - 1) . '</small>') : sprintf(_n('%d note', '%d notes', $post->comment_count, 'woocommerce'), $post->comment_count); echo '<span class="note-on tips" data-tip="' . $note_tip . '">' . __('Yes', 'woocommerce') . '</span>'; } } else { echo '<span class="na">–</span>'; } break; case 'order_total': echo esc_html(strip_tags($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>'; } break; case 'order_title': $customer_tip = ''; if ($address = $the_order->get_formatted_billing_address()) { $customer_tip .= __('Billing:', 'woocommerce') . ' ' . $address . '<br/><br/>'; } if ($the_order->billing_phone) { $customer_tip .= __('Tel:', 'woocommerce') . ' ' . $the_order->billing_phone; } echo '<div class="tips" data-tip="' . esc_attr($customer_tip) . '">'; if ($the_order->user_id) { $user_info = get_userdata($the_order->user_id); } if (!empty($user_info)) { $username = '******' . absint($user_info->ID) . '">'; if ($user_info->first_name || $user_info->last_name) { $username .= esc_html(ucfirst($user_info->first_name) . ' ' . ucfirst($user_info->last_name)); } else { $username .= esc_html(ucfirst($user_info->display_name)); } $username .= '</a>'; } else { if ($the_order->billing_first_name || $the_order->billing_last_name) { $username = trim($the_order->billing_first_name . ' ' . $the_order->billing_last_name); } else { $username = __('Guest', 'woocommerce'); } } printf(__('%s by %s', 'woocommerce'), '<a href="' . admin_url('post.php?post=' . absint($post->ID) . '&action=edit') . '"><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>'; } echo '</div>'; break; case 'order_actions': ?> <p> <?php do_action('woocommerce_admin_order_actions_start', $the_order); $actions = array(); if (in_array($the_order->status, array('pending', 'on-hold'))) { $actions['processing'] = array('url' => wp_nonce_url(admin_url('admin-ajax.php?action=woocommerce_mark_order_processing&order_id=' . $post->ID), 'woocommerce-mark-order-processing'), 'name' => __('Processing', 'woocommerce'), 'action' => "processing"); } if (in_array($the_order->status, array('pending', 'on-hold', 'processing'))) { $actions['complete'] = array('url' => wp_nonce_url(admin_url('admin-ajax.php?action=woocommerce_mark_order_complete&order_id=' . $post->ID), 'woocommerce-mark-order-complete'), 'name' => __('Complete', 'woocommerce'), 'action' => "complete"); } $actions['view'] = array('url' => admin_url('post.php?post=' . $post->ID . '&action=edit'), 'name' => __('View', 'woocommerce'), 'action' => "view"); $actions = apply_filters('woocommerce_admin_order_actions', $actions, $the_order); foreach ($actions as $action) { printf('<a class="button tips %s" href="%s" data-tip="%s">%s</a>', esc_attr($action['action']), esc_url($action['url']), esc_attr($action['name']), esc_attr($action['name'])); } do_action('woocommerce_admin_order_actions_end', $the_order); ?> </p><?php break; } }
function woocommerce_custom_order_columns($column) { global $post, $woocommerce; $order = new WC_Order($post->ID); switch ($column) { case "order_status": echo sprintf('<mark class="%s">%s</mark>', sanitize_title($order->status), __($order->status, 'woocommerce')); break; case "order_title": if ($order->user_id) { $user_info = get_userdata($order->user_id); } if (isset($user_info) && $user_info) { $user = '******' . esc_attr($user_info->ID) . '">'; if ($user_info->first_name || $user_info->last_name) { $user .= $user_info->first_name . ' ' . $user_info->last_name; } else { $user .= esc_html($user_info->display_name); } $user .= '</a>'; } else { $user = __('Guest', 'woocommerce'); } echo '<a href="' . admin_url('post.php?post=' . $post->ID . '&action=edit') . '"><strong>' . sprintf(__('Order #%s', 'woocommerce'), $post->ID) . '</strong></a> ' . __('made by', 'woocommerce') . ' ' . $user; if ($order->billing_email) { echo '<small class="meta">' . __('Email:', 'woocommerce') . ' ' . '<a href="' . esc_url('mailto:' . $order->billing_email) . '">' . esc_html($order->billing_email) . '</a></small>'; } if ($order->billing_phone) { echo '<small class="meta">' . __('Tel:', 'woocommerce') . ' ' . esc_html($order->billing_phone) . '</small>'; } break; case "billing_address": if ($order->get_formatted_billing_address()) { echo '<a target="_blank" href="' . esc_url('http://maps.google.com/maps?&q=' . urlencode($order->get_billing_address()) . '&z=16') . '">' . preg_replace('#<br\\s*/?>#i', ', ', $order->get_formatted_billing_address()) . '</a>'; } else { echo '–'; } if ($order->payment_method_title) { echo '<small class="meta">' . __('Via', 'woocommerce') . ' ' . esc_html($order->payment_method_title) . '</small>'; } break; case "shipping_address": if ($order->get_formatted_shipping_address()) { echo '<a target="_blank" href="' . esc_url('http://maps.google.com/maps?&q=' . urlencode($order->get_shipping_address()) . '&z=16') . '">' . preg_replace('#<br\\s*/?>#i', ', ', $order->get_formatted_shipping_address()) . '</a>'; } else { echo '–'; } if ($order->shipping_method_title) { echo '<small class="meta">' . __('Via', 'woocommerce') . ' ' . esc_html($order->shipping_method_title) . '</small>'; } break; case "total_cost": echo woocommerce_price($order->order_total); break; case "order_date": if ('0000-00-00 00:00:00' == $post->post_date) { $t_time = $h_time = __('Unpublished', 'woocommerce'); } else { $t_time = get_the_time(__('Y/m/d g:i:s A', 'woocommerce'), $post); $gmt_time = strtotime($post->post_date_gmt); $time_diff = current_time('timestamp', 1) - $gmt_time; if ($time_diff > 0 && $time_diff < 24 * 60 * 60) { $h_time = sprintf(__('%s ago', 'woocommerce'), human_time_diff($gmt_time, current_time('timestamp', 1))); } else { $h_time = get_the_time(__('Y/m/d', 'woocommerce'), $post); } } echo '<abbr title="' . $t_time . '">' . apply_filters('post_date_column_time', $h_time, $post) . '</abbr>'; break; case "order_actions": ?> <p> <?php if (in_array($order->status, array('pending', 'on-hold'))) { ?> <a class="button" href="<?php echo wp_nonce_url(admin_url('admin-ajax.php?action=woocommerce-mark-order-processing&order_id=' . $post->ID), 'woocommerce-mark-order-processing'); ?> "><?php _e('Processing', 'woocommerce'); ?> </a><?php } ?> <?php if (in_array($order->status, array('pending', 'on-hold', 'processing'))) { ?> <a class="button" href="<?php echo wp_nonce_url(admin_url('admin-ajax.php?action=woocommerce-mark-order-complete&order_id=' . $post->ID), 'woocommerce-mark-order-complete'); ?> "><?php _e('Complete', 'woocommerce'); ?> </a><?php } ?> <a class="button" href="<?php echo admin_url('post.php?post=' . $post->ID . '&action=edit'); ?> "><?php _e('View', 'woocommerce'); ?> </a> </p><?php break; case "note": if ($order->customer_note) { echo '<img src="' . $woocommerce->plugin_url() . '/assets/images/note.png" alt="yes" class="tips" tip="' . __('Yes', 'woocommerce') . '" />'; } else { echo '<img src="' . $woocommerce->plugin_url() . '/assets/images/note-off.png" alt="no" class="tips" tip="' . __('No', 'woocommerce') . '" />'; } break; case "order_comments": echo '<div class="post-com-count-wrapper"> <a href="' . admin_url('post.php?post=' . $post->ID . '&action=edit') . '" class="post-com-count"><span class="comment-count">' . $post->comment_count . '</span></a> </div>'; break; } }
public function order_delivery($order_id = 0) { if (!$order_id || !$this->settings['pickup_location'] || !$this->settings['pickup_name'] || !$this->settings['pickup_phone']) { return false; } // Get order object $order = new WC_Order($order_id); if (!$order) { return false; } // Get customer user ID $user = $order->get_user(); if (!$user) { return false; } $delivery_address = str_replace('<br/>', ', ', $order->get_formatted_shipping_address()); if (!$delivery_address) { return false; } if (!$order->billing_phone) { return false; } $delivery_address_data = $this->get_address_data($delivery_address); $args = array('pickup_address' => (string) $this->settings['pickup_location'], 'pickup_contact_name' => (string) $this->settings['pickup_name'], 'pickup_contact_phone' => (string) $this->settings['pickup_phone'], 'customer_identifier' => (string) $user->user_login, 'dropoff_contact_name' => (string) $user->display_name, 'dropoff_contact_phone' => (string) $order->billing_phone, 'dropoff_address' => (string) $delivery_address_data['address'], 'dropoff_coordinates' => (string) $delivery_address_data['location']); if ($this->settings['pickup_coords']) { $args['pickup_coordinates'] = (string) $this->settings['pickup_coords']; } if ($this->settings['pickup_remarks']) { $args['pickup_remarks'] = (string) $this->settings['pickup_remarks']; } if ($this->settings['city']) { $args['city'] = (string) $this->settings['city']; } $delivery_notes = $order->customer_note; if ($delivery_notes) { $args['dropoff_remarks'] = (string) $this->settings['delivery_notes']; } $delivery = $this->api('deliveries', $args, 'post'); if ($delivery && isset($delivery->id)) { update_post_meta($order_id, '_wumdrop_delivery_id', $delivery->id); if (isset($delivery->distance_estimate)) { update_post_meta($order_id, '_wumdrop_distance_estimate', $delivery->distance_estimate); } if (isset($delivery->time_estimate)) { update_post_meta($order_id, '_wumdrop_time_estimate', $delivery->time_estimate); } if (isset($delivery->message)) { update_post_meta($order_id, '_wumdrop_delivery_message', $delivery->message); } if (isset($delivery->time_estimate)) { update_post_meta($order_id, '_wumdrop_delivery_price', $delivery->price); } $order_note = __('WumDrop delivery order placed.', 'woocommerce-wumdrop'); if ('completed' != $order->get_status()) { $order->update_status('completed', $order_note); } else { $order->add_order_note($order_note); } return true; } return false; }
/** * Order data meta box * * Displays the meta box */ function woocommerce_order_data_meta_box($post) { global $post, $wpdb, $thepostid, $order_status; $thepostid = $post->ID; $order = new WC_Order($thepostid); wp_nonce_field('woocommerce_save_data', 'woocommerce_meta_nonce'); // Custom user $customer_user = (int) get_post_meta($post->ID, '_customer_user', true); // Order status $order_status = wp_get_post_terms($post->ID, 'shop_order_status'); if ($order_status) { $order_status = current($order_status); $order_status = $order_status->slug; } else { $order_status = 'pending'; } if (!isset($post->post_title) || empty($post->post_title)) { $order_title = 'Order'; } else { $order_title = $post->post_title; } ?> <style type="text/css"> #titlediv, #major-publishing-actions, #minor-publishing-actions, #visibility, #submitdiv { display:none } </style> <div class="panel-wrap woocommerce"> <input name="post_title" type="hidden" value="<?php echo esc_attr($order_title); ?> " /> <input name="post_status" type="hidden" value="publish" /> <div id="order_data" class="panel"> <div class="order_data_left"> <h2><?php _e('Order Details', 'woocommerce'); ?> — #<?php echo $thepostid; ?> </h2> <p class="form-field"><label for="order_status"><?php _e('Order status:', 'woocommerce'); ?> </label> <select id="order_status" name="order_status" class="chosen_select"> <?php $statuses = (array) get_terms('shop_order_status', array('hide_empty' => 0, 'orderby' => 'id')); foreach ($statuses as $status) { echo '<option value="' . $status->slug . '" '; if ($status->slug == $order_status) { echo 'selected="selected"'; } echo '>' . __($status->name, 'woocommerce') . '</option>'; } ?> </select></p> <p class="form-field form-field-wide"><label for="customer_user"><?php _e('Customer:', 'woocommerce'); ?> </label> <select id="customer_user" name="customer_user" class="chosen_select"> <option value=""><?php _e('Guest', 'woocommerce'); ?> </option> <?php $users = new WP_User_Query(array('orderby' => 'display_name')); $users = $users->get_results(); if ($users) { foreach ($users as $user) { echo '<option value="' . $user->ID . '" '; selected($customer_user, $user->ID); echo '>' . $user->display_name . ' (' . $user->user_email . ')</option>'; } } ?> </select></p> <p class="form-field form-field-wide"><label for="excerpt"><?php _e('Customer Note:', 'woocommerce'); ?> </label> <textarea rows="1" cols="40" name="excerpt" tabindex="6" id="excerpt" placeholder="<?php _e('Customer\'s notes about the order', 'woocommerce'); ?> "><?php echo $post->post_excerpt; ?> </textarea></p> </div> <div class="order_data_right"> <div class="order_data"> <h2><?php _e('Billing Details', 'woocommerce'); ?> <a class="edit_address" href="#">(<?php _e('Edit', 'woocommerce'); ?> )</a></h2> <?php $billing_data = apply_filters('woocommerce_admin_billing_fields', array('first_name' => array('label' => __('First Name', 'woocommerce'), 'show' => false), 'last_name' => array('label' => __('Last Name', 'woocommerce'), 'show' => false), 'company' => array('label' => __('Company', 'woocommerce'), 'show' => false), 'address_1' => array('label' => __('Address 1', 'woocommerce'), 'show' => false), 'address_2' => array('label' => __('Address 2', 'woocommerce'), 'show' => false), 'city' => array('label' => __('City', 'woocommerce'), 'show' => false), 'postcode' => array('label' => __('Postcode', 'woocommerce'), 'show' => false), 'country' => array('label' => __('Country', 'woocommerce'), 'show' => false), 'state' => array('label' => __('State/County', 'woocommerce'), 'show' => false), 'email' => array('label' => __('Email', 'woocommerce')), 'phone' => array('label' => __('Phone', 'woocommerce')))); // Display values echo '<div class="address">'; if ($order->get_formatted_billing_address()) { echo '<p><strong>' . __('Address', 'woocommerce') . ':</strong><br/> ' . $order->get_formatted_billing_address() . '</p>'; } else { echo '<p class="none_set"><strong>' . __('Address', 'woocommerce') . ':</strong> ' . __('No billing address set.', 'woocommerce') . '</p>'; } foreach ($billing_data as $key => $field) { if (isset($field['show']) && !$field['show']) { continue; } $field_name = 'billing_' . $key; echo '<p><strong>' . $field['label'] . ':</strong> ' . $order->{$field_name} . '</p>'; } echo '</div>'; // Display form echo '<div class="edit_address"><p><button class="button load_customer_billing">' . __('Load customer billing address', 'woocommerce') . '</button></p>'; foreach ($billing_data as $key => $field) { woocommerce_wp_text_input(array('id' => '_billing_' . $key, 'label' => $field['label'])); } echo '</div>'; ?> </div> <div class="order_data order_data_alt"> <h2><?php _e('Shipping Details', 'woocommerce'); ?> <a class="edit_address" href="#">(<?php _e('Edit', 'woocommerce'); ?> )</a></h2> <?php $shipping_data = apply_filters('woocommerce_admin_shipping_fields', array('first_name' => array('label' => __('First Name', 'woocommerce'), 'show' => false), 'last_name' => array('label' => __('Last Name', 'woocommerce'), 'show' => false), 'company' => array('label' => __('Company', 'woocommerce'), 'show' => false), 'address_1' => array('label' => __('Address 1', 'woocommerce'), 'show' => false), 'address_2' => array('label' => __('Address 2', 'woocommerce'), 'show' => false), 'city' => array('label' => __('City', 'woocommerce'), 'show' => false), 'postcode' => array('label' => __('Postcode', 'woocommerce'), 'show' => false), 'country' => array('label' => __('Country', 'woocommerce'), 'show' => false), 'state' => array('label' => __('State/County', 'woocommerce'), 'show' => false))); // Display values echo '<div class="address">'; if ($order->get_formatted_shipping_address()) { echo '<p><strong>' . __('Address', 'woocommerce') . ':</strong><br/> ' . $order->get_formatted_shipping_address() . '</p>'; } else { echo '<p class="none_set"><strong>' . __('Address', 'woocommerce') . ':</strong> ' . __('No shipping address set.', 'woocommerce') . '</p>'; } foreach ($shipping_data as $key => $field) { if (isset($field['show']) && !$field['show']) { continue; } $field_name = 'shipping_' . $key; echo '<p><strong>' . $field['label'] . ':</strong> ' . $order->{$field_name} . '</p>'; } echo '</div>'; // Display form echo '<div class="edit_address"><p><button class="button load_customer_shipping">' . __('Load customer shipping address', 'woocommerce') . '</button></p>'; foreach ($shipping_data as $key => $field) { woocommerce_wp_text_input(array('id' => '_shipping_' . $key, 'label' => $field['label'])); } echo '</div>'; ?> </div> </div> <div class="clear"></div> </div> </div> <?php }
/** * Get current vendor orders * * @return array */ function wcmp_get_vendor_orders() { global $WCMp; $user_id = get_current_user_id(); $vendor = get_wcmp_vendor($user_id); $orders = array(); $vendor_orders_array = $vendor->get_orders(); if (!$vendor_orders_array) { $vendor_orders_array = array(); } $_orders = array_unique($vendor_orders_array); if (!empty($_orders)) { foreach ($_orders as $order_id) { $order = new WC_Order($order_id); $valid_items = $vendor->get_vendor_items_from_order($order->id, $vendor->term_id); $products = ''; foreach ($valid_items as $key => $item) { $item_meta = new WC_Order_Item_Meta($item['item_meta']); // $item_meta = $item_meta->display( false, true ); $item_meta = $item_meta->get_formatted(); $products .= '<strong>' . $item['qty'] . ' x ' . $item['name'] . '</strong><br />'; foreach ($item_meta as $key => $meta) { // Remove the sold by meta key for display if (strtolower($key) != 'sold by') { if ($meta['label'] == 'flat_shipping_per_item') { $products .= __('Flat Shipping Charges', $WCMp->text_domain) . ' : ' . $meta['value'] . '<br />'; } else { $products .= $meta['label'] . ' : ' . $meta['value'] . '<br />'; } } } } $shippers = (array) get_post_meta($order->id, 'dc_pv_shipped', true); $shipped = in_array($user_id, $shippers) ? 'Yes' : 'No'; if ($order->id && $vendor->term_id) { $commission_total = 0; $commissions = false; $args = array('post_type' => 'dc_commission', 'post_status' => array('publish', 'private'), 'posts_per_page' => -1, 'meta_query' => array(array('key' => '_commission_vendor', 'value' => absint($vendor->term_id), 'compare' => '='), array('key' => '_commission_order_id', 'value' => absint($order->id), 'compare' => '='))); $commissions = get_posts($args); if (!empty($commissions)) { foreach ($commissions as $commission) { $commission_total = $commission_total + (double) get_post_meta($commission->ID, '_commission_amount', true) + (double) get_post_meta($commission->ID, '_shipping', true) + (double) get_post_meta($commission->ID, '_tax', true); } } } $extra_checkout_fields_for_brazil_active_datas = ''; if (WC_Dependencies_Product_Vendor::woocommerce_extra_checkout_fields_for_brazil_active_check()) { $settings = get_option('wcbcf_settings'); if (0 != $settings['person_type']) { // Person type information. if (1 == $order->billing_persontype && 1 == $settings['person_type'] || 2 == $settings['person_type']) { $extra_checkout_fields_for_brazil_active_datas .= '<strong>' . __('CPF', $WCMp->text_domain) . ': </strong>' . esc_html($order->billing_cpf) . '<br />'; if (isset($settings['rg'])) { $extra_checkout_fields_for_brazil_active_datas .= '<strong>' . __('RG', $WCMp->text_domain) . ': </strong>' . esc_html($order->billing_rg) . '<br />'; } } if (2 == $order->billing_persontype && 1 == $settings['person_type'] || 3 == $settings['person_type']) { $extra_checkout_fields_for_brazil_active_datas .= '<strong>' . __('Company Name', $WCMp->text_domain) . ': </strong>' . esc_html($order->billing_company) . '<br />'; $extra_checkout_fields_for_brazil_active_datas .= '<strong>' . __('CNPJ', $WCMp->text_domain) . ': </strong>' . esc_html($order->billing_cnpj) . '<br />'; if (isset($settings['ie'])) { $extra_checkout_fields_for_brazil_active_datas .= '<strong>' . __('State Registration', $WCMp->text_domain) . ': </strong>' . esc_html($order->billing_ie) . '<br />'; } } } else { $extra_checkout_fields_for_brazil_active_datas .= '<strong>' . __('Company', $WCMp->text_domain) . ': </strong>' . esc_html($order->billing_company) . '<br />'; } if (isset($settings['birthdate_sex'])) { // Birthdate information. $extra_checkout_fields_for_brazil_active_datas .= '<strong>' . __('Birthdate', $WCMp->text_domain) . ': </strong>' . esc_html($order->billing_birthdate) . '<br />'; // Sex Information. $extra_checkout_fields_for_brazil_active_datas .= '<strong>' . __('Sex', $WCMp->text_domain) . ': </strong>' . esc_html($order->billing_sex) . '<br />'; } $extra_checkout_fields_for_brazil_active_datas .= '<strong>' . __('Phone', $WCMp->text_domain) . ': </strong>' . esc_html($order->billing_phone) . '<br />'; // Cell Phone Information. if (!empty($order->billing_cellphone)) { $extra_checkout_fields_for_brazil_active_datas .= '<strong>' . __('Cell Phone', $WCMp->text_domain) . ': </strong>' . esc_html($order->billing_cellphone) . '<br />'; } } $customer_user_name = get_post_meta($order->id, '_shipping_first_name', true) . ' ' . get_post_meta($order->id, '_shipping_last_name', true); $order_items = array(); $order_items['order_id'] = $order->id; $order_items['customer'] = $customer_user_name . '<br>' . apply_filters('wcmp_dashboard_google_maps_link', '<a target="_blank" href="' . esc_url('http://maps.google.com/maps?&q=' . urlencode(esc_html(preg_replace('#<br\\s*/?>#i', ', ', $order->get_formatted_shipping_address()))) . '&z=16') . '">' . esc_html(preg_replace('#<br\\s*/?>#i', ', ', $order->get_formatted_shipping_address())) . '</a><br />' . $extra_checkout_fields_for_brazil_active_datas); $order_items['products'] = $products; $order_items['total'] = woocommerce_price($commission_total); $order_items['date'] = date_i18n(wc_date_format(), strtotime($order->order_date)); $order_items['status'] = $shipped; $orders[] = (object) $order_items; } } return $orders; }
/** * notify_new_order * * Send notification when new order is received * * @access public * @return void */ function notify_new_order($order_id) { global $woocommerce; $order = new WC_Order($order_id); // Send notifications if order total is greater than $0 // Or if free order notification is enabled if (0 < absint($order->order_total) || $this->notify_free_order) { $order_items = ""; $exclude = array("type", "item_meta", "tax_class", "product_id", "variation_id", "line_subtotal", "line_tax", "line_subtotal_tax"); $replace = array("name" => "Товар", "qty" => "Количество", "line_total" => "На сумму", "pa_base" => "Основа", "pa_size" => "Размер", "pa_color" => "Цвет"); foreach ($order->get_items() as $item_id => $id) { foreach ($id as $key => $value) { if (!in_array($key, $exclude)) { $order_items .= strtr($key, $replace) . ": " . urldecode($value) . "\r\n"; } } $order_items .= "\r\n"; } $title = sprintf(__('Заказ %d', 'wc_xmpp'), $order_id); $message = $order->get_formatted_shipping_address() . "\r\n" . $order_items . "Общая сумма: " . $order->order_total . $this->xmpp_get_currency_symbol(); $url = get_admin_url(); $this->send_notification($title, $message, $url); $this->add_log(__('Order items', 'wc_xmpp') . "\n" . print_r($order, true)); } }
/** * Values for the custom columns on the orders page. * * @access public * @param mixed $column * @return void */ function woocommerce_custom_order_columns($column) { global $post, $woocommerce, $the_order; if (empty($the_order) || $the_order->id != $post->ID) { $the_order = new WC_Order($post->ID); } switch ($column) { case "order_status": printf('<mark class="%s tips" data-tip="%s">%s</mark>', sanitize_title($the_order->status), esc_html__($the_order->status, 'woocommerce'), esc_html__($the_order->status, 'woocommerce')); break; case "order_title": if ($the_order->user_id) { $user_info = get_userdata($the_order->user_id); } if (!empty($user_info)) { $user = '******' . absint($user_info->ID) . '">'; if ($user_info->first_name || $user_info->last_name) { $user .= esc_html($user_info->first_name . ' ' . $user_info->last_name); } else { $user .= esc_html($user_info->display_name); } $user .= '</a>'; } else { $user = __('Guest', 'woocommerce'); } echo '<a href="' . admin_url('post.php?post=' . absint($post->ID) . '&action=edit') . '"><strong>' . sprintf(__('Order %s', 'woocommerce'), esc_attr($the_order->get_order_number())) . '</strong></a> ' . __('made by', 'woocommerce') . ' ' . $user; if ($the_order->billing_email) { echo '<small class="meta">' . __('Email:', 'woocommerce') . ' ' . '<a href="' . esc_url('mailto:' . $the_order->billing_email) . '">' . esc_html($the_order->billing_email) . '</a></small>'; } if ($the_order->billing_phone) { echo '<small class="meta">' . __('Tel:', 'woocommerce') . ' ' . esc_html($the_order->billing_phone) . '</small>'; } break; case "billing_address": if ($the_order->get_formatted_billing_address()) { echo '<a target="_blank" href="' . esc_url('http://maps.google.com/maps?&q=' . urlencode($the_order->get_billing_address()) . '&z=16') . '">' . esc_html(preg_replace('#<br\\s*/?>#i', ', ', $the_order->get_formatted_billing_address())) . '</a>'; } else { echo '–'; } if ($the_order->payment_method_title) { echo '<small class="meta">' . __('Via', 'woocommerce') . ' ' . esc_html($the_order->payment_method_title) . '</small>'; } break; case "shipping_address": if ($the_order->get_formatted_shipping_address()) { echo '<a target="_blank" href="' . esc_url('http://maps.google.com/maps?&q=' . urlencode($the_order->get_shipping_address()) . '&z=16') . '">' . esc_html(preg_replace('#<br\\s*/?>#i', ', ', $the_order->get_formatted_shipping_address())) . '</a>'; } else { echo '–'; } if ($the_order->shipping_method_title) { echo '<small class="meta">' . __('Via', 'woocommerce') . ' ' . esc_html($the_order->shipping_method_title) . '</small>'; } break; case "total_cost": echo esc_html(strip_tags($the_order->get_formatted_order_total())); break; case "order_date": if ('0000-00-00 00:00:00' == $post->post_date) { $t_time = $h_time = __('Unpublished', 'woocommerce'); } else { $t_time = get_the_time(__('Y/m/d g:i:s A', 'woocommerce'), $post); $gmt_time = strtotime($post->post_date_gmt . ' UTC'); $time_diff = current_time('timestamp', 1) - $gmt_time; if ($time_diff > 0 && $time_diff < 24 * 60 * 60) { $h_time = sprintf(__('%s ago', 'woocommerce'), human_time_diff($gmt_time, current_time('timestamp', 1))); } else { $h_time = get_the_time(__('Y/m/d', 'woocommerce'), $post); } } echo '<abbr title="' . esc_attr($t_time) . '">' . esc_html(apply_filters('post_date_column_time', $h_time, $post)) . '</abbr>'; break; case "order_actions": ?> <p> <?php do_action('woocommerce_admin_order_actions_start', $the_order); $actions = array(); if (in_array($the_order->status, array('pending', 'on-hold'))) { $actions['processing'] = array('url' => wp_nonce_url(admin_url('admin-ajax.php?action=woocommerce-mark-order-processing&order_id=' . $post->ID), 'woocommerce-mark-order-processing'), 'name' => __('Processing', 'woocommerce'), 'action' => "processing"); } if (in_array($the_order->status, array('pending', 'on-hold', 'processing'))) { $actions['complete'] = array('url' => wp_nonce_url(admin_url('admin-ajax.php?action=woocommerce-mark-order-complete&order_id=' . $post->ID), 'woocommerce-mark-order-complete'), 'name' => __('Complete', 'woocommerce'), 'action' => "complete"); } $actions['view'] = array('url' => admin_url('post.php?post=' . $post->ID . '&action=edit'), 'name' => __('View', 'woocommerce'), 'action' => "view"); $actions = apply_filters('woocommerce_admin_order_actions', $actions, $the_order); foreach ($actions as $action) { $image = isset($action['image_url']) ? $action['image_url'] : $woocommerce->plugin_url() . '/assets/images/icons/' . $action['action'] . '.png'; printf('<a class="button tips" href="%s" data-tip="%s"><img src="%s" alt="%s" width="14" /></a>', esc_url($action['url']), esc_attr($action['name']), esc_attr($image), esc_attr($action['name'])); } do_action('woocommerce_admin_order_actions_end', $the_order); ?> </p><?php break; case "note": if ($the_order->customer_note) { echo '<img src="' . $woocommerce->plugin_url() . '/assets/images/note.png" alt="yes" class="tips" data-tip="' . __('Yes', 'woocommerce') . '" width="14" height="14" />'; } else { echo '<img src="' . $woocommerce->plugin_url() . '/assets/images/note-off.png" alt="no" class="tips" data-tip="' . __('No', 'woocommerce') . '" width="14" height="14" />'; } break; case "order_comments": echo '<div class="post-com-count-wrapper"> <a href="' . esc_url(admin_url('post.php?post=' . $post->ID . '&action=edit')) . '" class="post-com-count"><span class="comment-count">' . $post->comment_count . '</span></a> </div>'; break; } }
$order_id = $_POST['orderReference']; $order = new WC_Order($order_id); $options = get_option('woocommerce_hygglig_checkout_settings'); $log = new WC_Logger(); //Live or test if ($options['testmode'] == 'yes') { $url = "http://sandbox.hygglig.com/"; } else { $url = "https://www.hygglig.com/"; } // Billing if (strlen($order->get_formatted_billing_address()) < 10) { $order->set_address(array('first_name' => $_POST['firstName'], 'last_name' => $_POST['lastName'], 'address_1' => $_POST['address'], 'city' => $_POST['city'], 'postcode' => $_POST['postalCode'], 'email' => $_POST['email'], 'phone' => $_POST['phoneNumber'])); } // Shipping if (strlen($order->get_formatted_shipping_address()) < 10) { $order->set_address(array('first_name' => $_POST['firstName'], 'last_name' => $_POST['lastName'], 'address_1' => $_POST['address'], 'city' => $_POST['city'], 'postcode' => $_POST['postalCode']), 'shipping'); } $order->payment_complete($_POST['orderNumber']); update_post_meta($order_id, '_payment_method', 'Hygglig'); update_post_meta($order_id, '_payment_method_title', 'Hygglig'); if ($options['debug'] == 'yes') { $log->add('marginalen', "Payment for Order #" . $order_id . " completed. Stocks reduced."); } // Store user id in order so the user can keep track of track it in My account if (email_exists($order->billing_email)) { if ($options['debug'] == 'yes') { $log->add('marginalen', 'Billing email: ' . $order->billing_email); } $user = get_user_by('email', $order->billing_email); if ($options['debug'] == 'yes') {
<?php echo $order->get_formatted_billing_address(); ?> </div> </div> </div> <div class="dokan-left" style="width:49%;"> <div class="dokan-panel dokan-panel-default"> <div class="dokan-panel-heading"><strong><?php _e('Shipping Address', 'dokan'); ?> </strong></div> <div class="dokan-panel-body"> <?php echo $order->get_formatted_shipping_address(); ?> </div> </div> </div> <div class="clear"></div> </div> </div> <div class="dokan-w4"> <div class="row dokan-clearfix"> <div class="" style="width:100%"> <div class="dokan-panel dokan-panel-default"> <div class="dokan-panel-heading"><strong><?php
function sendCustomerInvoice($order_id) { PlexLog::addLog(' Info =>@sendCustomerInvoice order_id=' . $order_id); $wooCommerceOrderObject = new WC_Order($order_id); $user_id = $wooCommerceOrderObject->get_user_id(); $customerMailId = $wooCommerceOrderObject->billing_email; $invoice_mail_content = ''; $invoice_mail_content .= ' <table border="0" cellpadding="0" cellspacing="0" width="600" id="template_container"> <tbody> <tr> <td align="center" valign="top"> <font face="Arial" style="font-weight:bold;background-color:#8fd1c8;color:#202020;"></font> <table border="0" cellpadding="0" cellspacing="0" width="600" id="template_header" bgcolor="#8fd1c8"> <tbody> <tr > <td width="20" height="20" bgcolor="#8fd1c8"> </td> <td bgcolor="#8fd1c8"> </td> <td width="20" bgcolor="#8fd1c8"> </td> </tr> <tr > <td width="20" bgcolor="#8fd1c8"> </td> <td bgcolor="#8fd1c8" style="font-weight:bold;font-size:24px;color:#ffffff;" ><h2 style="margin:0;">Welcome to ' . get_option('blogname') . '! <br>Thank you for your order. We\'ll be in touch shortly with additional order and shipping information.</h2></td> <td width="20" bgcolor="#8fd1c8"> </td> </tr> <tr > <td width="20" height="20" bgcolor="#8fd1c8"> </td> <td bgcolor="#8fd1c8"> </td> <td width="20" bgcolor="#8fd1c8"> </td> </tr> </tbody> </table> </td> </tr> <tr> <td align="center" valign="top"> <table border="0" cellpadding="0" cellspacing="0" width="600" id="template_body"> <tbody> <tr> <td valign="top"> <font style="background-color:#f9f9f9"> <table border="0" cellpadding="20" cellspacing="0" width="100%"> <tbody> <tr> <td valign="top"> <div> <font face="Arial" align="left" style="font-size:18px;color:#8a8a8a"> <p>Your order #' . get_post_meta($order_id, "plexOrderId", true) . ' has been received and is now being processed. Your order details are shown below for your reference:</p> <table cellspacing="0" cellpadding="6" border="1" style="width:100%;"> <thead> <tr> <th scope="col"> <font align="left">Product</font> </th> <th scope="col"> <font align="left">Quantity</font> </th> <th scope="col"> <font align="left">Price</font> </th> </tr> </thead> <tbody>'; $allItems = $wooCommerceOrderObject->get_items(); foreach ($allItems as $key => $value) { $invoice_mail_content .= ' <tr> <td> <font align="left">' . $value["name"] . '<br><small></small></font> </td> <td> <font align="left">' . $value["qty"] . '</font> </td> <td> <font align="left"> <span class="amount">$' . $value["line_subtotal"] . '</span> </font> </td> </tr>'; } $invoice_mail_content .= ' </tbody> <tfoot style="text-align: left;"> <tr> <th scope="row" colspan="2"> <font align="left">Cart Subtotal:</font> </th> <td> <font align="left"> <span class="amount">$' . sprintf('%0.2f', $wooCommerceOrderObject->get_subtotal()) . '</span> </font> </td> </tr>'; if ($wooCommerceOrderObject->get_total_discount() > 0.0) { $invoice_mail_content .= '<tr> <th scope="row" colspan="2"> <font align="left">Discount:</font> </th> <td> <font align="left"> <span class="amount">$' . sprintf('%0.2f', $wooCommerceOrderObject->get_total_discount()) . '</span> </font> </td> </tr>'; } $invoice_mail_content .= '<tr> <th scope="row" colspan="2"> <font align="left">Tax:</font> </th> <td> <font align="left"> <span class="amount">$' . sprintf('%0.2f', $wooCommerceOrderObject->get_cart_tax() + $wooCommerceOrderObject->get_shipping_tax()) . '</span> </font> </td> </tr> <tr> <th scope="row" colspan="2"> <font align="left">Shipping:</font> </th> <td> <font align="left"> <span class="amount">$' . $wooCommerceOrderObject->get_total_shipping() . '</span> <small>via ' . $wooCommerceOrderObject->get_shipping_method() . '</small> </font> </td> </tr> <tr> <th scope="row" colspan="2"> <font align="left">Payment Method:</font> </th> <td> <font align="left">' . $wooCommerceOrderObject->payment_method_title . '</font> </td> </tr> <tr> <th scope="row" colspan="2"> <font align="left">Order Total:</font> </th> <td> <font align="left"> <span class="amount">$' . sprintf('%0.2f', $wooCommerceOrderObject->get_total()) . '</span> </font> </td> </tr> </tfoot> </table> <h2> <font face="Arial" align="left" style="font-weight:bold;font-size:30px;color:#6d6d6d">Customer details</font> </h2> <p><strong>Email:</strong> ' . $customerMailId . '</p> <p><strong>Tel:</strong> ' . $wooCommerceOrderObject->billing_phone . '</p> <table cellspacing="0" cellpadding="0" border="0"> <tbody> <tr> <td valign="top" width="50%"> <h3> <font face="Arial" align="left" style="font-weight:bold;font-size:26px;color:#6d6d6d">Billing address</font> </h3> <p>' . $wooCommerceOrderObject->get_formatted_billing_address() . '</p> </td> <td valign="top" width="50%"> <h3> <font face="Arial" align="left" style="font-weight:bold;font-size:26px;color:#6d6d6d">Shipping address</font> </h3> <p>' . $wooCommerceOrderObject->get_formatted_shipping_address() . '</p> </td> </tr> </tbody> </table> </font> </div> </td> </tr> </tbody> </table> </font> </td> </tr> </tbody> </table> </td> </tr> <tr> <td align="center" valign="top"> <table border="0" cellpadding="10" cellspacing="0" width="600" id="template_footer"> <tbody> <tr> <td valign="top"> <table border="0" cellpadding="4" cellspacing="0" width="100%"> <tbody> <tr> <td colspan="2" valign="middle" id="credit" style="background-color: #777;"> <font face="Arial" align="center" style="font-size:12px;color:#bce3de"> <p>' . site_url() . '</p> </font> </td> </tr> </tbody> </table> </td> </tr> </tbody> </table> </td> </tr> </tbody> </table>'; $emailHeader = "Content-type: text/html"; // To send HTML mail, the Content-type header must be set $emailHeader = 'MIME-Version: 1.0' . "\r\n"; $emailHeader .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; // Additional emailHeader $emailHeader .= 'From: ' . get_bloginfo('name') . ' <*****@*****.**>' . "\r\n"; $emailSubject = "Your plexuser order receipt from " . date_i18n(wc_date_format(), strtotime($wooCommerceOrderObject->order_date)); wp_mail($customerMailId, $emailSubject, $invoice_mail_content, $emailHeader); }