Question

The woocommerce function woocommerce_account_orders($current_page) has 1 parameter called $current_page. The function is called via woocommerce_account_orders_endpoint via the following hook - add_action( 'woocommerce_account_orders_endpoint', 'woocommerce_account_orders' );

However, in the above hook, $current_page is not passed as an argument in the function. How is $current_page passed to woocommerce_account_orders() function?

Was it helpful?

Solution

Action hooks can pass variables do hooked callback functions. For example:

do_action( 'my_custom_action', $a_variable );

For that action, any callback function has access to $a_variable:

add_action( 'my_custom_action', 'my_custom_function' );

function my_custom_function( $a_variable ) {
     // etc.
}

The woocommerce_account_orders_endpoint action hook is defined like this:

do_action( 'woocommerce_account_' . $key . '_endpoint', $value );

Where $value would be passed to woocommerce_account_orders() which uses it as the $current_page argument.

Licensed under: CC-BY-SA with attribution
Not affiliated with wordpress.stackexchange
scroll top