Need to use woocommerce_before_shop_loop_item_title hook

This topic has 4 replies, 3 voices, and was last updated 2 years, 6 months ago ago by Olga Barlow

  • Avatar: La Tienda Vinos
    La Tienda Vinos
    Participant
    March 13, 2022 at 04:31

    Hi. I need to change the product title adding a custom (dynamically) other text.

    there is a hook called woocommerce_before_shop_loop_item_title but doesnt work.

    i read the forum and found this other 2 hooks

    et_before_shop_loop_title and et_after_shop_loop_title
    BUT

    et_before_shop_loop_title = prints my custom text before the title – not a solution.
    et_after_shop_loop_title = prints the product price and then adds my custom text.

    how can i resolve this ? thanks

    3 Answers
    Avatar: Rose Tyler
    Rose Tyler
    Support staff
    March 13, 2022 at 08:32

    Hello,

    Additional customization in files is outside the scope of our support, but we will check what can be done to help you. Please provide temporary wp-admin and FTP access. Then I will pass your question to one of our dev team.

    Regards

    Avatar: La Tienda Vinos
    La Tienda Vinos
    Participant
    March 14, 2022 at 20:06

    I did it in this way.. please tell me if it is ok and nothing will be broken on future

    remove_action('woocommerce_after_shop_loop_item_title','woocommerce_template_loop_price', 10 );
    
    function customize_shop_page_product_title() {
    	
    	$custom = 'hello!';   
    	echo '<h4 class="product-title"><a href="'.get_the_permalink().'">'.$custom.'</a></h4>';
    
    	woocommerce_template_loop_price();
    
    }
    add_action('woocommerce_after_shop_loop_item_title','customize_shop_page_product_title', 10);
    Avatar: Olga Barlow
    Olga Barlow
    Support staff
    March 15, 2022 at 18:59

    Hello,

    You may add next custom code in your child-theme/functions.php

    add_filter('the_title', function($title, $id) {
    if ( in_array(get_post_type($id), array('product', 'product_variation') ) ) {
    $title .= ' ' . __('Your custom text', 'xstore');
    }
    return $title;
    }, 10, 2);

    https://gyazo.com/45e8dadd9c96a6bc16f51ec50ce86181

    Regards

  • Viewing 4 results - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.Log in/Sign up

8theme customization service
We're using our own and third-party cookies to improve your experience and our website. Keep on browsing to accept our cookie policy.