Created
January 28, 2021 22:47
-
-
Save frosso/71d195bdf33be4e4a8f4225f761c2533 to your computer and use it in GitHub Desktop.
[PHP/WordPress/WooCommerce] Display category description on pagination
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| // the `woocommerce_taxonomy_archive_description` and the `woocommerce_product_archive_description` functions do not display the category's description on pagination | |
| // this code removes them from WooCommerce and rewrites them to show the description also on new pages | |
| // Before: page 1 (https://d.pr/i/E2iHoD) & page 2 (https://d.pr/i/RiiCOy) | |
| // After: page 1 (https://d.pr/i/E2iHoD) & page 2 (https://d.pr/i/DyGEVQ) | |
| remove_action( 'woocommerce_archive_description', 'woocommerce_taxonomy_archive_description', 10 ); | |
| remove_action( 'woocommerce_archive_description', 'woocommerce_product_archive_description', 10 ); | |
| add_action( 'woocommerce_archive_description', function () { | |
| if ( is_product_taxonomy() ) { | |
| $term = get_queried_object(); | |
| if ( $term && ! empty( $term->description ) ) { | |
| // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped | |
| echo '<div class="term-description">' . wc_format_content( $term->description ) . '</div>'; | |
| } | |
| } | |
| } ); | |
| add_action( 'woocommerce_archive_description', function () { | |
| // Don't display the description on search results page. | |
| if ( is_search() ) { | |
| return; | |
| } | |
| if ( is_post_type_archive( 'product' ) ) { | |
| $shop_page = get_post( wc_get_page_id( 'shop' ) ); | |
| if ( $shop_page ) { | |
| $description = wc_format_content( $shop_page->post_content ); | |
| if ( $description ) { | |
| // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped | |
| echo '<div class="page-description">' . $description . '</div>'; | |
| } | |
| } | |
| } | |
| } ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Description
Before:


On page 1 the description is present:
But on page 2 it isn't:
After:


On page 1 the description is present:
And it is also present on page 2:
How to use it
Use WordPress' guidelines to alter your theme's functions or write a new plugin.
As an alternative, just go to your theme's
functions.phpfile and add these lines (without the initial<?phptag)