使用以下代码,我将在WooCommerce中添加一个链接到我的订单详细信息:
add_action( 'woocommerce_order_details_after_order_table', 'nolo_custom_field_display_cust_order_meta', 10, 1 );
function nolo_custom_field_display_cust_order_meta( WC_Order $order ) {
echo '<a href="https://link.com.br">Request Sample</a>';
}
我希望此按钮仅在订单状态为:wc-processing
时显示。
您应该在回调函数中检查订单状态,为了实现这一点,您可以使用以下方法:
add_action( 'woocommerce_order_details_after_order_table', 'custom_link_for_processing_orders', 10, 1 );
function custom_link_for_processing_orders( $order ) {
/*
You can add other statuses to this array, like 'on-hold'.
Example for multiple statuses:
$statuses = array(
'processing',
'on-hold',
'failed'
);
*/
$statusesWithLink = array(
'processing'
);
// It checks the order status equals the statuses array items or not, and show the link if it equals
if ( $order->has_status( $statusesWithLink ) ) {
echo '<a href="https://link.com.br">Request Sample</a>';
}
}