LBarc
LBarc

Reputation: 27

Manipulate WooCommerce category description output

I have around 4000 categories in WooCommerce and I don't have the time to go through every category and manually update the category descriptions. I am wondering if it would be possible to output a generic category description based on the H1 tag?

For example:

if the title is 'Ford Focus Car Spares'

The category description would autofill to something like:

'Buy Ford Focus Car Spares - We stock a huge range of Ford Car Spares'

I would need a way of programmatically removing the keywords from the h1 title and outputting them into the description.

Thankyou to anybody that can help.

Upvotes: 0

Views: 60

Answers (1)

Sco
Sco

Reputation: 759

You can hook the display of the title of your category page

add_action( 'woocommerce_archive_description', 'custom_category_description', 10, 2);
function custom_category_description($woocommerce_taxonomy_archive_description, $int) {
    if ( is_product_category()) {
        $title_cat = get_the_title($int);
        echo 'Buy '.$title_cat.' - We stock a huge range of '.$title_cat;
    }
}

I haven't tested this part of code but this is what I will explore

Upvotes: 1

Related Questions