【问题标题】:Woocommerce Order Customer and Payment Details from Order订单中的 Woocommerce 订单客户和付款详细信息
【发布时间】:2015-01-28 17:21:06
【问题描述】:

我在woocommerce_payment_complete_order_status 过滤器中有$order = new WCOrder( $orderid );。我可以从那里获取有关订单的大量信息,但我想从$order 获取客户的电话和电子邮件地址,如管理界面的“编辑订单”页面上显示的那样.我还想获得交易费(例如,Stripe 或 PayPal 向我收取的交易费用)(如果有)。不过,您如何从 $order 获得这些值 - 我很快就丢失了 Woocommerce docs 的踪迹。 ?到目前为止,这是我的代码:

  public function my_hook_function( $order_status, $order_id ) {
    $order = new WC_Order( $order_id );
    $num_items = count( $order->get_items() );

    $ret = array();
    $ret["billing_address"] = $order->get_formatted_billing_address();
    $ret["shipping_address"] = $order->get_formatted_shipping_address();
    $ret["cart_discount"] = $order->get_cart_discount();
    $ret["cart_tax"] = $order->get_cart_tax();
    $ret["order_notes"] = $order->get_customer_order_notes();

    $ret["items"] = array();
    if ( $num_items > 0 ) {
      foreach( $order->get_items() as $item ) {
        if ( 'line_item' == $item['type'] ) {
          $item_data = array();
          $item_data['name'] = $item['name'];
          $item_data['quantity'] = $item['item_meta']['_qty'][0];
          $item_data['product_id'] = $item['item_meta']['_product_id'][0];
          $item_data['subtotal'] = $item['item_meta']['_line_subtotal'][0];
          $ret["items"][] = $item_data;
        }
      }
    }

    // do stuff with $ret

    return $order_status;
  }

【问题讨论】:

    标签: php api plugins woocommerce hook


    【解决方案1】:

    订单详情模板中出现以下代码sn-p:

    if ( $order->billing_email ) echo '<dt>' . __( 'Email:', 'woocommerce' ) . '</dt><dd>' . $order->billing_email . '</dd>';
    if ( $order->billing_phone ) echo '<dt>' . __( 'Telephone:', 'woocommerce' ) . '</dt><dd>' . $order->billing_phone . '</dd>';
    

    WC_Abstract_Order 类的这些属性并不明显,因为它们隐藏在魔术方法 __set 和 __get 后面。

    【讨论】:

      猜你喜欢
      • 2016-12-28
      • 2014-07-10
      • 1970-01-01
      • 2021-11-03
      • 2019-02-28
      • 2014-05-15
      • 2021-09-17
      • 2018-08-15
      • 2019-01-21
      相关资源
      最近更新 更多