.ai/skills/woocommerce-backend-dev/hooks.md
Name hook callback methods: handle_{hook_name} with @internal annotation.
Examples:
/**
* Handle the woocommerce_init hook.
*
* @internal
*/
public function handle_woocommerce_init() {
// Initialize components
}
/**
* Handle the woocommerce_before_checkout hook.
*
* @internal
*
* @param WC_Checkout $checkout The checkout object.
*/
public function handle_woocommerce_before_checkout( $checkout ) {
// Setup checkout process
}
If you modify a line that fires a hook without a docblock:
@param tagsgit log -S "hook_name" to find when it was introduced@since annotation with that version/**
* Fires after an order has been processed.
*
* @param int $order_id The processed order ID.
* @param array $order_data The order data.
*
* @since 8.2.0
*/
do_action( 'woocommerce_order_processed', $order_id, $order_data );
All hooks must have docblocks that include:
@param tags for each parameter passed to the hook@since annotation with the version number (last line, with blank line before)
includes/class-woocommerce.php on trunk, removing -dev suffixgit log -S "hook_name" to find when it was introducedAction hook example:
/**
* Fires after a product is saved.
*
* @param int $product_id The product ID.
* @param WC_Product $product The product object.
*
* @since 9.5.0
*/
do_action( 'woocommerce_product_saved', $product_id, $product );
Filter hook example:
/**
* Filters the product price before display.
*
* @param string $price The formatted price.
* @param WC_Product $product The product object.
*
* @since 9.5.0
*/
$price = apply_filters( 'woocommerce_product_price', $price, $product );