woocommerce / storefront

Official theme for WooCommerce
https://wordpress.org/themes/storefront/
972 stars 471 forks source link

Add actions to single product pagination and sticky add-to-cart template functions #2040

Closed LuigiPulcini closed 2 years ago

LuigiPulcini commented 2 years ago

At the moment, the storefront_single_product_pagination and storefront_sticky_single_add_to_cart() template functions do not feature any action hooks. The proposed changes add some extra calls to do_action() inside those two functions so that it would be possible not only to add any extra HTML markup before or after those elements (which could be even achieved by hooking to the appropriate actions those functions are hooked to) but also detect whether something is occurring inside those functions. For example, if a plugin needed to apply some filters but limit their adjustments only inside either the single product pagination or the single product sticky add-to-cart, the following logic could be used:

add_filter( 'woocommerce_single_product_image_html', 'my_change_to_product_thumbnail_html' );
function my_change_to_product_thumbnail_html( $html ) {
    if ( did_action( 'storefront_before_single_product_pagination' ) > did_action( 'storefront_after_single_product_pagination' ) ) {
        // we are inside the pagination element
        // so do something here to alter the markup of the product image
        $html = my_function_to_alter_the_product_thumbnail_html_markup( $html );
    }

    return $html;
}

Changelog

New - Added actions to single product pagination New - Added actions to sticky single add-to-cart

danieldudzic commented 2 years ago

Hi @LuigiPulcini,

We really appreciate you taking the time and creating this PR.

There is still an investment of time needed by our team to consider the impact of merging your PR to Storefront. Because at this time, your pull request does not fall into one of the criteria "buckets", we will go ahead and close it.

LuigiPulcini commented 2 years ago

Thanks for the explanation and for adding a link to the criteria "buckets" – as you call them.

To the best of my knowledge, adding do_action calls to template functions that do not currently make use of any template because the HTML they output is hardcoded into them should not have any consequences and produce no compatibility issues. So, I am not quite sure what kind of impact or investment of time you might be referring to.

In any case, thank you for considering my PR request.