• hi i have been using following code snippet to redirect add to cart to custom product page but something is messing up with entire website can u please check whats wrong with the snippet
    and what lines should i have to add to redirect add to cart button to a specific product page
    function my_custom_add_to_cart_redirect( $url ) {

    if ( ! isset( $_REQUEST[‘add-to-cart’] ) || ! is_numeric( $_REQUEST[‘add-to-cart’] ) ) {
    return $url;
    }

    $product_id = apply_filters( ‘woocommerce_add_to_cart_product_id’, absint( $_REQUEST[‘add-to-cart’] ) );

    // Only redirect the product IDs in the array to the checkout
    if ( in_array( $product_id, array( 334, 329, 321, 303, 311, 304) ) ) {
    $url = get_permalink( $product_id );
    }

    return $url;
    }
    add_filter( ‘woocommerce_add_to_cart_redirect’, ‘my_custom_add_to_cart_redirect’ );

Viewing 1 replies (of 1 total)
  • Make sure you are using straight quotes ' not smart quotes ‘

    Check you have valid code by coping and pasting it here:
    https://phpcodechecker.com/

    You don’t say where you have put the code. It goes in functions.php for your child theme or you can use the “My Custom Functions” plugin.

    If its the first snippet in the file, it should start with <?php

Viewing 1 replies (of 1 total)
  • The topic ‘code snippet turning theme in to blank page’ is closed to new replies.