If you’re customizing WooCommerce for your WordPress site , understanding single product page hooks is essential. This comprehensive guide will walk you through every important hook available on the WooCommerce single product page, complete with examples and implementation tips.
Introduction to WooCommerce Hooks
WooCommerce uses WordPress’s action and filter hook system extensively to allow developers to modify functionality without editing core files. For single product pages, these hooks provide precise control over every element’s placement and appearance.
Why Use WooCommerce Single Product Hooks?
- Customize product page layout without modifying template files
- Add/remove content at specific locations
- Modify default WooCommerce behavior
- Integrate third-party plugins seamlessly
- Optimize for conversions by rearranging elements
Complete List of Single Product Page Hooks
1. Before Main Content Hooks
These fire before the main product content begins.
/**
* Fires before the single product content
*/
do_action( 'woocommerce_before_single_product' );
/**
* Fires before the single product summary container
*/
do_action( 'woocommerce_before_single_product_summary' );
Usage Example:
add_action( 'woocommerce_before_single_product', function() {
echo '<div class="product-notice">Limited time offer!</div>';
});
2. Product Image Hooks
Control the product image gallery display.
/**
* Fires before the product image
*/
do_action( 'woocommerce_product_thumbnails' );
Usage Example:
add_action( 'woocommerce_product_thumbnails', 'add_video_to_gallery', 20 );
function add_video_to_gallery() {
// Add product video after thumbnails
echo '<div class="product-video">...</div>';
}
3. Product Summary Hooks
These control the main product details area.
/**
* Fires at start of product summary
*/
do_action( 'woocommerce_single_product_summary' );
// Specific summary hooks (in order):
do_action( 'woocommerce_single_product_summary' );
do_action( 'woocommerce_template_single_title' );
do_action( 'woocommerce_template_single_rating' );
do_action( 'woocommerce_template_single_price' );
do_action( 'woocommerce_template_single_excerpt' );
do_action( 'woocommerce_template_single_add_to_cart' );
do_action( 'woocommerce_template_single_meta' );
do_action( 'woocommerce_template_single_sharing' );
Usage Example – Move Price After Excerpt:
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_price', 10 );
add_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_price', 20 );
4. Add to Cart Section Hooks
Control the add to cart functionality.
/**
* Fires before add to cart form
*/
do_action( 'woocommerce_before_add_to_cart_form' );
/**
* Fires inside add to cart form
*/
do_action( 'woocommerce_before_add_to_cart_button' );
do_action( 'woocommerce_before_add_to_cart_quantity' );
do_action( 'woocommerce_after_add_to_cart_quantity' );
do_action( 'woocommerce_after_add_to_cart_button' );
/**
* Fires after add to cart form
*/
do_action( 'woocommerce_after_add_to_cart_form' );
Usage Example – Add Quantity Warning:
add_action( 'woocommerce_after_add_to_cart_quantity', function() {
echo '<p class="stock-warning">Only 5 items left in stock!</p>';
});
5. Product Tabs Hooks
Control the product tabs section (description, reviews, etc.).
/**
* Fires before product tabs
*/
do_action( 'woocommerce_before_single_product_summary' );
/**
* Filter product tabs
*/
apply_filters( 'woocommerce_product_tabs', $tabs );
/**
* Fires in each tab panel
*/
do_action( 'woocommerce_product_description_panel' );
do_action( 'woocommerce_product_additional_information_panel' );
do_action( 'woocommerce_product_reviews_panel' );
/**
* Fires after product tabs
*/
do_action( 'woocommerce_after_single_product_summary' );
Usage Example – Add Custom Tab:
add_filter( 'woocommerce_product_tabs', 'add_custom_product_tab' );
function add_custom_product_tab( $tabs ) {
$tabs['custom_tab'] = array(
'title' => __( 'Custom Tab', 'textdomain' ),
'priority' => 50,
'callback' => 'custom_tab_content'
);
return $tabs;
}
function custom_tab_content() {
echo '<h2>Custom Content</h2>';
echo '<p>This is my custom tab content</p>';
}
6. Related Products Hooks
Control the related products section.
/**
* Fires before related products
*/
do_action( 'woocommerce_after_single_product_summary' );
/**
* Filter related products args
*/
apply_filters( 'woocommerce_output_related_products_args', $args );
/**
* Fires to display related products
*/
do_action( 'woocommerce_after_single_product' );
Usage Example – Change Number of Related Products:
add_filter( 'woocommerce_output_related_products_args', function( $args ) {
$args['posts_per_page'] = 4; // 4 related products
$args['columns'] = 4; // arranged in 4 columns
return $args;
});
7. Product Meta Hooks
Control the product meta information (SKU, categories, tags).
/**
* Fires for product meta
*/
do_action( 'woocommerce_product_meta_start' );
do_action( 'woocommerce_product_meta_end' );
Usage Example – Add Custom Meta:
add_action( 'woocommerce_product_meta_start', function() {
echo '<span class="product-id">Product ID: ' . get_the_ID() . '</span>';
});
8. Review Section Hooks
Control the product review functionality.
/**
* Fires before reviews
*/
do_action( 'woocommerce_reviews_before' );
/**
* Fires for review list
*/
do_action( 'woocommerce_review_before' );
do_action( 'woocommerce_review_before_comment_meta' );
do_action( 'woocommerce_review_meta' );
do_action( 'woocommerce_review_comment_text' );
do_action( 'woocommerce_review_after_comment_text' );
/**
* Fires after reviews
*/
do_action( 'woocommerce_reviews_after' );
Advanced Hook Usage Examples
1. Customizing the Add to Cart Button
add_filter( 'woocommerce_product_single_add_to_cart_text', function( $text ) {
return __( 'Buy Now!', 'textdomain' );
});
add_action( 'woocommerce_after_add_to_cart_button', function() {
echo '<button type="button" class="quick-buy">Quick Buy</button>';
});
2. Adding Custom Fields to Product Page
add_action( 'woocommerce_before_add_to_cart_button', function() {
echo '<div class="custom-field">
<label for="engraving">Engraving Text:</label>
<input type="text" id="engraving" name="engraving">
</div>';
});
// Save custom field data
add_filter( 'woocommerce_add_cart_item_data', function( $cart_item_data, $product_id ) {
if( isset( $_POST['engraving'] ) {
$cart_item_data['engraving'] = sanitize_text_field( $_POST['engraving'] );
}
return $cart_item_data;
}, 10, 2 );
3. Creating a Sticky Add to Cart Bar
add_action( 'wp_footer', function() {
if( is_product() ) {
echo '<div class="sticky-add-to-cart">
<div class="container">
' . woocommerce_template_single_price() . '
' . woocommerce_template_single_add_to_cart() . '
</div>
</div>';
}
});
// Add CSS to header
add_action( 'wp_head', function() {
echo '<style>
.sticky-add-to-cart {
position: fixed;
bottom: 0;
left: 0;
right: 0;
background: #fff;
padding: 15px 0;
box-shadow: 0 -2px 10px rgba(0,0,0,0.1);
z-index: 999;
}
</style>';
});
Conclusion
Mastering WooCommerce single product page hooks gives you complete control over your product pages without modifying core files. Whether you’re adding custom content, rearranging elements, or optimizing for conversions, these hooks provide the flexibility you need.
For more WooCommerce tips and tutorials, keep visiting tarikul.blog where we regularly publish in-depth guides on WooCommerce customization, PHP development, and JavaScript integration.
Would you like me to elaborate on any specific hook or provide more advanced examples? Let me know in the comments!

Leave a Reply