Woocommerce 设置帐单和运输信息

兰迪·霍尔

更新 - 简短版本:

将使用什么方法将用户计费/运输信息保存到会话以供访客结账?


长版:

创建一个高度依赖于自定义 REST API 端点和 ajax 的自定义结账页面。我拥有WC()->checkout()->checkout_fields;从一次呼叫中返回的所有计费和运输字段,并将其呈现给用户以及所有这些。

我也有通过 API 调用返回的计算运费。但是,这仅在设置了用户地址时才有效 - 这是预期的。

我一生无法弄清楚的是我可以在 API 中调用什么方法来保存用户帐单和运输信息,以便我可以计算运输成本。现在我只能获取现有用户帐户的送货信息。即使只是在正确方向上的一根手指也可以节省我留下的头发。


一些代码

我如何获得送货(没有送货地址就无法工作,无法弄清楚如何设置帐单或送货信息)

function mytheme_get_shipping(){
    foreach( WC()->session->get('shipping_for_package_0')['rates'] as $method_id => $rate ){
        if( WC()->session->get('chosen_shipping_methods')[0] == $method_id ){
            $rate_label = $rate->label; // The shipping method label name
            $rate_cost_excl_tax = floatval($rate->cost); // The cost excluding tax
            // The taxes cost
            $rate_taxes = 0;
            foreach ($rate->taxes as $rate_tax)
                $rate_taxes += floatval($rate_tax);
            // The cost including tax
            $rate_cost_incl_tax = $rate_cost_excl_tax + $rate_taxes;

            return array('label' => $rate_label, 'total' => WC()->cart->get_cart_shipping_total());
        }
    }
}
外包WordPress

获取帐单和运输详细信息:

您可以获得如下所示的帐单和运输详细信息。

//whole customer details
print_r(WC()->customer);

//billing details
$billing = WC()->customer->get_billing(); 
$billing_first_name = WC()->customer->get_billing_first_name(); 
$billing_last_name = WC()->customer->get_billing_last_name(); 
$billing_company = WC()->customer->get_billing_company(); 
$billing_address = WC()->customer->get_billing_address(); 
$billing_address_1 = WC()->customer->get_billing_address_1(); 
$billing_address_2 = WC()->customer->get_billing_address_2(); 
$billing_city = WC()->customer->get_billing_city(); 
$billing_state = WC()->customer->get_billing_state(); 
$billing_postcode = WC()->customer->get_billing_postcode(); 
$billing_country = WC()->customer->get_billing_country(); 

//shipping details
$shipping = WC()->customer->get_shipping(); 
$shipping_first_name = WC()->customer->get_shipping_first_name(); 
$shipping_last_name = WC()->customer->get_shipping_last_name(); 
$shipping_company = WC()->customer->get_shipping_company(); 
$shipping_address = WC()->customer->get_shipping_address(); 
$shipping_address_1 = WC()->customer->get_shipping_address_1(); 
$shipping_address_2 = WC()->customer->get_shipping_address_2(); 
$shipping_city = WC()->customer->get_shipping_city(); 
$shipping_state = WC()->customer->get_shipping_state(); 
$shipping_postcode = WC()->customer->get_shipping_postcode(); 
$shipping_country = WC()->customer->get_shipping_country(); 

设置帐单和运输详细信息:

您可以设置如下所示的帐单和运输详细信息。

//billing details
$billing_first_name = $_POST['billing_first_name'];
$billing_last_name = $_POST['billing_last_name'];
$billing_company = $_POST['billing_company'];
$billing_address_1 = $_POST['billing_address_1'];
$billing_address_2 = $_POST['billing_address_2'];
$billing_city = $_POST['billing_city'];
$billing_state = $_POST['billing_state'];
$billing_postcode = $_POST['billing_postcode'];
$billing_country = $_POST['billing_country'];

WC()->customer->set_billing_first_name(wc_clean( $billing_first_name )); 
WC()->customer->set_billing_last_name(wc_clean( $billing_last_name )); 
WC()->customer->set_billing_company(wc_clean( $billing_company ));  
WC()->customer->set_billing_address_1(wc_clean( $billing_address_1 )); 
WC()->customer->set_billing_address_2(wc_clean( $billing_address_2 )); 
WC()->customer->set_billing_city(wc_clean( $billing_city )); 
WC()->customer->set_billing_state(wc_clean( $billing_state )); 
WC()->customer->set_billing_postcode(wc_clean( $billing_postcode )); 
WC()->customer->set_billing_country(wc_clean( $billing_country )); 

//shipping details
$shipping_first_name = $_POST['shipping_first_name'];
$shipping_last_name = $_POST['shipping_last_name'];
$shipping_company = $_POST['shipping_company'];
$shipping_address_1 = $_POST['shipping_address_1'];
$shipping_address_2 = $_POST['shipping_address_2'];
$shipping_city = $_POST['shipping_city'];
$shipping_state = $_POST['shipping_state'];
$shipping_postcode = $_POST['shipping_postcode'];
$shipping_country = $_POST['shipping_country'];

WC()->customer->set_shipping_first_name(wc_clean( $shipping_first_name )); 
WC()->customer->set_shipping_last_name(wc_clean( $shipping_last_name )); 
WC()->customer->set_shipping_company(wc_clean( $shipping_company ));    
WC()->customer->set_shipping_address_1(wc_clean( $shipping_address_1 )); 
WC()->customer->set_shipping_address_2(wc_clean( $shipping_address_2 )); 
WC()->customer->set_shipping_city(wc_clean( $shipping_city )); 
WC()->customer->set_shipping_state(wc_clean( $shipping_state )); 
WC()->customer->set_shipping_postcode(wc_clean( $shipping_postcode )); 
WC()->customer->set_shipping_country(wc_clean( $shipping_country )); 

创建新客户并设置帐单和运输详细信息:

您可以创建新客户,设置帐单和运输详细信息,如下所示。

//create new customer
$email = $_POST['email'];
$username = $_POST['username'];
$password = $_POST['password'];

$user_id = wc_create_new_customer( $email, $username, $password );

//billing details
$billing_first_name = $_POST['billing_first_name'];
$billing_last_name = $_POST['billing_last_name'];
$billing_company = $_POST['billing_company'];
$billing_address_1 = $_POST['billing_address_1'];
$billing_address_2 = $_POST['billing_address_2'];
$billing_city = $_POST['billing_city'];
$billing_state = $_POST['billing_state'];
$billing_postcode = $_POST['billing_postcode'];
$billing_country = $_POST['billing_country'];

update_user_meta( $user_id, "billing_first_name", $billing_first_name );
update_user_meta( $user_id, "billing_last_name", $billing_last_name );
update_user_meta( $user_id, "billing_company", $billing_company );
update_user_meta( $user_id, "billing_address_1", $billing_address_1 );
update_user_meta( $user_id, "billing_address_2", $billing_address_2 );
update_user_meta( $user_id, "billing_city", $billing_city );
update_user_meta( $user_id, "billing_state", $billing_state );
update_user_meta( $user_id, "billing_postcode", $billing_postcode );
update_user_meta( $user_id, "billing_country", $billing_country );

//shipping details
$shipping_first_name = $_POST['shipping_first_name'];
$shipping_last_name = $_POST['shipping_last_name'];
$shipping_company = $_POST['shipping_company'];
$shipping_address_1 = $_POST['shipping_address_1'];
$shipping_address_2 = $_POST['shipping_address_2'];
$shipping_city = $_POST['shipping_city'];
$shipping_state = $_POST['shipping_state'];
$shipping_postcode = $_POST['shipping_postcode'];
$shipping_country = $_POST['shipping_country'];

update_user_meta( $user_id, "shipping_first_name", $shipping_first_name );
update_user_meta( $user_id, "shipping_last_name", $shipping_last_name );
update_user_meta( $user_id, "shipping_company", $shipping_company );
update_user_meta( $user_id, "shipping_address_1", $shipping_address_1 );
update_user_meta( $user_id, "shipping_address_2", $shipping_address_2 );
update_user_meta( $user_id, "shipping_city", $shipping_city );
update_user_meta( $user_id, "shipping_state", $shipping_state );
update_user_meta( $user_id, "shipping_postcode", $shipping_postcode );
update_user_meta( $user_id, "shipping_country", $shipping_country );

希望这可以帮助。

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

WooCommerce PDF 发票和装箱单 - 更改发票模板中帐单和运输详细信息的宽度

来自分类Dev

在WooCommerce结帐上显示客户帐单邮寄地址和帐单城市,而不是“发货”标签

来自分类Dev

WooCommerce-在现有结帐字段上覆盖帐单状态和邮政编码

来自分类Dev

如何更改woocommerce结帐的收到订单页面上的收货地址和帐单地址的文本?

来自分类Dev

WooCommerce:在结帐,我的帐户,管理订单和WordPress用户中添加生日帐单字段

来自分类Dev

WooCommerce:在结帐,我的帐户,管理订单和WordPress用户中添加生日帐单字段

来自分类Dev

WooCommerce-在现有结帐字段上覆盖帐单状态和邮政编码

来自分类Dev

在帐单地址woocommerce上添加新字段

来自分类Dev

Woocommerce“订单支付”页面 - 显示帐单地址?

来自分类Dev

在WooCommerce中添加购物车之前及早设置运输邮政编码

来自分类Dev

在WooCommerce中为每10个订单设置自定义运输成本

来自分类Dev

根据产品类别自动设置WooCommerce产品运输类别

来自分类Dev

根据WooCommerce中的购物车小计将所有运输方式成本设置为零

来自分类Dev

通过WooCommerce订单和电子邮件中的文本更改运输方式以使用特定的运输方式

来自分类Dev

Woocommerce设置失败

来自分类Dev

Woocommerce集成设置API

来自分类Dev

WooCommerce-覆盖运输成本

来自分类Dev

根据运输方式更改 Woocommerce 订单状态

来自分类Dev

获取 Woocommerce 中选择的运输方式成本

来自分类Dev

WooCommerce - 重复订单的不同运输方式

来自分类Dev

WooCommerce:将成员分配到运输区

来自分类Dev

woocommerce 根据数量隐藏运输方式

来自分类Dev

EDI和运输跟踪信息

来自分类Dev

删除WooCommerce 2.6和3+中特定类别的运输统一费率方法

来自分类Dev

根据产品类别和运输方式添加费用WooCommerce

来自分类Dev

WooCommerce类别和ACF

来自分类Dev

WooCommerce主题和Javascript

来自分类Dev

根据WooCommerce中的自定义结帐单选按钮和文本字段设置动态费用

来自分类Dev

在 WooCommerce 中隐藏特定运输类别的运输方式

Related 相关文章

  1. 1

    WooCommerce PDF 发票和装箱单 - 更改发票模板中帐单和运输详细信息的宽度

  2. 2

    在WooCommerce结帐上显示客户帐单邮寄地址和帐单城市,而不是“发货”标签

  3. 3

    WooCommerce-在现有结帐字段上覆盖帐单状态和邮政编码

  4. 4

    如何更改woocommerce结帐的收到订单页面上的收货地址和帐单地址的文本?

  5. 5

    WooCommerce:在结帐,我的帐户,管理订单和WordPress用户中添加生日帐单字段

  6. 6

    WooCommerce:在结帐,我的帐户,管理订单和WordPress用户中添加生日帐单字段

  7. 7

    WooCommerce-在现有结帐字段上覆盖帐单状态和邮政编码

  8. 8

    在帐单地址woocommerce上添加新字段

  9. 9

    Woocommerce“订单支付”页面 - 显示帐单地址?

  10. 10

    在WooCommerce中添加购物车之前及早设置运输邮政编码

  11. 11

    在WooCommerce中为每10个订单设置自定义运输成本

  12. 12

    根据产品类别自动设置WooCommerce产品运输类别

  13. 13

    根据WooCommerce中的购物车小计将所有运输方式成本设置为零

  14. 14

    通过WooCommerce订单和电子邮件中的文本更改运输方式以使用特定的运输方式

  15. 15

    Woocommerce设置失败

  16. 16

    Woocommerce集成设置API

  17. 17

    WooCommerce-覆盖运输成本

  18. 18

    根据运输方式更改 Woocommerce 订单状态

  19. 19

    获取 Woocommerce 中选择的运输方式成本

  20. 20

    WooCommerce - 重复订单的不同运输方式

  21. 21

    WooCommerce:将成员分配到运输区

  22. 22

    woocommerce 根据数量隐藏运输方式

  23. 23

    EDI和运输跟踪信息

  24. 24

    删除WooCommerce 2.6和3+中特定类别的运输统一费率方法

  25. 25

    根据产品类别和运输方式添加费用WooCommerce

  26. 26

    WooCommerce类别和ACF

  27. 27

    WooCommerce主题和Javascript

  28. 28

    根据WooCommerce中的自定义结帐单选按钮和文本字段设置动态费用

  29. 29

    在 WooCommerce 中隐藏特定运输类别的运输方式

热门标签

归档