Mainart M
Mainart M

Reputation: 7

button appear with woocommerce status

With the following code, I'm adding a link to my order detail in WooCommerce:

add_action( 'woocommerce_order_details_after_order_table', 'nolo_custom_field_display_cust_order_meta', 10, 1 );
function nolo_custom_field_display_cust_order_meta( WC_Order $order ) {
    echo '<a href="https://link.com.br">Request Sample</a>';
}

I would like this button to only appear when the order status is: wc-processing.

Upvotes: 0

Views: 74

Answers (1)

S J
S J

Reputation: 530

You should check the order status in the callback function, to achieve that, you can use this:

add_action( 'woocommerce_order_details_after_order_table', 'custom_link_for_processing_orders', 10, 1 ); 

function custom_link_for_processing_orders( $order ) {

    /* 
        You can add other statuses to this array, like 'on-hold'.
        Example for multiple statuses:
        $statuses = array(
            'processing',
            'on-hold',
            'failed'
        );
    */
    $statusesWithLink = array(
        'processing'
    );

    // It checks the order status equals the statuses array items or not, and show the link if it equals
    if ( $order->has_status( $statusesWithLink ) ) {
        echo '<a href="https://link.com.br">Request Sample</a>';
    }
    
}

Upvotes: 2

Related Questions