我正在尝试创建一些与woocommerce订单数据相关的代码。
我有一个自定义页面,客户重定向到订单完成后。客人退房是禁用的,所以所有的客户购买将有一个帐户。在页面中,我想从订单中插入一些数据--通过短代码。下面是一个例子:
“你好,自定义--吴商-名字,谢谢你的购买。我们已经收到您的付款自定义-电子商务-总计通过自定义-电子商务-付款。一封电子邮件已经发送到自定义--woocommerce--电子邮件,诸如此类。你的订餐
因此,我要寻找的是访问以下数据:
$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();
}我哪里出问题了?
谢谢,
发布于 2020-02-03 09:57:44
你可以试试这个方法:
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();
}https://stackoverflow.com/questions/60036190
复制相似问题