• Resolved Gary Wright

    (@garywright)


    Hi all!

    I am trying to modify the ‘add-to-cart.php’ file in the loop so that I can run the following PHP query:

    <?php
    if(get_field('ad_activate_deposit') == "yes")
    {
    echo 'PLACE £99 DEPOSIT';
    } else {
    echo 'ADD TO CART';
    }
    ?>

    I currently have the above code modifying the single product add to cart button quite simply, however I am struggling with the loop.

    Any advice will be appreciated! ??

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Support con

    (@conschneider)

    Engineer

    Hi there,

    Maybe it is just a question of the correct filter giving you access. Here is a simple function to change the product loop add to cart button text

    https://gist.github.com/claudiosanches/3d493aefd37beb5748de

    Thread Starter Gary Wright

    (@garywright)

    Thanks for your reply Con.

    However in your example where would I include the IF part of the query?

    For reference in the /single-product/add-to-cart/simple.php I simply changed the code to:

    <button type="submit" name="add-to-cart" value="<?php echo esc_attr( $product->get_id() ); ?>" class="single_add_to_cart_button button alt">
    <?php
    if(get_field('ad_activate_deposit') == "yes")
    {
    echo 'PLACE £99 DEPOSIT';
    } else {
    echo 'ADD TO CART';
    }
    ?>
    </button>
    Plugin Support con

    (@conschneider)

    Engineer

    Hi again,

    Snippets like these usually go into your functions.php file: https://conschneider.de/how-to-use-wordpress-custom-code-snippets/

    I see you used a template overwrite instead. For the shop loop it should be /woocommerce/templates/archive-product.php

    Moderator Hari Shanker R

    (@harishanker)

    Hi @garywright

    I hope that our reply helped guide you in the right direction.

    I’m marking this thread as Resolved since we haven’t heard from you in a while, but if you have further questions, feel free to reach out to us here in the forums. We’re happy to help!

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘IF Controlled Add to Cart Loop Text’ is closed to new replies.