1

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.

3

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

2

Sorry I can not comment yet on this site

Could you be removing an action before it is registered? Have you tried wrapping this with an on init hook? Perhaps using remove_filter would be a better choice.

function my_init() {
  remove_filter( 'storefront_header', array( 'Galleria_Structure', 'galleria_top_bar_wrapper' ) );
  remove_filter( 'storefront_header', array( 'Galleria_Structure', 'galleria_top_bar_wrapper_close' ) );


}
add_action( 'init', 'my_init', 100 );
  • There is no need to be sorry, if you think that this is the issue, then go ahead with an answer.... the objections (if you saw it here) are to pure requests for info as an answer – Mark Kaplun May 2 '16 at 12:15
  • Hi Thanks for the suggestion however I tried it and it failed, after some further digging I believe it fails as they have added there hook as part of a larger function, so I have added in the relevant code above, I am hoping this new information will help. – Paul May 2 '16 at 14:25
  • I'm sorry, I can't get my head around this filter/action nor I found how to debug this messy fiddle diddle wordpress heart problem. – Antony Gibbs May 23 '16 at 17:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.