How To Add A Button To The Complete Order Popup

At the bottom of each order page, there are options to manage the order, such as contacting the vendor, disputing the order, and completing it. When the user clicks on the “Complete” option, a dialogue box appears.

I want to add a button that says “Send message to vendor” using the better messages plugin which I have integrated successfully following this guide by @andrij :muscle:t2:

However, I couldn’t find anything related to this feature in the hooks or developer documentation of hivepress. Is it possible to add this button, or did I miss something?

The standard HivePress Messages is hidding the button when the order status is not equal to processing, so I replicated the same logic for the Better Messages button, but its possible to overwrite Better Messages logic with PHP

The code to overwrite button will look like that:

add_action('init', 'overwrite_better_messages_hivepress_button');

function overwrite_better_messages_hivepress_button()
{
    if( class_exists('Better_Messages_HivePress') ){
        remove_action( 'better_messages_render_order_button', [ Better_Messages_HivePress::instance(), 'render_order_button' ] );
        add_action( 'better_messages_render_order_button', 'better_messages_custom_hivepress_button' );
    }
}

function better_messages_custom_hivepress_button()
{
    $hp_order = hivepress()->request->get_context( 'order' );

    if( $hp_order ){
        $order_id = $hp_order->get_id();
        $order = wc_get_order( $order_id );

        if( $order ){
            //if ( $order->get_status() === 'processing' ) :
                $buyer_id = $hp_order->get_buyer__id();

                $subject = esc_attr( sprintf( _x('Question about order #%d', 'HivePress Integration (Order Page)', 'bp-better-messages'), $order_id) );

                if ( get_current_user_id() === $buyer_id ) {
                    $btn_label = esc_attr(hivepress()->translator->get_string('contact_seller'));
                    $user_id = $hp_order->get_seller__id();
                } else {
                    $btn_label = esc_attr(hivepress()->translator->get_string('contact_buyer'));
                    $user_id = $buyer_id;
                }

                $unique_tag = 'hivepress_order_chat_' . $order_id;

                echo do_shortcode('[better_messages_live_chat_button
                        type="button"
                        class="hp-order__action hp-order__action--bm-message button button--primary alt"
                        text="' . Better_Messages()->shortcodes->esc_brackets( $btn_label ) . '"
                        user_id="' . $user_id . '"
                        subject="' . Better_Messages()->shortcodes->esc_brackets( $subject ) . '"
                        unique_tag="' . $unique_tag . '"
                        ]');
            // endif;
        }
    }
}

@andrij hi can you add priority order arrangement in BM setting for hivepress,
something like '_order' => 99,
message button shouuld be at the end not the first,
When there are many buttons on the order page, other important buttons become invisible
that why message button should be at the end

Interesting, so I will need both of the plugins to use this?

No, where did I say that?

By the way, is the cost for Voice Messages $11 for a one-time purchase or $11 monthly for a subscription?

11.99$/Yearly or 39.99$/Lifetime

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.