WC_Cart::get_checkout_url PHP Method

get_checkout_url() public method

Gets the url to the checkout page.
Deprecation: 2.5.0 in favor to wc_get_checkout_url()
public get_checkout_url ( ) : string
return string url to page
    public function get_checkout_url()
    {
        return wc_get_checkout_url();
    }

Usage Example

            /**
             * Generate form
             * @param $order_id
             * @return string
             */
            function generate_pagantis_form($order_id)
            {
                //Logs
                $this->log->add('pagantis', 'Acceso al pago con Paga+Tarde');
                $order = new WC_Order($order_id);
                //Total Amount
                $transaction_amount = number_format((double) $order->get_total(), 2, '.', '');
                $transaction_amount = str_replace('.', '', $transaction_amount);
                $transaction_amount = floatval($transaction_amount);
                // Product Description
                $products = WC()->cart->cart_contents;
                $i = 1;
                $products_form = "";
                $description = "";
                foreach ($products as $product) {
                    $products_form .= "\r\n                  <input name='items[" . $i . "][description]' type='hidden' value='" . $product['data']->post->post_title . ' (' . $product['quantity'] . ')' . "'>\r\n                  <input name='items[" . $i . "][quantity]' type='hidden' value='" . $product['quantity'] . "'>\r\n                  <input name='items[" . $i . "][amount]' type='hidden' value='" . round(($product['data']->price + $product['line_tax']) * $product['quantity'], 2) . "'>\r\n                  ";
                    $description[] = $product['data']->post->post_title . ' (' . $product['quantity'] . ')';
                    $i++;
                }
                $shipping = $order->get_items('shipping');
                foreach ($shipping as $shipping_method) {
                    if ($shipping_method['cost'] > 0) {
                        $products_form .= "\r\n                    <input name='items[" . $i . "][description]' type='hidden' value='" . __('Gastos de envio', 'pagantis') . "'>\r\n                    <input name='items[" . $i . "][quantity]' type='hidden' value='1'>\r\n                    <input name='items[" . $i . "][amount]' type='hidden' value='" . $shipping_method['cost'] . "'>\r\n                    ";
                        $description[] = 'Gastos de envio';
                        $i++;
                    }
                }
                $account_id = "";
                $dataToEncode = "";
                $this->ok_url = $this->get_return_url($order);
                $this->ko_url = htmlspecialchars_decode(WC_Cart::get_checkout_url());
                $this->cancelled_url = htmlspecialchars_decode(WC_Cart::get_checkout_url());
                //Test Environment Selected
                if ($this->environment == self::TEST_ENVIRONMENT) {
                    $this->key = $this->test_key;
                    $dataToEncode = $this->test_key . $this->test_account . $order_id . $transaction_amount . $this->currency . $this->ok_url . $this->ko_url . $this->callback_url . $this->discount . $this->cancelled_url;
                    $account_id = $this->test_account;
                } else {
                    $this->key = $this->real_key;
                    $dataToEncode = $this->real_key . $this->real_account . $order_id . $transaction_amount . $this->currency . $this->ok_url . $this->ko_url . $this->callback_url . $this->discount . $this->cancelled_url;
                    $account_id = $this->real_account;
                }
                $signature = hash('sha512', $dataToEncode);
                $form_url = $this->paga_mastarde_url;
                $adressInfo = explode("/", $order->billing_city);
                $customer = new WC_Customer();
                $countries = new WC_Countries();
                $address = $customer->get_address() . " " . $customer->get_address_2();
                $city = $customer->get_city();
                $postcode = $customer->get_postcode();
                $states = $countries->get_states();
                $state = $states[$order->shipping_country][$customer->get_state()];
                $saddress = $customer->shipping_address_1 . " " . $customer->shipping_address_2;
                $scity = $customer->shipping_city;
                $spostcode = $customer->shipping_postcode;
                $sstate = $states[$order->shipping_country][$customer->shipping_state];
                //Create Form
                $buyer_name = $order->billing_first_name . " " . $order->billing_last_name;
                $pagantis_form_fields = "\r\n                <input name='order_id' type='hidden' value='" . $order_id . "' />\r\n                <input name='amount' type='hidden' value='" . $transaction_amount . "' />\r\n                <input name='currency' type='hidden' value='" . $this->currency . "' />\r\n\r\n                <input name='ok_url' type='hidden' value='" . $this->ok_url . "' />\r\n                <input name='nok_url' type='hidden' value='" . $this->ko_url . "' />\r\n                <input name='cancelled_url' type='hidden' value='" . $this->cancelled_url . "' />\r\n\r\n                <input name='locale' type='hidden' value='" . $this->lang . "' />\r\n\r\n                <input name='full_name' type='hidden' value='" . $buyer_name . "'>\r\n                <input name='email' type='hidden' value='" . $order->billing_email . "'>\r\n\r\n                " . $products_form . "\r\n\r\n                <!-- firma de la operación -->\r\n                <input name='account_id' type='hidden' value='" . $account_id . "' />\r\n                <input name='signature' type='hidden' value='" . $signature . "' />\r\n\r\n                <!-- discount -->\r\n                <input name='discount[full]' type='hidden' value='" . $this->discount . "' />\r\n                <input name='iframe' type='hidden' value='" . $this->iframe . "' />\r\n\r\n                <!-- callback url -->\r\n                <input name='callback_url' type='hidden' value='" . $this->callback_url . "' />\r\n\r\n                <input name='description' type='hidden' value='" . implode(',', $description) . "' />\r\n\r\n                <!-- address -->\r\n                <input name='address[street]' type='hidden' value='" . $address . "'>\r\n                <input name='address[city]' type='hidden' value='" . $city . "'>\r\n                <input name='address[province]' type='hidden' value='" . $state . "'>\r\n                <input name='address[zipcode]' type='hidden' value='" . $postcode . "'>\r\n\r\n                <input name='shipping[street]' type='hidden' value='" . $saddress . "'>\r\n                <input name='shipping[city]' type='hidden' value='" . $scity . "'>\r\n                <input name='shipping[province]' type='hidden' value='" . $sstate . "'>\r\n                <input name='shipping[zipcode]' type='hidden' value='" . $spostcode . "'>\r\n\r\n                <!-- phone -->\r\n\r\n                <input name='mobile_phone' type='hidden' value='" . $order->billing_phone . "'>\r\n                ";
                $return_form = '<form action="' . $form_url . '" method="post" id="pagantis_payment_form">
                ' . $pagantis_form_fields . '
                <input type="submit" class="button-alt" id="submit_vme_payment_form" value="' . __('Realizar el pago', 'pagantis') . '" />

                </form>';
                if ($this->iframe == 'true') {
                    wp_enqueue_style('style', esc_url(plugins_url('pages/assets/css/iframe.css', __FILE__)));
                    $return_form .= '<div id="myModal" class="paylater_modal">
                    <!-- Modal content -->
                    <div class="paylater_modal-content">
                      <span id="paylater_close">x</span>
                      <iframe id="iframe-pagantis" name="iframe-pagantis" style="width:100%;height:600px;display:block"></iframe>
                    </div>
                  </div>';
                    $return_form .= '<script type="text/javascript">
                  el = document.getElementById("submit_vme_payment_form");
                  el.addEventListener("click", function (e){
                    e.preventDefault();
                    document.getElementById("pagantis_payment_form").setAttribute("target", "iframe-pagantis");
                    document.getElementById("pagantis_payment_form").submit();
                    document.getElementById("iframe-pagantis").style.display = "block";
                    document.getElementById("myModal").style.display = "block";
                  });

                  var closeModal = function closeModal(evt) {
                   evt.preventDefault();
                   document.getElementById("myModal").style.display = "none";
                  };

                  var elements = document.querySelectorAll("#paylater_close, #myModal");
                   Array.prototype.forEach.call(elements, function(el){
                   el.addEventListener("click", closeModal);
                  });

                  document.addEventListener("DOMContentLoaded", function(event) {
                    document.getElementById("pagantis_payment_form").setAttribute("target", "iframe-pagantis");
                    document.getElementById("pagantis_payment_form").submit();
                    document.getElementById("iframe-pagantis").style.display = "block";
                    document.getElementById("myModal").style.display = "block";
                    });
                  </script>';
                } else {
                    $return_form .= "<script type='text/javascript'>\r\n                  jQuery(document).ready(function() {\r\n                    jQuery('#submit_vme_payment_form').click();\r\n                  });\r\n                  </script>";
                }
                return $return_form;
            }
All Usage Examples Of WC_Cart::get_checkout_url
WC_Cart