我正在寻找一种在电子邮件中显示给客户的按钮的方法,该方法允许他更改状态订单以完成操作。我在我的帐户页面上找到了一个允许执行此操作的代码,并且有一条注释可以避免在电子邮件通知中显示此按钮,这就是我想要的。有人知道这样做的方法吗?
这是代码:
<?php
// My account > Orders (list): Rename "view" action button text when order needs to be approved
add_filter( 'woocommerce_my_account_my_orders_actions', 'change_my_account_my_orders_view_text_button', 10, 2 );
function change_my_account_my_orders_view_text_button( $actions, $order ) {
$required_order_status = 'processing'; // Order status that requires to be approved
if( $order->has_status($required_order_status) ) {
$actions['view']['name'] = __("Approve", "woocommerce"); // Change button text
}
return $actions;
}
// My account > View Order: Add an approval button on the order
add_action( 'woocommerce_order_details_after_order_table', 'approve_order_button_process' );
function approve_order_button_process( $order ){
// Avoiding displaying buttons on email notification
if( ! ( is_wc_endpoint_url( 'view-order' ) || is_wc_endpoint_url( 'order-received' ) ) ) return;
$approved_button_text = __("Approve this order", "woocommerce");
$required_order_status = 'processing'; // Order status that requires to be approved
$approved_order_status = 'completed'; // Approved order status
// On submit change order status
if( isset($_POST["approve_order"]) && $_POST["approve_order"] == $approved_button_text
&& $order->has_status( $required_order_status ) ) {
$order->update_status( $approved_order_status ); // Change order status
}
// Display a form with a button for order approval
if( $order->has_status($required_order_status) ) {
echo '<form class="cart" method="post" enctype="multipart/form-data" style="margin-top:12px;">
<input type="submit" class="button" name="approve_order" value="Approve this order" />
</form>';
}
}
// My account > View Order: Add a custom notice when order is approved
add_action( 'woocommerce_order_details_before_order_table', 'approved_order_message' );
function approved_order_message( $order ){
// Avoiding displaying buttons on email notification
if( ! ( is_wc_endpoint_url( 'view-order' ) || is_wc_endpoint_url( 'order-received' ) ) ) return;
$approved_order_status = 'completed'; // Approved order status
if( $order->has_status( $approved_order_status ) ) {
wc_print_notice( __("This order is approved", "woocommerce"), 'success' ); // Message
}
}
这是个人资料上的按钮外观 enter image description here
如果此按钮可以在进行电子邮件通知中使用,那就太好了!
感谢您的协助,我是php的新手:/