skip to Main Content

I have a child theme that I am trying to override a WooCommerce function.

WooCommerce file in plugin location: woocommerce/includes/wc-template-hooks.php. I created a new file in the same hierarchy in my child theme and it’s located here: my-child-theme/woocommerce/includes/wc-template-hooks.php

My edited section is I commented out the product title in child theme:

/**
 * Product Summary Box.
 *
 * @see woocommerce_template_single_title()
 * @see woocommerce_template_single_rating()
 * @see woocommerce_template_single_price()
 * @see woocommerce_template_single_excerpt()
 * @see woocommerce_template_single_meta()
 * @see woocommerce_template_single_sharing()
 */
//add_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_title', 5 ); //commented
add_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_rating', 10 );
add_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_price', 10 );
add_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_excerpt', 20 );
add_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_meta', 40 );
add_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_sharing', 50 );

However, when I goto my product page, I still see the title.

Any idea what I am doing wrong?

2

Answers


  1. function my_custom_action() { 
        echo '<p>Hello here</p>';
    };     
    add_action( 'woocommerce_single_product_summary', 'my_custom_action', 15 );
    
    Login or Signup to reply.
  2. You need to remove action woocommerce_single_product_summary to this work properly.

    add_action( 'woocommerce_before_single_product', 'remove_woocommerce_single_product_summary', 10 );
    function remove_woocommerce_single_product_summary() {
        remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_title', 5 );
    }
    

    Just add this to your functions.php and will do the magic.

    You also can try to add remove_action() out of the add_action(). Just like this…

    remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_title', 15 );
    

    …directly to functions.php

    Play with it.


    TIPS & TRICKS

    If you want to change your HTML in the title or do anything you want, here is example:

    add_action( 'woocommerce_before_single_product', 'remove_woocommerce_single_product_summary', 10 );
    function remove_woocommerce_single_product_summary() {
    
        // First, we remove it
        remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_title', 5 );
        
        // Second, we add new title
        add_action( 'woocommerce_single_product_summary', 'woocommerce_my_new_title', 1 );
        
    }
    function woocommerce_my_new_title(){
        echo '<h1 class="some-my-custom-classes">' . the_title() . '</h1>';
    }
    

    If your active theme does not support Woocommerce and you want to add
    a Woocommerce template to your active theme, you must register
    WooCommerce, or give Woocommerce features.

    Check out these links for more details:

    https://github.com/woocommerce/woocommerce/wiki/Declaring-WooCommerce-support-in-themes

    https://docs.woocommerce.com/document/template-structure/

    One important thing:

    If you change the template folder within the Woocommerce plugin, there is a good chance that you will lose your settings after the plugin update. That is why it is better to work in an active theme.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search