ukw
ukw

Reputation: 300

woocommerce_single_product_summary replace

I've tried to replace the content of single product page summary without success. All I could achieve so far is adding to the content using a filter:

add_filter( 'woocommerce_single_product_summary', 'my_custom_action', 20 );
    function my_custom_action()
    {
        echo '<p>This is my custom action function</p>';
    }

What function can I use to replace the content rather then adding to it?

Thanks, ukw.

Upvotes: 1

Views: 6759

Answers (2)

LoicTheAztec
LoicTheAztec

Reputation: 254271

First woocommerce_single_product_summary is not a filter hook, but an action hook.

To get this working you could try this:

add_action( 'woocommerce_single_product_summary', 'single_product_summary_action', 1 );
function single_product_summary_action() {
    // remove the single_excerpt
    remove_action('woocommerce_single_product_summary', 'woocommerce_template_single_excerpt', 20 );
    // Add our custom function replacement
    add_action( 'woocommerce_single_product_summary', 'single_excerpt_custom_replacement', 20 );
}

function single_excerpt_custom_replacement() {
    echo '<p>Adding some custom content</p>';
}

Code goes in function.php file of your active child theme (or theme) or also in any plugin file.

Tested and works.

Upvotes: 3

Shital Marakana
Shital Marakana

Reputation: 2887

add below function in child theme function.php file

// define the woocommerce_single_product_summary callback function

remove_action('woocommerce_single_product_summary', 'woocommerce_template_single_excerpt', 20 );
    function my_custom_action() { 
    echo '<p>This is my custom action function</p>';
}    
add_action( 'woocommerce_single_product_summary', 'my_custom_action', 15 );

Upvotes: 0

Related Questions