我想在woocommerce的退款电子邮件中显示退款原因。我直接在customer-refunded-order.php中进行编辑,该文件已复制到我的子主题中。
我看到杂物对象中的订单可以从那里到达refrease_reson
https://github.com/woocommerce/woocommerce/wiki/Order-and-Order-Line-Item-Data#refund
<?php printf( __( '%s', 'woocommerce' ), $order->get_refund_reason() ); ?>
我只是想看到退款原因显示在电子邮件中,但是此代码破坏了这一过程(当我开始退款时,页面将永远加载并且不会刷新,因为它卡在了电子邮件中)。
答案 0 :(得分:0)
已更新
首先,您不需要__( '%s', 'woocommerce' )
,因为没有要翻译的内容,因此您也不需要printf()
函数。
自WooCommerce 3起,WC_Order_Refund
方法get_refund_reason()
已弃用,并由get_reason()
方法取代。
这不起作用,因为您需要使用WC_Order
方法从get_refunds()
对象中获取退款订单(对于一个订单来说,很多)。
请尝试以下操作:
<?php
// Get the Order refunds (array of refunds)
$order_refunds = $order->get_refunds();
// Loop through refunded orders for the current WC_Order object
foreach( $order_refunds as $order_refund ){
// To be sure we check if that method exist and that is not empty
if( method_exists( $order_refund, 'get_reason' ) && $order_refund->get_reason() ) {
echo '<p>' . esc_html( $order_refund->get_reason() ) . '</p>';
}
}
?>
应该可以。