Articles

How to add a custom button in orders list’s action column | WordPress | Woocommerce

This code is used for a dynamic button in the Action column on the order’s ID and you have to put it to functions.php file in WordPress Woocommerce’s themes folder.

// Add your custom order status action button (for orders with "approved" status)
add_filter( 'woocommerce_admin_order_actions', 'add_custom_order_status_actions_button', 100, 2 );
function add_custom_order_status_actions_button( $actions, $order ) {
    // Display the button for all orders that have a 'approved' status
    if ( $order->has_status( array( 'approved' ) ) ) {

        // Get Order ID (compatibility all WC versions)
        $order_id = method_exists( $order, 'get_id' ) ? $order->get_id() : $order->id;
        // Set the action button
        $actions['approved'] = array(
            'url'       => wp_nonce_url( admin_url( 'admin-ajax.php?action=xc_woo_printer_job&document_type=invoice&order_id=' . $order_id ), 'xc_woo_printer_job' ),
            'name'      => __( 'Print Invoice', 'woocommerce' ),
            'action'    => "view approved xc_ajax_button", // keep "view" class for a clean button CSS
			
        );
    }
    return $actions;
}

// Here Set WooCommerce icon for your action button
add_action( 'admin_head', 'add_custom_order_status_actions_button_css' );
function add_custom_order_status_actions_button_css() {
    echo '<style>.view.approved::after {  content: "\f105" !important;}</style>';
}

The button will only show on an approved order and you can change it to another operation.

Thanks for visiting Sayf Jee

Tags

Saifullah Aslam

Owner & Founder of Sayf Jee Website

Leave a Reply

Back to top button
Close

Adblock Detected

Please consider supporting us by disabling your ad blocker