【问题标题】:Get the billing info onload in woocommerce before process payment在处理付款之前在 woocommerce 中获取账单信息
【发布时间】:2019-01-23 13:54:29
【问题描述】:

我们可以在处理付款之前使用 jquery 在 woocommerce 中获取帐单地址信息吗?使用最后一个焦点元素,我们可以获得输入的账单地址名字,姓氏等。

【问题讨论】:

    标签: php jquery wordpress woocommerce


    【解决方案1】:

    这是一个在 jQuery 中获取客户账单信息的示例(在处理付款之前):

    add_action( 'wp_footer', 'custom_checkout_js_script' );
    function custom_checkout_js_script() {
        // Targeting cart and checkout pages
        if ( is_cart() || ( is_checkout() && ! is_wc_endpoint_url() ) ) :
    
        $billing_first_name = WC()->customer->get_billing_first_name();
        $billing_last_name  = WC()->customer->get_billing_last_name();
    
        $billing_address_1  = WC()->customer->get_billing_address_1();
        $billing_address_2  = WC()->customer->get_billing_address_2();
        $billing_postcode   = WC()->customer->get_billing_postcode();
        $billing_city       = WC()->customer->get_billing_city();
        $billing_state      = WC()->customer->get_billing_state();
        $billing_country    = WC()->customer->get_billing_country();
    
        ?>
        <script type="text/javascript">
        jQuery( function($){
            var billing_first_name = '<?php echo $billing_first_name; ?>',
                billing_last_name  = '<?php echo $billing_last_name; ?>',
                billing_address_1  = '<?php echo $billing_address_1; ?>',
                billing_address_2  = '<?php echo $billing_address_2; ?>',
                billing_postcode   = '<?php echo $billing_postcode; ?>',
                billing_city       = '<?php echo $billing_city; ?>',
                billing_state      = '<?php echo $billing_state; ?>',
                billing_country    = '<?php echo $billing_country; ?>';
        });
        </script>
        <?php
        endif;
    }
    

    代码进入您的活动子主题(或活动主题)的 function.php 文件中。经过测试并且可以工作。

    【讨论】:

      猜你喜欢
      • 2019-06-17
      • 2018-04-05
      • 2019-01-21
      • 2011-08-20
      • 2019-02-25
      • 2014-03-14
      • 2014-04-15
      • 2019-02-28
      相关资源
      最近更新 更多