/** * Generates and saves the invoice to the uploads folder. * @param $dest * @return string */ public function save($dest) { if ($this->exists()) { die('Invoice already exists. First delete invoice.'); } // If the invoice is manually deleted from dir, delete data from database. $this->delete(); if ($this->template_options['bewpi_invoice_number_type'] === "sequential_number") { if (!$this->reset_counter() && !$this->new_year_reset()) { $this->number = $this->template_options['bewpi_last_invoice_number'] + 1; } } else { $this->number = $this->order->get_order_number(); } $this->number_of_columns = $this->get_number_of_columns(); $this->colspan = $this->get_colspan(); $this->formatted_number = $this->get_formatted_number(true); $this->year = date('Y'); $this->filename = BEWPI_INVOICES_DIR . (string) $this->year . '/' . $this->formatted_number . '.pdf'; // Template $this->css = $this->get_css(); $this->header = $this->get_header_html(); $this->body = $this->get_body_html(); $this->footer = $this->get_footer_html(); add_post_meta($this->order->id, '_bewpi_invoice_number', $this->number); add_post_meta($this->order->id, '_bewpi_invoice_year', $this->year); $this->template_options['bewpi_last_invoice_number'] = $this->number; $this->template_options['bewpi_last_invoiced_year'] = $this->year; delete_option('bewpi_template_settings'); add_option('bewpi_template_settings', $this->template_options); parent::generate($dest, $this); return $this->filename; }
/** * Get order ID * * @see Pronamic_Pay_PaymentDataInterface::get_order_id() * @return string */ public function get_order_id() { // @see https://github.com/woothemes/woocommerce/blob/v1.6.5.2/classes/class-wc-order.php#L269 $order_id = $this->order->get_order_number(); /* * An '#' charachter can result in the following iDEAL error: * code = SO1000 * message = Failure in system * detail = System generating error: issuer * consumer_message = Paying with iDEAL is not possible. Please try again later or pay another way. * * Or in case of Sisow: * <errorresponse xmlns="https://www.sisow.nl/Sisow/REST" version="1.0.0"> * <error> * <errorcode>TA3230</errorcode> * <errormessage>No purchaseid</errormessage> * </error> * </errorresponse> * * @see http://wcdocs.woothemes.com/user-guide/extensions/functionality/sequential-order-numbers/#add-compatibility * * @see page 30 http://pronamic.nl/wp-content/uploads/2012/09/iDEAL-Merchant-Integratie-Gids-NL.pdf * * The use of characters that are not listed above will not lead to a refusal of a batch or post, but the * character will be changed by Equens (formerly Interpay) to a space, question mark or asterisk. The * same goes for diacritical characters (à, ç, ô, ü, ý etcetera). */ $order_id = str_replace('#', '', $order_id); return $order_id; }
/** * Get Komoju Args for passing to Komoju hosted page * * @param WC_Order $order * @return array */ protected function get_komoju_args($order, $method) { WC_Gateway_Komoju::log('Generating payment form for order ' . $order->get_order_number() . '. Notify URL: ' . $this->notify_url); $params = array("transaction[amount]" => $order->get_subtotal() + $order->get_total_shipping(), "transaction[currency]" => get_woocommerce_currency(), "transaction[customer][email]" => $order->billing_email, "transaction[customer][phone]" => $order->billing_phone, "transaction[customer][given_name]" => $order->billing_first_name, "transaction[customer][family_name]" => $order->billing_last_name, "transaction[external_order_num]" => $this->gateway->get_option('invoice_prefix') . $order->get_order_number() . '-' . $this->request_id, "transaction[return_url]" => $this->gateway->get_return_url($order), "transaction[cancel_url]" => $order->get_cancel_order_url_raw(), "transaction[callback_url]" => $this->notify_url, "transaction[tax]" => strlen($order->get_total_tax()) == 0 ? 0 : $order->get_total_tax(), "timestamp" => time()); WC_Gateway_Komoju::log('Raw parametres: ' . print_r($params, true)); $qs_params = array(); foreach ($params as $key => $val) { $qs_params[] = urlencode($key) . '=' . urlencode($val); } sort($qs_params); $query_string = implode('&', $qs_params); $url = $this->Komoju_endpoint . $method . '/new' . '?' . $query_string; $hmac = hash_hmac('sha256', $url, $this->gateway->secretKey); $query_string .= '&hmac=' . $hmac; return $query_string; }
/** * createOrder * -- * @param $woo_commerce_order_id */ public function createOrder($woo_commerce_order_id) { // Fetch order from WC. $woo_order = new WC_Order($woo_commerce_order_id); // Contact Information $contact_infomation = $this->buildContactInformation($woo_order->billing_company, $woo_order->billing_first_name . " " . $woo_order->billing_last_name, "WC", $woo_order->billing_phone, $woo_order->shipping_first_name . " " . $woo_order->shipping_last_name, $woo_order->billing_email, "", ""); // Transaction Information $transaction_information = $this->buildTransactionInformation(new DateTime(), new DateTime(), new DateTime(), $woo_order->get_order_number(), $woo_order->get_order_number() . "-" . $woo_order->billing_last_name); // Address Information $address_information = $this->buildAddressInformation($woo_order->shipping_address_1, $woo_order->shipping_address_2, $woo_order->shipping_city, $woo_order->shipping_state, $woo_order->shipping_country, $woo_order->shipping_postcode); // Shipping Instructions $shipping_instructions = $this->buildShippingInstructionInformation($woo_order->customer_user, $woo_order->billing_postcode, $this::CARRIER, $this::CARRIER_DESC, $this::CARRIER_MODE, $woo_order->shipping_method_title, $woo_order->customer_note, $woo_order->shipping_postcode, $this::SCAC_CODE); // Extraneous Information. $shipping_info = null; // - not needed in this instance $fulfillment_info = null; // - not needed in this instance // Create new Order for API. $order = new Order(1); // Ship to, Transaction Info, Customer Notes $order->setShipTo($contact_infomation); $order->setTransInfo($transaction_information); $order->setNotes($woo_order->customer_note); // Shipping instructions $order->setShippingInstructions($shipping_instructions); // Order line item array $order_line_item_arr = []; // Loop over woo_commerce_order items, and // fetch products & product information out of every item. foreach ($woo_order->get_items() as $item) { // Retrieve product $product = $woo_order->get_product_from_item($item); // Build new order line item $arr_order = $this->buildOrderLineLitem($product->get_sku(), "", $product->get_stock_quantity(), "", $product->get_dimensions(), new DateTime(), $product->sale_price, "", ""); // Push order line item to [line item arr] array_push($order_line_item_arr, $arr_order); } // Set order line items $order->setOrderLineItems($order_line_item_arr); // Create an ArrayOfOrder object. $aoOrder = new ArrayOfOrder(); $aoOrder->setOrder([$order]); // Execute and return the order action return $this->apiHandler->getClient()->CreateOrders($this->apiHandler->getExtLoginData(), $aoOrder); }
/** * Output the shortcode. * * @access public * @param array $atts * @return void */ public static function output($atts) { global $woocommerce; $woocommerce->nocache(); if (!is_user_logged_in()) { return; } extract(shortcode_atts(array('order_count' => 10), $atts)); $user_id = get_current_user_id(); $order_id = isset($_GET['order']) ? $_GET['order'] : 0; $order = new WC_Order($order_id); if ($order_id == 0) { woocommerce_get_template('myaccount/my-orders.php', array('order_count' => 'all' == $order_count ? -1 : $order_count)); return; } if ($order->user_id != $user_id) { echo '<div class="woocommerce-error">' . __('Invalid order.', 'woocommerce') . ' <a href="' . get_permalink(woocommerce_get_page_id('myaccount')) . '">' . __('My Account →', 'woocommerce') . '</a>' . '</div>'; return; } $status = get_term_by('slug', $order->status, 'shop_order_status'); echo '<p class="order-info">' . sprintf(__('Order <mark class="order-number">%s</mark> made on <mark class="order-date">%s</mark>', 'woocommerce'), $order->get_order_number(), date_i18n(get_option('date_format'), strtotime($order->order_date))) . '. ' . sprintf(__('Order status: <mark class="order-status">%s</mark>', 'woocommerce'), __($status->name, 'woocommerce')) . '.</p>'; $notes = $order->get_customer_order_notes(); if ($notes) { ?> <h2><?php _e('Order Updates', 'woocommerce'); ?> </h2> <ol class="commentlist notes"> <?php foreach ($notes as $note) { ?> <li class="comment note"> <div class="comment_container"> <div class="comment-text"> <p class="meta"><?php echo date_i18n(__('l jS \\of F Y, h:ia', 'woocommerce'), strtotime($note->comment_date)); ?> </p> <div class="description"> <?php echo wpautop(wptexturize($note->comment_content)); ?> </div> <div class="clear"></div> </div> <div class="clear"></div> </div> </li> <?php } ?> </ol> <?php } do_action('woocommerce_view_order', $order_id); }
public function process_payment($order_id) { global $woocommerce; // Get customer order $customer_order = new WC_Order($order_id); // Generate URL $justgiving_qstr = array('amount' => $customer_order->order_total, 'reference' => woogiving_create_ref($order_id), 'currency' => get_woocommerce_currency(), 'exitUrl' => plugin_dir_url(__FILE__) . 'process.php?wg_action=process&wg_order_id=' . str_replace('#', '', $customer_order->get_order_number()) . '&jg_donation_id=JUSTGIVING-DONATION-ID'); $justgiving_url = 'https://www.justgiving.com/' . rawurlencode($this->username) . '/4w350m3/donate/?' . http_build_query($justgiving_qstr); // Redirect to JustGiving return array('result' => 'success', 'redirect' => $justgiving_url); }
function wps_wcc_new_order($order_id) { global $sms, $wps_options; $order = new WC_Order($order_id); if (!$get_mobile) { return; } $sms->to = array(get_option('wp_admin_mobile')); $string = $wps_options['wpsms_wc_no_tt']; $template_vars = array('order_id' => $order_id, 'status' => $order->get_status(), 'order_name' => $order->get_order_number()); $final_message = preg_replace('/%(.*?)%/ime', "\$template_vars['\$1']", $string); $sms->msg = $final_message; $sms->SendSMS(); }
/** * Saved by ajax the order information. */ public function transparent_checkout_ajax() { $settings = get_option('woocommerce_moip_settings'); if ('tc' != $settings['api']) { die; } check_ajax_referer('woocommerce_moip_transparent_checkout', 'security'); $method = $_POST['method']; $order_id = (int) $_POST['order_id']; $order = new WC_Order($order_id); if (function_exists('WC')) { $mailer = WC()->mailer(); } else { global $woocommerce; $mailer = $woocommerce->mailer(); } if ('CartaoCredito' == $method) { // Add payment information. $status = esc_attr(WC_Moip_Messages::translate_status($_POST['status'])); update_post_meta($order_id, 'woocommerce_moip_method', esc_attr($_POST['method'])); update_post_meta($order_id, 'woocommerce_moip_code', esc_attr($_POST['code'])); update_post_meta($order_id, 'woocommerce_moip_status', $status); // Send email with payment information. $message_body = '<p>'; $message_body .= WC_Moip_Messages::credit_cart_message($status, $_POST['code']); $message_body .= '</p>'; $message = $mailer->wrap_message(sprintf(__('Order %s received', 'woocommerce-moip'), $order->get_order_number()), apply_filters('woocommerce_moip_thankyou_creditcard_email_message', $message_body, $order_id)); $mailer->send($order->billing_email, sprintf(__('Order %s received', 'woocommerce-moip'), $order->get_order_number()), $message); } else { if ('DebitoBancario' == $method) { // Add payment information. update_post_meta($order_id, 'woocommerce_moip_method', esc_attr($_POST['method'])); update_post_meta($order_id, 'woocommerce_moip_url', esc_url($_POST['url'])); // Send email with payment information. $url = sprintf('<p><a class="button" href="%1$s" target="_blank">%1$s</a></p>', esc_url($_POST['url'])); $message_body = '<p>'; $message_body .= WC_Moip_Messages::debit_email_message(); $message_body .= '</p>'; $message = $mailer->wrap_message(sprintf(__('Order %s received', 'woocommerce-moip'), $order->get_order_number()), apply_filters('woocommerce_moip_thankyou_debit_email_message', $message_body, $order_id) . $url); $mailer->send($order->billing_email, sprintf(__('Order %s received', 'woocommerce-moip'), $order->get_order_number()), $message); } else { // Add payment information. update_post_meta($order_id, 'woocommerce_moip_method', esc_attr($_POST['method'])); update_post_meta($order_id, 'woocommerce_moip_url', esc_url($_POST['url'])); // Send email with payment information. $url = sprintf('<p><a class="button" href="%1$s" target="_blank">%1$s</a></p>', esc_url($_POST['url'])); $message_body = '<p>'; $message_body .= WC_Moip_Messages::billet_email_message(); $message_body .= '</p>'; $message = $mailer->wrap_message(sprintf(__('Order %s received', 'woocommerce-moip'), $order->get_order_number()), apply_filters('woocommerce_moip_thankyou_billet_email_message', $message_body, $order_id) . $url); $mailer->send($order->billing_email, sprintf(__('Order %s received', 'woocommerce-moip'), $order->get_order_number()), $message); } } die; }
public function offline_payment_notification($order_id, $customer) { global $woocommerce; $order = new WC_Order($order_id); $title = sprintf("Se ha efectuado el pago del pedido %s", $order->get_order_number()); $body_message = "<p style=\"margin:0 0 16px\">Se ha detectado el pago del siguiente pedido:</p><br />" . $this->assemble_email_payment($order); // Email for customer $mail_customer = $woocommerce->mailer(); $message = $mail_customer->wrap_message(sprintf(__('Hola, %s'), $customer), $body_message); $mail_customer->send($order->billing_email, $title, $message); unset($mail_customer); //Email for admin site $mail_admin = $woocommerce->mailer(); $message = $mail_admin->wrap_message(sprintf(__('Pago realizado satisfactoriamente')), $body_message); $mail_admin->send(get_option("admin_email"), $title, $message); unset($mail_admin); }
private function get_next_invoice_number() { // check if user uses the built in WooCommerce order numbers if ($this->template_options['bewpi_invoice_number_type'] !== "sequential_number") { return $this->order->get_order_number(); } // check if user did a counter reset if ($this->template_options['bewpi_reset_counter'] && $this->template_options['bewpi_next_invoice_number'] > 0) { $this->counter_reset = true; // uncheck option to actually change the value $this->template_options['bewpi_reset_counter'] = 0; update_option('bewpi_template_settings', $this->template_options); return $this->template_options['bewpi_next_invoice_number']; } $last_invoice_number = $this->get_max_invoice_number(); return $last_invoice_number == "" ? 1 : (int) $last_invoice_number + 1; }
/** * View order page * * @param int $order_id */ private static function view_order($order_id) { $user_id = get_current_user_id(); $order = new WC_Order($order_id); if (!current_user_can('view_order', $order_id)) { echo '<div class="woocommerce-error">' . __('Invalid order.', 'woocommerce') . ' <a href="' . get_permalink(wc_get_page_id('myaccount')) . '" class="wc-forward">' . __('My Account', 'woocommerce') . '</a>' . '</div>'; return; } $status = get_term_by('slug', $order->status, 'shop_order_status'); echo '<p class="order-info">' . sprintf(__('Order <mark class="order-number">%s</mark> was placed on <mark class="order-date">%s</mark> and is currently <mark class="order-status">%s</mark>.', 'woocommerce'), $order->get_order_number(), date_i18n(get_option('date_format'), strtotime($order->order_date)), __($status->name, 'woocommerce')) . '</p>'; if ($notes = $order->get_customer_order_notes()) { ?> <h2><?php _e('Order Updates', 'woocommerce'); ?> </h2> <ol class="commentlist notes"> <?php foreach ($notes as $note) { ?> <li class="comment note"> <div class="comment_container"> <div class="comment-text"> <p class="meta"><?php echo date_i18n(__('l jS \\o\\f F Y, h:ia', 'woocommerce'), strtotime($note->comment_date)); ?> </p> <div class="description"> <?php echo wpautop(wptexturize($note->comment_content)); ?> </div> <div class="clear"></div> </div> <div class="clear"></div> </div> </li> <?php } ?> </ol> <?php } do_action('woocommerce_view_order', $order_id); }
/** * Process the subscription payment and return the result * * @access public * @param WC_Order $order * @param int $amount * @return array */ public function process_subscription_payment($order, $amount = 0) { global $s4wc; // Can't send to stripe without a value, assume it's good to go. if ($amount === 0) { return true; } // Get customer id $customer = get_user_meta($order->user_id, $s4wc->settings['stripe_db_location'], true); // Set a default name, override with a product name if it exists for Stripe's dashboard $product_name = __('Subscription', 'stripe-for-woocommerce'); $order_items = $order->get_items(); // Grab first subscription name and use it foreach ($order_items as $key => $item) { if (isset($item['subscription_status'])) { $product_name = $item['name']; break; } } // Default charge description $charge_description = sprintf(__('Payment for %s (Order: %s)', 'stripe-for-woocommerce'), $product_name, $order->get_order_number()); // Allow options to be set without modifying sensitive data like amount, currency, etc. $charge_data = apply_filters('s4wc_subscription_charge_data', array(), $order); // Set up basics for charging $charge_data['amount'] = $amount * 100; // amount in cents $charge_data['currency'] = strtolower(get_woocommerce_currency()); $charge_data['customer'] = $customer['customer_id']; $charge_data['card'] = $customer['default_card']; $charge_data['description'] = apply_filters('s4wc_subscription_charge_description', $charge_description, $order); $charge = S4WC_API::create_charge($charge_data); if (isset($charge->id)) { $order->add_order_note(sprintf(__('Subscription paid (%s)', 'stripe-for-woocommerce'), $charge->id)); return $charge; } return false; }
public function process_payment($order_id) { global $woocommerce; $customer_order = new WC_Order($order_id); $environment = $this->environment == "yes" ? 'TRUE' : 'FALSE'; $environment_url = "FALSE" == $environment ? 'https://secure.authorize.net/gateway/transact.dll' : 'https://test.authorize.net/gateway/transact.dll'; $payload = array("x_tran_key" => $this->trans_key, "x_login" => $this->api_login, "x_version" => "3.1", "x_amount" => $customer_order->order_total, "x_card_num" => str_replace(array(' ', '-'), '', $_POST['GP_authorize_gateway-card-number']), "x_card_code" => isset($_POST['GP_authorize_gateway-card-cvc']) ? $_POST['GP_authorize_gateway-card-cvc'] : '', "x_exp_date" => str_replace(array('/', ' '), '', $_POST['GP_authorize_gateway-card-expiry']), "x_type" => 'AUTH_CAPTURE', "x_invoice_num" => str_replace("#", "", $customer_order->get_order_number()), "x_test_request" => $environment, "x_delim_char" => '|', "x_encap_char" => '', "x_delim_data" => "TRUE", "x_relay_response" => "FALSE", "x_method" => "CC", "x_first_name" => $customer_order->billing_first_name, "x_last_name" => $customer_order->billing_last_name, "x_address" => $customer_order->billing_address_1, "x_city" => $customer_order->billing_city, "x_state" => $customer_order->billing_state, "x_zip" => $customer_order->billing_postcode, "x_country" => $customer_order->billing_country, "x_phone" => $customer_order->billing_phone, "x_email" => $customer_order->billing_email, "x_ship_to_first_name" => $customer_order->shipping_first_name, "x_ship_to_last_name" => $customer_order->shipping_last_name, "x_ship_to_company" => $customer_order->shipping_company, "x_ship_to_address" => $customer_order->shipping_address_1, "x_ship_to_city" => $customer_order->shipping_city, "x_ship_to_country" => $customer_order->shipping_country, "x_ship_to_state" => $customer_order->shipping_state, "x_ship_to_zip" => $customer_order->shipping_postcode, "x_cust_id" => $customer_order->user_id, "x_customer_ip" => $_SERVER['REMOTE_ADDR']); $response = wp_remote_post($environment_url, array('method' => 'POST', 'body' => http_build_query($payload), 'timeout' => 90, 'sslverify' => false)); if (is_wp_error($response)) { do_action('gp_order_online_completed_failed', $response); } if (empty($response['body'])) { do_action('gp_order_online_completed_failed', $response); } $response_body = wp_remote_retrieve_body($response); // Parse the response into something we can read foreach (preg_split("/\r?\n/", $response_body) as $line) { $resp = explode("|", $line); } // Get the values we need $r['response_code'] = $resp[0]; $r['response_sub_code'] = $resp[1]; $r['response_reason_code'] = $resp[2]; $r['response_reason_text'] = $resp[3]; if ($r['response_code'] == 1 || $r['response_code'] == 4) { $customer_order->add_order_note(__('Authorize.net payment completed.', 'GP_authorize_gateway')); if ($this->mark_order == 'yes') { $woocommerce->cart->empty_cart(); $customer_order->payment_complete(); $customer_order->update_status('completed'); } do_action('gp_order_online_completed_successfully', $response); return array('result' => 'success', 'redirect' => $this->get_return_url($customer_order)); } else { do_action('gp_error_occurred', $r['response_reason_text']); } }
/** * Hosted payment args. * * @param WC_Order $order * * @return array */ protected function get_hosted_payments_args($order) { $args = apply_filters('woocommerce_simplify_commerce_hosted_args', array('sc-key' => $this->public_key, 'amount' => $order->get_total() * 100, 'reference' => $order->get_id(), 'name' => esc_html(get_bloginfo('name', 'display')), 'description' => sprintf(__('Order #%s', 'woocommerce'), $order->get_order_number()), 'receipt' => 'false', 'color' => $this->modal_color, 'redirect-url' => WC()->api_request_url('WC_Gateway_Simplify_Commerce'), 'address' => $order->get_billing_address_1() . ' ' . $order->get_billing_address_2(), 'address-city' => $order->get_billing_city(), 'address-state' => $order->get_billing_state(), 'address-zip' => $order->get_billing_postcode(), 'address-country' => $order->get_billing_country(), 'operation' => 'create.token'), $order->get_id()); return $args; }
/** * ecommerce tracking with piwik. * * @access public * @param int $order_id * @return void */ function woocommerce_ecommerce_tracking_piwik($order_id) { global $woocommerce; // Don't track admin if (current_user_can('manage_options')) { return; } // Call the Piwik ecommerce function if WP-Piwik is configured to add tracking codes to the page $wp_piwik_global_settings = get_option('wp-piwik_global-settings'); // Return if Piwik settings are not here, or if global is not set if (!isset($wp_piwik_global_settings['add_tracking_code']) || !$wp_piwik_global_settings['add_tracking_code']) { return; } if (!isset($GLOBALS['wp_piwik'])) { return; } // Get the order and get tracking code $order = new WC_Order($order_id); ob_start(); ?> try { // Add order items <?php if ($order->get_items()) { foreach ($order->get_items() as $item) { $_product = $order->get_product_from_item($item); ?> piwikTracker.addEcommerceItem( "<?php echo esc_js($_product->get_sku()); ?> ", // (required) SKU: Product unique identifier "<?php echo esc_js($item['name']); ?> ", // (optional) Product name "<?php if (isset($_product->variation_data)) { echo esc_js(woocommerce_get_formatted_variation($_product->variation_data, true)); } ?> ", // (optional) Product category. You can also specify an array of up to 5 categories eg. ["Books", "New releases", "Biography"] <?php echo esc_js($order->get_item_total($item)); ?> , // (recommended) Product price <?php echo esc_js($item['qty']); ?> // (optional, default to 1) Product quantity ); <?php } } ?> // Track order piwikTracker.trackEcommerceOrder( "<?php echo esc_js($order->get_order_number()); ?> ", // (required) Unique Order ID <?php echo esc_js($order->get_total()); ?> , // (required) Order Revenue grand total (includes tax, shipping, and subtracted discount) false, // (optional) Order sub total (excludes shipping) <?php echo esc_js($order->get_total_tax()); ?> , // (optional) Tax amount <?php echo esc_js($order->get_shipping()); ?> , // (optional) Shipping amount false // (optional) Discount offered (set to false for unspecified parameter) ); } catch( err ) {} <?php $code = ob_get_clean(); $woocommerce->add_inline_js($code); }
/** * Format the orders with just the products we want * * @param object $orders * @param int $product_id * * @return array */ public function format_order_details($orders, $product_id) { $body = $items = array(); $product = get_product($product_id)->get_title(); foreach ($orders as $i => $order) { $i = $order->order_id; $order = new WC_Order($i); $body[$i] = array('order_number' => $order->get_order_number(), 'product' => $product, 'name' => $order->shipping_first_name . ' ' . $order->shipping_last_name, 'address' => $order->shipping_address_1, 'city' => $order->shipping_city, 'state' => $order->shipping_state, 'zip' => $order->shipping_postcode, 'email' => $order->billing_email, 'date' => $order->order_date, 'comments' => wptexturize($order->customer_note)); if (!$this->can_view_emails) { unset($body[$i]['email']); } $items[$i]['total_qty'] = 0; foreach ($order->get_items() as $line_id => $item) { if ($item['product_id'] != $product_id && $item['variation_id'] != $product_id) { continue; } $items[$i]['items'][] = $item; $items[$i]['total_qty'] += $item['qty']; } } return array('body' => $body, 'items' => $items, 'product_id' => $product_id); }
/** * Backorder notification email. * * @access public * @param mixed $args * @return void */ function backorder($args) { $defaults = array('product' => '', 'quantity' => '', 'order_id' => ''); $args = wp_parse_args($args, $defaults); extract($args); if (!$product || !$quantity) { return; } $blogname = wp_specialchars_decode(get_option('blogname'), ENT_QUOTES); $subject = apply_filters('woocommerce_email_subject_backorder', sprintf('[%s] %s', $blogname, __('Product Backorder', 'woocommerce')), $product); $sku = $product->sku ? ' (' . $product->sku . ')' : ''; if (!empty($product->variation_id)) { $title = sprintf(__('Variation #%s of %s', 'woocommerce'), $product->variation_id, get_the_title($product->id)) . $sku; } else { $title = sprintf(__('Product #%s - %s', 'woocommerce'), $product->id, get_the_title($product->id)) . $sku; } $order = new WC_Order($order_id); $message = sprintf(__('%s units of %s have been backordered in order %s.', 'woocommerce'), $quantity, $title, $order->get_order_number()); // CC, BCC, additional headers $headers = apply_filters('woocommerce_email_headers', '', 'backorder', $args); // Attachments $attachments = apply_filters('woocommerce_email_attachments', array(), 'backorder', $args); // Send the mail wp_mail(get_option('woocommerce_stock_email_recipient'), $subject, $message, $headers, $attachments); }
/** * Hosted payment args. * * @param WC_Order $order * * @return array */ protected function get_hosted_payments_args($order) { $args = apply_filters('woocommerce_simplify_commerce_hosted_args', array('sc-key' => $this->public_key, 'amount' => $order->order_total * 100, 'reference' => $order->id, 'name' => esc_html(get_bloginfo('name', 'display')), 'description' => sprintf(__('Order #%s', 'woocommerce'), $order->get_order_number()), 'receipt' => 'false', 'color' => $this->modal_color, 'redirect-url' => WC()->api_request_url('WC_Gateway_Simplify_Commerce')), $order->id); return $args; }
/** * Get PayPal Args for passing to PP * * @param WC_Order $order * @return array */ protected function get_paypal_args($order) { WC_Gateway_Paypal::log('Generating payment form for order ' . $order->get_order_number() . '. Notify URL: ' . $this->notify_url); return apply_filters('woocommerce_paypal_args', array_merge(array('cmd' => '_cart', 'business' => $this->gateway->get_option('email'), 'no_note' => 1, 'currency_code' => get_woocommerce_currency(), 'charset' => 'utf-8', 'rm' => is_ssl() ? 2 : 1, 'upload' => 1, 'return' => esc_url(add_query_arg('utm_nooverride', '1', $this->gateway->get_return_url($order))), 'cancel_return' => esc_url($order->get_cancel_order_url()), 'page_style' => $this->gateway->get_option('page_style'), 'paymentaction' => $this->gateway->get_option('paymentaction'), 'bn' => 'WooThemes_Cart', 'invoice' => $this->gateway->get_option('invoice_prefix') . $order->get_order_number(), 'custom' => json_encode(array('order_id' => $order->id, 'order_key' => $order->order_key)), 'notify_url' => $this->notify_url, 'first_name' => $order->billing_first_name, 'last_name' => $order->billing_last_name, 'company' => $order->billing_company, 'address1' => $order->billing_address_1, 'address2' => $order->billing_address_2, 'city' => $order->billing_city, 'state' => $this->get_paypal_state($order->billing_country, $order->billing_state), 'zip' => $order->billing_postcode, 'country' => $order->billing_country, 'email' => $order->billing_email), $this->get_phone_number_args($order), $this->get_shipping_args($order), $this->get_line_item_args($order)), $order); }
/** * Outputs the pay page - payment gateways can hook in here to show payment forms etc **/ function woocommerce_pay() { global $woocommerce; $woocommerce->nocache(); do_action('before_woocommerce_pay'); $woocommerce->show_messages(); if (isset($_GET['pay_for_order']) && isset($_GET['order']) && isset($_GET['order_id'])) { // Pay for existing order $order_key = urldecode($_GET['order']); $order_id = (int) $_GET['order_id']; $order = new WC_Order($order_id); if ($order->id == $order_id && $order->order_key == $order_key && in_array($order->status, array('pending', 'failed'))) { // Set customer location to order location if ($order->billing_country) { $woocommerce->customer->set_country($order->billing_country); } if ($order->billing_state) { $woocommerce->customer->set_state($order->billing_state); } if ($order->billing_postcode) { $woocommerce->customer->set_postcode($order->billing_postcode); } // Show form woocommerce_get_template('checkout/form-pay.php', array('order' => $order)); } elseif (!in_array($order->status, array('pending', 'failed'))) { $woocommerce->add_error(__('Your order has already been paid for. Please contact us if you need assistance.', 'woocommerce')); $woocommerce->show_messages(); } else { $woocommerce->add_error(__('Invalid order.', 'woocommerce')); $woocommerce->show_messages(); } } else { // Pay for order after checkout step if (isset($_GET['order'])) { $order_id = $_GET['order']; } else { $order_id = 0; } if (isset($_GET['key'])) { $order_key = $_GET['key']; } else { $order_key = ''; } if ($order_id > 0) { $order = new WC_Order($order_id); if ($order->order_key == $order_key && in_array($order->status, array('pending', 'failed'))) { ?> <ul class="order_details"> <li class="order"> <?php _e('Order:', 'woocommerce'); ?> <strong><?php echo $order->get_order_number(); ?> </strong> </li> <li class="date"> <?php _e('Date:', 'woocommerce'); ?> <strong><?php echo date_i18n(get_option('date_format'), strtotime($order->order_date)); ?> </strong> </li> <li class="total"> <?php _e('Total:', 'woocommerce'); ?> <strong><?php echo $order->get_formatted_order_total(); ?> </strong> </li> <?php if ($order->payment_method_title) { ?> <li class="method"> <?php _e('Payment method:', 'woocommerce'); ?> <strong><?php echo $order->payment_method_title; ?> </strong> </li> <?php } ?> </ul> <?php do_action('woocommerce_receipt_' . $order->payment_method, $order_id); ?> <div class="clear"></div> <?php } elseif (!in_array($order->status, array('pending', 'failed'))) { $woocommerce->add_error(__('Your order has already been paid for. Please contact us if you need assistance.', 'woocommerce')); $woocommerce->show_messages(); } } else { $woocommerce->add_error(__('Invalid order.', 'woocommerce')); $woocommerce->show_messages(); } } do_action('after_woocommerce_pay'); }
/** * Update order status. * * @param array $posted PagSeguro post data. */ public function update_order_status($posted) { if (isset($posted->reference)) { $order_id = (int) str_replace($this->invoice_prefix, '', $posted->reference); $order = new WC_Order($order_id); // Checks whether the invoice number matches the order. // If true processes the payment. if ($order->id === $order_id) { if ('yes' == $this->debug) { $this->log->add($this->id, 'PagSeguro payment status for order ' . $order->get_order_number() . ' is: ' . intval($posted->status)); } // Order details. $order_details = array('type' => '', 'method' => '', 'installments' => '', 'link' => ''); if (isset($posted->code)) { update_post_meta($order->id, __('PagSeguro Transaction ID', 'woocommerce-pagseguro'), (string) $posted->code); } if (isset($posted->sender->email)) { update_post_meta($order->id, __('Payer email', 'woocommerce-pagseguro'), (string) $posted->sender->email); } if (isset($posted->sender->name)) { update_post_meta($order->id, __('Payer name', 'woocommerce-pagseguro'), (string) $posted->sender->name); } if (isset($posted->paymentMethod->type)) { $order_details['type'] = intval($posted->paymentMethod->type); update_post_meta($order->id, __('Payment type', 'woocommerce-pagseguro'), $this->api->get_payment_name_by_type($order_details['type'])); } if (isset($posted->paymentMethod->code)) { $order_details['method'] = $this->api->get_payment_method_name(intval($posted->paymentMethod->code)); update_post_meta($order->id, __('Payment method', 'woocommerce-pagseguro'), $order_details['method']); } if (isset($posted->installmentCount)) { $order_details['installments'] = (string) $posted->installmentCount; update_post_meta($order->id, __('Installments', 'woocommerce-pagseguro'), $order_details['installments']); } if (isset($posted->paymentLink)) { $order_details['link'] = (string) $posted->paymentLink; update_post_meta($order->id, __('Payment url', 'woocommerce-pagseguro'), $order_details['link']); } // Save/update payment information for transparente checkout. if ('transparent' == $this->method) { update_post_meta($order->id, '_wc_pagseguro_payment_data', $order_details); } switch (intval($posted->status)) { case 1: $order->update_status('on-hold', __('PagSeguro: The buyer initiated the transaction, but so far the PagSeguro not received any payment information.', 'woocommerce-pagseguro')); break; case 2: $order->update_status('on-hold', __('PagSeguro: Payment under review.', 'woocommerce-pagseguro')); break; case 3: $order->add_order_note(__('PagSeguro: Payment approved.', 'woocommerce-pagseguro')); // For WooCommerce 2.2 or later. add_post_meta($order->id, '_transaction_id', (string) $posted->code, true); // Changing the order for processing and reduces the stock. $order->payment_complete(); break; case 4: $order->add_order_note(__('PagSeguro: Payment completed and credited to your account.', 'woocommerce-pagseguro')); break; case 5: $order->update_status('on-hold', __('PagSeguro: Payment came into dispute.', 'woocommerce-pagseguro')); $this->send_email(sprintf(__('Payment for order %s came into dispute', 'woocommerce-pagseguro'), $order->get_order_number()), __('Payment in dispute', 'woocommerce-pagseguro'), sprintf(__('Order %s has been marked as on-hold, because the payment came into dispute in PagSeguro.', 'woocommerce-pagseguro'), $order->get_order_number())); break; case 6: $order->update_status('refunded', __('PagSeguro: Payment refunded.', 'woocommerce-pagseguro')); $this->send_email(sprintf(__('Payment for order %s refunded', 'woocommerce-pagseguro'), $order->get_order_number()), __('Payment refunded', 'woocommerce-pagseguro'), sprintf(__('Order %s has been marked as refunded by PagSeguro.', 'woocommerce-pagseguro'), $order->get_order_number())); break; case 7: $order->update_status('cancelled', __('PagSeguro: Payment canceled.', 'woocommerce-pagseguro')); break; default: // No action xD. break; } } else { if ('yes' == $this->debug) { $this->log->add($this->id, 'Error: Order Key does not match with PagSeguro reference.'); } } } }
</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' ); $item_count = $order->get_item_count(); ?><tr class="order"> <td class="order-number"> <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> </td> <td class="order-date"> <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-status" style="text-align:left; white-space:nowrap;"> <?php echo ucfirst( __( $status->name, 'woocommerce' ) ); ?> </td> <td class="order-total"> <?php echo sprintf( _n( '%s for %s item', '%s for %s items', $item_count, 'woocommerce' ), $order->get_formatted_order_total(), $item_count ); ?> </td> <td class="order-actions"> <?php $actions = array();
/** * Process the subscription * * Saves the card, if needed, and activates the subscription. This is called when the subscription is first purchased * * @param int $order_id * * @return array * * @since 0.6.0 */ public function process_subscription($order_id) { global $woocommerce; $order = new WC_Order($order_id); $user_id = get_current_user_id(); $profile_id = $this->profiles_enabled ? $this->saved_cards->get_user_profile_id($user_id) : false; $token = isset($_POST['card_connect_token']) ? wc_clean($_POST['card_connect_token']) : false; $card_name = isset($_POST['card_connect-card-name']) ? wc_clean($_POST['card_connect-card-name']) : false; $store_new_card = isset($_POST['card_connect-save-card']) ? wc_clean($_POST['card_connect-save-card']) : false; $saved_card_id = isset($_POST['card_connect-cards']) ? wc_clean($_POST['card_connect-cards']) : false; $card_alias = isset($_POST['card_connect-new-card-alias']) ? wc_clean($_POST['card_connect-new-card-alias']) : false; if (!$token && !$saved_card_id) { wc_add_notice(__('Payment error: ', 'woothemes') . 'Please make sure your card details have been entered correctly and that your browser supports JavaScript.', 'error'); return; } $request = array('merchid' => $this->api_credentials['mid'], 'cvv2' => wc_clean($_POST['card_connect-card-cvc']), 'amount' => $order->order_total * 100, 'currency' => "USD", 'orderid' => sprintf(__('%s - Order #%s', 'woocommerce'), esc_html(get_bloginfo('name', 'display')), $order->get_order_number()), 'name' => $card_name ? $card_name : trim($order->billing_first_name . ' ' . $order->billing_last_name), 'street' => $order->billing_address_1, 'city' => $order->billing_city, 'region' => $order->billing_state, 'country' => $order->billing_country, 'postal' => $order->billing_postcode, 'capture' => $this->mode === 'capture' ? 'Y' : 'N'); if ($saved_card_id) { // Payment is using a stored card, no token or account number to pass $request['profile'] = "{$profile_id}/{$saved_card_id}"; } else { // Either a basic purchase or adding a new card. Either way, include the expiration date $request['expiry'] = preg_replace('/[^\\d]/i', '', wc_clean($_POST['card_connect-card-expiry'])); // Adding an additional card to an existing profile -- This requires a separate API call, handled in `add_account_to_profile` if ($profile_id) { $request['profile'] = $profile_id; // The `token` key isn't used by the Auth/Capture service however it's ignored if it's passed as `account` when updating profiles $request['token'] = $token; // Get the new card's account id, remove the token key $new_account_id = $this->saved_cards->add_account_to_profile($user_id, $card_alias, $request); unset($request['token']); // Overwrite the profile field with the `profile/acctid` format required by the Auth/Capture service $request['profile'] = "{$profile_id}/{$new_account_id}"; // Adding a new card, no existing profile } else { $request['profile'] = 'Y'; $request['account'] = $token; } } //Authorizes transaction to be processed if (!is_null($this->get_cc_client())) { $response = $this->get_cc_client()->authorizeTransaction($request); } else { wc_add_notice(__('Payment error: ', 'woothemes') . 'CardConnect is not configured! ', 'error'); $order->add_order_note('CardConnect is not configured!'); return; } // 'A' response is for accepted if ('A' === $response['respstat']) { // Need to verify customer data before marking complete $order_verification = $this->verify_customer_data($response); if (!$order_verification['is_valid']) { $request = array('merchid' => $this->api_credentials['mid'], 'currency' => 'USD', 'retref' => $response['retref']); if (!is_null($this->get_cc_client())) { $void_response = $this->get_cc_client()->voidTransaction($request); } else { wc_add_notice(__('Payment error: ', 'woothemes') . 'CardConnect is not configured! ', 'error'); $order->add_order_note('CardConnect is not configured!'); return; } if ($void_response['authcode'] === 'REVERS') { $order->update_status('failed', __('Payment Failed', 'cardconnect-payment-gateway')); foreach ($order_verification['errors'] as $error) { $order->add_order_note(sprintf(__($error, 'woocommerce'))); wc_add_notice(__('Payment error: ', 'woothemes') . $error, 'error'); } return; } } // Mark order complete and begin completion process $order->payment_complete($response['retref']); update_post_meta($order_id, '_transaction_id', $response['retref']); // Reduce stock levels $order->reduce_order_stock(); // Remove cart $woocommerce->cart->empty_cart(); $order->add_order_note(sprintf(__('CardConnect payment approved (ID: %s, Authcode: %s)', 'woocommerce'), $response['retref'], $response['authcode'])); // First time this customer has saved a card, pull the response fields and store in user meta if (!$saved_card_id && !$profile_id) { $this->saved_cards->set_user_profile_id($user_id, $response['profileid']); $this->saved_cards->save_user_card($user_id, array($response['acctid'] => $card_alias)); } // Activate the subscription WC_Subscriptions_Manager::activate_subscriptions_for_order($order); // Return thankyou redirect return array('result' => 'success', 'redirect' => $this->get_return_url($order)); } else { if ('C' === $response['respstat']) { wc_add_notice(__('Payment error: ', 'woothemes') . 'Order Declined : ' . $response['resptext'], 'error'); $order->add_order_note(sprintf(__('CardConnect declined transaction. Response: %s', 'woocommerce'), $response['resptext'])); } else { wc_add_notice(__('Payment error: ', 'woothemes') . 'An error prevented this transaction from completing. Please confirm your information and try again.', 'error'); $order->add_order_note(sprintf(__('CardConnect failed transaction. Response: %s', 'woocommerce'), $response['resptext'])); } } $order->update_status('failed', __('Payment Failed', 'cardconnect-payment-gateway')); return; }
/** * process the payment and return the result * @param int $order_id * @return array */ public function process_payment($order_id) { global $woocommerce; $order = new WC_Order($order_id); $ccfields = $this->getCardFields(); $isLiveSite = ($this->eway_sandbox != 'yes'); if ($this->eway_stored == 'yes') $eway = new EwayPaymentsStoredPayment($this->eway_customerid, $isLiveSite); else $eway = new EwayPaymentsPayment($this->eway_customerid, $isLiveSite); $eway->invoiceDescription = get_bloginfo('name'); $eway->invoiceReference = $order->get_order_number(); // customer invoice reference $eway->transactionNumber = $order_id; // transaction reference $eway->cardHoldersName = $ccfields['eway_card_name']; $eway->cardNumber = strtr($ccfields['eway_card_number'], array(' ' => '', '-' => '')); $eway->cardExpiryMonth = $ccfields['eway_expiry_month']; $eway->cardExpiryYear = $ccfields['eway_expiry_year']; $eway->cardVerificationNumber = $ccfields['eway_cvn']; $eway->firstName = $order->billing_first_name; $eway->lastName = $order->billing_last_name; $eway->emailAddress = $order->billing_email; $eway->postcode = $order->billing_postcode; // for Beagle (free) security if ($this->eway_beagle == 'yes') { $eway->customerCountryCode = $order->billing_country; } // convert WooCommerce country code into country name $billing_country = $order->billing_country; if (isset($woocommerce->countries->countries[$billing_country])) { $billing_country = $woocommerce->countries->countries[$billing_country]; } // aggregate street, city, state, country into a single string $parts = array ( $order->billing_address_1, $order->billing_address_2, $order->billing_city, $order->billing_state, $billing_country, ); $eway->address = implode(', ', array_filter($parts, 'strlen')); // use cardholder name for last name if no customer name entered if (empty($eway->firstName) && empty($eway->lastName)) { $eway->lastName = $eway->cardHoldersName; } // allow plugins/themes to modify invoice description and reference, and set option fields $eway->invoiceDescription = apply_filters('woocommerce_eway_invoice_desc', $eway->invoiceDescription, $order_id); $eway->invoiceReference = apply_filters('woocommerce_eway_invoice_ref', $eway->invoiceReference, $order_id); $eway->option1 = apply_filters('woocommerce_eway_option1', '', $order_id); $eway->option2 = apply_filters('woocommerce_eway_option2', '', $order_id); $eway->option3 = apply_filters('woocommerce_eway_option3', '', $order_id); // if live, pass through amount exactly, but if using test site, round up to whole dollars or eWAY will fail $total = $order->order_total; $eway->amount = $isLiveSite ? $total : ceil($total); try { $response = $eway->processPayment(); if ($response->status) { // transaction was successful, so record details and complete payment update_post_meta($order_id, 'Transaction ID', $response->transactionNumber); if (!empty($response->authCode)) { update_post_meta($order_id, 'Authcode', $response->authCode); } if (!empty($response->beagleScore)) { update_post_meta($order_id, 'Beagle score', $response->beagleScore); } if ($this->eway_stored == 'yes') { // payment hasn't happened yet, so record status as 'on-hold' and reduce stock in anticipation $order->reduce_order_stock(); $order->update_status('on-hold', 'Awaiting stored payment'); unset($_SESSION['order_awaiting_payment']); } else { $order->payment_complete(); } $woocommerce->cart->empty_cart(); $result = array( 'result' => 'success', 'redirect' => $this->get_return_url($order), ); } else { // transaction was unsuccessful, so record transaction number and the error $order->update_status('failed', nl2br(esc_html($response->error))); wc_add_notice(nl2br(esc_html($response->error)), 'error'); $result = array('result' => 'failure'); } } catch (EwayPaymentsException $e) { // an exception occured, so record the error $order->update_status('failed', nl2br(esc_html($e->getMessage()))); wc_add_notice(nl2br(esc_html($e->getMessage())), 'error'); $result = array('result' => 'failure'); } return $result; }
public function meta_box_inner($post) { wp_nonce_field('wc_bookings_details_meta_box', 'wc_bookings_details_meta_box_nonce'); // Scripts. wp_enqueue_script('ajax-chosen'); wp_enqueue_script('chosen'); wp_enqueue_script('jquery-ui-datepicker'); $customer_id = get_post_meta($post->ID, '_booking_customer_id', true); $order_parent_id = apply_filters('woocommerce_order_number', _x('#', 'hash before order number', 'woocommerce-bookings') . $post->post_parent, $post->post_parent); ?> <style type="text/css"> #post-body-content, #titlediv, #major-publishing-actions, #minor-publishing-actions, #visibility, #submitdiv { display:none } </style> <div class="panel-wrap woocommerce"> <div id="booking_data" class="panel"> <h2><?php _e('Booking Details', 'woocommerce-bookings'); ?> </h2> <p class="booking_number"><?php printf(__('Booking number: #%s.', 'woocommerce-bookings'), esc_html($post->ID)); if ($post->post_parent) { $order = new WC_Order($post->post_parent); printf(' ' . __('Order number: %s.', 'woocommerce-bookings'), '<a href="' . admin_url('post.php?post=' . absint($post->post_parent) . '&action=edit') . '">' . esc_html($order->get_order_number()) . '</a>'); } ?> </p> <div class="booking_data_column_container"> <div class="booking_data_column"> <h4><?php _e('General Details', 'woocommerce-bookings'); ?> </h4> <p class="form-field form-field-wide"> <label for="_booking_order_id"><?php _e('Order ID:', 'woocommerce-bookings'); ?> </label> <select id="_booking_order_id" name="_booking_order_id" class="ajax_chosen_select_booking_order_id" data-placeholder="<?php _e('Select an order…', 'woocommerce-bookings'); ?> "> <?php if ($post->post_parent) { echo '<option value="' . esc_attr($post->post_parent) . '" ' . selected(1, 1, false) . '>' . $order_parent_id . ' – ' . esc_html(get_the_title($post->post_parent)) . '</option>'; } ?> </select> </p> <p class="form-field form-field-wide"><label for="booking_date"><?php _e('Date created:', 'woocommerce-bookings'); ?> </label> <input type="text" class="date-picker-field" name="booking_date" id="booking_date" maxlength="10" value="<?php echo date_i18n('Y-m-d', strtotime($post->post_date)); ?> " pattern="[0-9]{4}-(0[1-9]|1[012])-(0[1-9]|1[0-9]|2[0-9]|3[01])" /> @ <input type="text" class="hour" placeholder="<?php _e('h', 'woocommerce-bookings'); ?> " name="booking_date_hour" id="booking_date_hour" maxlength="2" size="2" value="<?php echo date_i18n('H', strtotime($post->post_date)); ?> " pattern="\-?\d+(\.\d{0,})?" />:<input type="text" class="minute" placeholder="<?php _e('m', 'woocommerce-bookings'); ?> " name="booking_date_minute" id="booking_date_minute" maxlength="2" size="2" value="<?php echo date_i18n('i', strtotime($post->post_date)); ?> " pattern="\-?\d+(\.\d{0,})?" /> </p> <?php $statuses = array('unpaid' => __('unpaid', 'woocommerce-bookings'), 'pending' => __('pending', 'woocommerce-bookings'), 'confirmed' => __('confirmed', 'woocommerce-bookings'), 'paid' => __('paid', 'woocommerce-bookings'), 'cancelled' => __('cancelled', 'woocommerce-bookings'), 'complete' => __('complete', 'woocommerce-bookings')); ?> <p class="form-field form-field-wide"> <label for="_booking_status"><?php _e('Booking Status:', 'woocommerce-bookings'); ?> </label> <select id="_booking_status" name="_booking_status"> <?php foreach ($statuses as $key => $value) { echo '<option value="' . esc_attr($key) . '" ' . selected($key, $post->post_status, false) . '>' . esc_html__($value, 'woocommerce-bookings') . '</option>'; } ?> </select> </p> <p class="form-field form-field-wide"> <label for="_booking_customer_id"><?php _e('Customer:', 'woocommerce-bookings'); ?> </label> <select id="_booking_customer_id" name="_booking_customer_id" class="ajax_chosen_select_customer"> <option value=""><?php _e('Guest', 'woocommerce-bookings'); ?> </option> <?php if ($customer_id) { $user = get_user_by('id', $customer_id); echo '<option value="' . esc_attr($user->ID) . '" ' . selected(1, 1, false) . '>' . esc_html($user->display_name) . ' (#' . absint($user->ID) . ' – ' . esc_html($user->user_email) . ')</option>'; } ?> </select> </p> <?php do_action('woocommerce_admin_booking_data_after_booking_details', $post->ID); ?> </div> <div class="booking_data_column"> <h4><?php _e('Booking Specification', 'woocommerce-bookings'); ?> </h4> <?php $bookable_products = array('' => __('N/A', 'woocommerce-bookings')); $products = WC_Bookings_Admin::get_booking_products(); foreach ($products as $product) { $bookable_products[$product->ID] = $product->post_title; $resources = wc_booking_get_product_resources($product->ID); foreach ($resources as $resource) { $bookable_products[$product->ID . '=>' . $resource->ID] = ' ' . $resource->post_title; } } $product_id = get_post_meta($post->ID, '_booking_product_id', true); $resource_id = get_post_meta($post->ID, '_booking_resource_id', true); woocommerce_wp_select(array('id' => 'product_or_resource_id', 'label' => __('Booked Product', 'woocommerce-bookings'), 'options' => $bookable_products, 'value' => $resource_id ? $product_id . '=>' . $resource_id : $product_id)); woocommerce_wp_text_input(array('id' => '_booking_parent_id', 'label' => __('Parent Booking ID', 'woocommerce-bookings'), 'placeholder' => 'N/A')); $persons = get_post_meta($post->ID, '_booking_persons', true); if (!empty($persons) && is_array($persons)) { echo '<br class="clear" />'; echo '<h4>' . __('Person(s)', 'woocommerce-bookings') . '</h4>'; foreach ($persons as $person_id => $person_count) { woocommerce_wp_text_input(array('id' => '_booking_person_' . $person_id, 'label' => get_the_title($person_id), 'placeholder' => '0', 'value' => $person_count, 'wrapper_class' => 'booking-person')); } } ?> </div> <div class="booking_data_column"> <h4><?php _e('Booking Date/Time', 'woocommerce-bookings'); ?> </h4> <?php woocommerce_wp_text_input(array('id' => 'booking_start_date', 'label' => __('Start date', 'woocommerce-bookings'), 'placeholder' => 'yyyy-mm-dd', 'value' => date('Y-m-d', strtotime(get_post_meta($post->ID, '_booking_start', true))), 'class' => 'date-picker-field')); woocommerce_wp_text_input(array('id' => 'booking_end_date', 'label' => __('End date', 'woocommerce-bookings'), 'placeholder' => 'yyyy-mm-dd', 'value' => date('Y-m-d', strtotime(get_post_meta($post->ID, '_booking_end', true))), 'class' => 'date-picker-field')); woocommerce_wp_checkbox(array('id' => '_booking_all_day', 'label' => __('All day', 'woocommerce-bookings'), 'description' => __('Check this box if the booking is for all day.', 'woocommerce-bookings'), 'value' => get_post_meta($post->ID, '_booking_all_day', true) ? 'yes' : 'no')); woocommerce_wp_text_input(array('id' => 'booking_start_time', 'label' => __('Start time', 'woocommerce-bookings'), 'placeholder' => 'hh:mm', 'value' => date('H:i', strtotime(get_post_meta($post->ID, '_booking_start', true))), 'class' => 'datepicker')); woocommerce_wp_text_input(array('id' => 'booking_end_time', 'label' => __('End time', 'woocommerce-bookings'), 'placeholder' => 'hh:mm', 'value' => date('H:i', strtotime(get_post_meta($post->ID, '_booking_end', true))))); ?> </div> </div> <div class="clear"></div> </div> <?php wc_enqueue_js("\n\t\t\t\t\$( '#_booking_all_day' ).change( function () {\n\t\t\t\t\tif ( \$( this ).is( ':checked' ) ) {\n\t\t\t\t\t\t\$( '#booking_start_time, #booking_end_time' ).closest( 'p' ).hide();\n\t\t\t\t\t} else {\n\t\t\t\t\t\t\$( '#booking_start_time, #booking_end_time' ).closest( 'p' ).show();\n\t\t\t\t\t}\n\t\t\t\t}).change();\n\n\t\t\t\t\$( 'select#_booking_order_id' ).ajaxChosen({\n\t\t\t\t\tmethod: 'GET',\n\t\t\t\t\turl: '" . admin_url('admin-ajax.php') . "',\n\t\t\t\t\tdataType: 'json',\n\t\t\t\t\tafterTypeDelay: 100,\n\t\t\t\t\tminTermLength: 1,\n\t\t\t\t\tdata: {\n\t\t\t\t\t\taction: 'wc_bookings_json_search_order',\n\t\t\t\t\t\tsecurity: '" . wp_create_nonce('search-booking-order') . "'\n\t\t\t\t\t}\n\t\t\t\t}, function ( data ) {\n\n\t\t\t\t\tvar orders = {};\n\n\t\t\t\t\t\$.each( data, function ( i, val ) {\n\t\t\t\t\t\torders[i] = val;\n\t\t\t\t\t});\n\n\t\t\t\t\treturn orders;\n\t\t\t\t});\n\n\t\t\t\t\$( 'select#_booking_status' ).chosen({\n\t\t\t\t\tdisable_search: true\n\t\t\t\t});\n\n\t\t\t\t\$( 'select.ajax_chosen_select_customer' ).ajaxChosen({\n\t\t\t\t\tmethod: 'GET',\n\t\t\t\t\turl: '" . admin_url('admin-ajax.php') . "',\n\t\t\t\t\tdataType: 'json',\n\t\t\t\t\tafterTypeDelay: 100,\n\t\t\t\t\tminTermLength: 1,\n\t\t\t\t\tdata: {\n\t\t\t\t\t\taction: 'woocommerce_json_search_customers',\n\t\t\t\t\t\tsecurity: '" . wp_create_nonce('search-customers') . "'\n\t\t\t\t\t}\n\t\t\t\t}, function ( data ) {\n\n\t\t\t\t\tvar terms = {};\n\n\t\t\t\t\t\$.each( data, function ( i, val ) {\n\t\t\t\t\t\tterms[i] = val;\n\t\t\t\t\t});\n\n\t\t\t\t\treturn terms;\n\t\t\t\t});\n\n\t\t\t\t\$( 'select#product_or_resource_id' ).chosen();\n\n\t\t\t\t\$( '.date-picker-field' ).datepicker({\n\t\t\t\t\tdateFormat: 'yy-mm-dd',\n\t\t\t\t\tnumberOfMonths: 1,\n\t\t\t\t\tshowButtonPanel: true,\n\t\t\t\t});\n\t\t\t"); }
/** * Add payment and transaction information as class members of WC_Order * instance for use in credit card capture transactions. Standard information * can include: * * $order->capture_total - the capture total * * @since 2.0.0 * @param WC_Order $order order being processed * @return WC_Order object with payment and transaction information attached */ protected function get_order_for_capture($order) { // set capture total here so it can be modified later as needed prior to capture $order->capture_total = number_format($order->get_total(), 2, '.', ''); // capture-specific order description $order->description = sprintf(_x('%s - Capture for Order %s', 'Capture order description', $this->text_domain), esc_html(get_bloginfo('name')), $order->get_order_number()); return apply_filters('wc_payment_gateway_' . $this->get_id() . '_get_order_for_capture', $order, $this); }
//$order = new WC_Order(); //print_r($order_userids); foreach ($customer_orders as $customer_order) { $order = new WC_Order(); $order->populate($customer_order); $status = get_term_by('slug', $order->status, 'shop_order_status'); $item_count = $order->get_item_count(); ?> <tr class="order"> <td class="order-number"> <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> </td> <td class="order-date"> <time datetime="<?php echo date('Y-m-d', strtotime($order->order_date)); ?> " title="<?php echo esc_attr(strtotime($order->order_date)); ?> "><?php echo date_i18n(get_option('date_format'), strtotime($order->order_date)); ?> </time> </td>
/** * Return/Show order number */ public function get_order_number() { // try parent first if (get_post_type($this->export->order->id) == 'shop_order_refund' && ($parent_order_id = wp_get_post_parent_id($this->export->order->id))) { $parent_order = new WC_Order($parent_order_id); $order_number = $parent_order->get_order_number(); } else { $order_number = $this->export->order->get_order_number(); } // Trim the hash to have a clean number but still // support any filters that were applied before. $order_number = ltrim($order_number, '#'); return apply_filters('wpo_wcpdf_order_number', $order_number); }
/** * Outputs the content for each column. * * @param array $item A singular item (one full row's worth of data) * @param array $column_name The name/slug of the column to be processed * @return string Text or HTML to be placed inside the column <td> * @since 1.0 */ public function column_default($item, $column_name) { global $woocommerce; $current_gmt_time = gmdate('U'); switch ($column_name) { case 'status': $actions = array(); $action_url = add_query_arg(array('page' => $_REQUEST['page'], 'user' => $item['user_id'], 'subscription' => $item['subscription_key'], '_wpnonce' => wp_create_nonce($item['subscription_key']))); if (isset($_REQUEST['status'])) { $action_url = add_query_arg(array('status' => $_REQUEST['status']), $action_url); } $order = new WC_Order($item['order_id']); $all_statuses = array('active' => __('Reactivate', WC_Subscriptions::$text_domain), 'on-hold' => __('Suspend', WC_Subscriptions::$text_domain), 'cancelled' => __('Cancel', WC_Subscriptions::$text_domain), 'trash' => __('Trash', WC_Subscriptions::$text_domain), 'deleted' => __('Delete Permanently', WC_Subscriptions::$text_domain)); foreach ($all_statuses as $status => $label) { if (WC_Subscriptions_Manager::can_subscription_be_changed_to($status, $item['subscription_key'], $item['user_id'])) { $action = 'deleted' == $status ? 'delete' : $status; // For built in CSS $actions[$action] = sprintf('<a href="%s">%s</a>', add_query_arg('new_status', $status, $action_url), $label); } } if ($item['status'] == 'pending') { unset($actions['active']); unset($actions['trash']); } elseif (!in_array($item['status'], array('cancelled', 'expired', 'suspended'))) { unset($actions['trash']); } $actions = apply_filters('woocommerce_subscriptions_list_table_actions', $actions, $item); $column_content = sprintf('<mark class="%s">%s</mark> %s', sanitize_title($item[$column_name]), WC_Subscriptions_Manager::get_status_to_display($item[$column_name], $item['subscription_key'], $item['user_id']), $this->row_actions($actions)); $column_content = apply_filters('woocommerce_subscriptions_list_table_column_status_content', $column_content, $item, $actions, $this); break; case 'title': //Return the title contents $column_content = sprintf('<a href="%s">%s</a>', get_edit_post_link($item['product_id']), WC_Subscriptions_Order::get_item_name($item['order_id'], $item['product_id'])); $column_content .= sprintf('<input type="hidden" class="%1$s" name="%2$s[%3$s][%4$s][][%1$s]" value="%5$s" />', 'product_id', $this->_args['plural'], $item['user_id'], $item['subscription_key'], $item['product_id']); $order = new WC_Order($item['order_id']); $order_item = WC_Subscriptions_Order::get_item_by_product_id($order, $item['product_id']); $product = $order->get_product_from_item($order_item); if (isset($product->variation_data)) { $column_content .= '<br />' . woocommerce_get_formatted_variation($product->variation_data, true); } break; case 'order_id': $order = new WC_Order($item[$column_name]); $column_content = sprintf('<a href="%1$s">%2$s</a>', get_edit_post_link($item[$column_name]), sprintf(__('Order %s', WC_Subscriptions::$text_domain), $order->get_order_number())); $column_content .= sprintf('<input type="hidden" class="%1$s" name="%2$s[%3$s][%4$s][][%1$s]" value="%5$s" />', $column_name, $this->_args['plural'], $item['user_id'], $item['subscription_key'], $item[$column_name]); break; case 'user': $user = get_user_by('id', $item['user_id']); $column_content = sprintf('<a href="%s">%s</a>', admin_url('user-edit.php?user_id=' . $user->ID), ucfirst($user->display_name)); $column_content .= sprintf('<input type="hidden" class="%1$s" name="%2$s[%3$s][%4$s][][%1$s]" value="%5$s" />', 'user_id', $this->_args['plural'], $item['user_id'], $item['subscription_key'], $item['user_id']); break; case 'start_date': case 'expiry_date': case 'end_date': if ($column_name == 'expiry_date' && $item[$column_name] == 0) { $column_content = __('Never', WC_Subscriptions::$text_domain); } else { if ($column_name == 'end_date' && $item[$column_name] == 0) { $column_content = __('Not yet ended', WC_Subscriptions::$text_domain); } else { $gmt_timestamp = strtotime($item[$column_name]); $user_timestamp = $gmt_timestamp + get_option('gmt_offset') * 3600; $column_content = sprintf('<time title="%s">%s</time>', esc_attr($gmt_timestamp), date_i18n(get_option('date_format'), $user_timestamp)); } } break; case 'trial_expiry_date': $trial_expiration = WC_Subscriptions_Manager::get_trial_expiration_date($item['subscription_key'], $item['user_id'], 'timestamp'); if (empty($trial_expiration)) { $column_content = '-'; } else { $column_content = sprintf('<time title="%s">%s</time>', esc_attr($trial_expiration), date_i18n(get_option('date_format'), $trial_expiration + get_option('gmt_offset') * 3600)); } break; case 'last_payment_date': if (empty($item['completed_payments'])) { $column_content = '-'; } else { $last_payment_timestamp = strtotime(array_pop($item['completed_payments'])); $time_diff = $current_gmt_time - $last_payment_timestamp; if ($time_diff > 0 && $time_diff < 7 * 24 * 60 * 60) { $last_payment = sprintf(__('%s ago', WC_Subscriptions::$text_domain), human_time_diff($last_payment_timestamp, $current_gmt_time)); } else { $last_payment = date_i18n(get_option('date_format'), $last_payment_timestamp + get_option('gmt_offset') * 3600); } $column_content = sprintf('<time title="%s">%s</time>', esc_attr($last_payment_timestamp), $last_payment); } break; case 'next_payment_date': $next_payment_timestamp = WC_Subscriptions_Manager::get_next_payment_date($item['subscription_key'], $item['user_id'], 'timestamp'); if ($next_payment_timestamp == 0) { $column_content = '-'; } else { // Convert to site time $time_diff = $next_payment_timestamp - $current_gmt_time; if ($time_diff > 0 && $time_diff < 7 * 24 * 60 * 60) { $next_payment = sprintf(__('In %s', WC_Subscriptions::$text_domain), human_time_diff($current_gmt_time, $next_payment_timestamp)); } else { $next_payment = date_i18n(get_option('date_format'), $next_payment_timestamp + get_option('gmt_offset') * 3600); } $column_content = sprintf('<time class="next-payment-date" title="%s">%s</time>', esc_attr($next_payment_timestamp), $next_payment); if (WC_Subscriptions_Manager::can_subscription_be_changed_to('new-payment-date', $item['subscription_key'], $item['user_id'])) { $column_content .= '<div class="edit-date-div row-actions hide-if-no-js">'; $column_content .= '<img class="date-picker-icon" src="' . admin_url('images/date-button.gif') . '" title="Date Picker Icon"/>'; $column_content .= '<a href="#edit_timestamp" class="edit-timestamp" tabindex="4">' . __('Change', WC_Subscriptions::$text_domain) . '</a>'; $column_content .= '<div class="date-picker-div hide-if-js">'; $column_content .= WC_Subscriptions_Manager::touch_time(array('date' => date('Y-m-d', $next_payment_timestamp), 'echo' => false, 'multiple' => true, 'include_time' => false)); $column_content .= '</div>'; $column_content .= '</form>'; } } break; case 'renewal_order_count': $count = WC_Subscriptions_Renewal_Order::get_renewal_order_count($item['order_id']); $column_content = sprintf('<a href="%1$s">%2$d</a>', admin_url('edit.php?post_status=all&post_type=shop_order&_renewal_order_parent_id=' . absint($item['order_id'])), $count); break; } return $column_content; }
/** * Process the payment and return the result * * @access public * @param int $order_id * @return array */ function process_payment($order_id) { global $woocommerce; $order = new WC_Order($order_id); if ('yes' == $this->debug) { $this->log('Generating payment form for order ' . $order->get_order_number() . '. Notify URL: ' . $this->notify_url); } return array('result' => 'success', 'redirect' => add_query_arg('order', $order->id, add_query_arg('key', $order->order_key, get_permalink(woocommerce_get_page_id('pay'))))); }