Code to place snippets only on certain Woocommerce product pages is Not working
-
I want to replace “add to cart” with “Checkout”, and the code works fine, but I wanted it to work only on product pages, not on the shop page for example.
I added this code at the top as requested here, but nothing – it either replaces every “add to cart” with “Checkout” ( no !) or it doesn’t (with !).
the code in question:
if ( ! is_singular( [ 'product' ] ) ) return;
the entire code
if ( ! is_singular( [ 'product' ] ) ) return; add_action( ‘wp_head’, function () {if(is_woocommerce()) { ?> if ( ! is_product() ) return; add_filter( 'woocommerce_product_single_add_to_cart_text', 'cw_btntext_cart' ); add_filter( 'woocommerce_product_add_to_cart_text', 'cw_btntext_cart' ); function cw_btntext_cart() { return __( 'Checkout', 'woocommerce' ); }) <?php }} );
I tried to replace ‘product’ with product IDs, titles, tags, with ‘ and without, 2-3 hours of trying to get this right, in vain.
– my theme is porto if it matters
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
- The topic ‘Code to place snippets only on certain Woocommerce product pages is Not working’ is closed to new replies.