Woocommerce 订单详细信息未正确加载
Woocommerce Order Details Not Loading Properly
我正在使用 WooCommerce 打印发票和装箱单插件。我想在订单发票中添加一些自定义字段值。但是这些字段没有正确加载。
add_action('wc_pip_after_body', 'dvsi_invoice_footer');
function dvsi_invoice_footer ($order_id) {
$order = new WC_Order( $order_id );
echo '<h4>'.__('Name: ').'</strong> ' . $order->billing_first_name . '</h4>';
echo '<h4>'.__('Note: ').'</strong> ' . get_post_meta( $order->id, 'public_details_new', true ) . '</h4>';
?>
<h4 style="margin-bottom:0px;">Important:</h4>
<p>If you have purchased Domain, Hosting, SSL certificate or any other service that has an Expiry date then please contact us 10 days before prior to the Expiry date so we can renew or repurchase it on time.<p>
<h4 style="margin-bottom:0px;">Contact Details</h4>
<p><strong>Office: </strong>AL-Hafeez Heights Gulberg III, Lahore<p>
<p><strong>Mobile: </strong>0323-4152099<p>
<p><strong>Email: </strong>contact@devsol.pk<p>
<?php
}
输出没有加载我的自定义字段值并显示空白。它只加载 html 个值。
这是可用插件挂钩的 link:https://docs.woocommerce.com/document/woocommerce-print-invoices-packing-lists-developer-reference/#section-1
有什么帮助吗?
不确定这是否能解决问题,但需要使用 WooCommerce CRUD 吸气剂。
$order = new WC_Order( $order_id );
echo '<h4>'.__('Name: ').'</strong> ' . $order->get_billing_first_name() . '</h4>';
echo '<h4>'.__('Note: ').'</strong> ' . $order->get_meta( 'public_details_new', true ) . '</h4>';
直接访问对象属性已经被弃用了几年,至少会引发很多警告。
您可能还需要验证您的自定义元数据是否已正确保存。
wc_pip_after_body
钩子没有 $order_id
参数,但可以使用以下参数:$type
、$action
、$document
和 $order
.
因此您可以在代码中以这种方式使用它(假设 public_details_new
自定义字段存在):
add_action('wc_pip_after_body', 'dvsi_invoice_footer', 90, 4 );
function dvsi_invoice_footer ( $type, $action, $document, $order ) {
echo '<h4>'.__('Name: ').'</strong> ' . $order->get_billing_first_name() . '</h4>';
echo '<h4>'.__('Note: ').'</strong> ' . $order->get_meta( 'public_details_new' ) . '</h4>';
echo '<h4 style="margin-bottom:0px;">'.__('Important: ').'</h4>
<p>'.__('If you have purchased Domain, Hosting, SSL certificate or any other service that has an Expiry date then please contact us 10 days before prior to the Expiry date so we can renew or repurchase it on time.').'<p>';
echo '<h4 style="margin-bottom:0px;">'.__('Contact Details: ').'</h4>
<p><strong>Office: </strong>'.__('AL-Hafeez Heights Gulberg III, Lahore').'<p>
<p><strong>Mobile: </strong>'.__('0323-4152099').'<p>
<p><strong>Email: </strong>'.__('contact@devsol.pk').'<p>';
}
它应该更好用。
注意: 正如@helgatheviking 所说 WC_Order
自 Woocommerce 3 以来,对象属性不再可访问,您需要改用 the corresponding available methods。
我正在使用 WooCommerce 打印发票和装箱单插件。我想在订单发票中添加一些自定义字段值。但是这些字段没有正确加载。
add_action('wc_pip_after_body', 'dvsi_invoice_footer');
function dvsi_invoice_footer ($order_id) {
$order = new WC_Order( $order_id );
echo '<h4>'.__('Name: ').'</strong> ' . $order->billing_first_name . '</h4>';
echo '<h4>'.__('Note: ').'</strong> ' . get_post_meta( $order->id, 'public_details_new', true ) . '</h4>';
?>
<h4 style="margin-bottom:0px;">Important:</h4>
<p>If you have purchased Domain, Hosting, SSL certificate or any other service that has an Expiry date then please contact us 10 days before prior to the Expiry date so we can renew or repurchase it on time.<p>
<h4 style="margin-bottom:0px;">Contact Details</h4>
<p><strong>Office: </strong>AL-Hafeez Heights Gulberg III, Lahore<p>
<p><strong>Mobile: </strong>0323-4152099<p>
<p><strong>Email: </strong>contact@devsol.pk<p>
<?php
}
输出没有加载我的自定义字段值并显示空白。它只加载 html 个值。
这是可用插件挂钩的 link:https://docs.woocommerce.com/document/woocommerce-print-invoices-packing-lists-developer-reference/#section-1
有什么帮助吗?
不确定这是否能解决问题,但需要使用 WooCommerce CRUD 吸气剂。
$order = new WC_Order( $order_id );
echo '<h4>'.__('Name: ').'</strong> ' . $order->get_billing_first_name() . '</h4>';
echo '<h4>'.__('Note: ').'</strong> ' . $order->get_meta( 'public_details_new', true ) . '</h4>';
直接访问对象属性已经被弃用了几年,至少会引发很多警告。
您可能还需要验证您的自定义元数据是否已正确保存。
wc_pip_after_body
钩子没有 $order_id
参数,但可以使用以下参数:$type
、$action
、$document
和 $order
.
因此您可以在代码中以这种方式使用它(假设 public_details_new
自定义字段存在):
add_action('wc_pip_after_body', 'dvsi_invoice_footer', 90, 4 );
function dvsi_invoice_footer ( $type, $action, $document, $order ) {
echo '<h4>'.__('Name: ').'</strong> ' . $order->get_billing_first_name() . '</h4>';
echo '<h4>'.__('Note: ').'</strong> ' . $order->get_meta( 'public_details_new' ) . '</h4>';
echo '<h4 style="margin-bottom:0px;">'.__('Important: ').'</h4>
<p>'.__('If you have purchased Domain, Hosting, SSL certificate or any other service that has an Expiry date then please contact us 10 days before prior to the Expiry date so we can renew or repurchase it on time.').'<p>';
echo '<h4 style="margin-bottom:0px;">'.__('Contact Details: ').'</h4>
<p><strong>Office: </strong>'.__('AL-Hafeez Heights Gulberg III, Lahore').'<p>
<p><strong>Mobile: </strong>'.__('0323-4152099').'<p>
<p><strong>Email: </strong>'.__('contact@devsol.pk').'<p>';
}
它应该更好用。
注意: 正如@helgatheviking 所说 WC_Order
自 Woocommerce 3 以来,对象属性不再可访问,您需要改用 the corresponding available methods。