• Resolved eyewayonline

    (@eyewayonline)


    My website is having a custom code within the “functions.php” file. This code added a “Return Request” button to the “Orders” section of the “My Account” page. The button only appeared for orders whose status had recently changed to “Completed” and remained visible for ten days. Clicking the button changed the order status to a custom-created status named “wc-return-requested”. Below is the code

    add_filter( 'woocommerce_my_account_my_orders_actions', 'add_return_request_button', 10, 2 );
    function add_return_request_button( $actions, $order ) {
        if ( $order->has_status( 'completed' ) ) {
            $date_modified = $order->get_date_modified();
            $date_now = new WC_DateTime();
            $date_diff = $date_now->diff( $date_modified );
            if ( $date_diff->days <= 10 ) {
                $actions['return-request'] = array(
                    'url'  => wp_nonce_url( admin_url( 'admin-ajax.php?action=woocommerce_mark_order_status&status=return-requested&order_id='.$order->get_id() ), 'woocommerce-mark-order-status' ),
                    'name' => __( 'Return Request', 'woocommerce' )
                );
            }
        }
        return $actions;
    }

    it used to work earlier, but now after pressing RETURN REQUEST button, it just refreshes the page without changing the status of that order.

    Kindly Assist

    Thank you

    The page I need help with: [log in to see the link]

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Support ckadenge (woo-hc)

    (@ckadenge)

    Hello @eyewayonline,

    This is a fairly complex development topic. I’m going to leave it open for a bit to see if anyone is able to chime in to help you out.

    Helping out with custom coding of this nature is outside the scope of support, although I would recommend the following:

    1. Running the exact question you’re asking, along with the code provided, through an AI platform like ChatGPT for recommendations/changes to your code;
    2. Joining our WooCommerce Slack community (it does have a developer channel where you can ask coding questions): https://woo.com/community-slack/
    3. Hiring a developer.

    You can also visit the WooCommerce Facebook group. We’re lucky to have a great community of open-source developers for WooCommerce, and many of our developers hang out there, as well.

    Hope this helps.

    We haven’t heard back from you in a while, so I’m going to mark this as resolved – we’ll be here if and/or when you are ready to continue.

    • This reply was modified 8 months, 4 weeks ago by anastas10s. Reason: typo
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Add Return Request button via custom code’ is closed to new replies.