Z
Z
ZNiko2019-07-20 11:14:11
WordPress
ZNiko, 2019-07-20 11:14:11

How to display text block on specific product pages in Woocommerce?

Hello! Tell the experts how to display a text block through a hook on certain product pages. I am writing such a function for the function.php file

add_action( 'woocommerce_before_add_to_cart_form', 'my_infa' );
function my_infa() {
if (is_product('stedt-dh-150')) {
echo '<div class="contex-cats">Акция!!! подарок</div>';
}
}

Using this code, it displays "Promotion!!! gift" on all pages with the product, although it is only necessary on the page with the stedt-dh-150 slug and a couple more pages (how to list them in the code?). Tell me how to write correctly so that it works.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Denis Yanchevsky, 2019-07-20
@deniscopro

Hello.
Can be by ID:

add_action( 'woocommerce_before_add_to_cart_form', 'my_infa' );
function my_infa() {
    if ( is_product() && get_the_ID() == 10 ) {
        echo 'Акция!!! подарок';
    }
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question