Unhook action from child theme

I have decided to use a WooCommerce Storefront child theme called Galleria, when I have previously used the Storefront theme I have used the common remove_action to unhook the defaults and replaced with my own add_action.

However as Galleria is a child theme of Storefront, it has its own add_action in the file class-galleria-structure.php though the structure of the add_action seems different.

A typical add_action in storefront looks like this…

add_action( 'storefront_header', 'storefront_site_branding', 20 );

I would usually use the following to unhook it in my functions.php file like so…

remove_action( 'storefront_header', 'storefront_site_branding', 20 );

In the Galleria child theme the add_actions looks like this…

add_action( 'storefront_header', array( 'Galleria_Structure', 'galleria_top_bar_wrapper' ), 1 );
add_action( 'storefront_header', array( 'Galleria_Structure', 'galleria_top_bar_wrapper_close' ), 6 );

So I assumed that by doing the following it would simply unhook them…

remove_action( 'storefront_header', array( 'Galleria_Structure', 'galleria_top_bar_wrapper' ), 1 );
remove_action( 'storefront_header', array( 'Galleria_Structure', 'galleria_top_bar_wrapper_close' ), 6 );

Having tried this in my functions.php file I find it has no effect.

I tried the suggestion of using ‘init’ but that failed, however after some further digging I realised that they have created these hooks as part of a larger function as seen here…

<?php
/**
 * Galleria Structure
 *
 * @author   WooThemes
 * @since    2.0
 */

if ( ! defined( 'ABSPATH' ) ) {
    exit;
}

if ( ! class_exists( 'Galleria_Structure' ) ) :

class Galleria_Structure {

    /**
     * Setup class.
     *
     * @since 1.0
     */
    public function __construct() {
        add_action( 'wp', array( $this, 'layout_adjustments' ) );
        add_filter( 'storefront_products_per_page', array( $this, 'products_per_page' ) );
        add_filter( 'woocommerce_breadcrumb_defaults', array( $this, 'change_breadcrumb_delimeter' ) );
    }

    /**
     * Layout adjustments
     * @return rearrange markup through add_action and remove_action
     */
    public function layout_adjustments() {

        if ( is_woocommerce_activated() ) {
            remove_action( 'woocommerce_after_shop_loop_item_title', 'woocommerce_template_loop_rating', 5 );
            remove_action( 'woocommerce_after_shop_loop_item_title', 'woocommerce_template_loop_price', 10 );
            add_action( 'woocommerce_before_shop_loop_item_title', array( 'Galleria_Structure', 'galleria_product_loop_title_price_wrap' ), 11 );
            add_action( 'woocommerce_after_shop_loop_item_title', 'woocommerce_template_loop_rating', 2 );
            add_action( 'woocommerce_after_shop_loop_item_title', 'woocommerce_template_loop_price', 1 );
            add_action( 'woocommerce_after_shop_loop_item_title', array( 'Galleria_Structure', 'galleria_product_loop_title_price_wrap_close' ), 2 );

            add_action( 'woocommerce_before_subcategory_title', array( 'Galleria_Structure', 'galleria_product_loop_title_price_wrap' ), 11 );
            add_action( 'woocommerce_after_subcategory_title', array( 'Galleria_Structure', 'galleria_product_loop_title_price_wrap_close' ), 2 );

            remove_action( 'storefront_header', 'storefront_header_cart', 60 );
            add_action( 'storefront_header', 'storefront_header_cart', 4 );

            remove_action( 'storefront_header', 'storefront_product_search', 40 );
            add_action( 'storefront_header', 'storefront_product_search', 3 );
        }

        remove_action( 'storefront_header', 'storefront_secondary_navigation', 30 );
        add_action( 'storefront_header', 'storefront_secondary_navigation', 6 );

        remove_action( 'storefront_header', 'storefront_site_branding', 20 );
        add_action( 'storefront_header', 'storefront_site_branding', 5 );

        remove_action( 'woocommerce_cart_collaterals', 'woocommerce_cross_sell_display' );
        add_action( 'woocommerce_after_cart', 'woocommerce_cross_sell_display', 30 );

        add_action( 'storefront_header', array( 'Galleria_Structure', 'galleria_primary_navigation_wrapper' ), 49 );
        add_action( 'storefront_header', array( 'Galleria_Structure', 'galleria_primary_navigation_wrapper_close' ), 61 );

        add_action( 'storefront_header', array( 'Galleria_Structure', 'galleria_top_bar_wrapper' ), 1 );
        add_action( 'storefront_header', array( 'Galleria_Structure', 'galleria_top_bar_wrapper_close' ), 6 );

    }

    /**
     * Product title wrapper
     * @return void
     */
    public static function galleria_product_loop_title_price_wrap() {
        echo '<section class="g-product-title">';
    }

    /**
     * Product title wrapper close
     * @return void
     */
    public static function galleria_product_loop_title_price_wrap_close() {
        echo '</section>';
    }

    /**
     * Primary navigation wrapper
     * @return void
     */
    public static function galleria_primary_navigation_wrapper() {
        echo '<section class="g-primary-navigation">';
    }

    /**
     * Primary navigation wrapper close
     * @return void
     */
    public static function galleria_primary_navigation_wrapper_close() {
        echo '</section>';
    }

    /**
     * Top bar wrapper
     * @return void
     */
    public static function galleria_top_bar_wrapper() {
        echo '<section class="g-top-bar">';
    }

    /**
     * Top bar wrapper close
     * @return void
     */
    public static function galleria_top_bar_wrapper_close() {
        echo '</section>';
    }

    /**
     * Products per page
     * @return int products to display per page
     */
    public function products_per_page( $per_page ) {
        $per_page = 19;
        return intval( $per_page );
    }

    public function change_breadcrumb_delimeter( $defaults ) {
        $defaults['delimiter'] = ' <span>/</span> ';
        return $defaults;
    }
}

endif;

return new Galleria_Structure();

Can someone please point me in the right direction? I am at a loss as to why this is not working.

2 Answers
2

I eventually figured this out, I don’t know exactly why, but it seems the issue was due to the original use of init, once i replaced it with ‘wp_head’ it worked correctly, my final code looked like this

function change_default_galleria_header() {
remove_action( 'storefront_header', 'storefront_header_cart', 4 );
remove_action( 'storefront_header', 'storefront_product_search', 3 );
remove_action( 'storefront_header', 'storefront_secondary_navigation', 6 );
remove_action( 'storefront_header', 'storefront_site_branding', 5 );
remove_action( 'storefront_header', array( 'Galleria_Structure', 'galleria_primary_navigation_wrapper' ), 49 );
remove_action( 'storefront_header', array( 'Galleria_Structure', 'galleria_primary_navigation_wrapper_close' ), 61 );
remove_action( 'storefront_header', array( 'Galleria_Structure', 'galleria_top_bar_wrapper' ), 1 );
remove_action( 'storefront_header', array( 'Galleria_Structure', 'galleria_top_bar_wrapper_close' ), 6 );

}
add_action( 'wp_head', 'change_default_galleria_header' );

I do hope this information helps someone else in future.
Thanks

Leave a Comment