我正在尝试创建与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代码段,可为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();
}
我要去哪里错了?
谢谢,
您可以这样尝试:
add_shortcode( 'custom-woocommerce-name' , 'custom_first_name' );
function custom_first_name(){
$customer_id = get_current_user_id();
$order = wc_get_customer_last_order( $customer_id );
return $order->get_billing_first_name();
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句