Support » Plugin: WooCommerce » Override woocommerce add_to_cart link (shop page)

  • bigsaysjay

    (@bigsaysjay)


    Hello !

    WebSite : http://www.games-brand.com/shop

    On this page i’m displaying different product types (variable / simple). The problem is on the simple product side -> the button is linked to add_to_cart and not to the product page (what i want).

    I’ve tried to override add-to-cart.php template without success. Modified url still send you on the add_to_cart action and not on the product page.

    Thanks

Viewing 6 replies - 1 through 6 (of 6 total)
  • souravkr

    (@souravkr)

    hi,

    please put following code within functions.php file of your theme…

    //—————————————————————————-

    add_filter( ‘woocommerce_loop_add_to_cart_link’, ‘srv_add_product_link’ );
    function srv_add_product_link( $link ) {
    global $product;
    $product_id = $product->id;
    $product_sku = $product->get_sku();
    $link = ‘‘.sfws_woocommerce_product_add_to_cart_text().’‘;
    return $link;
    }

    souravkr

    (@souravkr)

    hi,

    please put following code within functions.php file of your theme…

    //—————————————————————————-

    add_filter( ‘woocommerce_loop_add_to_cart_link’, ‘srv_add_product_link’ );
    function srv_add_product_link( $link ) {
    global $product;
    $product_id = $product->id;
    $product_sku = $product->get_sku();
    $link = ‘‘.srv_woocommerce_product_add_to_cart_text().’‘;
    return $link;
    }

    • This reply was modified 3 years ago by  souravkr.
    bigsaysjay

    (@bigsaysjay)

    Hi souravkr, maybe i wasn’t clear (even if the part of code you gave me isn’t working and it blocks the loop.)

    I need to modify the simple product’s link (on shop page). Currently the button link add the product to the cart. How can i override this link to the send on product page.

    It is only with simple products !

    thanks

    souravkr

    (@souravkr)

    Hi,

    Please try following code working or not with your theme…
    add following code within your theme’s functions.php file.
    ———————————————————————–

    function srv_woocommerce_product_add_to_cart_text() {
    global $product;

    $product_type = $product->product_type;

    switch ( $product_type ) {
    case ‘external’:
    return __( ‘More Details’, ‘woocommerce’ );
    break;
    case ‘grouped’:
    return __( ‘More Details’, ‘woocommerce’ );
    break;
    case ‘simple’:
    return __( ‘More Details’, ‘woocommerce’ );
    break;
    case ‘variable’:
    return __( ‘More Details’, ‘woocommerce’ );
    break;
    default:
    return __( ‘More Details’, ‘woocommerce’ );
    }

    }

    add_filter( ‘woocommerce_loop_add_to_cart_link’, ‘srv_add_product_link’ );
    function srv_add_product_link( $link ) {
    global $product;
    $product_id = $product->id;
    $product_sku = $product->get_sku();
    $link = ‘‘.srv_woocommerce_product_add_to_cart_text().’‘;
    return $link;
    }

    thankyou.

    bigsaysjay

    (@bigsaysjay)

    Hi !

    Thanks for reply. This is not what i’m searching for 🙂

    The following code override the text displayed on the shop page product’s button.

    I suppose there is a method that define if the product’s button display is an add_to_cart_button or a read_more_button, you know what I mean ?

    Something like
    <?php echo '<a href="get_product_page_url($product_id), ">More details</a>'; ?>

    And i’ve try to get the full correct code without a great success. Please use code tags to insert code (it is directly executed otherwise). Thanks

    • This reply was modified 3 years ago by  bigsaysjay.
    • This reply was modified 3 years ago by  bigsaysjay.
    • This reply was modified 3 years ago by  bigsaysjay.
    bigsaysjay

    (@bigsaysjay)

    It is working as well after trying to get the good value of $link, which was executed and not displayed 🙂

    Thanks a lot it works

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Override woocommerce add_to_cart link (shop page)’ is closed to new replies.