get_states() public method

Get the states for a country.
public get_states ( string $cc = null ) : array
$cc string country code
return array of states
?>
</label>
								<input type="text" name="billing_postcode" id="billing_postcode" value="<?php 
if (isset($customer)) {
    echo $customer['billing_postcode'];
}
?>
" tabindex="1" />
							</div>
							<div class="field_block">
								<?php 
global $woocommerce;
$countries_obj = new WC_Countries();
$countries = $countries_obj->__get('countries');
$default_country = $countries_obj->get_base_country();
$default_county_states = $countries_obj->get_states($default_country);
if (isset($customer['billing_state'])) {
    $default_state = $customer['billing_state'];
} else {
    $default_state = '';
}
woocommerce_form_field('billing_state', array('type' => 'select', 'class' => array('chzn-drop'), 'label' => $state, 'placeholder' => __('Select a State'), 'options' => $default_county_states, 'default' => $default_state));
?>
							</div>
							<div style="clear:both;"></div>
						</div>

						<div class="woocommerce" style="text-align:center;">
							<a class="checkout-button button alt wc-forward" href="#" onclick="jQuery('form.cart').submit();return(false);"><?php 
echo $addcart;
?>
Beispiel #2
0
 function woo_ce_expand_state_name($country_prefix = '', $state_prefix = '')
 {
     $output = $state_prefix;
     if ($output) {
         $countries = new WC_Countries();
         if ($states = $countries->get_states($country_prefix)) {
             if (isset($states[$state_prefix])) {
                 $state = $states[$state_prefix];
                 $output = $state;
             }
         }
     }
     return $output;
 }
    /**
     * Generate form
     * @param $order_id
     * @return string
     */
    function generate_pagantis_eom_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='" . $product['data']->price * $product['quantity'] . "'>\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++;
            }
        }
        $this->ok_url = $this->get_return_url($order);
        $this->ko_url = htmlspecialchars_decode($order->get_cancel_order_url());
        $account_id = "";
        $dataToEncode = "";
        //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;
            $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;
            $account_id = $this->real_account;
        }
        $signature = sha1($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()];
        //todo can include shipping information
        //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\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='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            <!-- eom -->\r\n            <input name='end_of_month' type='hidden' value='true'>\r\n            <!-- phone -->\r\n\r\n            <input name='phone' type='hidden' value='" . $order->billing_phone . "'>\r\n            ";
        $return_form = '<form action="' . $form_url . '" method="post" id="pagantis_payment_form">
            ' . $pagantis_form_fields . '
            <a class="button cancel floatLeft" href="' . $order->get_cancel_order_url() . '">' . __('Cancelar Pedido', 'pagantis') . '</a>
            <input type="submit" class="button-alt" id="submit_vme_payment_form" value="' . __('Realizar el pago', 'pagantis') . '" />

            </form>';
        if ($this->iframe == 'true') {
            $return_form .= "<script type='text/javascript'>\r\n\r\n            jQuery(document).ready(function() {\r\n              if (jQuery.isFunction(jQuery.fancybox) ){\r\n                 jQuery('#submit_vme_payment_form').on('click', function (e) {\r\n                  e.preventDefault(); // avoids calling success.php from the link\r\n                  //post data to get form url.\r\n                  jQuery.ajax({\r\n                    type: 'POST',\r\n                    url: '" . get_site_url() . "/wp-content/plugins/pagamastarde-payment-gateway-for-woocommerce/getPmtUrl.php',\r\n                    data: jQuery('#pagantis_payment_form').serialize(),\r\n                    success: function(data, textStatus, jqXHR)\r\n                    {\r\n                      jQuery.fancybox({\r\n                        // fancybox API options\r\n                        type: 'iframe',\r\n                        fitToView: false,\r\n                        openEffect: 'none',\r\n                        closeEffect: 'none',\r\n                        'width'  : 920,\r\n                        'minHeight' : 230,\r\n                        'href': data\r\n                      }); // fancybox\r\n                    }\r\n                  });\r\n                }); // on\r\n              }\r\n            }); //ready\r\n\r\n            </script>";
        }
        return $return_form;
    }
 public function get_states()
 {
     $country = isset($_POST['country']) ? sanitize_text_field($_POST['country']) : '';
     $countries = new WC_Countries();
     $states = $countries->get_states($country);
     $this->send_json($states);
 }
            /**
             * 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;
            }
 public function get_settings()
 {
     $settings = get_option('slp_general_settings');
     $countries = new WC_Countries();
     return apply_filters('slp_general_settings', array(array('id' => 'slp_location_settings', 'title' => __('Location Settings', 'slp'), 'type' => 'title', 'desc' => __('Tell us about your business', 'slp'), 'autoload' => false), array('id' => 'company_name', 'title' => __('Company Name', 'slp'), 'type' => 'text', 'default' => '', 'value' => isset($settings['company_name']) ? $settings['company_name'] : '', 'autoload' => false), array('id' => 'address_1', 'title' => __('Address 1', 'slp'), 'type' => 'text', 'desc' => __('Street Address or PO Box', 'slp'), 'default' => '', 'value' => isset($settings['address_1']) ? $settings['address_1'] : '', 'autoload' => false), array('id' => 'address_2', 'title' => __('Address 2', 'slp'), 'type' => 'text', 'desc' => __('Suite, unit, etc', 'slp'), 'default' => '', 'value' => isset($settings['address_2']) ? $settings['address_2'] : '', 'autoload' => false), array('id' => 'address_3', 'title' => __('Address 3', 'slp'), 'type' => 'text', 'desc' => __('Floor, room, ect', 'slp'), 'default' => '', 'value' => isset($settings['address_3']) ? $settings['address_3'] : '', 'autoload' => false), array('id' => 'city', 'title' => __('City', 'slp'), 'type' => 'text', 'desc' => '', 'default' => '', 'value' => isset($settings['city']) ? $settings['city'] : '', 'autoload' => false), array('id' => 'country', 'title' => __('Country', 'slp'), 'type' => 'select', 'css' => 'width: 200px;', 'class' => 'chosen_select', 'default' => 'US', 'value' => isset($settings['country']) ? $settings['country'] : 'US', 'settings' => $countries->get_countries(), 'autoload' => false), array('id' => 'state', 'title' => __('State', 'slp'), 'type' => 'select', 'css' => 'width: 200px;', 'class' => 'chosen_select', 'default' => 'AL', 'value' => isset($settings['state']) ? $settings['state'] : '', 'settings' => $countries->get_states(isset($settings['country']) ? $settings['country'] : 'US'), 'autoload' => false), array('id' => 'zipcode', 'title' => __('Zip Code', 'slp'), 'type' => 'text', 'desc' => '5 digit zipcode', 'default' => '', 'tooltip' => false, 'value' => isset($settings['zipcode']) ? $settings['zipcode'] : '', 'autoload' => false), array('id' => 'phone', 'title' => __('Phone Number', 'slp'), 'type' => 'text', 'desc' => '', 'value' => isset($settings['phone']) ? $settings['phone'] : '', 'autoload' => false), array('type' => 'sectionend', 'id' => 'slp_location_settings')));
 }
	public function get_shipping_address( $order ) {
		$countries = new WC_Countries();

		$name =  $order->shipping_first_name . ' ' . $order->shipping_last_name ;
		$domestic = in_array( $order->shipping_country, $this->domestic );
		$postcode = $domestic ? trim( str_replace( ' - ' , '' , $order->shipping_postcode ) ) : '';
		
		$request  = 
			"<ShipTo>
				<CompanyName>$name</CompanyName>
				<Address>
					 <AddressLine1>$order->shipping_address_1</AddressLine1>";
		if( !empty( $order->shipping_address_2 ) ) 
		$request .=	"<AddressLine2>$order->shipping_address_2</AddressLine2>";
		$request .=	"<City>$order->shipping_city</City>";	
						
		
		$state = ! $domestic && $order->shipping_country == 'CA' ? substr( $order->shipping_state, 5 ) : strlen( $order->shipping_state ) > 2 ? array_search( ucwords( strtolower( $order->shipping_state ) ), $countries->get_states( $order->shipping_country ) ) : $order->shipping_state;
				
		if( isset( $state ) ) 
			$request .= "<StateProvinceCode>$state</StateProvinceCode>";
		if( $domestic && isset( $postcode ) ) 
			$request .="<PostalCode>$postcode</PostalCode>";
			$request .="<CountryCode>$order->shipping_country</CountryCode>			
				</Address>
				<PhoneNumber>$order->billing_phone</PhoneNumber>
				<AttentionName>$name</AttentionName>
			</ShipTo>";
			
		return $request;
	}