Reputation: 381
I just have a little question, I want to understand something in this code:
add_action('woocommerce_after_shop_loop_item' ,
'custom_woocommerce_before_cart_shop', 10, 2 );
What does 10, 2
mean here?
Upvotes: 0
Views: 94
Reputation: 1258
from the wordpress codex
<?php add_action( $hook, $function_to_add, $priority, $accepted_args ); ?>
priority is used to specify the order in which the functions associated with a particular action are executed. Lower numbers correspond with earlier execution, and functions with the same priority are executed in the order in which they were added to the action. (the default value is 10 )
accepted_args are the number of arguments the hooked function accepts. In WordPress 1.5.1+, hooked functions can take extra arguments that are set when the matching do_action() or apply_filters() call is run. For example, the action comment_id_not_found will pass any functions that hook onto it the ID of the requested comment.
If u know what a hooks is in wordpress this is really simple to understand but here would be an example:
function echo_comment_id( $comment_id ) {
echo 'Comment ID ' . $comment_id . ' could not be found';
}
add_action( 'comment_id_not_found', 'echo_comment_id', 10, 1 );
The args are used mainly when you use the do_action function
<?php do_action( $tag, [$arg1, $arg2, ...] ); ?>
you just use the "tag" associated to the hook and the args passed to it.
Looking on internet I couldn't find the custom_woocommerce_before_cart_shop
function, so, just search it on woocomerce code, it should be a function with 2 arguments.
Upvotes: 1