• Resolved cvaliandes

    (@cvaliandes)


    Hello,

    I’ve been trying to change the buy now button on shop page for free($0) products with the text labelling FREE and not buy now. Any ideas on how to do it?

    Christos

Viewing 2 replies - 1 through 2 (of 2 total)
  • There is a filter for the add-to-cart text: ‘woocommerce_product_single_add_to_cart_text’. It has two parameters, the standard text and the product. So you would need to write something like this:

    add_filter( 'woocommerce_product_single_add_to_cart_text', 'my_func', 10, 2 );
    function my_func( $default_text, $product ) {
      $price = (float) $product->get_price();
      if( $price ) {
        return $default_text;
      } else {
        return 'FREE';
      }
    }

    Not tested, so I hope you will be able to debug it if necessary.

    Plugin Support abwaita a11n

    (@abwaita)

    Hi,
    We’ve not heard back from you in a while, so I’m marking this thread as resolved. Hopefully, the above code snippet by @lorro was helpful!

    If you have further questions, please feel free to open a new topic.

    Thanks.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Rename Buy now button for Free products’ is closed to new replies.