dejan
dejan

Reputation: 55

Dokan action to update order status

I need help with dokan actions on Orders page. Currently here i have two actions, to mark order complete or processing. What I want is to create action to mark order cancelled and on-hold.

I have accessed file that contains these two actions and they are in file Ajax.php:

  add_action( 'wp_ajax_dokan-mark-order-complete', array( $this, 'complete_order' ) );
  add_action( 'wp_ajax_dokan-mark-order-processing', array( $this, 'process_order' ) );

Is there a way to define similar action:

add_action( 'wp_ajax_dokan-mark-order-cancelled', array( $this, 'cancel_order' ) );

?

Upvotes: 0

Views: 1101

Answers (1)

ALUAWY ninT
ALUAWY ninT

Reputation: 1

I already made a custom action that mark the order as shipped(custom status):

first you can add the below to include/Ajax.php > in the __construct function.

add_action( 'wp_ajax_dokan-mark-order-shipped', array( $this, 'ship_order' ) );

Then you have to include the custom function (in the same file):

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();
}

then make sure that you modify the 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' ),

Please let me know if you need any help

Upvotes: 0

Related Questions