1How do WooCommerce action and filter hooks differ?
Actions execute custom functions at specific points (e.g., `woocommerce_before_add_to_cart_button`), while filters modify data and return it (e.g., `woocommerce_product_single_add_to_cart_text`). Map requirements to hook type: render UI or trigger processes via actions, edit values via filters. Keep functions pure for filters and always return the modified value.
Run `do_action( 'woocommerce_before_main_content' );` searches in the plugin codebase to understand firing order.
2How should you manage priorities and arguments?
Pass priority as the third parameter in `add_action` / `add_filter` to control execution order (default 10). Higher priority runs later. Use the fourth parameter to define accepted arguments so WooCommerce can pass context objects like `$cart` or `$product`. Document priorities in a customization log to prevent collisions across snippets.
Reserve priority ranges by purpose (e.g., 5 for core overrides, 20 for marketing) to avoid future confusion.
3How can you apply conditional logic safely?
Use WooCommerce helper functions (`is_product`, `is_cart`, `is_checkout`) and object properties (`$product->is_type( 'variable' )`). For cart tweaks, reference `$cart->get_cart_contents_count()` before running heavy loops. Always bail early when conditions fail to save resources.
Leverage `WC()->session` or `WC()->customer` objects instead of hitting the database for known session values.
4How do you debug hook-based customizations?
Enable Query Monitor to inspect hooks fired on each request, view passed arguments, and track slow callbacks. Use `error_log` statements with unique prefixes, and wrap experimental code in `function_exists` checks. On staging, combine Xdebug breakpoints with `do_action_ref_array` traces to confirm argument order.
Turn on WP_DEBUG_LOG and tail the log during checkout tests to catch silent hook failures.
5What keeps hook customizations theme-safe?
Place code in custom plugins or the `mu-plugins` directory rather than child theme `functions.php`. Namespaces or unique prefixes prevent collisions. Version control every snippet, add inline comments with hook names, and reference WooCommerce changelogs each quarter to verify hooks remain stable.
Create reusable utility classes for cart or checkout hooks so logic stays organized.
