Automattic\WooCommerce\Blocks\Templates
AbstractTemplateCompatibility::remove_default_hooks
Remove the default callback added by WooCommerce. We replaced these callbacks by blocks so we have to remove them to prevent duplicated content.
Method of the class: AbstractTemplateCompatibility{}
Hooks from the method
Returns
null. Nothing (null).
Usage
// protected - for code of main (parent) or child class $result = $this->remove_default_hooks();
AbstractTemplateCompatibility::remove_default_hooks() AbstractTemplateCompatibility::remove default hooks code WC 10.8.1
protected function remove_default_hooks() {
foreach ( $this->hook_data as $hook => $data ) {
if ( ! isset( $data['hooked'] ) ) {
continue;
}
foreach ( $data['hooked'] as $callback => $priority ) {
remove_action( $hook, $callback, $priority );
}
}
$class_name = basename( str_replace( '\\', '/', get_class( $this ) ) );
/**
* When extensions implement their equivalent blocks of the template
* hook functions, they can use this filter to register their old hooked
* data here, so in the blockified template, the old hooked functions
* can be removed in favor of the new blocks while keeping the old
* hooked functions working in classic templates.
*
* Accepts an array of hooked data. The array should be in the following
* format:
* [
* [
* hook => <hook-name>,
* function => <function-name>,
* priority => <priority>,
* ],
* ...
* ]
* Where:
* - hook-name is the name of the hook that have the functions hooked to.
* - function-name is the hooked function name.
* - priority is the priority of the hooked function.
*
* @since 9.5.0
* @param array $data Additional hooked data. Default to empty
* @param string $class_name Class name within which the hook is called.
* Either ArchiveProductTemplatesCompatibility or SingleProductTemplateCompatibility.
*/
$additional_hook_data = apply_filters( 'woocommerce_blocks_hook_compatibility_additional_data', array(), $class_name );
if ( empty( $additional_hook_data ) || ! is_array( $additional_hook_data ) ) {
return;
}
foreach ( $additional_hook_data as $data ) {
if ( ! isset( $data['hook'], $data['function'], $data['priority'] ) ) {
continue;
}
remove_action( $data['hook'], $data['function'], $data['priority'] );
}
}