/** * Dispatch the email * * @since 1.0 */ public function trigger($args) { if (!empty($args)) { $defaults = array('order' => '', 'message' => ''); $args = wp_parse_args($args, $defaults); extract($args); if (!is_object($order)) { return; } $this->object = $order; $this->recipient = $this->object->billing_email; $this->message = $message; $this->availability_date = WC_Pre_Orders_Product::get_localized_availability_date(WC_Pre_Orders_Order::get_pre_order_product($this->object)); $this->find[] = '{order_date}'; $this->replace[] = date_i18n(woocommerce_date_format(), strtotime($this->object->order_date)); $this->find[] = '{release_date}'; $this->replace[] = $this->availability_date; $this->find[] = '{order_number}'; $this->replace[] = $this->object->get_order_number(); } if (!$this->is_enabled() || !$this->get_recipient()) { return; } $this->send($this->get_recipient(), $this->get_subject(), $this->get_content(), $this->get_headers(), $this->get_attachments()); }
/** * Force tokenization for pre-orders * * @since 4.1.0 * @see SV_WC_Payment_Gateway::tokenization_forced() * @param boolean $force_tokenization whether tokenization should be forced * @return boolean true if tokenization should be forced, false otherwise */ public function maybe_force_tokenization($force_tokenization) { // pay page with pre-order? $pay_page_pre_order = false; if ($this->get_gateway()->is_pay_page_gateway()) { $order_id = $this->get_gateway()->get_checkout_pay_page_order_id(); if ($order_id) { $pay_page_pre_order = WC_Pre_Orders_Order::order_contains_pre_order($order_id) && WC_Pre_Orders_Product::product_is_charged_upon_release(WC_Pre_Orders_Order::get_pre_order_product($order_id)); } } if (WC_Pre_Orders_Cart::cart_contains_pre_order() && WC_Pre_Orders_Product::product_is_charged_upon_release(WC_Pre_Orders_Cart::get_pre_order_product()) || $pay_page_pre_order) { // always tokenize the card for pre-orders that are charged upon release $force_tokenization = true; } return $force_tokenization; }
/** * Dispatch the email * * @since 1.0 */ public function trigger($order_id, $message) { if ($order_id) { $this->object = new WC_Order($order_id); $this->recipient = $this->object->billing_email; $this->message = $message; $this->find[] = '{order_date}'; $this->replace[] = date_i18n(woocommerce_date_format(), strtotime($this->object->order_date)); $this->find[] = '{release_date}'; $this->replace[] = WC_Pre_Orders_Product::get_localized_availability_date(WC_Pre_Orders_Order::get_pre_order_product($this->object)); $this->find[] = '{order_number}'; $this->replace[] = $this->object->get_order_number(); } if (!$this->is_enabled() || !$this->get_recipient()) { return; } $this->send($this->get_recipient(), $this->get_subject(), $this->get_content(), $this->get_headers(), $this->get_attachments()); }
/** * Process payment for an order: * 1) If the order contains a subscription, process the initial subscription payment (could be $0 if a free trial exists) * 2) If the order contains a pre-order, process the pre-order total (could be $0 if the pre-order is charged upon release) * 3) Otherwise use the parent::process_payment() method for regular product purchases * * @since 2.0 * @param int $order_id * @return array */ public function process_payment($order_id) { $order = $this->get_order($order_id); try { /* processing subscription */ if (wc_amazon_fps()->is_subscriptions_active() && WC_Subscriptions_Order::order_contains_subscription($order)) { // calculate the lifetime amount to be charged for the subscription, with a multiplier applied to account for upgrades / price increases $order->amazon_lifetime_subscription_total = $this->calculate_lifetime_subscription_total($order); // set a subscription-specific description $order->amazon_description = sprintf(__('%s - Subscription Order %s', WC_Amazon_FPS::TEXT_DOMAIN), esc_html(get_bloginfo('name')), $order->get_order_number()); $url = $this->get_api()->get_subscriptions_purchase_url($order); /* processing pre-order */ } elseif (wc_amazon_fps()->is_pre_orders_active() && WC_Pre_Orders_Order::order_contains_pre_order($order_id) && WC_Pre_Orders_Order::order_requires_payment_tokenization($order->id)) { // Amazon requires an expiration date for the token so use the pre-order release date + 6 months to account for pre-order delays $release_date = WC_Pre_Orders_Product::get_localized_availability_date(WC_Pre_Orders_Order::get_pre_order_product($order)); $order->amazon_pre_order_release_date = strtotime("{$release_date} +6 months"); $url = $this->get_api()->get_pre_order_purchase_url($order); /* processing regular product (or a pre-order charged upfront) */ } else { return parent::process_payment($order_id); } // add to log $this->log($url, 'request'); // redirect to Amazon return array('result' => 'success', 'redirect' => $url); } catch (Exception $e) { $this->mark_order_as_failed($order, $e->getMessage()); } }
/** * 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; }
/** * Completes the pre-order by updating the pre-order status to 'completed' and following this process for handling payment : * * - for a pre-order charged upon released AND containing a payment token, an action is fired for the supported gateway * to hook into an charge the total payment amount. Note that the supported gateway will then call WC_Order::payment_complete() * upon successful charge * * - for a pre-order charged upon released with no payment token, the order status is changed to 'pending' and an email * is sent containing a link for the customer to come back to and pay for their order * * - for a pre-order charged upfront, the order status is changed to 'completed' or 'processing' based on the same rules * from WC_Order::payment_complete() -- this is because payment_complete() has already occurred for these order * * @since 1.0 * @param int|WC_Order $order post IDs or order object to complete the pre-order for * @param string $message optional message to include in 'pre-order completed' email to customer */ public static function complete_pre_order($order, $message = '') { if (!is_object($order)) { $order = new WC_Order($order); } if (!self::can_pre_order_be_changed_to('completed', $order)) { return; } // complete pre-order charged upon release if (WC_Pre_Orders_Order::order_will_be_charged_upon_release($order)) { // update order status to pending so it can be paid by automatic payment, or on pay page by customer if 'pay later' gateway was used $order->update_status('pending'); if (WC_Pre_Orders_Order::order_has_payment_token($order)) { global $woocommerce; // load payment gateways $woocommerce->payment_gateways(); // fire action for payment gateway to charge pre-order do_action('wc_pre_orders_process_pre_order_completion_payment_' . $order->payment_method, $order); } // complete pre-order charged upfront } else { $product = WC_Pre_Orders_Order::get_pre_order_product($order); // update order status to completed or processing - based on same process from WC_Order::payment_complete() if ($product->is_downloadable() && $product->is_virtual() || !apply_filters('woocommerce_order_item_needs_processing', true, $product, $order->id)) { $order->update_status('completed'); } else { $order->update_status('processing'); } } // update pre-order status to completed WC_Pre_Orders_Order::update_pre_order_status($order, 'completed', $message); do_action('wc_pre_orders_pre_order_completed', $order, $message); }