WC_Payment_Gateway::get_order_total PHP Méthode

get_order_total() protected méthode

Get the order total in checkout and pay_for_order.
protected get_order_total ( ) : float
Résultat float
    protected function get_order_total()
    {
        $total = 0;
        $order_id = absint(get_query_var('order-pay'));
        // Gets order total from "pay for order" page.
        if (0 < $order_id) {
            $order = wc_get_order($order_id);
            $total = (double) $order->get_total();
            // Gets order total from cart/checkout.
        } elseif (0 < WC()->cart->total) {
            $total = (double) WC()->cart->total;
        }
        return $total;
    }

Usage Example

            public function payment_fields()
            {
                global $woocommerce;
                if (!$GLOBALS['paymill_active']) {
                    paymill_load_frontend_scripts();
                    // load frontend scripts
                    // settings
                    $GLOBALS['paymill_active'] = true;
                    $cart_total = WC_Payment_Gateway::get_order_total() * 100;
                    $currency = get_woocommerce_currency();
                    $no_logos = true;
                    // form ids
                    echo '<script>
						paymill_form_checkout_id = "form.checkout, form#order_review";
						paymill_form_checkout_submit_id = "#place_order";
						paymill_shop_name = "woocommerce";
						paymill_pcidss3 = ' . (empty($GLOBALS['paymill_settings']->paymill_general_settings['pci_dss_3']) || $GLOBALS['paymill_settings']->paymill_general_settings['pci_dss_3'] != '1' ? 1 : 0) . ';
						paymill_pcidss3_lang = "' . substr(apply_filters('plugin_locale', get_locale(), $domain), 0, 2) . '";
						</script>';
                    echo '<a href="https://www.paymill.com/" target="_blank"><img src="' . WC_HTTPS::force_https_url($this->logo_small) . '" alt="' . $this->title . '" /></a>';
                    echo '<p class="paymill_payment_description">' . $this->settings['description'] . '</p>';
                    require_once PAYMILL_DIR . 'lib/tpl/checkout_form.php';
                } else {
                    echo '<div class="paymill_notification paymill_notification_once_only"><strong>Error:</strong> Paymill can be loaded once only on the same page.</div>';
                }
                return true;
            }