Fre*_*køt 14 wordpress woocommerce
我正在与Woocommerce合作,我即将发出订单确认电子邮件.
它希望邮件说:
"嗨[客户名称]"
你如何让Woocommerce打印客户名称?
Kyl*_*yle 17
你需要订单对象,所以根据你使用的钩子它应该在那里.尝试这样的事情:
add_action('woocommerce_order_status_completed','my_woo_email');
function my_woo_email($order_id){
$order = new WC_Order( $order_id );
$to = $order->billing_email;
$subject = 'this is my subject';
$message = 'Hi '.$order->billing_first_name.' '.$order->billing_email;$order->billing_last_name.', thanks for the order!';
woocommerce_mail( $to, $subject, $message, $headers = "Content-Type: text/htmlrn", $attachments = "" )
}
Run Code Online (Sandbox Code Playgroud)
这是未经测试但应该让你开始
从WooCommerce 3.x开始,$order不应该像以前的答案中那样直接访问对象的属性.现在正确的方法是:
echo 'Hi ' . $order->get_billing_first_name() . ' ' . $order->get_billing_last_name();
Run Code Online (Sandbox Code Playgroud)
小智 5
这是在WP_Query循环中获取大量WooCommerce客户信息的示例示例:
$args = array(
'post_status' => 'any',
'post_type' => 'shop_order',
'posts_per_page' => -1,
'order' => 'ASC'
);
$query = new WP_Query( $args );
while ( $query->have_posts() ) {
$query->the_post();
$order = new WC_Order( $query->post->ID );
echo $order->billing_address_1;
echo $order->billing_address_2;
echo $order->billing_city;
echo $order->billing_company;
echo $order->billing_country;
echo $order->billing_email;
echo $order->billing_first_name;
echo $order->billing_last_name;
echo $order->billing_phone;
echo $order->billing_postcode;
echo $order->billing_state;
echo $order->cart_discount;
echo $order->cart_discount_tax;
echo $order->customer_ip_address;
echo $order->customer_user;
echo $order->customer_user_agent;
echo $order->order_currency;
echo $order->order_discount;
echo $order->order_key;
echo $order->order_shipping;
echo $order->order_shipping_tax;
echo $order->order_tax;
echo $order->order_total;
echo $order->payment_method;
echo $order->payment_method_title;
echo $order->shipping_address_1;
echo $order->shipping_address_2;
echo $order->shipping_city;
echo $order->shipping_company;
echo $order->shipping_country;
echo $order->shipping_first_name;
echo $order->shipping_last_name;
echo $order->shipping_method_title;
echo $order->shipping_postcode;
echo $order->shipping_state;
}
wp_reset_postdata();
Run Code Online (Sandbox Code Playgroud)
希望这对其他人有帮助。
| 归档时间: |
|
| 查看次数: |
29787 次 |
| 最近记录: |