Site logo

Archived topic

Apply php code only on single product page.

3 replies · Started by Jusung on March 9, 2023

Viewing posts 1–4 of 4

Hello. I have added php code, but one code break the cart page.

I found a function is breaking the cart page. So, I need to apply the function only on single page.

Is there any way to apply a code to a single page?

I tried this, but not working

function asfasdf() {
if( is_product() ) {
}
}

Hi there,

try this:

add_action( 'wp', function(){
    // do stuff on single product
    if ( is_product() ){
        add_action( 'woocommerce_after_quantity_input_field', 'action_woocommerce_single_product_summary', 31, 0 );
    }
});

Thank you!!!

It works well!

Glad to hear that!

This archived topic is closed to new replies.