コード例 #1
0
 //Recalc all totals
 $order->set_total(WC()->cart->shipping_total, 'shipping');
 $order->set_total(WC()->cart->get_cart_discount_total(), 'cart_discount');
 $order->set_total(WC()->cart->get_cart_discount_tax_total(), 'cart_discount_tax');
 $order->set_total(WC()->cart->tax_total, 'tax');
 $order->set_total(WC()->cart->shipping_tax_total, 'shipping_tax');
 $order->set_total(WC()->cart->total);
 // Cart Contents
 if (sizeof($order->get_items()) > 0) {
     foreach ($order->get_items() as $item) {
         if ($item['qty']) {
             $_product = $order->get_product_from_item($item);
             // We manually calculate the tax percentage here
             if ($_product->is_taxable() && $order->get_line_tax($item) > 0) {
                 // Calculate tax percentage
                 $item_tax_percentage = round($order->get_item_tax($item, false) / $order->get_item_total($item, false, false), 2) * 100;
             } else {
                 $item_tax_percentage = 00;
             }
             $item_name = $item['name'];
             $item_meta = new WC_Order_Item_Meta($item);
             if ($meta = $item_meta->display(true, true)) {
                 $item_name .= ' ( ' . $meta . ' )';
             }
             // apply_filters to item price so we can filter this if needed
             $hygglig_item_price_including_tax = $order->get_item_total($item, true);
             $item_price = apply_filters('hygglig_item_price_including_tax', $hygglig_item_price_including_tax);
             // Get SKU or product id [TEMP ONLY USE ID]
             $reference = $_product->id;
             //If variation of product - add ID
             if ($item['variation_id']) {
コード例 #2
0
    /**
     * Process the payment
     */
    function process_payment($order_id)
    {
        if (!session_id()) {
            session_start();
        }
        $order = new WC_Order($order_id);
        if ($this->debug) {
            $this->log->add('paypal-pro', 'Processing order #' . $order_id);
        }
        $card_type = isset($_POST['paypal_pro_card_type']) ? wc_clean($_POST['paypal_pro_card_type']) : '';
        $card_number = isset($_POST['paypal_pro_card_number']) ? wc_clean($_POST['paypal_pro_card_number']) : '';
        $card_csc = isset($_POST['paypal_pro_card_csc']) ? wc_clean($_POST['paypal_pro_card_csc']) : '';
        $card_exp_month = isset($_POST['paypal_pro_card_expiration_month']) ? wc_clean($_POST['paypal_pro_card_expiration_month']) : '';
        $card_exp_year = isset($_POST['paypal_pro_card_expiration_year']) ? wc_clean($_POST['paypal_pro_card_expiration_year']) : '';
        // Format card expiration data
        $card_exp_month = (int) $card_exp_month;
        if ($card_exp_month < 10) {
            $card_exp_month = '0' . $card_exp_month;
        }
        $card_exp_year = (int) $card_exp_year;
        $card_exp_year += 2000;
        // Format card number
        $card_number = str_replace(array(' ', '-'), '', $card_number);
        /**
         * 3D Secure Handling
         */
        if ($this->enable_3dsecure) {
            if (!class_exists('CentinelClient')) {
                include_once 'lib/CentinelClient.php';
            }
            $this->clear_centinel_session();
            $centinelClient = new CentinelClient();
            $centinelClient->add("MsgType", "cmpi_lookup");
            $centinelClient->add("Version", "1.7");
            $centinelClient->add("ProcessorId", $this->centinel_pid);
            $centinelClient->add("MerchantId", $this->centinel_mid);
            $centinelClient->add("TransactionPwd", $this->centinel_pwd);
            $centinelClient->add("UserAgent", $_SERVER["HTTP_USER_AGENT"]);
            $centinelClient->add("BrowserHeader", $_SERVER["HTTP_ACCEPT"]);
            $centinelClient->add("TransactionType", 'C');
            // Standard cmpi_lookup fields
            $centinelClient->add('OrderNumber', $order_id);
            $centinelClient->add('Amount', $order->order_total * 100);
            $centinelClient->add('CurrencyCode', $this->iso4217[get_woocommerce_currency()]);
            $centinelClient->add('TransactionMode', 'S');
            // Items
            $item_loop = 0;
            if (sizeof($order->get_items()) > 0) {
                foreach ($order->get_items() as $item) {
                    $item_loop++;
                    $centinelClient->add('Item_Name_' . $item_loop, $item['name']);
                    $centinelClient->add('Item_Price_' . $item_loop, number_format($order->get_item_total($item, true, true) * 100));
                    $centinelClient->add('Item_Quantity_' . $item_loop, $item['qty']);
                    $centinelClient->add('Item_Desc_' . $item_loop, $item['id'] . ' - ' . $item['name']);
                }
            }
            // Payer Authentication specific fields
            $centinelClient->add('CardNumber', $card_number);
            $centinelClient->add('CardExpMonth', $card_exp_month);
            $centinelClient->add('CardExpYear', $card_exp_year);
            // Send request
            $centinelClient->sendHttp($this->centinel_url, "5000", "15000");
            // Save response in session
            $_SESSION["Centinel_orderid"] = $order_id;
            // Save lookup response in session
            $_SESSION["Centinel_cmpiMessageResp"] = $centinelClient->response;
            // Save lookup response in session
            $_SESSION["Centinel_Enrolled"] = $centinelClient->getValue("Enrolled");
            $_SESSION["Centinel_TransactionId"] = $centinelClient->getValue("TransactionId");
            $_SESSION["Centinel_OrderId"] = $centinelClient->getValue("OrderId");
            $_SESSION["Centinel_ACSUrl"] = $centinelClient->getValue("ACSUrl");
            $_SESSION["Centinel_Payload"] = $centinelClient->getValue("Payload");
            $_SESSION["Centinel_ErrorNo"] = $centinelClient->getValue("ErrorNo");
            $_SESSION["Centinel_ErrorDesc"] = $centinelClient->getValue("ErrorDesc");
            $_SESSION["Centinel_EciFlag"] = $centinelClient->getValue("EciFlag");
            $_SESSION["Centinel_TransactionType"] = "C";
            $_SESSION['Centinel_TermUrl'] = str_replace('http:', 'https:', add_query_arg('wc-api', 'WC_Gateway_PayPal_Pro', home_url('/')));
            /******************************************************************************/
            /*                                                                            */
            /*                          Result Processing Logic                           */
            /*                                                                            */
            /******************************************************************************/
            if ($_SESSION['Centinel_ErrorNo'] == 0) {
                if ($_SESSION['Centinel_Enrolled'] == 'Y') {
                    @ob_clean();
                    ?>
                    <html>
                    <head>
                        <title>3DSecure Payment Authorisation</title>
                    </head>
                    <body>
                    <form name="frmLaunchACS" id="3ds_submit_form" method="POST" action="<?php 
                    echo $_SESSION["Centinel_ACSUrl"];
                    ?>
">
                        <input type="hidden" name="PaReq" value="<?php 
                    echo $_SESSION["Centinel_Payload"];
                    ?>
">
                        <input type="hidden" name="TermUrl" value="<?php 
                    echo $_SESSION['Centinel_TermUrl'];
                    ?>
">
                        <input type="hidden" name="MD" value="<?php 
                    echo urlencode(serialize(array('card' => $card_number, 'type' => $card_type, 'csc' => $card_csc, 'card_exp_month' => $card_exp_month, 'card_exp_year' => $card_exp_year)));
                    ?>
">
                        <noscript>
                            <div class="woocommerce_message"><?php 
                    _e('Processing your Payer Authentication Transaction', 'paypal-for-woocommerce');
                    ?>
 - <?php 
                    _e('Please click Submit to continue the processing of your transaction.', 'paypal-for-woocommerce');
                    ?>
  <input type="submit" class="button" id="3ds_submit" value="Submit" /></div>
                        </noscript>
                    </form>
                    <script>
                        document.frmLaunchACS.submit();
                    </script>
                    </body>
                    </html>
                    <?php 
                    exit;
                } elseif ($this->liability_shift && $_SESSION['Centinel_Enrolled'] != 'N') {
                    $pc_3d_secure_authentication_unavailable = apply_filters('angelleye_pc_process_payment_authentication_unavailable', __('Authentication unavailable. Please try a different payment method or card.', 'paypal-for-woocommerce'));
                    wc_add_notice($pc_3d_secure_authentication_unavailable, "error");
                    return;
                } else {
                    // Customer not-enrolled, so just carry on with PayPal process
                    return $this->do_payment($order, $card_number, $card_type, $card_exp_month, $card_exp_year, $card_csc, '', $_SESSION['Centinel_Enrolled'], '', $_SESSION["Centinel_EciFlag"], '');
                }
            } else {
                $pc_3d_secure_authentication = apply_filters('angelleye_pc_process_payment_authentication', __('Error in 3D secure authentication: ', 'paypal-for-woocommerce') . $_SESSION['Centinel_ErrorNo'], $_SESSION['Centinel_ErrorNo']);
                wc_add_notice($pc_3d_secure_authentication, "error");
                return;
            }
        }
        // Do payment with paypal
        return $this->do_payment($order, $card_number, $card_type, $card_exp_month, $card_exp_year, $card_csc);
    }
コード例 #3
0
 /**
  * Google Analytics eCommerce tracking
  *
  * @access public
  * @param mixed $order_id
  * @return void
  */
 function ecommerce_tracking_code($order_id)
 {
     global $woocommerce;
     if ($this->ga_ecommerce_tracking_enabled == "no" || current_user_can('manage_options') || get_post_meta($order_id, '_ga_tracked', true) == 1) {
         return;
     }
     $tracking_id = $this->ga_id;
     if (!$tracking_id) {
         return;
     }
     // Doing eCommerce tracking so unhook standard tracking from the footer
     remove_action('wp_footer', array($this, 'google_tracking_code'));
     // Get the order and output tracking code
     $order = new WC_Order($order_id);
     $loggedin = is_user_logged_in() ? 'yes' : 'no';
     if (is_user_logged_in()) {
         $user_id = get_current_user_id();
         $current_user = get_user_by('id', $user_id);
         $username = $current_user->user_login;
     } else {
         $user_id = '';
         $username = __('Guest', 'woocommerce');
     }
     if (!empty($this->ga_set_domain_name)) {
         $set_domain_name = "['_setDomainName', '" . esc_js($this->ga_set_domain_name) . "'],";
     } else {
         $set_domain_name = '';
     }
     $code = "\r\n\t\t\tvar _gaq = _gaq || [];\r\n\r\n\t\t\t_gaq.push(\r\n\t\t\t\t['_setAccount', '" . esc_js($tracking_id) . "'], " . $set_domain_name . "\r\n\t\t\t\t['_setCustomVar', 1, 'logged-in', '" . esc_js($loggedin) . "', 1],\r\n\t\t\t\t['_trackPageview']\r\n\t\t\t);\r\n\r\n\t\t\t_gaq.push(['_addTrans',\r\n\t\t\t\t'" . esc_js($order->get_order_number()) . "', // order ID - required\r\n\t\t\t\t'" . esc_js(get_bloginfo('name')) . "',  \t// affiliation or store name\r\n\t\t\t\t'" . esc_js($order->get_total()) . "',   \t    // total - required\r\n\t\t\t\t'" . esc_js($order->get_total_tax()) . "',    // tax\r\n\t\t\t\t'" . esc_js($order->get_shipping()) . "',\t    // shipping\r\n\t\t\t\t'" . esc_js($order->billing_city) . "',       // city\r\n\t\t\t\t'" . esc_js($order->billing_state) . "',      // state or province\r\n\t\t\t\t'" . esc_js($order->billing_country) . "'     // country\r\n\t\t\t]);\r\n\t\t";
     // Order items
     if ($order->get_items()) {
         foreach ($order->get_items() as $item) {
             $_product = $order->get_product_from_item($item);
             $code .= "_gaq.push(['_addItem',";
             $code .= "'" . esc_js($order->get_order_number()) . "',";
             $code .= "'" . esc_js($_product->get_sku() ? __('SKU:', 'woocommerce') . ' ' . $_product->get_sku() : $_product->id) . "',";
             $code .= "'" . esc_js($item['name']) . "',";
             if (isset($_product->variation_data)) {
                 $code .= "'" . esc_js(woocommerce_get_formatted_variation($_product->variation_data, true)) . "',";
             } else {
                 $out = array();
                 $categories = get_the_terms($_product->id, 'product_cat');
                 if ($categories) {
                     foreach ($categories as $category) {
                         $out[] = $category->name;
                     }
                 }
                 $code .= "'" . esc_js(join("/", $out)) . "',";
             }
             $code .= "'" . esc_js($order->get_item_total($item, true, true)) . "',";
             $code .= "'" . esc_js($item['qty']) . "'";
             $code .= "]);";
         }
     }
     $code .= "\r\n\t\t\t_gaq.push(['_trackTrans']); \t\t\t\t\t// submits transaction to the Analytics servers\r\n\r\n\t\t\t(function() {\r\n\t\t\t\tvar ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;\r\n\t\t\t\tga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';\r\n\t\t\t\tvar s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);\r\n\t\t\t})();\r\n\t\t";
     echo '<script type="text/javascript">' . $code . '</script>';
     update_post_meta($order_id, '_ga_tracked', 1);
 }
コード例 #4
0
 /**
  * Get the order data for the given ID.
  *
  * @since  2.5.0
  * @param  WC_Order $order The order instance
  * @return array
  */
 protected function get_order_data($order)
 {
     $order_post = get_post($order->id);
     $dp = wc_get_price_decimals();
     $order_data = array('id' => $order->id, 'order_number' => $order->get_order_number(), 'created_at' => $this->format_datetime($order_post->post_date_gmt), 'updated_at' => $this->format_datetime($order_post->post_modified_gmt), 'completed_at' => $this->format_datetime($order->completed_date, true), 'status' => $order->get_status(), 'currency' => $order->get_order_currency(), 'total' => wc_format_decimal($order->get_total(), $dp), 'subtotal' => wc_format_decimal($order->get_subtotal(), $dp), 'total_line_items_quantity' => $order->get_item_count(), 'total_tax' => wc_format_decimal($order->get_total_tax(), $dp), 'total_shipping' => wc_format_decimal($order->get_total_shipping(), $dp), 'cart_tax' => wc_format_decimal($order->get_cart_tax(), $dp), 'shipping_tax' => wc_format_decimal($order->get_shipping_tax(), $dp), 'total_discount' => wc_format_decimal($order->get_total_discount(), $dp), 'shipping_methods' => $order->get_shipping_method(), 'payment_details' => array('method_id' => $order->payment_method, 'method_title' => $order->payment_method_title, 'paid' => isset($order->paid_date)), 'billing_address' => array('first_name' => $order->billing_first_name, 'last_name' => $order->billing_last_name, 'company' => $order->billing_company, 'address_1' => $order->billing_address_1, 'address_2' => $order->billing_address_2, 'city' => $order->billing_city, 'state' => $order->billing_state, 'postcode' => $order->billing_postcode, 'country' => $order->billing_country, 'email' => $order->billing_email, 'phone' => $order->billing_phone), 'shipping_address' => array('first_name' => $order->shipping_first_name, 'last_name' => $order->shipping_last_name, 'company' => $order->shipping_company, 'address_1' => $order->shipping_address_1, 'address_2' => $order->shipping_address_2, 'city' => $order->shipping_city, 'state' => $order->shipping_state, 'postcode' => $order->shipping_postcode, 'country' => $order->shipping_country), 'note' => $order->customer_note, 'customer_ip' => $order->customer_ip_address, 'customer_user_agent' => $order->customer_user_agent, 'customer_id' => $order->get_user_id(), 'view_order_url' => $order->get_view_order_url(), 'line_items' => array(), 'shipping_lines' => array(), 'tax_lines' => array(), 'fee_lines' => array(), 'coupon_lines' => array());
     // add line items
     foreach ($order->get_items() as $item_id => $item) {
         $product = $order->get_product_from_item($item);
         $product_id = null;
         $product_sku = null;
         // Check if the product exists.
         if (is_object($product)) {
             $product_id = isset($product->variation_id) ? $product->variation_id : $product->id;
             $product_sku = $product->get_sku();
         }
         $meta = new WC_Order_Item_Meta($item, $product);
         $item_meta = array();
         foreach ($meta->get_formatted(null) as $meta_key => $formatted_meta) {
             $item_meta[] = array('key' => $meta_key, 'label' => $formatted_meta['label'], 'value' => $formatted_meta['value']);
         }
         $order_data['line_items'][] = array('id' => $item_id, 'subtotal' => wc_format_decimal($order->get_line_subtotal($item, false, false), $dp), 'subtotal_tax' => wc_format_decimal($item['line_subtotal_tax'], $dp), 'total' => wc_format_decimal($order->get_line_total($item, false, false), $dp), 'total_tax' => wc_format_decimal($item['line_tax'], $dp), 'price' => wc_format_decimal($order->get_item_total($item, false, false), $dp), 'quantity' => wc_stock_amount($item['qty']), 'tax_class' => !empty($item['tax_class']) ? $item['tax_class'] : null, 'name' => $item['name'], 'product_id' => $product_id, 'sku' => $product_sku, 'meta' => $item_meta);
     }
     // Add shipping.
     foreach ($order->get_shipping_methods() as $shipping_item_id => $shipping_item) {
         $order_data['shipping_lines'][] = array('id' => $shipping_item_id, 'method_id' => $shipping_item['method_id'], 'method_title' => $shipping_item['name'], 'total' => wc_format_decimal($shipping_item['cost'], $dp));
     }
     // Add taxes.
     foreach ($order->get_tax_totals() as $tax_code => $tax) {
         $order_data['tax_lines'][] = array('id' => $tax->id, 'rate_id' => $tax->rate_id, 'code' => $tax_code, 'title' => $tax->label, 'total' => wc_format_decimal($tax->amount, $dp), 'compound' => (bool) $tax->is_compound);
     }
     // Add fees.
     foreach ($order->get_fees() as $fee_item_id => $fee_item) {
         $order_data['fee_lines'][] = array('id' => $fee_item_id, 'title' => $fee_item['name'], 'tax_class' => !empty($fee_item['tax_class']) ? $fee_item['tax_class'] : null, 'total' => wc_format_decimal($order->get_line_total($fee_item), $dp), 'total_tax' => wc_format_decimal($order->get_line_tax($fee_item), $dp));
     }
     // Add coupons.
     foreach ($order->get_items('coupon') as $coupon_item_id => $coupon_item) {
         $order_data['coupon_lines'][] = array('id' => $coupon_item_id, 'code' => $coupon_item['name'], 'amount' => wc_format_decimal($coupon_item['discount_amount'], $dp));
     }
     $order_data = apply_filters('woocommerce_cli_order_data', $order_data);
     return $this->flatten_array($order_data);
 }
コード例 #5
0
 /**
  * Get order items.
  *
  * @param  WC_Order $order Order data.
  *
  * @return array           Items list, extra amount and shipping cost.
  */
 protected function get_order_items($order)
 {
     $items = array();
     $extra_amount = 0;
     $shipping_cost = 0;
     // Force only one item.
     if ('yes' == $this->gateway->send_only_total) {
         $items[] = array('description' => $this->sanitize_description(sprintf(__('Order %s', 'woocommerce-pagseguro'), $order->get_order_number())), 'amount' => $this->money_format($order->get_total()), 'quantity' => 1);
     } else {
         // Products.
         if (0 < count($order->get_items())) {
             foreach ($order->get_items() as $order_item) {
                 if ($order_item['qty']) {
                     $item_name = $order_item['name'];
                     if (defined('WC_VERSION') && version_compare(WC_VERSION, '2.4.0', '<')) {
                         $item_meta = new WC_Order_Item_Meta($order_item['item_meta']);
                     } else {
                         $item_meta = new WC_Order_Item_Meta($order_item);
                     }
                     if ($meta = $item_meta->display(true, true)) {
                         $item_name .= ' - ' . $meta;
                     }
                     $items[] = array('description' => $this->sanitize_description($item_name), 'amount' => $this->money_format($order->get_item_total($order_item, false)), 'quantity' => $order_item['qty']);
                 }
             }
         }
         // Fees.
         if (0 < count($order->get_fees())) {
             foreach ($order->get_fees() as $fee) {
                 $items[] = array('description' => $this->sanitize_description($fee['name']), 'amount' => $this->money_format($fee['line_total']), 'quantity' => 1);
             }
         }
         // Taxes.
         if (0 < count($order->get_taxes())) {
             foreach ($order->get_taxes() as $tax) {
                 $items[] = array('description' => $this->sanitize_description($tax['label']), 'amount' => $this->money_format($tax['tax_amount'] + $tax['shipping_tax_amount']), 'quantity' => 1);
             }
         }
         // Shipping Cost.
         if (0 < $order->get_total_shipping()) {
             $shipping_cost = $this->money_format($order->get_total_shipping());
         }
         // Discount.
         if (defined('WC_VERSION') && version_compare(WC_VERSION, '2.3', '<')) {
             if (0 < $order->get_order_discount()) {
                 $extra_amount = '-' . $this->money_format($order->get_order_discount());
             }
         }
     }
     return array('items' => $items, 'extra_amount' => $extra_amount, 'shipping_cost' => $shipping_cost);
 }
コード例 #6
0
 /**
  * Get vendor commission per item for an order
  *
  * @param int $product_id
  * @param int $variation_id
  * @param array $item
  * @param int $order_id
  *
  * @return $commission_amount
  */
 public function get_item_commission($product_id, $variation_id, $item, $order_id, $item_id = '')
 {
     global $WCMp;
     $order = new WC_Order($order_id);
     $amount = 0;
     $commission = array();
     if (isset($WCMp->vendor_caps->payment_cap['commission_include_coupon'])) {
         $line_total = $order->get_item_total($item, false, false) * $item['qty'];
     } else {
         $line_total = $order->get_item_subtotal($item, false, false) * $item['qty'];
     }
     if ($product_id && $line_total) {
         $vendor_id = $order->get_item_meta($item_id, '_vendor_id', true);
         if ($vendor_id) {
             $vendor = get_wcmp_vendor($vendor_id);
         } else {
             $vendor = get_wcmp_product_vendors($product_id);
         }
         if ($vendor) {
             $commission = $this->get_commission_amount($product_id, $vendor->term_id, $variation_id, $item_id, $order);
             if (!empty($commission)) {
                 if ($WCMp->vendor_caps->payment_cap['commission_type'] == 'fixed_with_percentage') {
                     $amount = (double) $line_total * ((double) $commission['commission_val'] / 100) + (double) $commission['commission_fixed'];
                 } else {
                     if ($WCMp->vendor_caps->payment_cap['commission_type'] == 'fixed_with_percentage_qty') {
                         $amount = (double) $line_total * ((double) $commission['commission_val'] / 100) + (double) $commission['commission_fixed'] * $item['qty'];
                     } else {
                         if ($WCMp->vendor_caps->payment_cap['commission_type'] == 'percent') {
                             $amount = (double) $line_total * ((double) $commission['commission_val'] / 100);
                         } else {
                             if ($WCMp->vendor_caps->payment_cap['commission_type'] == 'fixed') {
                                 $amount = (double) $commission['commission_val'] * $item['qty'];
                             }
                         }
                     }
                 }
                 if (isset($WCMp->vendor_caps->payment_cap['revenue_sharing_mode'])) {
                     if ($WCMp->vendor_caps->payment_cap['revenue_sharing_mode'] == 'admin') {
                         $amount = (double) $line_total - (double) $amount;
                         if ($amount < 0) {
                             $amount = 0;
                         }
                     }
                 }
                 return apply_filters('vendor_commission_amount', $amount);
             }
         }
     }
     return apply_filters('vendor_commission_amount', $amount);
 }
    /**
     * Output the order tracking code for link connector
     *
     * @param WC_Order $order
     *
     * @return string
     */
    public function output_impact_radius_order_code($order)
    {
        if (!$this->impact_radius_src) {
            return;
        }
        $code = '<script src="https://' . $this->impact_radius_src . '"></script>';
        $code .= '<script>/* <![CDATA[ */
    irEvent.setOrderId("' . esc_js($order->get_order_number()) . '");';
        if ($order->get_items()) {
            foreach ($order->get_items() as $item) {
                $_product = $order->get_product_from_item($item);
                $categories = get_the_terms($_product->id, 'product_cat');
                $category = $categories ? $category[0]->name : '';
                $sku = $_product->get_sku() ? $_product->get_sku() : $_product->id;
                $code .= '
    irEvent.addItem("' . esc_js($category) . '", "' . esc_js($sku) . '", "' . esc_js($order->get_item_total($item)) . '", "' . esc_js($item['qty']) . '");';
            }
        }
        $coupons = $order->get_used_coupons();
        $coupon = $coupons ? $coupons[0] : '';
        $code .= '
    irEvent.setPromoCode("' . esc_js($coupon) . '");
    irEvent.fire();
/* ]]> */</script>';
        echo $code;
    }
コード例 #8
0
        /**
         * Generate the Google Checkout button link
         **/
        public function generate_googlecheckout_form($order_id)
        {
            global $woocommerce;
            require_once GOOGLE_CHECKOUT_LIB . 'googlecart.php';
            require_once GOOGLE_CHECKOUT_LIB . 'googleitem.php';
            require_once GOOGLE_CHECKOUT_LIB . 'googleshipping.php';
            require_once GOOGLE_CHECKOUT_LIB . 'googletax.php';
            $order = new WC_Order($order_id);
            $shipping_name = explode(' ', $order->shipping_method);
            // Check if this is a test purchase
            if ($this->testmode == 'yes') {
                $server_type = "sandbox";
            } else {
                $server_type = "checkout";
            }
            $merchant_id = $this->merchant_id;
            // Your Merchant ID
            $merchant_key = $this->merchant_key;
            // Your Merchant Key
            $currency = get_option('woocommerce_currency');
            $cart = new GoogleCart($merchant_id, $merchant_key, $server_type, $currency);
            // Specify <edit-cart-url>
            $cart->SetEditCartUrl(get_permalink(get_option('woocommerce_cart_page_id')));
            // Specify "Return to xyz" link
            $cart->SetContinueShoppingUrl(add_query_arg('key', $order->order_key, add_query_arg('order', $order_id, get_permalink(get_option('woocommerce_thanks_page_id')))));
            // Order key
            $cart->SetMerchantPrivateData(new MerchantPrivateData(array("cart-id" => $order->id)));
            // Request buyer's phone number
            $cart->SetRequestBuyerPhone(true);
            // Default tax  - for shipping, if used
            if ($order->order_shipping_tax > 0) {
                // We manually calculate the shipping tax percentage here
                $calculated_shipping_tax_percentage = $order->order_shipping_tax / $order->order_shipping;
                $tax_rule_for_shipping = new GoogleDefaultTaxRule($calculated_shipping_tax_percentage, 'true');
                $tax_rule_for_shipping->SetWorldArea(true);
                $cart->AddDefaultTaxRules($tax_rule_for_shipping);
            }
            // Shipping Cost
            if ($order->order_shipping > 0) {
                $ship_1 = new GoogleFlatRateShipping($order->shipping_method, number_format($order->order_shipping, 2));
                $restriction_1 = new GoogleShippingFilters();
                $restriction_1->SetAllowedWorldArea(true);
                $ship_1->AddShippingRestrictions($restriction_1);
                $cart->AddShipping($ship_1);
            }
            // Cart Contents
            $item_loop = 0;
            $myvat = array();
            if (sizeof($order->get_items()) > 0) {
                foreach ($order->get_items() as $item) {
                    $_product = new WC_Product($item['id']);
                    if ($_product->exists() && $item['qty']) {
                        $item_loop++;
                        // Change tax format from 25.00 to 0.25
                        $item_tax_percentage = number_format($order->get_item_tax($item, false) / $order->get_item_total($item, false, false) * 100, 2, '.', '');
                        $item_vat = $item_tax_percentage / 100;
                        $myvat[$item_loop] = $item_vat;
                        ${"item_" . $item_loop} = new GoogleItem($item['name'], "", $item['qty'], $order->get_item_total($item, false, false));
                        // Name the alternate-tax-table
                        $vat_name = "vat" . $item_vat;
                        ${"item_" . $item_loop}->SetMerchantItemId($item['id']);
                        ${"item_" . $item_loop}->SetTaxTableSelector($vat_name);
                        $cart->AddItem(${"item_" . $item_loop});
                    }
                }
            }
            // Discount
            if ($order->order_discount > 0) {
                $item_loop++;
                ${"item_" . $item_loop} = new GoogleItem(__('Discount', 'woothemes'), "", "1", -$order->order_discount);
                ${"item_" . $item_loop}->SetTaxTableSelector("no_tax");
                $cart->AddItem(${"item_" . $item_loop});
            }
            // Tax
            // Loops through all tax classes that has been added to the cart and add these as Alternate tax tables to google Checkout.
            $taxrule_loop = 1;
            $no_duplicate_vat = array_unique($myvat);
            foreach ($no_duplicate_vat as $value) {
                // Name the alternate-tax-table
                $vat_name = "vat" . $value;
                $tax_table = new GoogleAlternateTaxTable($vat_name);
                ${"tax_rule_" . $taxrule_loop} = new GoogleAlternateTaxRule($value);
                ${"tax_rule_" . $taxrule_loop}->SetWorldArea(true);
                $tax_table->AddAlternateTaxRules(${"tax_rule_" . $taxrule_loop});
                $cart->AddAlternateTaxTables($tax_table);
                $taxrule_loop++;
            }
            // The form
            return $cart->CheckoutButtonCode("SMALL") . '<script type="text/javascript">
						jQuery(function(){
							jQuery("body").block(
								{ 
									message: "<img src=\\"' . $woocommerce->plugin_url() . '/assets/images/ajax-loader.gif\\" alt=\\"Redirecting...\\" />' . __('Thank you for your order. We are now redirecting you to Google Checkout to make payment.', 'woothemes') . '", 
									overlayCSS: 
									{ 
										background: "#fff", 
										opacity: 0.6 
									},
									css: { 
                                   		padding:        20, 
                                   		textAlign:      "center", 
                                   		color:          "#555", 
                                   		border:         "3px solid #aaa", 
                                   		backgroundColor:"#fff", 
                                   		cursor:         "wait",
                                   		lineHeight:        "32px"
                               		} 
								});
							jQuery("#submit_googlecheckout_payment_form").click();
						});
					</script>';
        }
 protected function formItemsArray(\WC_Order $order)
 {
     $items = $order->get_items();
     $this->items = array();
     foreach ($items as $item) {
         $product = $order->get_product_from_item($item);
         $this->items[] = array('order_id' => $order->id, 'product_id' => $product->get_sku() ?: $item['item_meta_array']['_product_id'], 'name' => $product->get_title(), 'price' => $order->get_item_total($item), 'quantity' => !empty($item['qty']) ? $item['qty'] : 1);
     }
     return $this->items;
 }
コード例 #10
0
    /**
     * Process the payment
     */
    public function process_payment($order_id)
    {
        $order = new WC_Order($order_id);
        $this->log('Processing order #' . $order_id);
        $card_number = isset($_POST['paypal_pro-card-number']) ? wc_clean($_POST['paypal_pro-card-number']) : '';
        $card_cvc = isset($_POST['paypal_pro-card-cvc']) ? wc_clean($_POST['paypal_pro-card-cvc']) : '';
        $card_expiry = isset($_POST['paypal_pro-card-expiry']) ? wc_clean($_POST['paypal_pro-card-expiry']) : '';
        // Format values
        $card_number = str_replace(array(' ', '-'), '', $card_number);
        $card_expiry = array_map('trim', explode('/', $card_expiry));
        $card_exp_month = str_pad($card_expiry[0], 2, "0", STR_PAD_LEFT);
        $card_exp_year = $card_expiry[1];
        if (isset($_POST['paypal_pro-card-start'])) {
            $card_start = wc_clean($_POST['paypal_pro-card-start']);
            $card_start = array_map('trim', explode('/', $card_start));
            $card_start_month = str_pad($card_start[0], 2, "0", STR_PAD_LEFT);
            $card_start_year = $card_start[1];
        } else {
            $card_start_month = '';
            $card_start_year = '';
        }
        if (strlen($card_exp_year) == 2) {
            $card_exp_year += 2000;
        }
        /**
         * 3D Secure Handling
         */
        if ($this->enable_3dsecure) {
            if (!class_exists('CentinelClient')) {
                include_once 'lib/CentinelClient.php';
            }
            $this->clear_centinel_session();
            $centinelClient = new CentinelClient();
            $centinelClient->add("MsgType", "cmpi_lookup");
            $centinelClient->add("Version", "1.7");
            $centinelClient->add("ProcessorId", $this->centinel_pid);
            $centinelClient->add("MerchantId", $this->centinel_mid);
            $centinelClient->add("TransactionPwd", $this->centinel_pwd);
            $centinelClient->add("UserAgent", $_SERVER["HTTP_USER_AGENT"]);
            $centinelClient->add("BrowserHeader", $_SERVER["HTTP_ACCEPT"]);
            $centinelClient->add("TransactionType", 'C');
            // Standard cmpi_lookup fields
            $centinelClient->add('OrderNumber', $order_id);
            $centinelClient->add('Amount', $order->order_total * 100);
            $centinelClient->add('CurrencyCode', $this->iso4217[$order->get_order_currency()]);
            $centinelClient->add('TransactionMode', 'S');
            // Items
            $item_loop = 0;
            if (sizeof($order->get_items()) > 0) {
                foreach ($order->get_items() as $item) {
                    $item_loop++;
                    $centinelClient->add('Item_Name_' . $item_loop, $item['name']);
                    $centinelClient->add('Item_Price_' . $item_loop, number_format($order->get_item_total($item, true, true) * 100));
                    $centinelClient->add('Item_Quantity_' . $item_loop, $item['qty']);
                    $centinelClient->add('Item_Desc_' . $item_loop, $item['name']);
                }
            }
            // Payer Authentication specific fields
            $centinelClient->add('CardNumber', $card_number);
            $centinelClient->add('CardExpMonth', $card_exp_month);
            $centinelClient->add('CardExpYear', $card_exp_year);
            // Send request
            $centinelClient->sendHttp($this->centinel_url, "5000", "15000");
            $this->log('Centinal client request: ' . print_r($centinelClient->request, true));
            $this->log('Centinal client response: ' . print_r($centinelClient->response, true));
            // Save response in session
            WC()->session->set("paypal_pro_orderid", $order_id);
            // Save lookup response in session
            WC()->session->set("Centinel_cmpiMessageResp", $centinelClient->response);
            WC()->session->set("Centinel_Enrolled", $centinelClient->getValue("Enrolled"));
            WC()->session->set("Centinel_TransactionId", $centinelClient->getValue("TransactionId"));
            WC()->session->set("Centinel_ACSUrl", $centinelClient->getValue("ACSUrl"));
            WC()->session->set("Centinel_Payload", $centinelClient->getValue("Payload"));
            WC()->session->set("Centinel_ErrorNo", $centinelClient->getValue("ErrorNo"));
            WC()->session->set("Centinel_ErrorDesc", $centinelClient->getValue("ErrorDesc"));
            WC()->session->set("Centinel_EciFlag", $centinelClient->getValue("EciFlag"));
            WC()->session->set("Centinel_TransactionType", "C");
            WC()->session->set('Centinel_TermUrl', WC()->api_request_url('WC_Gateway_PayPal_Pro', true));
            WC()->session->set('Centinel_OrderId', $centinelClient->getValue("OrderId"));
            $this->log('3dsecure Centinel_Enrolled: ' . WC()->session->get('Centinel_Enrolled'));
            /******************************************************************************/
            /*                                                                            */
            /*                          Result Processing Logic                           */
            /*                                                                            */
            /******************************************************************************/
            if (WC()->session->get('Centinel_ErrorNo') == 0) {
                if (WC()->session->get('Centinel_Enrolled') == 'Y') {
                    $this->log('Doing 3dsecure payment authorization');
                    $this->log('ASCUrl: ' . WC()->session->get("Centinel_ACSUrl"));
                    $this->log('PaReq: ' . WC()->session->get("Centinel_Payload"));
                    $this->log('TermUrl: ' . WC()->session->get("Centinel_TermUrl"));
                    @ob_clean();
                    ?>
					<html>
						<head>
							<title>3DSecure Payment Authorisation</title>
						</head>
						<body>
							<form name="frmLaunchACS" id="3ds_submit_form" method="POST" action="<?php 
                    echo WC()->session->get("Centinel_ACSUrl");
                    ?>
">
						        <input type="hidden" name="PaReq" value="<?php 
                    echo WC()->session->get("Centinel_Payload");
                    ?>
">
						        <input type="hidden" name="TermUrl" value="<?php 
                    echo WC()->session->get('Centinel_TermUrl');
                    ?>
">
						        <input type="hidden" name="MD" value="<?php 
                    echo urlencode(json_encode(array('card' => $card_number, 'csc' => $card_cvc, 'card_exp_month' => $card_exp_month, 'card_exp_year' => $card_exp_year, 'card_start_month' => $card_start_month, 'card_start_year' => $card_start_year, 'order_id' => $order_id)));
                    ?>
">
						        <noscript>
						        	<div class="woocommerce_message"><?php 
                    _e('Processing your Payer Authentication Transaction', 'woocommerce-gateway-paypal-pro');
                    ?>
 - <?php 
                    _e('Please click Submit to continue the processing of your transaction.', 'woocommerce-gateway-paypal-pro');
                    ?>
  <input type="submit" class="button" id="3ds_submit" value="Submit" /></div>
						        </noscript>
						    </form>
						    <script>
						    	document.frmLaunchACS.submit();
						    </script>
						</body>
					</html>
					<?php 
                    exit;
                } elseif ($this->liability_shift && WC()->session->get('Centinel_Enrolled') != 'N') {
                    wc_add_notice(__('Authentication unavailable. Please try a different payment method or card.', 'woocommerce-gateway-paypal-pro'), 'error');
                    return;
                } else {
                    // Customer not-enrolled, so just carry on with PayPal process
                    return $this->do_payment($order, $card_number, '', $card_exp_month, $card_exp_year, $card_cvc, $card_start_month, $card_start_year, '', WC()->session->get('Centinel_Enrolled'), '', WC()->session->get("Centinel_EciFlag"), '');
                }
            } else {
                wc_add_notice(__('Error in 3D secure authentication: ', 'woocommerce-gateway-paypal-pro') . WC()->session->get('Centinel_ErrorNo'), 'error');
                return;
            }
        }
        // Do payment with paypal
        return $this->do_payment($order, $card_number, '', $card_exp_month, $card_exp_year, $card_cvc, $card_start_month, $card_start_year);
    }
コード例 #11
0
/**
 * ecommerce tracking with piwik.
 *
 * @access public
 * @param int $order_id
 * @return void
 */
function woocommerce_ecommerce_tracking_piwik($order_id)
{
    global $woocommerce;
    if (is_admin()) {
        return;
    }
    // Don't track admin
    // Call the Piwik ecommerce function if WP-Piwik is configured to add tracking codes to the page
    $wp_piwik_global_settings = get_option('wp-piwik_global-settings');
    // Return if Piwik settings are not here, or if global is not set
    if (!isset($wp_piwik_global_settings['add_tracking_code']) || !$wp_piwik_global_settings['add_tracking_code']) {
        return;
    }
    if (!isset($GLOBALS['wp_piwik'])) {
        return;
    }
    // Remove WP-Piwik from wp_footer and run it here instead, to get Piwik
    // loaded *before* we do our ecommerce tracking calls
    remove_action('wp_footer', array($GLOBALS['wp_piwik'], 'footer'));
    $GLOBALS['wp_piwik']->footer();
    // Get the order and output tracking code
    $order = new WC_Order($order_id);
    ?>
	<script type="text/javascript">
	try {
		// Add order items
		<?php 
    if ($order->get_items()) {
        foreach ($order->get_items() as $item) {
            $_product = $order->get_product_from_item($item);
            ?>
			piwikTracker.addEcommerceItem(
				"<?php 
            echo esc_js($_product->sku);
            ?>
",	// (required) SKU: Product unique identifier
				"<?php 
            echo esc_js($item['name']);
            ?>
",		// (optional) Product name
				"<?php 
            if (isset($_product->variation_data)) {
                echo esc_js(woocommerce_get_formatted_variation($_product->variation_data, true));
            }
            ?>
",	// (optional) Product category. You can also specify an array of up to 5 categories eg. ["Books", "New releases", "Biography"]
				<?php 
            echo esc_js($order->get_item_total($item));
            ?>
,		// (recommended) Product price
				<?php 
            echo esc_js($item['qty']);
            ?>
 		// (optional, default to 1) Product quantity
			);
		<?php 
        }
    }
    ?>
		// Track order
		piwikTracker.trackEcommerceOrder(
			"<?php 
    echo esc_js($order_id);
    ?>
",		// (required) Unique Order ID
			<?php 
    echo esc_js($order->order_total);
    ?>
,	// (required) Order Revenue grand total (includes tax, shipping, and subtracted discount)
			false,					// (optional) Order sub total (excludes shipping)
			<?php 
    echo esc_js($order->get_total_tax());
    ?>
,	// (optional) Tax amount
			<?php 
    echo esc_js($order->get_shipping());
    ?>
,	// (optional) Shipping amount
			false 					// (optional) Discount offered (set to false for unspecified parameter)
		);
	} catch( err ) {}
	</script>
	<?php 
}
コード例 #12
0
 /**
  * Google Analytics eCommerce tracking
  *
  * @param int $order_id
  *
  * @return string
  */
 protected function get_ecommerce_tracking_code($order_id)
 {
     // Get the order and output tracking code
     $order = new WC_Order($order_id);
     $logged_in = is_user_logged_in() ? 'yes' : 'no';
     if ('yes' === $logged_in) {
         $user_id = get_current_user_id();
         $current_user = get_user_by('id', $user_id);
         $username = $current_user->user_login;
     } else {
         $user_id = '';
         $username = __('Guest', 'woocommerce-google-analytics-integration');
     }
     if ('yes' == $this->ga_use_universal_analytics) {
         if (!empty($this->ga_set_domain_name)) {
             $set_domain_name = esc_js($this->ga_set_domain_name);
         } else {
             $set_domain_name = 'auto';
         }
         $support_display_advertising = '';
         if ('yes' == $this->ga_support_display_advertising) {
             $support_display_advertising = "ga('require', 'displayfeatures');";
         }
         $anonymize_enabled = '';
         if ('yes' == $this->ga_anonymize_enabled) {
             $anonymize_enabled = "ga('set', 'anonymizeIp', true);";
         }
         $code = "\n\t(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){\n\t(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),\n\tm=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)\n\t})(window,document,'script','//www.google-analytics.com/analytics.js','ga');\n\n\tga('create', '" . esc_js($this->ga_id) . "', '" . $set_domain_name . "');" . $support_display_advertising . $anonymize_enabled . "\n\tga('set', 'dimension1', '" . $logged_in . "');\n\tga('send', 'pageview');\n\n\tga('require', 'ecommerce', 'ecommerce.js');\n\n\tga('ecommerce:addTransaction', {\n\t\t'id': '" . esc_js($order->get_order_number()) . "',         // Transaction ID. Required\n\t\t'affiliation': '" . esc_js(get_bloginfo('name')) . "',    // Affiliation or store name\n\t\t'revenue': '" . esc_js($order->get_total()) . "',           // Grand Total\n\t\t'shipping': '" . esc_js($order->get_total_shipping()) . "', // Shipping\n\t\t'tax': '" . esc_js($order->get_total_tax()) . "',           // Tax\n\t\t'currency': '" . esc_js($order->get_order_currency()) . "'  // Currency\n\t});\n";
         // Order items
         if ($order->get_items()) {
             foreach ($order->get_items() as $item) {
                 $_product = $order->get_product_from_item($item);
                 $code .= "ga('ecommerce:addItem', {";
                 $code .= "'id': '" . esc_js($order->get_order_number()) . "',";
                 $code .= "'name': '" . esc_js($item['name']) . "',";
                 $code .= "'sku': '" . esc_js($_product->get_sku() ? $_product->get_sku() : $_product->id) . "',";
                 if (isset($_product->variation_data)) {
                     $code .= "'category': '" . esc_js(woocommerce_get_formatted_variation($_product->variation_data, true)) . "',";
                 } else {
                     $out = array();
                     $categories = get_the_terms($_product->id, 'product_cat');
                     if ($categories) {
                         foreach ($categories as $category) {
                             $out[] = $category->name;
                         }
                     }
                     $code .= "'category': '" . esc_js(join("/", $out)) . "',";
                 }
                 $code .= "'price': '" . esc_js($order->get_item_total($item)) . "',";
                 $code .= "'quantity': '" . esc_js($item['qty']) . "'";
                 $code .= "});";
             }
         }
         $code .= "ga('ecommerce:send');      // Send transaction and item data to Google Analytics.";
     } else {
         if ($this->ga_support_display_advertising == 'yes') {
             $ga_url = "('https:' == document.location.protocol ? 'https://' : 'http://') + 'stats.g.doubleclick.net/dc.js'";
         } else {
             $ga_url = "('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js'";
         }
         $anonymize_enabled = '';
         if ('yes' == $this->ga_anonymize_enabled) {
             $anonymize_enabled = "['_gat._anonymizeIp'],";
         }
         if (!empty($this->ga_set_domain_name)) {
             $set_domain_name = "['_setDomainName', '" . esc_js($this->ga_set_domain_name) . "'],";
         } else {
             $set_domain_name = '';
         }
         $code = "\n\tvar _gaq = _gaq || [];\n\n\t_gaq.push(\n\t\t['_setAccount', '" . esc_js($this->ga_id) . "'], " . $set_domain_name . $anonymize_enabled . "\n\t\t['_setCustomVar', 1, 'logged-in', '" . esc_js($logged_in) . "', 1],\n\t\t['_trackPageview'],\n\t\t['_set', 'currencyCode', '" . esc_js($order->get_order_currency()) . "']\n\t);\n\n\t_gaq.push(['_addTrans',\n\t\t'" . esc_js($order->get_order_number()) . "', \t// order ID - required\n\t\t'" . esc_js(get_bloginfo('name')) . "',  \t\t// affiliation or store name\n\t\t'" . esc_js($order->get_total()) . "',   \t    \t// total - required\n\t\t'" . esc_js($order->get_total_tax()) . "',    \t// tax\n\t\t'" . esc_js($order->get_total_shipping()) . "',\t// shipping\n\t\t'" . esc_js($order->billing_city) . "',       \t// city\n\t\t'" . esc_js($order->billing_state) . "',      \t// state or province\n\t\t'" . esc_js($order->billing_country) . "'     \t// country\n\t]);\n";
         // Order items
         if ($order->get_items()) {
             foreach ($order->get_items() as $item) {
                 $_product = $order->get_product_from_item($item);
                 $code .= "_gaq.push(['_addItem',";
                 $code .= "'" . esc_js($order->get_order_number()) . "',";
                 $code .= "'" . esc_js($_product->get_sku() ? $_product->get_sku() : $_product->id) . "',";
                 $code .= "'" . esc_js($item['name']) . "',";
                 if (isset($_product->variation_data)) {
                     $code .= "'" . esc_js(woocommerce_get_formatted_variation($_product->variation_data, true)) . "',";
                 } else {
                     $out = array();
                     $categories = get_the_terms($_product->id, 'product_cat');
                     if ($categories) {
                         foreach ($categories as $category) {
                             $out[] = $category->name;
                         }
                     }
                     $code .= "'" . esc_js(join("/", $out)) . "',";
                 }
                 $code .= "'" . esc_js($order->get_item_total($item)) . "',";
                 $code .= "'" . esc_js($item['qty']) . "'";
                 $code .= "]);";
             }
         }
         $code .= "\n\t_gaq.push(['_trackTrans']); // submits transaction to the Analytics servers\n\n\t(function() {\n\t\tvar ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;\n\t\tga.src = " . $ga_url . ";\n\t\tvar s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);\n\t})();\n";
     }
     // Mark the order as tracked
     update_post_meta($order_id, '_ga_tracked', 1);
     return "\n<!-- WooCommerce Google Analytics Integration -->\n" . $this->get_generic_ga_code() . "\n<script type='text/javascript'>{$code}</script>\n<!-- /WooCommerce Google Analytics Integration -->\n";
 }
コード例 #13
0
ファイル: test.php プロジェクト: nueverest/blowdrycss
            print_r("Id: " . $order->id);
            ?>
                                    </div>

                                    <div>
                                        <?php 
            foreach ($order_items as $item) {
                print_r("Amount Paid: \$" . $order->get_line_total($item));
            }
            ?>
                                    </div>

                                    <div>
                                        <?php 
            foreach ($order_items as $item) {
                $unit_cost = $order->get_item_total($item);
                $total_cost = $order->get_line_total($item);
                $duration = $total_cost / $unit_cost;
                print_r("Reading Duration: " . $duration . ' minutes');
            }
            ?>
                                    </div>

                                    <div>
                                        <?php 
            print_r("Customer Name: " . $first_name . " " . $last_name);
            ?>
                                    </div>

                                    <div>
                                        <?php 
コード例 #14
0
/**
 * ecommerce tracking with piwik.
 *
 * @access public
 * @param int $order_id
 * @return void
 */
function woocommerce_ecommerce_tracking_piwik($order_id)
{
    global $woocommerce;
    // Don't track admin
    if (current_user_can('manage_options')) {
        return;
    }
    // Call the Piwik ecommerce function if WP-Piwik is configured to add tracking codes to the page
    $wp_piwik_global_settings = get_option('wp-piwik_global-settings');
    // Return if Piwik settings are not here, or if global is not set
    if (!isset($wp_piwik_global_settings['add_tracking_code']) || !$wp_piwik_global_settings['add_tracking_code']) {
        return;
    }
    if (!isset($GLOBALS['wp_piwik'])) {
        return;
    }
    // Get the order and get tracking code
    $order = new WC_Order($order_id);
    ob_start();
    ?>
	try {
		// Add order items
		<?php 
    if ($order->get_items()) {
        foreach ($order->get_items() as $item) {
            $_product = $order->get_product_from_item($item);
            ?>

			piwikTracker.addEcommerceItem(
				"<?php 
            echo esc_js($_product->get_sku());
            ?>
",			// (required) SKU: Product unique identifier
				"<?php 
            echo esc_js($item['name']);
            ?>
",					// (optional) Product name
				"<?php 
            if (isset($_product->variation_data)) {
                echo esc_js(woocommerce_get_formatted_variation($_product->variation_data, true));
            }
            ?>
",	// (optional) Product category. You can also specify an array of up to 5 categories eg. ["Books", "New releases", "Biography"]
				<?php 
            echo esc_js($order->get_item_total($item));
            ?>
,	// (recommended) Product price
				<?php 
            echo esc_js($item['qty']);
            ?>
 						// (optional, default to 1) Product quantity
			);

		<?php 
        }
    }
    ?>

		// Track order
		piwikTracker.trackEcommerceOrder(
			"<?php 
    echo esc_js($order->get_order_number());
    ?>
",	// (required) Unique Order ID
			<?php 
    echo esc_js($order->get_total());
    ?>
,			// (required) Order Revenue grand total (includes tax, shipping, and subtracted discount)
			false,													// (optional) Order sub total (excludes shipping)
			<?php 
    echo esc_js($order->get_total_tax());
    ?>
,		// (optional) Tax amount
			<?php 
    echo esc_js($order->get_shipping());
    ?>
,		// (optional) Shipping amount
			false 													// (optional) Discount offered (set to false for unspecified parameter)
		);
	} catch( err ) {}
	<?php 
    $code = ob_get_clean();
    $woocommerce->add_inline_js($code);
}
    /**
     * Google Analytics eCommerce tracking
     *
     * @access public
     * @param mixed $order_id
     * @return void
     */
    function ecommerce_tracking_code($order_id)
    {
        global $woocommerce;
        if ($this->disable_tracking($this->ga_eeT) || current_user_can("manage_options") || get_post_meta($order_id, "_tracked", true) == 1) {
            return;
        }
        $tracking_id = $this->ga_id;
        if (!$tracking_id) {
            return;
        }
        // Doing eCommerce tracking so unhook standard tracking from the footer
        remove_action("wp_footer", array($this, "ee_settings"));
        // Get the order and output tracking code
        $order = new WC_Order($order_id);
        //Get Applied Coupon Codes
        $coupons_list = '';
        if ($order->get_used_coupons()) {
            $coupons_count = count($order->get_used_coupons());
            $i = 1;
            foreach ($order->get_used_coupons() as $coupon) {
                $coupons_list .= $coupon;
                if ($i < $coupons_count) {
                    $coupons_list .= ', ';
                }
                $i++;
            }
        }
        //get domain name if value is set
        if (!empty($this->ga_Dname)) {
            $set_domain_name = esc_js($this->ga_Dname);
        } else {
            $set_domain_name = "auto";
        }
        //add display features
        if ($this->ga_DF) {
            $ga_display_feature_code = 'ga("require", "displayfeatures");';
        } else {
            $ga_display_feature_code = "";
        }
        //add Pageview on order page if user checked Add Standard UA code
        if ($this->ga_ST) {
            $ga_pageview = 'ga("send", "pageview");';
        } else {
            $ga_pageview = "";
        }
        $code = '(function(i,s,o,g,r,a,m){i["GoogleAnalyticsObject"]=r;i[r]=i[r]||function(){
			(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
			m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
			})(window,document,"script","//www.google-analytics.com/analytics.js","ga");
                        
			ga("create", "' . esc_js($tracking_id) . '", "' . $set_domain_name . '");
                        ' . $ga_display_feature_code . '
			ga("require", "ec", "ec.js");
                        ' . $ga_pageview . '
                        ';
        // Order items
        if ($order->get_items()) {
            foreach ($order->get_items() as $item) {
                $_product = $order->get_product_from_item($item);
                if (isset($_product->variation_data)) {
                    $categories = esc_js(woocommerce_get_formatted_variation($_product->variation_data, true));
                } else {
                    $out = array();
                    $categories = get_the_terms($_product->id, "product_cat");
                    if ($categories) {
                        foreach ($categories as $category) {
                            $out[] = $category->name;
                        }
                    }
                    $categories = esc_js(join(",", $out));
                }
                //orderpage Prod json
                $orderpage_prod_Array[get_permalink($_product->id)] = array("tvc_id" => esc_html($_product->id), "tvc_i" => esc_js($_product->get_sku() ? $_product->get_sku() : $_product->id), "tvc_n" => esc_js($item["name"]), "tvc_p" => esc_js($order->get_item_total($item)), "tvc_c" => $categories, "tvc_q" => esc_js($item["qty"]));
            }
            //make json for prod meta data on order page
            $this->wc_version_compare("tvc_oc=" . json_encode($orderpage_prod_Array) . ";");
        }
        //get shipping cost based on version >2.1 get_total_shipping() < get_shipping
        if (version_compare($woocommerce->version, "2.1", ">=")) {
            $tvc_sc = $order->get_total_shipping();
        } else {
            $tvc_sc = $order->get_shipping();
        }
        //orderpage transcation data json
        $orderpage_trans_Array = array("id" => esc_js($order->get_order_number()), "affiliation" => esc_js(get_bloginfo('name')), "revenue" => esc_js($order->get_total()), "tax" => esc_js($order->get_total_tax()), "shipping" => esc_js($tvc_sc), "coupon" => $coupons_list);
        //make json for trans data on order page
        $this->wc_version_compare("tvc_td=" . json_encode($orderpage_trans_Array) . ";");
        $code .= '
                //set local currencies
            ga("set", "&cu", tvc_lc);  
            for(var t_item in tvc_oc){
                ga("ec:addProduct", { 
                    "id": tvc_oc[t_item].tvc_i,
                    "name": tvc_oc[t_item].tvc_n, 
                    "category": tvc_oc[t_item].tvc_c,
                    "price": tvc_oc[t_item].tvc_p,
                    "quantity": tvc_oc[t_item].tvc_q,
			});
            }
            ga("ec:setAction","purchase", {
				"id": tvc_td.id,
				"affiliation": tvc_td.affiliation,
				"revenue": tvc_td.revenue,
                                "tax": tvc_td.tax,
				"shipping": tvc_td.shipping,
                                "coupon": tvc_td.coupon
			});
                        
        ga("send", "event", "Enhanced-Ecommerce","load", "order_confirmation", {"nonInteraction": 1});      
    ';
        //check woocommerce version
        $this->wc_version_compare($code);
        update_post_meta($order_id, "_tracked", 1);
    }
コード例 #16
0
ファイル: class-sv-wc-helper.php プロジェクト: javolero/dabba
 /**
  * Get order line items (products) in a neatly-formatted array of objects
  * with properties:
  *
  * + id - item ID
  * + name - item name, usually product title, processed through htmlentities()
  * + description - formatted item meta (e.g. Size: Medium, Color: blue), processed through htmlentities()
  * + quantity - item quantity
  * + item_total - item total (line total divided by quantity, excluding tax & rounded)
  * + line_total - line item total (excluding tax & rounded)
  * + meta - formatted item meta array
  * + product - item product or null if getting product from item failed
  * + item - raw item array
  *
  * @since 3.0.0
  * @param \WC_Order $order
  * @return array
  */
 public static function get_order_line_items($order)
 {
     $line_items = array();
     foreach ($order->get_items() as $id => $item) {
         $line_item = new stdClass();
         $product = $order->get_product_from_item($item);
         $meta = SV_WC_Plugin_Compatibility::is_wc_version_gte_2_4() ? $item : $item['item_meta'];
         // get meta + format it
         $item_meta = new WC_Order_Item_Meta($meta);
         $item_meta = $item_meta->get_formatted();
         if (!empty($item_meta)) {
             $item_desc = array();
             foreach ($item_meta as $meta) {
                 $item_desc[] = sprintf('%s: %s', $meta['label'], $meta['value']);
             }
             $item_desc = implode(', ', $item_desc);
         } else {
             // default description to SKU
             $item_desc = is_callable(array($product, 'get_sku')) && $product->get_sku() ? sprintf('SKU: %s', $product->get_sku()) : null;
         }
         $line_item->id = $id;
         $line_item->name = htmlentities($item['name'], ENT_QUOTES, 'UTF-8', false);
         $line_item->description = htmlentities($item_desc, ENT_QUOTES, 'UTF-8', false);
         $line_item->quantity = $item['qty'];
         $line_item->item_total = isset($item['recurring_line_total']) ? $item['recurring_line_total'] : $order->get_item_total($item);
         $line_item->line_total = $order->get_line_total($item);
         $line_item->meta = $item_meta;
         $line_item->product = is_object($product) ? $product : null;
         $line_item->item = $item;
         $line_items[] = $line_item;
     }
     return $line_items;
 }
コード例 #17
0
 /**
  * Get order line items (products) in a neatly-formatted array of objects
  * with properties:
  *
  * + id - item ID
  * + name - item name, usually product title, processed through htmlentities()
  * + description - formatted item meta (e.g. Size: Medium, Color: blue), processed through htmlentities()
  * + quantity - item quantity
  * + item_total - item total (line total divided by quantity, excluding tax & rounded)
  * + line_total - line item total (excluding tax & rounded)
  * + meta - formatted item meta array
  * + product - item product or null if getting product from item failed
  * + item - raw item array
  *
  * @since 3.0.0
  * @param \WC_Order $order
  * @return array
  */
 public static function get_order_line_items($order)
 {
     $line_items = array();
     foreach ($order->get_items() as $id => $item) {
         $line_item = new stdClass();
         $product = $order->get_product_from_item($item);
         $item_desc = array();
         // add SKU to description if available
         if (is_callable(array($product, 'get_sku')) && $product->get_sku()) {
             $item_desc[] = sprintf('SKU: %s', $product->get_sku());
         }
         // get meta + format it
         $item_meta = new WC_Order_Item_Meta($item);
         $item_meta = $item_meta->get_formatted();
         if (!empty($item_meta)) {
             foreach ($item_meta as $meta) {
                 $item_desc[] = sprintf('%s: %s', $meta['label'], $meta['value']);
             }
         }
         $item_desc = implode(', ', $item_desc);
         $line_item->id = $id;
         $line_item->name = htmlentities($item['name'], ENT_QUOTES, 'UTF-8', false);
         $line_item->description = htmlentities($item_desc, ENT_QUOTES, 'UTF-8', false);
         $line_item->quantity = $item['qty'];
         $line_item->item_total = isset($item['recurring_line_total']) ? $item['recurring_line_total'] : $order->get_item_total($item);
         $line_item->line_total = $order->get_line_total($item);
         $line_item->meta = $item_meta;
         $line_item->product = is_object($product) ? $product : null;
         $line_item->item = $item;
         $line_items[] = $line_item;
     }
     return $line_items;
 }