2
votes

I needed a request for quote system on my Woocommerce site and couldn't find any that are compatible with the Composite Products plugin. So I'm going to have customers check out normally using a "no shipping / quote" shipping option and a "request for quote payment gateway. That way I can see the quotes in the backend, approve them, then the customer can order (technically reorder) their quote from their my account section.

I got the buttons for Completed orders and Quote Approved to show up using this:

/**
 * Add order again button in my orders completed actions.
 *
 * @param  array $actions
 * @param  WC_Order $order
 * @return array
 */
function cs_add_order_again_to_my_orders_actions( $actions, $order ) {
    if ( $order->has_status( 'completed' ) ) {
        $actions['order-again'] = array(
            'url'  => wp_nonce_url( add_query_arg( 'order_again', $order->id ) , 'woocommerce-order_again' ),
            'name' => __( 'Order Again', 'woocommerce' )
        );
    }
    return $actions;
}
add_filter( 'woocommerce_my_account_my_orders_actions', 'cs_add_order_again_to_my_orders_actions', 50, 2 );

/**
 * Add Place order button in my orders quote-approved actions.
 *
 * @param  array $actions
 * @param  WC_Order $order
 * @return array
 */
function cs_add_place_order_to_my_orders_actions( $actions, $order ) {
    if ( $order->has_status( 'quote-approved' ) ) {
        $actions['place-order'] = array(
            'url'  => wp_nonce_url( add_query_arg( 'order_again', $order->id ) , 'woocommerce-place_order' ),
            'name' => __( 'place order', 'woocommerce' )
        );
    }
    return $actions;
}
add_filter( 'woocommerce_my_account_my_orders_actions', 'cs_add_place_order_to_my_orders_actions', 50, 2 );

But my second button doesn't function, I believe because of this:

if ( ! function_exists( 'woocommerce_order_again_button' ) ) {

    /**
     * Display an 'order again' button on the view order page.
     *
     * @param object $order Order.
     */
    function woocommerce_order_again_button( $order ) {
        if ( ! $order || ! $order->has_status( apply_filters( 'woocommerce_valid_order_statuses_for_order_again', array( 'completed' ) ) ) || ! is_user_logged_in() ) {
            return;
        }

        wc_get_template( 'order/order-again.php', array(
            'order' => $order,
        ) );
    }
}

in woocommerce/includes/wc-template-functions.php

So I think I just need to add 'quote-approved' to

woocommerce_valid_order_statuses_for_order_again 

array

which I tried using this:

//Make order again work for Place order , see below

add_filter('woocommerce_valid_order_statuses_for_order_again', function( $statuses ){

    $statuses = wc_get_order_statuses('completed', 'quote-approved');

    return $statuses;

}, 10, 2);

Which I found here: Woocommerce - Allowing Order Again for different statuses

But I can't get it to work. Anyone know what I'm doing wrong? Any help would be greatly appreciated. Thanks!

1

1 Answers

1
votes

The problem comes from wc_get_order_statuses() function that has no arguments and just gives an indexed array of all available orders status.

Instead, you just need to add your custom order status slug this way:

add_filter( 'woocommerce_valid_order_statuses_for_order_again', 'add_custom_status_for_order_again', 20, 1 );
function add_custom_status_for_order_again( $statuses ){
    $statuses[] = 'quote-approved';

    return $statuses;
}

Code goes in function.php file of your active child theme (or active theme). Tested and works.