在 WooCommerce 中,我尝试在打印订单中使用由 Checkout Field Editor for WooCommerce 插件制作的自定义字段。我们使用连接到 BizSwoop 打印服务的 BizPrint Print Manager 插件在我们的餐厅打印它们。
以下是操作挂钩的开发人员文档: https://getbizprint.com/documentation/developer/#actions
我尝试使用以下代码,但遗憾的是它不起作用:
add_action( 'Zprinttemplatesorder-htmlafterShippingDetails', 'afterShippingDetails', 10, 1 );
function afterShippingDetails( int $order_id ): void {
echo 'Sede de dónde sale el pedido ' . $order_id->billing_sede;
}
但是如果我将其硬编码到 html/php 中,如下所示:
<tr>
<td colspan="4"><?php _e('Sede de dónde sale el pedido :', 'Print-Google-Cloud-Print-GCP-WooCommerce'); ?>
<?= $order->billing_sede; ?></td>
</tr>
它会起作用...
如有任何帮助,我们将不胜感激。
您的代码中有错误,请尝试以下其中一项:
add_action( 'Zprinttemplatesorder-htmlafterShippingDetails', 'get_head_office_order_origin', 10, 1 );
function get_head_office_order_origin( int $order_id ) : void {
printf( __('Sede de dónde sale el pedido %s'), get_post_meta( $order_id, 'billing_sede', true ) );
}
add_action( 'Zprinttemplatesorder-htmlafterShippingDetails', 'get_head_office_order_origin', 10, 1 );
function get_head_office_order_origin( int $order_id ) : void {
$order = wc_get_order( $order_id ); // Get the WC_Order object instance
printf( __('Sede de dónde sale el pedido %s'), $order->get_meta('billing_sede') );
}
代码位于子主题的functions.php 文件中(或插件中)。两种方法都应该有效。