Author: WooThemes
Inheritance: extends WC_Abstract_Order
 /**
  * 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;
 }
示例#2
1
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 custom order actions in order list view
  *
  * @since 1.0.0
  * @param array $actions
  * @param \WC_Order $order
  * @return array
  */
 public function custom_order_actions($actions, WC_Order $order)
 {
     $status = new WC_Order_Status_Manager_Order_Status($order->get_status());
     // Sanity check: bail if no status was found.
     // This can happen if some statuses are registered late
     if (!$status || !$status->get_id()) {
         return $actions;
     }
     $next_statuses = $status->get_next_statuses();
     $order_statuses = wc_get_order_statuses();
     $custom_actions = array();
     // TODO: Change action to `woocommerce_mark_order_status` for 2.3.x compatibility
     // TODO: Change nonce_action to `woocommerce-mark-order-status` for 2.3.x compatibility
     $action = 'wc_order_status_manager_mark_order_status';
     $nonce_action = 'wc-order-status-manager-mark-order-status';
     // Add next statuses as actions
     if (!empty($next_statuses)) {
         foreach ($next_statuses as $next_status) {
             $custom_actions[$next_status] = array('url' => wp_nonce_url(admin_url('admin-ajax.php?action=' . $action . '&status=' . $next_status . '&order_id=' . $order->id), $nonce_action), 'name' => $order_statuses['wc-' . $next_status], 'action' => $next_status);
             // Remove duplicate built-in complete action
             if ('completed' === $next_status) {
                 unset($actions['complete']);
             }
         }
     }
     // Next status actions are prepended to any existing actions
     return $custom_actions + $actions;
 }
 /**
  * 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);
 }
 public function add_meta_boxes()
 {
     global $post;
     if (isset($_GET['post'])) {
         if (get_post_meta($_GET['post'], '_payment_method', true) == 'inicis_escrow_bank') {
             $payment_method = get_post_meta($_GET['post'], '_payment_method', true);
             $tmp_settings = get_option('woocommerce_' . $payment_method . '_settings', true);
             $refund_mypage_status = $tmp_settings['possible_register_delivery_info_status_for_admin'];
             //관리자 배송정보 등록/환불 가능 주문상태 지정
             $order = new WC_Order($post->ID);
             $paid_order = get_post_meta($post->ID, "_paid_date", true);
             if (in_array($order->get_status(), $refund_mypage_status) && !empty($paid_order)) {
                 add_meta_box('ifw-order-escrow-register-delivery-request', __('이니시스 에스크로', 'codem_inicis'), 'IFW_Meta_Box_Escrow_Register_Delivery::output', 'shop_order', 'side', 'default');
             }
         } else {
             if (get_post_meta($_GET['post'], '_payment_method', true) == 'inicis_vbank') {
                 add_meta_box('ifw-order-vbank-refund-request', __('가상계좌 무통장입금 환불 처리', 'codem_inicis'), 'IFW_Meta_Box_Vbank_Refund::output', 'shop_order', 'side', 'default');
             } else {
                 if (in_array(get_post_meta($_GET['post'], '_payment_method', true), array('inicis_card', 'inicis_bank', 'inicis_hpp', 'inicis_kpay', 'inicis_stdcard'))) {
                     $order = new WC_Order($_GET['post']);
                     if (!in_array($order->get_status(), array('pending', 'on-hold'))) {
                         add_meta_box('ifw-order-refund-request', __('결제내역', 'codem_inicis'), 'IFW_Meta_Box_Refund::output', 'shop_order', 'side', 'default');
                     }
                 }
             }
         }
     }
 }
 /**
  * Add content to the WC emails.
  *
  * @access public
  * @param WC_Order $order
  * @param bool $sent_to_admin
  * @param bool $plain_text
  *
  * @return void
  */
 public function email_instructions($order, $sent_to_admin, $plain_text = false)
 {
     if (!$sent_to_admin && 'bKash' === $order->payment_method && $order->has_status('on-hold')) {
         if ($this->instructions) {
             echo wpautop(wptexturize($this->instructions)) . PHP_EOL;
         }
     }
 }
 /**
  * @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'];
 }
 /**
  * Track custom user properties via the Mixpanel API
  *
  * This example illustrates how to add/update the "Last Subscription Billing Amount"
  * user property when a subscription is renewed.
  *
  * @param \WC_Order  $renewal_order
  * @param \WC_Order  $original_order
  * @param int        $product_id the
  * @param \WC_Order  $new_order_role
  */
 function sv_wc_mixpanel_renewed_subscription($renewal_order, $original_order, $product_id, $new_order_role)
 {
     if (!function_exists('wc_mixpanel')) {
         return;
     }
     $properties = array('Last Subscription Billing Amount' => $renewal_order->get_total());
     wc_mixpanel()->get_integration()->custom_user_properties_api($properties, $renewal_order->user_id);
 }
    /**
     * Output the order tracking code for enabled networks
     *
     * @param int $order_id
     *
     * @return string
     */
    public function output_order_tracking_code($order_id)
    {
        $order = new WC_Order($order_id);
        $code = "<script>fbq('track', 'Purchase', {value: '" . esc_js($order->get_total()) . "', currency: '" . esc_js($order->get_order_currency()) . "'});</script>";
        $code .= '<noscript><img height="1" width="1" style="display:none"
src="https://www.facebook.com/tr?id=' . esc_js($this->facebook_id) . '&ev=Purchase&amp;cd[value]=' . urlencode($order->get_total()) . '&amp;cd[currency]=' . urlencode($order->get_order_currency()) . '&noscript=1"
/></noscript>';
        echo $code;
    }
示例#10
0
 /**
  * Add content to the WC emails.
  *
  * Note: The difference from WC_Gateway_BACS is that we use __() before
  * passing the string through wptexturize() and wpautop().
  *
  * @param WC_Order $order
  * @param bool     $sent_to_admin
  * @param bool     $plain_text
  */
 public function email_instructions($order, $sent_to_admin, $plain_text = false)
 {
     if (!$sent_to_admin && 'bacs' === $order->payment_method && $order->has_status('on-hold')) {
         if ($this->instructions) {
             echo wpautop(wptexturize(function_exists('pll__') ? pll__($this->instructions) : __($this->instructions, 'woocommerce'))) . PHP_EOL;
         }
         $this->bank_details($order->id);
     }
 }
    /**
     * 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 &rarr;', '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);
    }
 /**
  * Get a link to the transaction on the 3rd party gateway size (if applicable)
  *
  * @param  WC_Order $order the order object
  * @return string transaction URL, or empty string
  */
 public function get_transaction_url($order)
 {
     $return_url = '';
     $transaction_id = $order->get_transaction_id();
     if (!empty($this->view_transaction_url) && !empty($transaction_id)) {
         $return_url = sprintf($this->view_transaction_url, $transaction_id);
     }
     return apply_filters('woocommerce_get_transaction_url', $return_url, $order, $this);
 }
 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);
             }
         }
     }
 }
 /**
  * Retrieve an order.
  * 
  * @param int $order_id
  * @return WC_Order or null
  */
 public static function get_order($order_id = '')
 {
     $result = null;
     $order = new WC_Order($order_id);
     if ($order->get_order($order_id)) {
         $result = $order;
     }
     return $result;
 }
 /**
  * Output for the order received page.
  */
 public function thankyou_page($order_id)
 {
     $order = new WC_Order($order_id);
     if ('completed' == $order->get_status()) {
         echo '<p>' . __('Your booking has been confirmed. Thank you.', 'woocommerce-bookings') . '</p>';
     } else {
         echo '<p>' . __('Your booking is awaiting confirmation. You will be notified by email as soon as we\'ve confirmed availability.', 'woocommerce-bookings') . '</p>';
     }
 }
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;
}
示例#17
-1
文件: Meta.php 项目: TakenCdosG/chefs
 /**
  * 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);
     }
 }
 public function process_payment($order_id)
 {
     try {
         global $woocommerce;
         $customer_order = new WC_Order($order_id);
         PayU_Middleware::$api_key = $this->api_key;
         PayU_Middleware::$api_login = $this->api_login;
         PayU_Middleware::$merchant_id = $this->merchant_id;
         PayU_Middleware::$account_id = $this->account_id;
         PayU_Middleware::$test_mode = $this->environment == 'yes';
         $cardNumber = str_replace(array(' ', ''), '', $_POST['GP_PayU_online_Gateway-card-number']);
         $expirationArray = explode('/', $_POST['GP_PayU_online_Gateway-card-expiry']);
         $expirationDate = '20' . $expirationArray[1] . '/' . $expirationArray[0];
         $expirationDate = str_replace(' ', '', $expirationDate);
         $payerName = $customer_order->billing_first_name . ' ' . $customer_order->billing_last_name;
         $cvv = $_POST['GP_PayU_online_Gateway-card-cvc'];
         $res = PayU_Middleware::do_payment($order_id, $this->payment_description . $order_id, $customer_order->order_total, $customer_order->billing_email, $payerName, '111', $cardNumber, $cvv, $expirationDate, '', false);
         if (isset($res['code']) == true && isset($res['state']) == true && $res['code'] == 'SUCCESS' && $res['state'] == "APPROVED") {
             do_action('gp_order_online_completed_successfully', $res);
             if ($this->mark_order == 'yes') {
                 $woocommerce->cart->empty_cart();
                 $customer_order->payment_complete();
                 $customer_order->update_status('completed');
             }
             return array('result' => 'success', 'redirect' => $this->thankyou_page_url . '?order_id=' . $order_id);
         } else {
             do_action('gp_order_online_completed_failed', $res);
         }
     } catch (PayUException $e) {
         do_action('gp_error_occurred', $e);
     } catch (Exception $e) {
         do_action('gp_error_occurred', $e);
     }
 }
            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 
                    }
                }
            }
 /**
  *  Main callback function
  * 
  */
 function gocoin_callback()
 {
     if (isset($_GET['gocoin_callback'])) {
         global $woocommerce;
         require plugin_dir_path(__FILE__) . 'gocoin-lib.php';
         $gateways = $woocommerce->payment_gateways->payment_gateways();
         if (!isset($gateways['gocoin'])) {
             return;
         }
         $gocoin = $gateways['gocoin'];
         $response = getNotifyData();
         if (isset($response->error)) {
             var_dump($response);
         } else {
             $orderId = (int) $response->payload->order_id;
             $order = new WC_Order($orderId);
             switch ($response->event) {
                 case 'invoice_created':
                 case 'invoice_payment_received':
                     break;
                 case 'invoice_ready_to_ship':
                     if (in_array($order->status, array('on-hold', 'pending', 'failed'))) {
                         $order->payment_complete();
                     }
                     break;
             }
         }
     }
 }
示例#21
-1
文件: User.php 项目: a-kachuk/wp
 public function getRefMoney()
 {
     $sum_ref = 0;
     $args = array('post_type' => 'shop_order', 'post_status' => 'publish', 'posts_per_page' => 10, 'tax_query' => array(array('taxonomy' => 'shop_order_status', 'field' => 'slug', 'terms' => array('completed'))));
     $arr = $this->get_refals();
     $orders = get_posts($args);
     foreach ($orders as $order) {
         #print_r ($order);
         $info = new WC_Order($order->ID);
         #print $info->user_id;
         /*My Orders */
         if ($info->user_id == $this->id) {
             $this->orders[] = $info;
         }
         if (!$this->in_ref($info->user_id, $arr)) {
             continue;
         }
         $sum = $info->get_total();
         $sum_ref += $sum;
     }
     if ($sum_ref > 0) {
         $sum_ref = $sum_ref * 0.1;
     }
     return $sum_ref;
 }
 /**
  * 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);
 }
示例#23
-1
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;
}
 public function process_payment($order_id)
 {
     try {
         global $woocommerce;
         $customer_order = new WC_Order($order_id);
         PayU_Middleware::$api_key = $this->api_key;
         PayU_Middleware::$api_login = $this->api_login;
         PayU_Middleware::$merchant_id = $this->merchant_id;
         PayU_Middleware::$account_id = $this->account_id;
         PayU_Middleware::$test_mode = $this->environment == 'yes';
         $payerName = $customer_order->billing_first_name . ' ' . $customer_order->billing_last_name;
         $method = $_POST["GP_PayU_offline_Gateway-offlinemethod"];
         $res = PayU_Middleware::do_payment($order_id, $this->payment_description . $order_id, $customer_order->order_total, $customer_order->billing_email, $payerName, '123', '', '', '', $method, true);
         if ($res['code'] == 'SUCCESS' && $res['state'] == "PENDING") {
             if ($this->mark_order == 'yes') {
                 $woocommerce->cart->empty_cart();
                 $customer_order->update_status('pending');
             }
             return array('result' => 'success', 'redirect' => $this->thankyou_page_url . '?order_id=' . $order_id . '&receipt_url=' . $res['payment_url']);
         }
     } catch (PayUException $e) {
         do_action('gp_error_occurred', $e);
     } catch (Exception $e) {
         do_action('gp_error_occurred', $e);
     }
 }
 /**
  * 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);
 }
示例#26
-1
/**
 * 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 . "')");
            }
        }
    }
}
 /**
  * @param int $order_id
  * @return array
  */
 public function process_payment($order_id)
 {
     // get order object
     $order = new WC_Order($order_id);
     $cashback = isset($_POST['pos-cashback']) ? wc_format_decimal($_POST['pos-cashback']) : 0;
     if ($cashback !== 0) {
         // add order meta
         update_post_meta($order_id, '_pos_card_cashback', $cashback);
         // add cashback as fee line item
         // TODO: this should be handled by $order->add_fee after WC 2.2
         $item_id = wc_add_order_item($order_id, array('order_item_name' => __('Cashback', 'woocommerce-pos'), 'order_item_type' => 'fee'));
         if ($item_id) {
             wc_add_order_item_meta($item_id, '_line_total', $cashback);
             wc_add_order_item_meta($item_id, '_line_tax', 0);
             wc_add_order_item_meta($item_id, '_line_subtotal', $cashback);
             wc_add_order_item_meta($item_id, '_line_subtotal_tax', 0);
             wc_add_order_item_meta($item_id, '_tax_class', 'zero-rate');
         }
         // update the order total to include fee
         $order_total = get_post_meta($order_id, '_order_total', true);
         $order_total += $cashback;
         update_post_meta($order_id, '_order_total', $order_total);
     }
     // payment complete
     $order->payment_complete();
     // success
     return array('result' => 'success');
 }
示例#28
-1
/**
 * Create a new order programmatically.
 *
 * Returns a new order object on success which can then be used to add additional data.
 *
 * @param  array $args
 * @return WC_Order
 */
function wc_create_order($args = array())
{
    $default_args = array('status' => null, 'customer_id' => null, 'customer_note' => null, 'parent' => null, 'created_via' => null, 'cart_hash' => null, 'order_id' => 0);
    $args = wp_parse_args($args, $default_args);
    $order = new WC_Order($args['order_id']);
    // Update props that were set (not null)
    if (!is_null($args['parent'])) {
        $order->set_parent_id(absint($args['parent']));
    }
    if (!is_null($args['status'])) {
        $order->set_status($args['status']);
    }
    if (!is_null($args['customer_note'])) {
        $order->set_customer_note($args['customer_note']);
    }
    if (!is_null($args['customer_id'])) {
        $order->set_customer_id(is_numeric($args['customer_id']) ? absint($args['customer_id']) : 0);
    }
    if (!is_null($args['created_via'])) {
        $order->set_created_via(sanitize_text_field($args['created_via']));
    }
    if (!is_null($args['cart_hash'])) {
        $order->set_cart_hash(sanitize_text_field($args['cart_hash']));
    }
    // Update other order props set automatically
    $order->set_currency(get_woocommerce_currency());
    $order->set_prices_include_tax('yes' === get_option('woocommerce_prices_include_tax'));
    $order->set_customer_ip_address(WC_Geolocation::get_ip_address());
    $order->set_customer_user_agent(wc_get_user_agent());
    $order->save();
    return $order;
}
示例#29
-1
 /**
  * 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;
 }
 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;
 }