在woocommerce電子郵件中添加額外內容時,我嘗試獲取訂單ID,是否有人知道這有什麼問題......? 由於如何在Woocomerce中獲取訂單ID電子郵件
add_action('woocommerce_email_after_order_table', 'add_content', 20);
function add_content() {
global $woocommerce;
echo $order_id
echo $order->id;
}
在woocommerce電子郵件中添加額外內容時,我嘗試獲取訂單ID,是否有人知道這有什麼問題......? 由於如何在Woocomerce中獲取訂單ID電子郵件
add_action('woocommerce_email_after_order_table', 'add_content', 20);
function add_content() {
global $woocommerce;
echo $order_id
echo $order->id;
}
你可以傳遞參數$order
並獲得$order->get_id();
是這樣的:
function add_content($order) {
echo $order->get_id();
}
我一定是太慢了。 :)但是你不需要全局聲明'$ woocommerce',並且如果你需要woocommerce實例,你應該使用'WC()'來代替。 – helgatheviking
查找範圍的source,$order
是傳遞給woocommerce_email_after_order_table
鉤第一可變。
add_action('woocommerce_email_after_order_table', 'so_43612005_add_content', 20, 4);
function so_43612005_add_content($order, $sent_to_admin, $plain_text, $email) {
// WooCommerce 3.0
if(method_exists($order, 'get_id')) {
$order_id = $order->get_id();
// WooCommerce 2.6.x
} else {
$order_id = $order->id;
}
echo $order_id;
}
'method_exists()'好主意,你可以向前和向後兼容的方式。 – helgatheviking
add_action('woocommerce_email_after_order_table', 'wdm_add_shipping_method_to_order_email', 10, 2);
function wdm_add_shipping_method_to_order_email($order, $is_admin_email) {
echo '<p><h4>Order Id:</h4> ' . $order->get_order_number() . '</p>';
}
你絕對不需要'全局變量$ woocommerce;'作爲公認的答案...這是過時的,沒有必要... – LoicTheAztec