Search code examples
woocommercestorefront

woocomerce + storefront - add custom field between hooks/actions on homepage


I want to reorder and add my own code between action on storefront home page. I know how to add/reorder actions, but i don't know how to add my own code.

function storefront_child_reorder_homepage_contant() {
    remove_action('homepage', 'storefront_homepage_content', 10 );
    remove_action('homepage', 'storefront_product_categories', 20 );
    remove_action('homepage', 'storefront_recent_products', 30 );
    remove_action('homepage', 'storefront_featured_products', 40 );
    remove_action('homepage', 'storefront_popular_products', 50 );
    remove_action('homepage', 'storefront_on_sale_products', 60 );
    remove_action('homepage', 'storefront_best_selling_products', 70 );
    add_action('homepage', 'storefront_best_selling_products', 10 );
    **<--- HERE I WANT TO ADD MY OWN PHP CODE (ADVANCED CUSTOM FIELD GALLERY FIELD)**
    add_action('homepage', 'storefront_recent_products', 30 );
}
add_action('init', 'storefront_child_reorder_homepage_contant');

As you can see I want: 1. Best selling products 2. ACF gallery 3. Recent products

How to add my custom code to generate gallery between best selling and recent products?


Solution

  • Ok I've just figured it out:

    function storefront_child_add_custom_php() {
        PHP CODE HERE
    }
    
    function storefront_child_reorder_homepage_contant() {
        remove_action('homepage', 'storefront_homepage_content', 10 );
        remove_action('homepage', 'storefront_product_categories', 20 );
        remove_action('homepage', 'storefront_recent_products', 30 );
        remove_action('homepage', 'storefront_featured_products', 40 );
        remove_action('homepage', 'storefront_popular_products', 50 );
        remove_action('homepage', 'storefront_on_sale_products', 60 );
        remove_action('homepage', 'storefront_best_selling_products', 70 );
        add_action('homepage', 'storefront_best_selling_products', 10 );
       add_action('homepage', ' storefront_child_add_custom_php', 20 );
        add_action('homepage', 'storefront_recent_products', 30 );
    }
    add_action('init', 'storefront_child_reorder_homepage_contant');