/** * Get column content, this is called once per column, per row item ($order) * returns the content to be rendered within that cell. * * @see WP_List_Table::single_row_columns() * @since 1.0 * @param WC_Order $order one row (item) in the table * @param string $column_name the column slug * @return string the column content */ public function column_default($order, $column_name) { switch ($column_name) { case 'status': $actions = array(); // base action url $action_url = add_query_arg('order_id[]', $order->id); // determine any available actions if (WC_Pre_Orders_Manager::can_pre_order_be_changed_to('cancelled', $order)) { $actions['cancel'] = sprintf('<a href="%s">%s</a>', add_query_arg('action', 'cancel', $action_url), __('Cancel', 'wc-pre-orders')); } $column_content = sprintf('<mark class="%s tips" data-tip="%s">%s</mark>', WC_Pre_Orders_Order::get_pre_order_status($order), WC_Pre_Orders_Order::get_pre_order_status_to_display($order), WC_Pre_Orders_Order::get_pre_order_status_to_display($order)); $column_content .= $this->row_actions($actions); break; case 'customer': if (0 !== $order->user_id) { $column_content = sprintf('<a href="%s">%s</a>', get_edit_user_link($order->user_id), $order->billing_email); } else { $column_content = $order->billing_email; } break; case 'product': $item = WC_Pre_Orders_Order::get_pre_order_item($order); $product_edit = get_edit_post_link($item['product_id']); $column_content = $product_edit ? sprintf('<a href="%s">%s</a>', $product_edit, $item['name']) : $item['name']; break; case 'order': $column_content = sprintf('<a href="%s">%s</a>', get_edit_post_link($order->id), sprintf(__('Order %s', 'wc-pre-orders'), $order->get_order_number())); break; case 'order_date': $column_content = date_i18n(woocommerce_date_format(), strtotime($order->order_date)); break; case 'availability_date': $product = WC_Pre_Orders_Order::get_pre_order_product($order); $column_content = WC_Pre_Orders_Product::get_localized_availability_date($product, '--'); break; default: $column_content = ''; break; } return $column_content; }
/** * Add pre-order emails to the list of order emails that can be resent, based on the pre-order status * * @since 1.0 * @param array $available_emails simple array of WC_Email class IDs that can be resent * @return array */ public function maybe_allow_resend_of_pre_order_emails($available_emails) { global $theorder; if (WC_Pre_Orders_Order::order_contains_pre_order($theorder)) { $available_emails[] = 'wc_pre_orders_pre_ordered'; $pre_order_status = WC_Pre_Orders_Order::get_pre_order_status($theorder); if ('cancelled' === $pre_order_status) { $available_emails[] = 'wc_pre_orders_pre_order_cancelled'; } if ('completed' === $pre_order_status) { $available_emails[] = 'wc_pre_orders_pre_order_available'; } } return $available_emails; }
/** * Change the release date for pre-orders by updating the availability date for the pre-ordered product to a new date in the future * * @since 1.0 * @param object|int $product the product to change the release date for all pre-orders for * @param string $new_availability_date the new availability date * @param string $message an optional message to include in communications to the customer */ public static function change_release_date_for_all_pre_orders($product, $new_availability_date, $message = '') { if (!is_object($product)) { $product = get_product($product); } // get new availability date timestamp try { // get datetime object from site timezone $datetime = new DateTime($new_availability_date, new DateTimeZone(WC_Pre_Orders_Product::get_wp_timezone_string())); // get the unix timestamp (adjusted for the site's timezone already) $timestamp = $datetime->format('U'); // don't allow availability dates in the past if ($timestamp <= time()) { $timestamp = ''; } } catch (Exception $e) { global $wc_pre_orders; $wc_pre_orders->log($e->getMessage()); $timestamp = ''; } // set new availability date for product update_post_meta($product->id, '_wc_pre_orders_availability_datetime', $timestamp); // get associated orders $orders = self::get_all_pre_orders_by_product($product); // fire action for each order foreach ($orders as $order) { if (!is_object($order)) { $order = new WC_Order($order); } // only delay active pre-orders if ('active' !== WC_Pre_Orders_Order::get_pre_order_status($order)) { continue; } // add 'release date changed' order note for admins $order->add_order_note(sprintf(__('Pre-Order Release Date Changed to %s', 'wc-pre-orders'), WC_Pre_Orders_Product::get_localized_availability_date($product, __('N/A', 'wc-pre-orders')))); do_action('wc_pre_orders_pre_order_date_changed', array('order' => $order, 'availability_date' => $new_availability_date, 'message' => $message)); } }