Tuesday, 11:00 AM
The designer: "SKU and categories right under the product title."
You try three things:
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_meta' )— nothing.- Move it to
init— nothing. - Copy the template into the theme — it works, and now the copy is yours forever.
All it needed was one number. WooCommerce adds the meta at priority 40, and remove_action without a priority looks for 10.
Goal
After the lesson you find a hook and its priority in a minute and rearrange the product page without copying templates.
Key concepts
- Action — "do something at this moment", filter — "change a value and return it"
- WooCommerce templates are built from hooks with priorities:
woocommerce_single_product_summary remove_action()works only with the same callback and the same priority- Dynamic hooks:
woocommerce_order_status_{status},woocommerce_product_get_{prop} - Where to look: template code, developer.woocommerce.com, Query Monitor → Hooks
Diagram
The product summary is one hook. Each block is a callback, and the priority sets the order:
flowchart TB
S(["woocommerce_single_product_summary"])
S --> T["5 · title"]
T --> R["10 · rating"]
R --> P["10 · price"]
P --> E["20 · short description"]
E --> A["30 · Add to cart"]
A --> M["40 · meta: SKU, categories"]
M --> SH["50 · sharing"]
Code
Move the price below the short description and add a badge:
<?php
add_action( 'init', static function () {
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_price', 10 );
add_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_price', 25 );
} );
add_action( 'woocommerce_single_product_summary', static function () {
global $product;
if ( $product instanceof WC_Product && $product->is_on_sale() ) {
echo '<p class="badge-sale">' . esc_html__( 'Sale ends Sunday', 'my-plugin' ) . '</p>';
}
}, 26 );
Filter: change the button text for one category.
<?php
add_filter( 'woocommerce_product_single_add_to_cart_text', static function ( string $text, WC_Product $product ): string {
return has_term( 'preorder', 'product_cat', $product->get_id() ) ? __( 'Pre-order', 'my-plugin' ) : $text;
}, 10, 2 );
Common mistakes
| Symptom | Cause | Fix |
|---|---|---|
remove_action does nothing | A different priority, or it runs before the hook is added | Check the priority in WooCommerce code; remove on init or wp |
| A filter "breaks" the page | The callback returns nothing | A filter always returns a value |
| No visible change in a block theme | The product page is rendered by blocks, not a PHP template | See lesson 2.2 and module 5 |
Weak and strong answer
Question: How do you move the price on the product page?
Weak answer. Copy
single-product/content-single-product.phpinto the theme and move the code.
Strong answer. In a classic theme —
remove_actionwith priority 10 andadd_actionwith a new priority. No template copy. In a block theme the price is a block in the Single Product template, so I move it in the Site Editor or in the theme'stemplates/single-product.html.
Why the second is stronger: The hook survives updates, and the candidate tells a classic theme from a block theme.
Practice
Move the meta block (SKU, categories) right under the product title, then change the button text for the preorder category. Two tasks in the IDE below, verified with Run.
On your own site: open a product page with Query Monitor, go to the Hooks panel and find every woocommerce_single_product_summary callback with its priority.
Interview Questions
An action does something at a given moment and returns nothing. A filter receives a value, changes it and must return it. Technically both run on the same WP_Hook system.
Look in includes/wc-template-hooks.php, in Query Monitor → Hooks, or dump $wp_filter['hook_name'].
A hook whose name contains a variable part. For example, woocommerce_order_status_completed or woocommerce_product_get_price — WooCommerce builds them from a status or property name.