Expected placement for the payment instructions
在“我的帐户”>“查看订单”页面上,我想显示处于“暂停”状态的订单的付款说明。
如何添加到订单明细表之前或之后?
我找到的代码片段 (Add custom text under order details on WooCommerce My account view order pages),但不起作用
add_action( 'woocommerce_order_details_after_order_table', 'view_order_custom_payment_instruction', 5, 1); // Email notifications
function view_order_custom_payment_instruction( $order ){
// Only for "on-hold" order statuses and on 'view-order' page
if( in_array( $order->get_status(), array( 'on-hold' ) ) && is_wc_endpoint_url( 'view-order' ) ){
// The "Payment instructions" will be displayed with that:
do_action( 'woocommerce_thankyou_' . $order->get_payment_method(), $order->get_id() );
}
}
请帮忙
答案 0 :(得分:1)
您面临的问题是网关并未在任何地方加载,而只是在结帐页面上加载。您可以将代码更改为显式加载网关,从而执行您缺少的操作
add_action( 'woocommerce_order_details_after_order_table', 'view_order_custom_payment_instruction', 5, 1); // Email notifications
function view_order_custom_payment_instruction( $order ){
// Only for "on-hold" order statuses and on 'view-order' page
if( in_array( $order->get_status(), array( 'on-hold' ) ) && is_wc_endpoint_url( 'view-order' ) ){
WC()->payment_gateways();
// The "Payment instructions" will be displayed with that:
do_action( 'woocommerce_thankyou_' . $order->get_payment_method(), $order->get_id() );
}
}