• I have a recurring issue in my WooCommerce customizations: getting the current order id inside a function.

    For example, in the context of a user’s account page for a specific order, the following doesn’t work.

    The problem is that $order_id is empty, of course. But how would I get the ID of the order into this function?

    add_action( 'woocommerce_order_items_table', 'xcsn_woocommerce_order_items_table');
    function xcsn_woocommerce_order_items_table ( $order_id ) {
    
        $order = new WC_Order( $order_id );
    
        echo 'The order ID is: ' . $order->get_order_number();
    
        // or
    
        echo '<br>The order ID is: ' . $order->id;
    
    }

    The code is stored in functions.php or my plugin – it doesn’t matter.

    https://wordpress.org/plugins/woocommerce/

Viewing 1 replies (of 1 total)
  • Thread Starter Pat Gilmour

    (@patgilmour)

    Here’s the answer for this particular hook:

    add_action( 'woocommerce_order_items_table', 'xcsn_woocommerce_order_items_table');
    function xcsn_woocommerce_order_items_table ( $order ) {
    	echo $order->id;
    }

    Still open to any suggestions as to how do this reliably!

Viewing 1 replies (of 1 total)
  • The topic ‘Passing Order ID to a hook’ is closed to new replies.