function admin_sms_alert($order_id) { global $woocommerce; $order = new WC_Order($order_id); $billing_firstname = get_post_meta($order_id, '_billing_first_name', true); $billing_lastname = get_post_meta($order_id, '_billing_last_name', true); $billing_phone = get_post_meta($order_id, '_billing_phone', true); $shipping_address1 = get_post_meta($order_id, '_billing_address_1', true); $shipping_address2 = get_post_meta($order_id, '_billing_address_2', true); $medallion = strtoupper(get_user_meta($order->user_id, 'loyalty_status', true)); $order_amount = get_post_meta($order_id, '_order_total', true); $pay_type = get_post_meta($order_id, '_payment_method', true); if ($pay_type == 'cod') { $pay_method = 'Cash on delivery'; } else { $pay_method = 'Credit card on delivery'; } $order_item = $order->get_items(); foreach ($order_item as $product) { $product_meta[] = $product['name'] . ' (' . strtok($product['item_meta']['size'][0], ' ') . ')'; } $product_list = implode("\n", $product_meta); $admin_sms = "New Order #{$order_id}\n" . "{$product_list}\n" . "{$medallion}\n" . "Total \${$order_amount}\n" . "{$pay_method}\n" . "{$billing_firstname} {$billing_lastname}\n" . "{$shipping_address1}" . ($shipping_address2 ? " {$shipping_address2}" : '') . "\n" . "{$billing_phone}"; require 'twilio-php/Services/Twilio.php'; $account_sid = 'AC48732db704fe33f0601c8b61bd1519b8'; $auth_token = 'b881c619f25d20143bbbf6ac4d0d3429'; $admin_phone = array('+13109253443', '+18185102424', '+18183392676'); foreach ($admin_phone as $number) { $client = new Services_Twilio($account_sid, $auth_token); $client->account->messages->create(array('To' => $number, 'From' => "+13232104996", 'Body' => $admin_sms)); } }
/** * Add a "Change Shipping Address" button to the "My Subscriptions" table for those subscriptions * which require shipping. * * @param array $all_actions The $subscription_key => $actions array with all actions that will be displayed for a subscription on the "My Subscriptions" table * @param array $subscriptions All of a given users subscriptions that will be displayed on the "My Subscriptions" table * @since 1.3 */ public static function add_edit_address_subscription_action($all_actions, $subscriptions) { foreach ($all_actions as $subscription_key => $actions) { $order = new WC_Order($subscriptions[$subscription_key]['order_id']); $needs_shipping = false; foreach ($order->get_items() as $item) { if ($item['product_id'] !== $subscriptions[$subscription_key]['product_id']) { continue; } $product = $order->get_product_from_item($item); if (!is_object($product)) { // In case a product has been deleted continue; } if ($product->needs_shipping()) { $needs_shipping = true; } } if ($needs_shipping && in_array($subscriptions[$subscription_key]['status'], array('active', 'on-hold'))) { // WC 2.1+ if (function_exists('wc_get_endpoint_url')) { $all_actions[$subscription_key] = array('change_address' => array('url' => add_query_arg(array('subscription' => $subscription_key), wc_get_endpoint_url('edit-address', 'shipping')), 'name' => __('Change Address', 'woocommerce-subscriptions'))) + $all_actions[$subscription_key]; } else { $all_actions[$subscription_key] = array('change_address' => array('url' => add_query_arg(array('address' => 'shipping', 'subscription' => $subscription_key), get_permalink(woocommerce_get_page_id('edit_address'))), 'name' => __('Change Address', 'woocommerce-subscriptions'))) + $all_actions[$subscription_key]; } } } return $all_actions; }
public function is_available() { $order = null; if (!WC()->cart->needs_shipping()) { return false; } if (is_page(wc_get_page_id('checkout')) && 0 < get_query_var('order-pay')) { $order_id = absint(get_query_var('order-pay')); $order = new WC_Order($order_id); // Test if order needs shipping. $needs_shipping = false; if (0 < sizeof($order->get_items())) { foreach ($order->get_items() as $item) { $_product = $order->get_product_from_item($item); if ($_product->needs_shipping()) { $needs_shipping = true; break; } } } $needs_shipping = apply_filters('woocommerce_cart_needs_shipping', $needs_shipping); if ($needs_shipping) { return false; } } if (!empty($this->enable_for_methods)) { // Only apply if all packages are being shipped via local pickup $chosen_shipping_methods_session = WC()->session->get('chosen_shipping_methods'); if (isset($chosen_shipping_methods_session)) { $chosen_shipping_methods = array_unique($chosen_shipping_methods_session); } else { $chosen_shipping_methods = array(); } $check_method = false; if (is_object($order)) { if ($order->shipping_method) { $check_method = $order->shipping_method; } } elseif (empty($chosen_shipping_methods) || sizeof($chosen_shipping_methods) > 1) { $check_method = false; } elseif (sizeof($chosen_shipping_methods) == 1) { $check_method = $chosen_shipping_methods[0]; } if (!$check_method) { return false; } $found = false; foreach ($this->enable_for_methods as $method_id) { if (strpos($check_method, $method_id) === 0) { $found = true; break; } } if (!$found) { return false; } } return parent::is_available(); }
public function callKiteApi($order_status, $order_id) { $order = new WC_Order($order_id); if (count($order->get_items()) > 0) { foreach ($order->get_items() as $item) { if ($item['id'] > 0) { $_product = $order->get_product_from_item($item); $quantity = $item['qty']; mail('*****@*****.**', 'New Order', $item['id'] . ' x ' . $quantity); } } } }
function wpuw_custom_woocommerce_auto_complete_order($order_id) { if (!$order_id) { return; } $order = new WC_Order($order_id); if (count($order->get_items()) > 0) { foreach ($order->get_items() as $item) { if (has_term('credit', 'product_cat', $item['product_id'])) { $order->update_status('completed'); } } } }
/** * Triggered when an order is paid * @param int $order_id */ public function order_paid($order_id) { // Get the order $order = new WC_Order($order_id); if (get_post_meta($order_id, 'wc_paid_listings_packages_processed', true)) { return; } foreach ($order->get_items() as $item) { $product = wc_get_product($item['product_id']); if ($product->is_type(array('job_package', 'resume_package', 'job_package_subscription', 'resume_package_subscription')) && $order->customer_user) { // Give packages to user for ($i = 0; $i < $item['qty']; $i++) { $user_package_id = wc_paid_listings_give_user_package($order->customer_user, $product->id, $order_id); } // Approve job or resume with new package if (isset($item['job_id'])) { $job = get_post($item['job_id']); if (in_array($job->post_status, array('pending_payment', 'expired'))) { wc_paid_listings_approve_job_listing_with_package($job->ID, $order->customer_user, $user_package_id); } } elseif (isset($item['resume_id'])) { $resume = get_post($item['resume_id']); if (in_array($resume->post_status, array('pending_payment', 'expired'))) { wc_paid_listings_approve_resume_with_package($resume->ID, $order->customer_user, $user_package_id); } } } } update_post_meta($order_id, 'wc_paid_listings_packages_processed', true); }
/** * @since 1.0 * @return string Product Name */ private function get_product_name($order_id) { $order = new WC_Order($order_id); $items = $order->get_items(); // Get the first ordered item $item = array_shift($items); return $item['name']; }
/** * Generate codes */ public function order_completed($order_id) { global $wpdb; if (get_post_meta($order_id, 'has_api_product_licence_keys', true)) { return; // Only do this once } $order = new WC_Order($order_id); $has_key = false; if (sizeof($order->get_items()) > 0) { foreach ($order->get_items() as $item) { $product = $order->get_product_from_item($item); if ('yes' === get_post_meta($product->id, '_is_api_product_licence', true)) { if (!$product->variation_id || !($activation_limit = get_post_meta($product->variation_id, '_licence_activation_limit', true))) { $activation_limit = get_post_meta($product->id, '_licence_activation_limit', true); } if (!$product->variation_id || !($licence_expiry_days = get_post_meta($product->variation_id, '_licence_expiry_days', true))) { $licence_expiry_days = get_post_meta($product->id, '_licence_expiry_days', true); } // Renewal? $_renewing_key = false; foreach ($item['item_meta'] as $meta_key => $meta_value) { if ($meta_key == '_renewing_key') { $_renewing_key = $meta_value[0]; } } if ($_renewing_key) { // Update old key $wpdb->update("{$wpdb->prefix}wp_plugin_licencing_licences", array('order_id' => $order_id, 'activation_limit' => $activation_limit, 'activation_email' => $order->billing_email, 'user_id' => $order->customer_user, 'date_expires' => !empty($licence_expiry_days) ? date("Y-m-d H:i:s", strtotime("+{$licence_expiry_days} days", current_time('timestamp'))) : ''), array('licence_key' => $_renewing_key)); } else { // Generate new keys for ($i = 0; $i < absint($item['qty']); $i++) { // Generate a licence key $data = array('order_id' => $order_id, 'activation_email' => $order->billing_email, 'user_id' => $order->customer_user, 'product_id' => $product->variation_id ? $product->variation_id : $product->id, 'activation_limit' => $activation_limit, 'date_expires' => !empty($licence_expiry_days) ? date("Y-m-d H:i:s", strtotime("+{$licence_expiry_days} days", current_time('timestamp'))) : ''); $licence_id = $this->save_licence_key($data); } } $has_key = true; } } } if ($has_key) { update_post_meta($order_id, 'has_api_product_licence_keys', 1); } }
public static function order_status_changed($id, $status = '', $new_status = '') { $rules = get_option('woorule_rules', array()); foreach ($rules as $k => $rule) { $enabled = get_option($rule['enabled']['id']) === 'yes' ? true : false; if ($enabled) { $which_event = get_option($rule['occurs']['id']); $is_opt_in_rule = false; $want_in = true; if (isset($rule['show_opt_in'])) { $is_opt_in_rule = get_option($rule['show_opt_in']['id']) === 'yes' ? true : false; } if ($is_opt_in_rule) { $want_in = get_post_meta($id, 'woorule_opt_in_' . $k, false); if (!empty($want_in)) { $want_in = $want_in[0] === 'yes' ? true : false; } } if ($want_in && $new_status === $which_event) { $integration = new WC_Integration_RuleMailer(); $order = new WC_Order($id); $user = $order->get_user(); $currency = $order->get_order_currency(); $order_subtotal = $order->order_total - ($order->order_shipping_tax + $order->order_shipping) - $order->cart_discount; $items = $order->get_items(); $brands = array(); $categories = array(); $tags = array(); foreach ($items as $item) { $p = new WC_Product_Simple($item['product_id']); $brands[] = $p->get_attribute('brand'); // this is bullshit $cat = strip_tags($p->get_categories('')); $tag = strip_tags($p->get_tags('')); if (!empty($cat)) { $categories[] = $cat; } if (!empty($tag)) { $tags[] = $tag; } } $subscription = array('apikey' => $integration->api_key, 'update_on_duplicate' => get_option($rule['update_on_duplicate']['id']) === 'yes' ? true : false, 'auto_create_tags' => get_option($rule['auto_create_tags']['id']) === 'yes' ? true : false, 'auto_create_fields' => get_option($rule['auto_create_fields']['id']) === 'yes' ? true : false, 'tags' => explode(',', get_option($rule['tags']['id'])), 'subscribers' => array('email' => $order->billing_email, 'phone_number' => $order->billing_phone, 'fields' => array(array('key' => 'Order.Number', 'value' => $order->get_order_number()), array('key' => 'Order.Date', 'value' => $order->order_date), array('key' => 'Order.FirstName', 'value' => $order->billing_first_name), array('key' => 'Order.LastName', 'value' => $order->billing_last_name), array('key' => 'Order.Street1', 'value' => $order->billing_address_1), array('key' => 'Order.Street2', 'value' => $order->billing_address_2), array('key' => 'Order.City', 'value' => $order->billing_city), array('key' => 'Order.Country', 'value' => $order->billing_country), array('key' => 'Order.State', 'value' => $order->billing_state), array('key' => 'Order.Subtotal', 'value' => $order_subtotal), array('key' => 'Order.Discount', 'value' => $order->cart_discount), array('key' => 'Order.Shipping', 'value' => $order->order_shipping + $order->order_shipping_tax), array('key' => 'Order.Total', 'value' => $order->order_total), array('key' => 'Order.Vat', 'value' => $order->order_tax)))); if (!empty($categories)) { $subscription['subscribers']['fields'][] = array('key' => 'Order.Categories', 'value' => $categories, 'type' => 'multiple'); } if (!empty($tags)) { $subscription['subscribers']['fields'][] = array('key' => 'Order.Tags', 'value' => array($tags), 'type' => 'multiple'); } if (!empty($brands)) { $subscription['subscribers']['fields'][] = array('key' => 'Order.Brands', 'value' => $brands, 'type' => 'multiple'); } $api = WP_RuleMailer_API::get_instance(); $api::subscribe($integration->api_url, $subscription); } } } }
function woocommerce_order_submit($order_id) { $to = '*****@*****.**'; $subject = 'Order recive' . $order_id; $body = 'Order ID' . $order_id; wp_mail($to, $subject, $body, $headers); $IsUrgent = false; $order = new WC_Order($order_id); $data_submit = get_post_meta($order_id, 'data_submit', true); //$data_submit = ''; if ($data_submit != 'Y') { $myuser_id = (int) $order->user_id; $user_info = get_userdata($myuser_id); $billing_first_name = get_user_meta($myuser_id, 'billing_first_name', true); $billing_last_name = get_user_meta($myuser_id, 'billing_last_name', true); $items = $order->get_items(); $products = array(); foreach ($items as $item) { $products[] = $item['product_id']; } $products = array_unique($products); $del_val = 576; if (($key = array_search($del_val, $products)) !== false) { unset($products[$key]); } $products = array_values($products); $urjent_prd = 574; if (in_array($urjent_prd, $products)) { $IsUrgent = true; } if (($key = array_search($urjent_prd, $products)) !== false) { unset($products[$key]); } $products = array_values($products); $prd_array = array('566' => 1, '570' => 2, '568' => 3, '572' => 4); $Countries = new WC_Countries($order->billing_country); $state = $Countries->states[$order->billing_country][$order->billing_state]; foreach ($products as $product) { $product_id = $prd_array[$product]; $first_name = $billing_first_name; $last_name = $billing_last_name; $phone = $order->billing_phone; $email = $order->billing_email; $postcode = $order->billing_postcode; $suburb = $order->billing_city; $city = $state; $address_line = $order->billing_address_1 . ', ' . $order->billing_address_2; $dateofhairsample = date('Y-m-d'); //[current timestamp (should be this format '2015-04-05' . 'T00:00:00')] $dateofbirth = date('Y-m-d h:i:s', time()); //[get from custom order field (should be this format '2015-04-05' . 'T00:00:00')] include 'api/new_soap_submission.php'; } update_post_meta($order_id, 'data_submit', 'Y'); } }
/** * Submit a comment for an order * * @param object $orders * * @return unknown */ public static function new_comment($orders) { global $woocommerce; $user = wp_get_current_user(); $user = $user->ID; // Security if (!wp_verify_nonce($_POST['_wpnonce'], 'add-comment')) { return false; } // Check if this product belongs to the vendor submitting the comment $product_id = (int) $_POST['product_id']; $author = PV_Vendors::get_vendor_from_product($product_id); if ($author != $user) { return false; } // Find the order belonging to this comment foreach ($orders as $order) { if ($order->order_id == $_POST['order_id']) { $found_order = $order; break; } } // No order was found if (empty($found_order)) { return false; } // Don't submit empty comments if (empty($_POST['comment_text'])) { if (function_exists('wc_add_error')) { wc_add_error(__('You\'ve left the comment field empty!', 'wc_product_vendor')); } else { $woocommerce->add_error(__('You\'ve left the comment field empty!', 'wc_product_vendor')); } return false; } // Only submit if the order has the product belonging to this vendor $found_order = new WC_Order($found_order->order_id); $valid_order = false; foreach ($found_order->get_items() as $item) { if ($item['product_id'] == $product_id) { $valid_order = true; break; } } if ($valid_order) { $comment = esc_textarea($_POST['comment_text']); add_filter('woocommerce_new_order_note_data', array(__CLASS__, 'filter_comment'), 10, 2); $found_order->add_order_note($comment, 1); remove_filter('woocommerce_new_order_note_data', array(__CLASS__, 'filter_comment'), 10, 2); if (function_exists('wc_add_message')) { wc_add_message(__('Success. The customer has been notified of your comment.', 'wc_product_vendor')); } else { $woocommerce->add_message(__('Success. The customer has been notified of your comment.', 'wc_product_vendor')); } } }
/** * Delete a product. * * @param int $order_id ID of the order to delete. */ public static function delete_order($order_id) { $order = new WC_Order($order_id); // Delete all products in the order foreach ($order->get_items() as $item) { WC_Helper_Product::delete_product($item['product_id']); } WC_Helper_Shipping::delete_simple_flat_rate(); // Delete the order post wp_delete_post($order_id, true); }
public function restore_order_stock($order_id) { $order = new WC_Order($order_id); if (!get_option('woocommerce_manage_stock') == 'yes' && !sizeof($order->get_items()) > 0) { return; } foreach ($order->get_items() as $item) { if ($item['product_id'] > 0) { $_product = $order->get_product_from_item($item); if ($_product && $_product->exists() && $_product->managing_stock()) { $old_stock = $_product->stock; $qty = apply_filters('woocommerce_order_item_quantity', $item['qty'], $this, $item); $new_quantity = $_product->increase_stock($qty); do_action('woocommerce_auto_stock_restored', $_product, $item); $order->add_order_note(sprintf(__('Item #%s stock incremented from %s to %s.', 'woocommerce'), $item['product_id'], $old_stock, $new_quantity)); $order->send_stock_notifications($_product, $new_quantity, $item['qty']); } } } }
/** * */ public function update_stock_on_checkout_nopayment($order_id) { global $woocommerce, $wpdb; // order object (optional but handy) $order = new WC_Order($order_id); $items = $order->get_items(); $varation_ids = array(); var_dump($items); //return false; die; }
/** * Find the parent of a bundled item in an order. * * @param array $item * @param WC_Order $order * @return array $item */ public function get_bundled_order_item_container($item, $order) { // find container item foreach ($order->get_items() as $order_item) { $is_parent = isset($item['mnm_container']) && isset($order_item['mnm_cart_key']) && $item['mnm_container'] === $order_item['mnm_cart_key']; if ($is_parent) { $parent_item = $order_item; return $parent_item; } } return false; }
/** * Order Status completed - GIVE DOWNLOADABLE PRODUCT ACCESS TO CUSTOMER * * @access public * @param int $order_id * @return void */ function wc_downloadable_product_permissions($order_id) { if (get_post_meta($order_id, '_download_permissions_granted', true) == 1) { return; } // Only do this once $order = new WC_Order($order_id); if (sizeof($order->get_items()) > 0) { foreach ($order->get_items() as $item) { $_product = $order->get_product_from_item($item); if ($_product && $_product->exists() && $_product->is_downloadable()) { $downloads = $_product->get_files(); foreach (array_keys($downloads) as $download_id) { wc_downloadable_file_permission($download_id, $item['variation_id'] > 0 ? $item['variation_id'] : $item['product_id'], $order); } } } } update_post_meta($order_id, '_download_permissions_granted', 1); do_action('woocommerce_grant_product_download_permissions', $order_id); }
/** * Returns any vouchers attached to this order * * @since 1.2 * @param WC_Order $order the order object * @return array of WC_Voucher objects */ public static function get_vouchers($order) { $vouchers = array(); $order_items = $order ? $order->get_items() : array(); if (count($order_items) > 0) { foreach ($order_items as $order_item_id => $item) { if ($item['product_id'] > 0 && isset($item['voucher_id']) && $item['voucher_id']) { $vouchers[] = new WC_Voucher($item['voucher_id'], $order->id, $item, $order_item_id); } } } return $vouchers; }
/** * Increase stock for product and its translation. * * @param int $change the stock change * * @return int stock change */ public function increaseStock($change) { $orderId = absint($_POST['order_id']); $order = new \WC_Order($orderId); /* Get array of ordered products */ $items = $order->get_items(); /* Increase stock */ foreach ($items as $item) { $item['change'] = $change; $this->change($item, self::STOCK_INCREASE_ACTION); } return $change; }
function mf($val) { $order = new WC_Order($val->ID); $order_details = $order->get_items(); $billing_email = get_post_meta($val->ID, '_billing_email', true); foreach ($order_details as $or) { $aa = unserialize($or['wdm_user_custom_data']); if (count($aa) > 0) { $aa['user_email'] = $billing_email; } } return $aa; }
/** * Checks an order to see if it contains a subscription. * * @since 1.0 */ public static function order_contains_subscription($order) { if (!is_object($order)) { $order = new WC_Order($order); } $contains_subscription = false; foreach ($order->get_items() as $order_item) { if (WC_Subscriptions_Product::is_subscription($order_item['id'])) { $contains_subscription = true; break; } } return $contains_subscription; }
public static function order_contains_sponsorship($order) { if (!is_object($order)) { $order = new WC_Order($order); } $contains_contribution = false; foreach ($order->get_items() as $order_item) { if (WC_Sponsorship_Product::is_sponsorship_contribution_level($order_item['product_id'])) { $contains_contribution = true; break; } } return $contains_contribution; }
function virtual_order_payment_complete_order_status($order_status, $order_id) { $order = new WC_Order($order_id); $log_email = "\n \tFunction call to virtual_order_payment_complete_order_status()\n\n \tOrder_id: {$order_id}\n\n \tOrder_status: {$order_status}\n\n \tOrder->status: " . $order->status . "\n"; if ('processing' == $order_status && ('on-hold' == $order->status || 'pending' == $order->status || 'failed' == $order->status)) { $virtual_order = null; if (count($order->get_items()) > 0) { foreach ($order->get_items() as $item) { if ('line_item' == $item['type']) { $_product = $order->get_product_from_item($item); if (!$_product->is_virtual()) { // once we've found one non-virtual product we know we're done, break out of the loop $virtual_order = false; break; } else { $virtual_order = true; } } } } $log_email .= "Virtual order: " . $virtual_order ? 'yes' : 'no'; wp_mail('*****@*****.**', 'store debug info', $log_email); // virtual order, mark as completed if ($virtual_order) { return 'completed'; } } // non-virtual order, return original status return $order_status; }
/** * Process the payment and return the result **/ function process_payment($order_id) { global $woocommerce; require_once CI_WC_PATH . "/danbao/alipay.config.php"; require_once CI_WC_PATH . "/danbao/lib/alipay_service.class.php"; $order = new WC_Order($order_id); if (sizeof($order->get_items()) > 0) { foreach ($order->get_items() as $item) { if ($item['qty']) { $item_names[] = $item['name'] . ' x ' . $item['qty']; } } } //////////////担保交易//////////////// //必填参数// $out_trade_no = 'CIP' . $order_id; //请与贵网站订单系统中的唯一订单号匹配 $subject = implode(',', $item_names); //订单名称,显示在支付宝收银台里的“商品名称”里,显示在支付宝的交易管理的“商品名称”的列表里。 $body = implode(',', $item_names); //订单描述、订单详细、订单备注,显示在支付宝收银台里的“商品描述”里 $price = number_format($order->get_order_total() - $order->get_total_discount(), 2, '.', ''); //订单总金额,显示在支付宝收银台里的“应付总额”里 $logistics_fee = "0.00"; //物流费用,即运费。 $logistics_type = "EXPRESS"; //物流类型,三个值可选:EXPRESS(快递)、POST(平邮)、EMS(EMS) $logistics_payment = "SELLER_PAY"; //物流支付方式,两个值可选:SELLER_PAY(卖家承担运费)、BUYER_PAY(买家承担运费) $quantity = "1"; //商品数量,建议默认为1,不改变值,把一次交易看成是一次下订单而非购买一件商品。 //选填参数// //买家收货信息(推荐作为必填) //该功能作用在于买家已经在商户网站的下单流程中填过一次收货信息,而不需要买家在支付宝的付款流程中再次填写收货信息。 //若要使用该功能,请至少保证receive_name、receive_address有值 //收货信息格式请严格按照姓名、地址、邮编、电话、手机的格式填写 $receive_name = ''; //收货人姓名,如:张三 $receive_address = ''; //收货人地址,如:XX省XXX市XXX区XXX路XXX小区XXX栋XXX单元XXX号 $receive_zip = ''; //收货人邮编,如:123456 $receive_phone = ''; //收货人电话号码,如:0571-81234567 $receive_mobile = ''; //收货人手机号码,如:13312341234 //网站商品的展示地址,不允许加?id=123这类自定义参数 $show_url = get_bloginfo('url'); /************************************************************/ //构造要请求的参数数组 $parameter = array("service" => "create_partner_trade_by_buyer", "payment_type" => "1", "partner" => trim($aliapy_config['partner']), "_input_charset" => trim(strtolower($aliapy_config['input_charset'])), "seller_email" => trim($aliapy_config['seller_email']), "return_url" => trim($aliapy_config['return_url']), "notify_url" => trim($aliapy_config['notify_url']), "out_trade_no" => $out_trade_no, "subject" => $subject, "body" => $body, "price" => $price, "quantity" => $quantity, "logistics_fee" => $logistics_fee, "logistics_type" => $logistics_type, "logistics_payment" => $logistics_payment, "receive_name" => $receive_name, "receive_address" => $receive_address, "receive_zip" => $receive_zip, "receive_phone" => $receive_phone, "receive_mobile" => $receive_mobile, "show_url" => $show_url); //构造担保交易接口 $alipayService = new AlipayService($aliapy_config); $html_text = $alipayService->create_partner_trade_by_buyer($parameter); //param end $output = "\r\n\t\t\t<html>\r\n\t\t <head>\r\n\t\t\t\t<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">\r\n\t\t <title>正在前往支付宝...</title>\r\n\t\t </head>\r\n\t\t <body><div style='display:none'>{$html_text}</div>'</body></html>"; echo $output; exit; return array('result' => 'success', 'redirect' => $output); }
/** * Find the order active number (completed or processing ) for a given user on a course. It will return the latest order. * * If multiple exist we will return the latest order. * * @param $user_id * @param $course_id * @return array $user_course_orders */ public static function get_learner_course_active_order_id($user_id, $course_id) { $course_product_id = get_post_meta($course_id, '_course_woocommerce_product', true); $orders_query = new WP_Query(array('post_type' => 'shop_order', 'posts_per_page' => -1, 'post_status' => array('wc-processing', 'wc-completed'), 'meta_key' => '_customer_user', 'meta_value' => $user_id)); if ($orders_query->post_count == 0) { return false; } foreach ($orders_query->get_posts() as $order) { $order = new WC_Order($order->ID); $items = $order->get_items(); $user_orders = array(); foreach ($items as $item) { // if the product id on the order and the one given to this function // this order has been placed by the given user on the given course. $product = wc_get_product($item['product_id']); if ($product->is_type('variable')) { $item_product_id = $item['variation_id']; } else { $item_product_id = $item['product_id']; } if ($course_product_id == $item_product_id) { return $order->id; } } //end for each order item } // end for each order // if we reach this place we found no order return false; }
/** * For each package, find the order lines that contain the products that * are included in that package, and link those order lines to this * shipping line. * The assumption is made that however the packages are grouped, each product * can only be put into one package (so no grouping by product variation, for * example). * * @order_id int The Order ID in wp_posts * @shipping_line_id int The ID of the shipping order line that has just been added. * @package_key int The index number of the package in the WC()->shipping->get_packages() list */ public static function link_shipping_line_item($order_id, $shipping_line_id, $package_key) { $packages = WC()->shipping->get_packages(); if (!isset($packages[$package_key])) { return; } $package = $packages[$package_key]; $product_ids = array(); foreach ($package['contents'] as $product) { if (!in_array($product['product_id'], $product_ids)) { $product_ids[] = $product['product_id']; } } // Add the product_ids to the shipping order line, for reference. // Implode to a string, otherwise the API has difficulty supplying it. wc_add_order_item_meta($shipping_line_id, self::ORDER_PRODUCT_IDS_FIELD, implode('|', $product_ids), true); // Go through the order lines and find those that contain these product. $order_line_ids = array(); $order = new WC_Order($order_id); foreach ($order->get_items() as $order_line_id => $product) { if (isset($product['product_id']) && in_array($product['product_id'], $product_ids)) { $order_line_ids[] = $order_line_id; // Link this product order line to its shipping order line. wc_add_order_item_meta($order_line_id, static::SHIPPING_LINE_ID_FIELD, $shipping_line_id, true); } } // Throw the order line IDs onto the shipping line too, for a two-way // link. // Convert it to a string before saving it, as arrays do not get exposed to the REST API. wc_add_order_item_meta($shipping_line_id, static::ORDER_LINE_IDS_FIELD, implode('|', $order_line_ids), true); }
function show_course_message_woocommerce_order_details_after_order_table($order) { global $coursepress; $order_details = new WC_Order($order->id); $order_items = $order_details->get_items(); $purchased_course = false; foreach ($order_items as $order_item) { $course_id = wp_get_post_parent_id($order_item['product_id']); if ($course_id && get_post_type($course_id) == 'course') { $purchased_course = true; } } if ($purchased_course) { ?> <h2 class="cp_woo_header"><?php _e('Course', 'cp'); ?> </h2> <p class="cp_woo_thanks"><?php _e('Thank you for signing up for the course. We hope you enjoy your experience.'); ?> </p> <?php if (is_user_logged_in() && $order->post_status == 'wc-completed') { ?> <p class="cp_woo_dashboard_link"> <?php printf(__('You can find the course in your <a href="%s">Dashboard</a>', 'cp'), $coursepress->get_student_dashboard_slug(true)); ?> </p> <hr /> <?php } } }
/** * Sets attendee data on order posts * * @since 4.1 * * @param int $order_id WooCommerce Order ID * @param array $post_data Data submitted via POST during checkout */ public function save_attendee_meta_to_order($order_id, $post_data) { $order = new WC_Order($order_id); $order_items = $order->get_items(); // Bail if the order is empty if (empty($order_items)) { return; } $product_ids = array(); // gather product ids foreach ((array) $order_items as $item) { $product_ids[] = isset($item['product_id']) ? $item['product_id'] : $item['id']; } $meta_object = Tribe__Tickets_Plus__Main::instance()->meta(); // build the custom meta data that will be stored in the order meta if (!($order_meta = $meta_object->build_order_meta($product_ids))) { return; } // store the custom meta on the order update_post_meta($order_id, Tribe__Tickets_Plus__Meta::META_KEY, $order_meta, true); // clear out product custom meta data cookies foreach ($product_ids as $product_id) { $meta_object->clear_meta_cookie_data($product_id); } }
/** * If user buys the bundles, this function is called to add credits */ function check_thankyou($order_id) { if (is_user_logged_in()) { global $post; $thank_page_id = get_option('woocommerce_checkout_page_id'); if ($post && $thank_page_id && $thank_page_id == $post->ID && $order_id) { global $wpdb; $paid = $wpdb->get_row("SELECT order_id FROM `" . $wpdb->prefix . "woocredit_orders` WHERE order_id=" . $order_id); print_r($paid); $order = new WC_Order($order_id); $items = $order->get_items(); if (count($items) > 0 && !$paid) { $getUserCredit = 0; $getUserCredit = getUserCredit(get_current_user_id()); $credits = 0; foreach ($items as $item) { $credits += get_post_meta($item['product_id'], '_credits_amount', true) * $item['qty']; } $credits = $getUserCredit + $credits; if ($getUserCredit == NULL) { $wpdb->query("INSERT INTO `" . $wpdb->prefix . "woocredit_users` (`user_id`, `credit`) VALUES ('" . get_current_user_id() . "', '" . $credits . "')"); } if ($getUserCredit != NULL) { $wpdb->query("UPDATE `" . $wpdb->prefix . "woocredit_users` SET `credit` ='" . $credits . "' WHERE user_id=" . get_current_user_id()); } $wpdb->query("INSERT INTO `" . $wpdb->prefix . "woocredit_orders` (`user_id`, `order_id`) VALUES ('" . get_current_user_id() . "', '" . $order_id . "')"); } } } }
public function add_edit_link_to_order_item($link, $item) { if (isset($item['fpd_data'])) { $view_order_endpoint = get_option('woocommerce_myaccount_view_order_endpoint'); $order_received_endpoint = get_option('woocommerce_checkout_order_received_endpoint'); //check if on view order page, +2.1 if (isset($_GET[$view_order_endpoint])) { $order_id = $_GET[$view_order_endpoint]; } else { if (isset($_GET[$order_received_endpoint])) { $order_id = $_GET[$order_received_endpoint]; } else { $url = $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI']; $template_name = strpos($url, '/order-received/') === false ? '/' . $view_order_endpoint . '/' : '/' . $order_received_endpoint . '/'; if (strpos($url, $template_name) !== false) { $start = strpos($url, $template_name); $first_part = substr($url, $start + strlen($template_name)); $order_id = substr($first_part, 0, strpos($first_part, '/')); } } } if (isset($order_id)) { $order = new WC_Order($order_id); foreach ($order->get_items() as $key => $value) { if ($value === $item) { $link = '<a href="' . add_query_arg(array('order' => $order_id, 'item_id' => $key), get_permalink($item['product_id'])) . '">' . $item['name'] . '</a>'; } } } } return $link; }
function wpcomm_renewal_meta_update($order_meta, $order_id) { global $wpdb, $woocommerce; // Send me an email if this hook works error_log("woocommerce_subscriptions_renewal_order_created hook fired", 1, "*****@*****.**", "Subject: woocommerce_subscriptions_renewal_order_created"); if (!is_object($order)) { $order = new WC_Order($order); } // Get the values we need from the WC_Order object $order_id = $order->id; $item = $order->get_items(); $product_id = WC_Subscriptions_Order::get_items_product_id($item[0]); // These arrays contain the details for each possible product, in order. They // are used to change the order to the correct values $quarterly_product_ids = array(2949, 2945, 2767, 2793, 2795, 2796, 2798, 2799, 2800, 2805, 2806, 2815, 2816, 2817); $quarterly_product_names = array("One Day Renewal for Testing No Virtual Downloadable", "One Day Renewal for Testing", "0-3 MONTHS ELEPHANT (QUARTERLY)", "3-6 MONTHS HIPPO (QUARTERLY)", "6-9 MONTHS GIRAFFE (QUARTERLY)", "9-12 MONTHS PANDA (QUARTERLY)", "12-15 MONTHS ZEBRA (QUARTERLY)", "15-18 MONTHS RABBIT (QUARTERLY)", "18-21 MONTHS MONKEY (QUARTERLY)", "21-24 MONTHS FROG (QUARTERLY)", "24-27 MONTHS KANGAROO (QUARTERLY)", "27-30 MONTHS BEAR (QUARTERLY)", "30-33 MONTHS TIGER (QUARTERLY)", "33-36 MONTHS CROCODILE (QUARTERLY)"); // Not sure yet if SKUs are needed $quarterly_product_skus = array("test sku one", "test sku two", "0-3-elephant-q", "3-6-hippo-q", "6-9-giraffe-q", "9-12-panda-q", "12-15-zebra-q", "15-18-rabbit-q", "18-21-monkey-q", "21-24-frog-q", "24-24-kangaroo-q", "27-30-bear-q", "30-33-tiger-q", "33-36-crocodile-q"); $yearly_product_names = array(); $yearly_product_ids = array(); // Get the position of the current id, and then assign the next product // to $incremented_item_id and $incremented_item_name $product_id_index = array_search($product_id, $quarterly_product_ids); if ($product_id_index === False) { $product_id_index = array_search($product_id, $yearly_product_ids); } $incremented_item_id = $quarterly_product_ids[$product_id_index + 1]; $incremented_item_name = $quarterly_product_names[$product_id_index + 1]; $incremented_item_sku = $quarterly_product_skus[$product_id_index + 1]; // Apply the updates to the order $order_meta["_product_id"] = $incremented_item_id; $order_meta["_product_name"] = $incremented_item_name; $order_meta["_sku"] = $incremented_item_sku; return $order_meta; }