WordPress Hook
The "WordPress Hook" element empowers you to seamlessly integrate any WordPress or WooCommerce hook into your page, post, product, or template.
Hooks provide developers with the ability to modify or enhance WordPress’ functionality without the need to directly edit the core code of WordPress. For more insights into WordPress Hooks and their usage, refer to this article: https://www.wpbeginner.com/glossary/hooks/
You can easily locate the "WordPress Hook" element in the content elements overview:
Selecting Hook TypeCopy link
Manual Input
function example_callback( ) {
// (maybe) do something like:
echo 'Test Message';
}
add_action( 'example_action', 'example_callback' );
WooCommerce Hooks
However, if you've crafted your unique custom product page template within TheGem templates builder, the "Compare" button might not appear due to the absence of the "woocommerce_single_product_summary" hook:
Why is this the case? When you create a custom product page template, you assemble it with selected content elements, such as "Product Title" and "Product Add to Cart." However, this approach might eliminate the standard PHP hooks that WooCommerce offers by default, often causing issues with compatibility of third-party plugins that rely on these hooks. In our example, the YITH WooCommerce Compare plugin fails to locate the expected hook on the product page, resulting in the inability to present its functionality.
This is where the "WordPress Hook" content element proves invaluable. To address this situation, simply insert the "WordPress Hook" element into your single product template using the page builder and choose "WooCommerce Hooks" in the "Hook Type" field.
Following this, you can specify:
WooCommerce Hook Type
In this section, you can select from three primary categories of WooCommerce hooks:
- hooks for product pages
- hooks for the cart page
- and hooks for the checkout page.
Hook
In this section, you can select the specific hook from the list of available WooCommerce hooks. The default value is "Default for plugins compatibility," which is recommended to ensure compatibility with most WooCommerce third-party plugins (like in the "YITH WooCommerce Compare" example).
Note: in some cases, the "Default for plugins compatibility" option might not yield the desired result. In such cases, consult the documentation of the respective third-party plugin to determine the specific WooCommerce hook it employs. Afterward, you can select the corresponding hook in the "Hook" field. For example, if you would need to add "Request a Quote" button using YITH Request a Quote plugin, you would need to insert following hooks:
- in the beginning of the product template you need to insert "woocommerce_before_single_product" hook
- and then, in the position where you need to display the "Request a Quote" button, you need to insert "woocommerce_single_product_summary" hook
The WordPress Hook element also provides an option to "Clean actions." Enabling this option is typically advisable to eliminate the default elements hooked by WooCommerce itself. You can display these elements using appropriate widgets, thereby bypassing the need for their display via hooks. Hooks generally serve the purpose of ensuring compatibility with third-party plugins or incorporating your own custom PHP code.