有人知道如何通过钩子定制电子邮件模板的订单id吗?
我正在使用一个自定义API,该API基于订单id返回账单,我还试图在电子邮件模板中打印它。
这就是我迄今尝试过的:
add_action( 'woocommerce_email_before_order_table', function ( $order, $sent_to_admin, $plain_text, $email ) {
echo '<pre>' . FS4E_VSDC::fs4e_get_order_slip( $order->get_id() ) . '</pre>';
}, 10, 4 );那样的话,我就得不到账单了。但是如果我硬编码订单id,那么一切都正常。
编辑
当我转储$order时,我得到了完整的对象:
["items":protected]=>
array(5) {
["line_items"]=>
array(3) {
[118]=>
object(WC_Order_Item_Product)#2019 (11) {
["extra_data":protected]=>
array(9) {
["product_id"]=>
int(0)
["variation_id"]=>
int(0)
["quantity"]=>
int(1)
["tax_class"]=>
string(0) ""
["subtotal"]=>
int(0)
["subtotal_tax"]=>
int(0)
["total"]=>
int(0)
["total_tax"]=>
int(0)
["taxes"]=>
array(2) {
["subtotal"]=>
array(0) {
}
["total"]=>
array(0) {
}
}
}
["data":protected]=>
array(11) {
["order_id"]=>
int(55)
["name"]=>
string(9) "Product 1"
["product_id"]=>
int(11)
["variation_id"]=>
int(0)
["quantity"]=>
int(1)
["tax_class"]=>
string(0) ""
["subtotal"]=>
string(1) "0"
["subtotal_tax"]=>
string(1) "0"
["total"]=>
string(1) "0"
["total_tax"]=>
string(1) "0"
["taxes"]=>
array(2) {
["total"]=>
array(0) {
}
["subtotal"]=>
array(0) {
}
}
}
["cache_group":protected]=>
string(11) "order-items"
["meta_type":protected]=>
string(10) "order_item"
["object_type":protected]=>
string(10) "order_item"
["id":protected]=>
int(118)
["changes":protected]=>
array(0) {
}
["object_read":protected]=>
bool(true)
["default_data":protected]=>
array(11) {但是,当我试图以以下方式访问它时:
add_action( 'woocommerce_email_before_order_table', function ( $order, $sent_to_admin, $plain_text, $email ) {
echo '<pre>' . FS4E_VSDC::fs4e_get_order_slip( $order[order_id] ) . '</pre>';
}, 10, 4 );我发现了一个内部服务器错误。
谢谢
发布于 2022-03-23 12:51:02
尝尝这个,
add_action( 'woocommerce_email_before_order_table', function ( $order, $sent_to_admin, $plain_text, $email ) {
$order = wc_get_order( $order_id );
$order_data = $order->get_data(); // The Order data
$order_id = $order_data['id'];
echo '<pre>' . FS4E_VSDC::fs4e_get_order_slip($order_id ) . '</pre>';
}, 10, 4 );发布于 2022-03-23 12:47:58
正如CBroe所提到的,请验证订单包含哪些内容。
我记得当我和WooCommerce一起工作时,$order->get_id()是帖子的id,我必须使用$order->get_order_number()
发布于 2022-03-24 09:32:41
所讨论的API可能需要订单编号,而不是post id。变化
FS4E_VSDC::fs4e_get_order_slip( $order->get_id() ) 至
FS4E_VSDC::fs4e_get_order_slip( $order->get_order_number() ) https://stackoverflow.com/questions/71587405
复制相似问题