我已经做了一个自定义操作,将订单标记为已发货(自定义状态):
首先,您可以将以下内容添加到 __construct 函数中的 include/Ajax.php > 中。
add_action('wp_ajax_dokan-mark-order-shipped', array($this, 'ship_order'));
然后你必须包含自定义函数(在同一个文件中):
public function ship_order() {
if ( ! is_admin() ) {
die();
}
if ( ! current_user_can( 'dokandar' ) || 'on' != dokan_get_option( 'order_status_change', 'dokan_selling', 'on' ) ) {
wp_die( esc_html__( 'You do not have sufficient permissions to access this page.', 'dokan-lite' ) );
}
if ( ! check_admin_referer( 'dokan-mark-order-shipped' ) ) {
wp_die( esc_html__( 'You have taken too long. Please go back and retry.', 'dokan-lite' ) );
}
$order_id = ! empty( $_GET['order_id'] ) ? intval( $_GET['order_id'] ) : 0;
if ( ! $order_id ) {
die();
}
if ( ! dokan_is_seller_has_order( dokan_get_current_user_id(), $order_id ) ) {
wp_die( esc_html__( 'You do not have permission to change this order', 'dokan-lite' ) );
}
$order = dokan()->order->get( $order_id );
$order->update_status( 'wc-completed' );
wp_safe_redirect( wp_get_referer() );
die();
}
然后确保修改 URL:
'url' => wp_nonce_url( admin_url( 'admin-ajax.php?action=dokan-mark-order-shipped&order_id=' . dokan_get_prop( $order, 'id' ) ), 'dokan-mark-order-shipped' ),
如果您需要任何帮助,请告诉我