【发布时间】:2020-02-03 09:18:23
【问题描述】:
我正在尝试创建一些与 woocommerce 订单数据相关的简码。
我有一个自定义页面,客户在完成订单后被重定向到该页面。客人结账功能被禁用,因此所有购买的客户都将拥有一个帐户。在页面中,我想通过简码从订单中插入一些数据。这是一个例子:
“嗨 [custom-woocommerce-name],感谢您的购买。我们已收到您通过 [custom-woocommerce-payment] 支付的 [custom-woocommerce-total] 款项。
一封电子邮件已发送到 [custom-woocommerce-email],等等等等。您的订单 #[custom-woocommerce-orderid],已经打包好了。”
所以我正在寻找的是访问以下数据:
$order->get_billing_first_name();
$order->get_total();
$order->get_payment_method();
$order->get_billing_email();
$order->get_id();
我有一个工作的 php sn-p,它为 wordpress 用户名创建了一个简码:
add_shortcode( ‘custom-wordpress-name' , ‘custom_user_name' );
function custom_user_name(){
$user = wp_get_current_user();
return $user->user_firstname;
}
我尝试过调整,但我对 php 的理解非常有限,并且会产生错误。
add_shortcode( ‘custom-woocommerce-name' , ‘custom_first_name' );
function custom_first_name(){
$order = wc_get_order( $order_id );
return $order->get_billing_first_name();
}
我哪里出错了?
谢谢,
【问题讨论】:
-
在你的第二个sn-p中,你如何获得
$order_id值? -
我没有,我猜错了。 @Dmitry 已经解决了!
标签: php wordpress woocommerce shortcode