/** * Create a order. * * @since 2.4 * * @return WC_Order Order object. */ public static function create_order() { // Create product $product = WC_Helper_Product::create_simple_product(); WC_Helper_Shipping::create_simple_flat_rate(); $order_data = array('status' => 'pending', 'customer_id' => 1, 'customer_note' => '', 'total' => ''); $_SERVER['REMOTE_ADDR'] = '127.0.0.1'; // Required, else wc_create_order throws an exception $order = wc_create_order($order_data); // Add order products $item_id = $order->add_product($product, 4); // Set billing address $billing_address = array('country' => 'US', 'first_name' => 'Jeroen', 'last_name' => 'Sormani', 'company' => 'WooCompany', 'address_1' => 'WooAddress', 'address_2' => '', 'postcode' => '123456', 'city' => 'WooCity', 'state' => 'NY', 'email' => '*****@*****.**', 'phone' => '555-32123'); $order->set_address($billing_address, 'billing'); // Add shipping costs $shipping_taxes = WC_Tax::calc_shipping_tax('10', WC_Tax::get_shipping_tax_rates()); $order->add_shipping(new WC_Shipping_Rate('flat_rate_shipping', 'Flat rate shipping', '10', $shipping_taxes, 'flat_rate')); // Set payment gateway $payment_gateways = WC()->payment_gateways->payment_gateways(); $order->set_payment_method($payment_gateways['bacs']); // Set totals $order->set_total(10, 'shipping'); $order->set_total(0, 'cart_discount'); $order->set_total(0, 'cart_discount_tax'); $order->set_total(0, 'tax'); $order->set_total(0, 'shipping_tax'); $order->set_total(40, 'total'); // 4 x $10 simple helper product return wc_get_order($order->id); }
/** * Process a refund if supported * @param int $order_id * @param float $amount * @param string $reason * @return bool|wp_error True or false based on success, or a WP_Error object */ public function process_refund($order_id, $amount = null, $reason = '') { $order = wc_get_order($order_id); $transaction_id = null; $args = array('post_id' => $order->id, 'approve' => 'approve', 'type' => ''); remove_filter('comments_clauses', array('WC_Comments', 'exclude_order_comments')); $comments = get_comments($args); foreach ($comments as $comment) { if (strpos($comment->comment_content, 'Transaction ID: ') !== false) { $exploded_comment = explode(": ", $comment->comment_content); $transaction_id = $exploded_comment[1]; } } add_filter('comments_clauses', array('WC_Comments', 'exclude_order_comments')); if (!$order || !$transaction_id) { return false; } // Add transaction-specific details to the request $transaction_details = array('username' => $this->username, 'password' => $this->password, 'type' => 'refund', 'transactionid' => $transaction_id, 'ipaddress' => $_SERVER['REMOTE_ADDR']); if (!is_null($amount)) { $transaction_details['amount'] = number_format($amount, 2, '.', ''); } // Send request and get response from server $response = $this->post_and_get_response($transaction_details); // Check response if ($response['response'] == 1) { // Success $order->add_order_note(__('Inspire Commerce refund completed. Refund Transaction ID: ', 'woocommerce') . $response['transactionid']); return true; } else { // Failure $order->add_order_note(__('Inspire Commerce refund error. Response data: ', 'woocommerce') . http_build_query($response)); return false; } }
public function admin_order_item_values($_product, $item, $item_id) { if (is_object($_product)) { global $post_id; $wc_order = wc_get_order($post_id); if ($wc_order !== false) { $fpd_data = $wc_order->get_item_meta($item_id, 'fpd_data', true); if (!empty($fpd_data)) { ?> <td class="fancy-product" width="100px"> <button class='button button-secondary fpd-show-order-item' data-order_id='<?php echo $post_id; ?> ' data-order_item_id='<?php echo $item_id; ?> '><?php _e('Load in Order Viewer', 'radykal'); ?> </button> </td> <?php } } } }
/** * Get bank details and place into a list format. * * Note: Since this is declared as a private function in WC_Gateway_BACS, it needs * to be copied here 1:1 * * @param int $order_id */ private function bank_details($order_id = '') { if (empty($this->account_details)) { return; } // Get order and store in $order $order = wc_get_order($order_id); // Get the order country and country $locale $country = $order->billing_country; $locale = $this->get_country_locale(); // Get sortcode label in the $locale array and use appropriate one $sortcode = isset($locale[$country]['sortcode']['label']) ? $locale[$country]['sortcode']['label'] : __('Sort Code', 'woocommerce'); $bacs_accounts = apply_filters('woocommerce_bacs_accounts', $this->account_details); if (!empty($bacs_accounts)) { echo '<h2>' . __('Our Bank Details', 'woocommerce') . '</h2>' . PHP_EOL; foreach ($bacs_accounts as $bacs_account) { $bacs_account = (object) $bacs_account; if ($bacs_account->account_name || $bacs_account->bank_name) { echo '<h3>' . wp_unslash(implode(' - ', array_filter(array($bacs_account->account_name, $bacs_account->bank_name)))) . '</h3>' . PHP_EOL; } echo '<ul class="order_details bacs_details">' . PHP_EOL; // BACS account fields shown on the thanks page and in emails $account_fields = apply_filters('woocommerce_bacs_account_fields', array('account_number' => array('label' => __('Account Number', 'woocommerce'), 'value' => $bacs_account->account_number), 'sort_code' => array('label' => $sortcode, 'value' => $bacs_account->sort_code), 'iban' => array('label' => __('IBAN', 'woocommerce'), 'value' => $bacs_account->iban), 'bic' => array('label' => __('BIC', 'woocommerce'), 'value' => $bacs_account->bic)), $order_id); foreach ($account_fields as $field_key => $field) { if (!empty($field['value'])) { echo '<li class="' . esc_attr($field_key) . '">' . esc_attr($field['label']) . ': <strong>' . wptexturize($field['value']) . '</strong></li>' . PHP_EOL; } } echo '</ul>'; } } }
function _add_recipient_partner($emails, $objects) { $order_id = isset($objects->id) ? $objects->id : false; if ($order_id) { // change order currency if ($currency = get_post_meta($order_id, '_order_currency', true)) { TravelHelper::change_current_currency($currency); } $order = wc_get_order($order_id); if (sizeof($order->get_items()) > 0) { $partner_email_array = array(); foreach ($order->get_items() as $item_id => $item) { if (!empty($item['item_meta']['_st_st_booking_id'][0]) and $st_booking_id = $item['item_meta']['_st_st_booking_id'][0]) { $post_type = !empty($item['item_meta']['_st_st_booking_post_type']) ? $item['item_meta']['_st_st_booking_post_type'] : false; $post_type = st_wc_parse_order_item_meta($post_type); $partner_email = apply_filters('st_get_owner_email_' . $post_type, $st_booking_id); if ($partner_email != $st_booking_id) { if (!in_array($partner_email, $partner_email_array)) { $partner_email_array[] = $partner_email; } } } } if (!empty($partner_email_array)) { $emails .= ',' . implode(',', $partner_email_array); } } } return $emails; }
public function complete_order_if_admin($order_id) { if (current_user_can('manage_options')) { $order = wc_get_order($order_id); $order->payment_complete(); } }
/** * Get page title for an endpoint. * @param string * @return string */ public function get_endpoint_title($endpoint) { global $wp; switch ($endpoint) { case 'order-pay': $title = __('Pay for Order', 'woocommerce'); break; case 'order-received': $title = __('Order Received', 'woocommerce'); break; case 'view-order': $order = wc_get_order($wp->query_vars['view-order']); $title = $order ? sprintf(__('Order #%s', 'woocommerce'), $order->get_order_number()) : ''; break; case 'edit-account': $title = __('Edit Account Details', 'woocommerce'); break; case 'edit-address': $title = __('Edit Address', 'woocommerce'); break; case 'add-payment-method': $title = __('Add Payment Method', 'woocommerce'); break; case 'lost-password': $title = __('Lost Password', 'woocommerce'); break; default: $title = ''; break; } return $title; }
/** * Save the download permissions on the individual subscriptions as well as the order. Hooked into * 'woocommerce_grant_product_download_permissions', which is strictly after the order received all the info * it needed, so we don't need to play with priorities. * * @param integer $order_id the ID of the order. At this point it is guaranteed that it has files in it and that it hasn't been granted permissions before */ public static function save_downloadable_product_permissions($order_id) { global $wpdb; $order = wc_get_order($order_id); if (wcs_order_contains_subscription($order, 'any')) { $subscriptions = wcs_get_subscriptions_for_order($order, array('order_type' => array('any'))); } else { return; } foreach ($subscriptions as $subscription) { if (sizeof($subscription->get_items()) > 0) { foreach ($subscription->get_items() as $item) { $_product = $subscription->get_product_from_item($item); if ($_product && $_product->exists() && $_product->is_downloadable()) { $downloads = $_product->get_files(); $product_id = wcs_get_canonical_product_id($item); foreach (array_keys($downloads) as $download_id) { // grant access on subscription if it does not already exist if (!$wpdb->get_var($wpdb->prepare("SELECT download_id FROM {$wpdb->prefix}woocommerce_downloadable_product_permissions WHERE `order_id` = %d AND `product_id` = %d AND `download_id` = '%s'", $subscription->id, $product_id, $download_id))) { wc_downloadable_file_permission($download_id, $product_id, $subscription, $item['qty']); } self::revoke_downloadable_file_permission($product_id, $order_id, $order->user_id); } } } } update_post_meta($subscription->id, '_download_permissions_granted', 1); } }
/** * Output the shortcode. * * @param array $atts */ public static function output($atts) { // Check cart class is loaded or abort if (is_null(WC()->cart)) { return; } extract(shortcode_atts(array(), $atts)); global $post; if (!empty($_REQUEST['orderid']) && isset($_POST['_wpnonce']) && wp_verify_nonce($_POST['_wpnonce'], 'woocommerce-order_tracking')) { $order_id = empty($_REQUEST['orderid']) ? 0 : esc_attr($_REQUEST['orderid']); $order_email = empty($_REQUEST['order_email']) ? '' : esc_attr($_REQUEST['order_email']); if (!$order_id) { echo '<p class="woocommerce-error">' . __('Please enter a valid order ID', 'woocommerce') . '</p>'; } elseif (!$order_email) { echo '<p class="woocommerce-error">' . __('Please enter a valid order email', 'woocommerce') . '</p>'; } else { $order = wc_get_order(apply_filters('woocommerce_shortcode_order_tracking_order_id', $order_id)); if ($order && $order->get_id() && $order_email) { if (strtolower($order->get_billing_email()) == strtolower($order_email)) { do_action('woocommerce_track_order', $order->get_id()); wc_get_template('order/tracking.php', array('order' => $order)); return; } } else { echo '<p class="woocommerce-error">' . sprintf(__('Sorry, we could not find that order ID in our database.', 'woocommerce'), get_permalink($post->ID)) . '</p>'; } } } wc_get_template('order/form-tracking.php'); }
/** * create_export_customers_tool. * * @version 2.3.9 * @since 2.3.9 */ function create_export_customers_tool() { $html = ''; $html .= '<pre>'; $html .= __('Nr.', 'woocommerce-jetpack') . ',' . __('Email', 'woocommerce-jetpack') . ',' . __('First Name', 'woocommerce-jetpack') . ',' . __('Last Name', 'woocommerce-jetpack') . ',' . __('Order Date', 'woocommerce-jetpack') . PHP_EOL; $total_customers = 0; $orders = array(); $offset = 0; $block_size = 96; while (true) { $args_orders = array('post_type' => 'shop_order', 'post_status' => 'any', 'posts_per_page' => $block_size, 'orderby' => 'date', 'order' => 'DESC', 'offset' => $offset); $loop_orders = new WP_Query($args_orders); if (!$loop_orders->have_posts()) { break; } while ($loop_orders->have_posts()) { $loop_orders->the_post(); $order_id = $loop_orders->post->ID; $order = wc_get_order($order_id); if (isset($order->billing_email) && '' != $order->billing_email && !in_array($order->billing_email, $orders)) { $emails_to_skip = array(); if (!in_array($order->billing_email, $emails_to_skip)) { $total_customers++; $html .= $total_customers . ',' . $order->billing_email . ',' . $order->billing_first_name . ',' . $order->billing_last_name . ',' . get_the_date('Y/m/d') . PHP_EOL; $orders[] = $order->billing_email; } } } $offset += $block_size; } $html .= '</pre>'; echo $html; }
/** * Reduce stock levels for items within an order. * @since 2.7.0 * @param int $order_id */ function wc_reduce_stock_levels($order_id) { $order = wc_get_order($order_id); if ('yes' === get_option('woocommerce_manage_stock') && $order && apply_filters('woocommerce_can_reduce_order_stock', true, $order) && sizeof($order->get_items()) > 0) { foreach ($order->get_items() as $item) { if ($item->is_type('line_item') && ($product = $item->get_product()) && $product->managing_stock()) { $qty = apply_filters('woocommerce_order_item_quantity', $item->get_quantity(), $order, $item); $item_name = $product->get_formatted_name(); $new_stock = wc_update_product_stock($product, $qty, 'decrease'); if (!is_wp_error($new_stock)) { /* translators: 1: item name 2: old stock quantity 3: new stock quantity */ $order->add_order_note(sprintf(__('%1$s stock reduced from %2$s to %3$s.', 'woocommerce'), $item_name, $new_stock + $qty, $new_stock)); if ('' !== get_option('woocommerce_notify_no_stock_amount') && $new_stock <= get_option('woocommerce_notify_no_stock_amount')) { do_action('woocommerce_no_stock', $product); } elseif ('' !== get_option('woocommerce_notify_low_stock_amount') && $new_stock <= get_option('woocommerce_notify_low_stock_amount')) { do_action('woocommerce_low_stock', $product); } if ($new_stock < 0) { do_action('woocommerce_product_on_backorder', array('product' => $product, 'order_id' => $order_id, 'quantity' => $qty_ordered)); } } } } do_action('woocommerce_reduce_order_stock', $order); } }
/** * Trigger. * * @version 2.4.0 */ function trigger($order_id) { if ($order_id) { $this->object = wc_get_order($order_id); if ($this->customer_email) { $this->recipient = $this->object->billing_email; } $this->find['order-date'] = '{order_date}'; $this->find['order-number'] = '{order_number}'; $this->replace['order-date'] = date_i18n(wc_date_format(), strtotime($this->object->order_date)); $this->replace['order-number'] = $this->object->get_order_number(); } if (!$this->is_enabled() || !$this->get_recipient()) { return; } if ($order_id) { global $post; $order = wc_get_order($order_id); $post = $order->post; setup_postdata($post); } $this->send($this->get_recipient(), $this->get_subject(), do_shortcode($this->get_content()), $this->get_headers(), $this->get_attachments()); if ($order_id) { wp_reset_postdata(); } }
/** * Get the order from the PayPal 'Custom' variable * * @param string $raw_custom JSON Data passed back by PayPal * @return bool|WC_Order object */ protected function get_paypal_order($raw_custom) { // We have the data in the correct format, so get the order if (($custom = json_decode($raw_custom)) && is_object($custom)) { $order_id = $custom->order_id; $order_key = $custom->order_key; // Fallback to serialized data if safe. This is @deprecated in 2.3.11 } elseif (preg_match('/^a:2:{/', $raw_custom) && !preg_match('/[CO]:\\+?[0-9]+:"/', $raw_custom) && ($custom = maybe_unserialize($raw_custom))) { $order_id = $custom[0]; $order_key = $custom[1]; // Nothing was found } else { WC_Gateway_Paypal::log('Error: Order ID and key were not found in "custom".'); return false; } if (!($order = wc_get_order($order_id))) { // We have an invalid $order_id, probably because invoice_prefix has changed $order_id = wc_get_order_id_by_order_key($order_key); $order = wc_get_order($order_id); } if (!$order || $order->order_key !== $order_key) { WC_Gateway_Paypal::log('Error: Order Keys do not match.'); return false; } return $order; }
/** * Output custom columns for orders * * @param string $column * @version 2.2.6 * @since 2.2.4 */ public function render_order_columns($column) { if ('profit' === $column) { $total_profit = 0; $the_order = wc_get_order(get_the_ID()); if ('completed' === $the_order->get_status()) { $is_forecasted = false; foreach ($the_order->get_items() as $item_id => $item) { // $product = $this->get_product_from_item( $item ); $the_profit = 0; if (0 != ($purchase_price = wc_get_product_purchase_price($item['product_id']))) { $the_profit = $item['line_total'] + $item['line_tax'] - $purchase_price * $item['qty']; // $total_profit += $the_profit; // echo $item['line_total'] . ' ~ ' . $purchase_price . ' ~ ' . $item['qty']; } else { //$the_profit = ( $item['line_total'] + $item['line_tax'] ) * 0.2; $is_forecasted = true; } $total_profit += $the_profit; } } if (0 != $total_profit) { if (!$is_forecasted) { echo '<span style="color:green;">'; } echo wc_price($total_profit); if (!$is_forecasted) { echo '</span>'; } } } }
/** * Get parent order object. * @return int */ public function get_order() { if (!$this->_order) { $this->_order = wc_get_order($this->get_order_id()); } return $this->_order; }
/** * trigger function. * * @access public * @return void */ function trigger($order) { if (!is_object($order)) { $order = wc_get_order(absint($order)); } if ($order) { $this->object = $order; $this->recipient = $this->object->billing_email; $this->find['order-date'] = '{order_date}'; $this->find['order-number'] = '{order_number}'; $this->replace['order-date'] = date_i18n(wc_date_format(), strtotime($this->object->order_date)); $this->replace['order-number'] = $this->object->get_order_number(); } if (!$this->get_recipient()) { return; } if (version_compare(WOOCOMMERCE_VERSION, '2.2', '<')) { return; } $refunds = $order->get_refunds(); if (empty($refunds)) { return; } $result = $this->send($this->get_recipient(), $this->get_subject(), $this->get_content(), $this->get_headers(), $this->get_attachments()); do_action('wpo_wcpdf_pro_email_sent', $result, $this->id, $order); }
/** * Export the orders and display an admin notice showing the # of successful/failed exports and any error messages * * @since 1.0 */ public function export() { global $wc_sage_erp_connector; $success = $failure = 0; foreach ($this->order_ids as $order_id) { $order = wc_get_order($order_id); $export = $this->export_order($order); // keep track of the number of successful/failed exports if ($export) { $success++; } else { $failure++; } } // add an admin message displaying the number of successful exports if ($success) { $wc_sage_erp_connector->messages->add_message(sprintf(_n('Order exported to Sage ERP.', '%s orders exported to Sage ERP.', $success, WC_Sage_ERP_Connector::TEXT_DOMAIN), number_format_i18n($success))); } // add an admin error message displaying the number of failed exports if ($failure) { $wc_sage_erp_connector->messages->add_error(sprintf(_n('Order failed export to Sage ERP.', '%s orders failed export to Sage ERP.', $failure, WC_Sage_ERP_Connector::TEXT_DOMAIN), number_format_i18n($failure))); } // persist errors / messages to display on next page load $wc_sage_erp_connector->messages->set_messages(); }
/** * Output custom columns for orders * * @param string $column * @version 2.5.9 * @since 2.2.4 * @todo forecasted profit */ function render_order_columns($column) { if ('profit' === $column) { $total_profit = 0; $the_order = wc_get_order(get_the_ID()); if (!in_array($the_order->get_status(), array('cancelled', 'refunded', 'failed'))) { $is_forecasted = false; foreach ($the_order->get_items() as $item_id => $item) { $the_profit = 0; $product_id = isset($item['variation_id']) && 0 != $item['variation_id'] ? $item['variation_id'] : $item['product_id']; if (0 != ($purchase_price = wc_get_product_purchase_price($product_id))) { // $line_total = ( 'yes' === get_option('woocommerce_prices_include_tax') ) ? ( $item['line_total'] + $item['line_tax'] ) : $item['line_total']; $line_total = $the_order->prices_include_tax ? $item['line_total'] + $item['line_tax'] : $item['line_total']; $the_profit = $line_total - $purchase_price * $item['qty']; } else { // $the_profit = ( $item['line_total'] + $item['line_tax'] ) * $average_profit_margin; $is_forecasted = true; } $total_profit += $the_profit; } } if (0 != $total_profit) { if (!$is_forecasted) { echo '<span style="color:green;">'; } echo wc_price($total_profit); if (!$is_forecasted) { echo '</span>'; } } } }
/** * Returns an array of payment token objects associated with the passed order ID. * @since 2.6.0 * @param int $order_id Order ID * @return array Array of token objects */ public static function get_order_tokens($order_id) { $order = wc_get_order($order_id); if (!$order) { return array(); } $token_ids = get_post_meta($order_id, '_payment_tokens', true); if (empty($token_ids)) { return array(); } global $wpdb; $token_ids_as_string = implode(',', array_map('intval', $token_ids)); $token_results = $wpdb->get_results("SELECT * FROM {$wpdb->prefix}woocommerce_payment_tokens WHERE token_id IN ( {$token_ids_as_string} )"); if (empty($token_results)) { return array(); } $tokens = array(); foreach ($token_results as $token_result) { $_token = self::get($token_result->token_id, $token_result); if (!empty($_token)) { $tokens[$token_result->token_id] = $_token; } } return apply_filters('woocommerce_get_order_payment_tokens', $tokens, $order_id); }
/** * init_atts. */ function init_atts($atts) { $this->the_order = 'shop_order' === get_post_type($atts['order_id']) ? wc_get_order($atts['order_id']) : null; if (!$this->the_order) { return false; } return $atts; }
public static function get_order() { $invoice = self::get_invoice(); if (!$invoice->order) { return false; } return wc_get_order($invoice->order); }
/** * Create a schedule record * * @since 1.0.0 * @param $order_id int the order id * @return void * @author Alberto Ruggiero */ static function schedule_mail($order_id) { if (self::check_exists_schedule($order_id) == 0) { global $wpdb; $order = wc_get_order($order_id); $scheduled_date = date('Y-m-d', strtotime(current_time('mysql') . ' + ' . get_option('ywrr_mail_schedule_day') . ' days')); $wpdb->insert($wpdb->prefix . 'ywrr_email_schedule', array('order_id' => $order_id, 'mail_status' => 'pending', 'scheduled_date' => $scheduled_date, 'order_date' => $order->modified_date), array('%d', '%s', '%s', '%s')); } }
/** * Create a schedule record * * @since 1.0.0 * * @param $order_id int the order id * @param $list * * @return void * @author Alberto Ruggiero */ public function schedule_mail($order_id, $list = '') { if ($this->check_exists_schedule($order_id) == 0) { global $wpdb; $order = wc_get_order($order_id); $scheduled_date = date('Y-m-d', strtotime(current_time('mysql') . ' + ' . get_option('ywrr_mail_schedule_day') . ' days')); $wpdb->insert($wpdb->prefix . 'ywrr_email_schedule', array('order_id' => $order_id, 'mail_status' => 'pending', 'scheduled_date' => $scheduled_date, 'order_date' => $order->modified_date, 'request_items' => maybe_serialize($list)), array('%d', '%s', '%s', '%s', '%s')); } }
/** * Get all the orders which have recorded a switch for a given subscription. * * @param int|WC_Subscription $subscription_id The post_id of a shop_subscription post or an instance of a WC_Subscription object * @return array Order details in post_id => WC_Order form. * @since 2.0 */ function wcs_get_switch_orders_for_subscription($subscription_id) { $orders = array(); // Select the orders which switched item/s from this subscription $order_ids = get_posts(array('post_type' => 'shop_order', 'post_status' => 'any', 'fields' => 'ids', 'posts_per_page' => -1, 'meta_query' => array(array('key' => '_subscription_switch', 'value' => $subscription_id)))); foreach ($order_ids as $order_id) { $orders[$order_id] = wc_get_order($order_id); } return $orders; }
/** * @param int $order_id * @return boolean */ public function subscribe_from_woocommerce_checkout($order_id) { if (!$this->triggered($order_id)) { return false; } $order = wc_get_order($order_id); $data = array('EMAIL' => $order->billing_email, 'NAME' => "{$order->billing_first_name} {$order->billing_last_name}", 'FNAME' => $order->billing_first_name, 'LNAME' => $order->billing_last_name); // TODO: add billing address fields, maybe by finding MailChimp field of type "address"? return $this->subscribe($data, $order_id); }
/** * Process the gateway integration * * @param int $order_id * * @return void */ public function process_payment($order_id) { $order = wc_get_order($order_id); // Mark as on-hold (we're awaiting the payment) $order->update_status('on-hold', __('Awaiting bKash payment', 'wc-bkash')); // Remove cart WC()->cart->empty_cart(); // Return thankyou redirect return array('result' => 'success', 'redirect' => $this->get_return_url($order)); }
/** * Output the metabox */ public static function output($post) { global $thepostid, $theorder; if (!is_object($theorder)) { $theorder = wc_get_order($thepostid); } $order = $theorder; $data = get_post_meta($post->ID); include 'views/html-order-items.php'; }
/** * Embed Referralcandy code. */ public function woocommerce_order_referralcandy($order_id) { $order = wc_get_order($order_id); $date = DateTime::createFromFormat('Y-m-d H:i:s', $order->order_date); $divData = array('id' => 'refcandy-mint', 'data-app-id' => $this->get_option('app_id'), 'data-fname' => $order->billing_first_name, 'data-lname' => $order->billing_last_name, 'data-email' => $order->billing_email, 'data-amount' => $order->get_total(), 'data-currency' => $order->get_order_currency(), 'data-timestamp' => $date->getTimestamp(), 'data-signature' => md5($order->billing_email . ',' . $order->billing_first_name . ',' . $order->get_total() . ',' . $date->getTimestamp() . ',' . $this->get_option('secret_key'))); $div = '<div ' . implode(' ', array_map(function ($v, $k) { return $k . '="' . addslashes($v) . '"'; }, $divData, array_keys($divData))) . ' ></div>'; $script = '<script>(function(e){var t,n,r,i,s,o,u,a,f,l,c,h,p,d,v;f="script";l="refcandy-purchase-js";c="refcandy-mint";p="go.referralcandy.com/purchase/";t="data-app-id";r={email:"a",fname:"b",lname:"c",amount:"d",currency:"e","accepts-marketing":"f",timestamp:"g","referral-code":"h",locale:"i",signature:"ab"};i=e.getElementsByTagName(f)[0];s=function(e,t){if(t){return""+e+"="+encodeURIComponent(t)}else{return""}};d=function(e){return""+p+h.getAttribute(t)+".js?aa=75&"};if(!e.getElementById(l)){h=e.getElementById(c);if(h){o=e.createElement(f);o.id=l;a=function(){var e;e=[];for(n in r){u=r[n];v=h.getAttribute("data-"+n);e.push(s(u,v))}return e}();o.src=""+e.location.protocol+"//"+d(h.getAttribute(t))+a.join("&");return i.parentNode.insertBefore(o,i)}}})(document);</script>'; echo $div . $script; }
/** * Constructor * * Initialize plugin and registers actions and filters to be used * * @since 1.0 * @author Lorenzo Giuffrida * @access public * @return void */ public function __construct($order_id) { /** * Get the WooCommerce order for this order id */ $this->order = wc_get_order($order_id); /** * Check if an order exists for this order id */ $this->is_valid = isset($this->order); }
public static function createSimpleOrder($total = 40) { $product = self::createSimpleProduct(); self::createSimpleShippingFlatRate(); $order_data = array('status' => 'pending', 'customer_id' => 1, 'customer_note' => '', 'total' => ''); // Required, else wc_create_order throws an exception $_SERVER['REMOTE_ADDR'] = '127.0.0.1'; $order = wc_create_order($order_data); // Add order products $order->add_product($product, 4); // Set billing address $shipping_address = array('country' => 'US', 'first_name' => 'Jeroen', 'last_name' => 'Sormani', 'company' => 'WooCompany', 'address_1' => 'WooAddress', 'address_2' => '', 'postcode' => '123456', 'city' => 'WooCity', 'state' => 'NY', 'email' => '*****@*****.**', 'phone' => '555-32123'); $order->set_address($shipping_address, 'shipping'); // Add shipping costs $shipping_taxes = \WC_Tax::calc_shipping_tax('10', \WC_Tax::get_shipping_tax_rates()); $order->add_shipping(new \WC_Shipping_Rate('flagship_shipping_method|Purolator|PurolatorExpress|Purolator Express|1473811200', 'Purolator - Purolator Express', '10', $shipping_taxes, 'flagship_shipping_method')); // Set totals $order->set_total(10, 'shipping'); $order->set_total(0, 'cart_discount'); $order->set_total(0, 'cart_discount_tax'); $order->set_total(0, 'tax'); $order->set_total(0, 'shipping_tax'); $order->set_total($total, 'total'); // 4 x $10 simple helper product return wc_get_order($order->id); }