• Resolved AnitaMic

    (@anitamic)


    K so i’ve been doing finishing touches on my website & I was wanted to change “Add to cart” to “Add to bag” So i read on this website https://chrislema.com/changing-add-to-cart-in-woocommerce-and-other-quick-changes/ and a question on here how to do it

    so I pasted:

    <?php

    add_filter(‘single_add_to_cart_text’, ‘woo_custom_cart_button_text’);

    function woo_custom_cart_button_text() {

    return __(‘My Button Text’, ‘woocommerce’);

    }

    ?>

    to my functions.php and when I pressed update file I got this message
    “Parse error: syntax error, unexpected ‘<‘ in /home/lottemae/public_html/wp-content/themes/vintage/functions.php on line 31”

    So I went back and deleted it, pressed update and I got that message again. and now I’m panicked because I can’t go to my website or anything:(

    helpppp is it a virus? Can i get my site back???

Viewing 4 replies - 1 through 4 (of 4 total)
  • Nope, you just have a stray bracket somewhere. I’m suspecting that you didn’t need the <?php, which is what tells the browser that the following code will be in php. The ?> closes php, and tells the browser that everything after it is html. So, if you put a <?php into line 31, but the file begins with a <?php, that would cause the error. Make sense?

    Deactivate the WooCommerce plugin by deleting the files from FTP.
    You have edited the php file wrongly.
    Do not experiment with a live website, do the experiments on a localhost installation. And last but not the least, always keep backup while doing experiments.

    helpppp is it a virus? Can i get my site back???

    No. You have edited the PHP file wrongly, that is throwing error when the theme’s some function is calling the edited file. If you open the functions.php file in any text editor like Gedit, near line number 31 you will see the syntax error.

    Mac, Linux usually do not get virus like Windows. You need not to know so many things now, simply understand :

    Editing any PHP file of WordPress wrongly – be it of core, theme or plugin, can render a website unusable.
    But use a localhost installation. Please search with “Installing WordPress Locally” on this website, you will understand the thing.

    Deactivate the WooCommerce plugin by deleting the files from FTP.

    Do not do this.

    @abhishek The OP edited their functions.php file, not the woocommerce files.

    Andrew Bartel said right, I have not noticed that OP (AnitaMic) has added filter in functions.php file which is possibly of WordPress.

    @anitamic :

    Best if you can follow Andrew’s reply (https://www.ads-software.com/support/topic/help-my-sites-not-working-anymore?replies=4#post-4097472) or replace the functions.php file (from backup if changes are made from default beforehand).

    Actually (as per the guide OP wrote) Andrew wanted to say to add only this part :

    add_filter('single_add_to_cart_text', 'woo_custom_cart_button_text');
    function woo_custom_cart_button_text() {
    return __('My Button Text', 'woocommerce');
    }

    If you see one example source code :

    https://core.svn.www.ads-software.com/trunk/wp-includes/functions.php

    You will notice it starts with <?php but there is no ?> ending. There can be such php files in WordPress.
    You will notice there are written comments within /** */ for the developers. Not any snippet can be added anywhere. We usually refer add this before the line which reads ‘else do this’.

    Definitely Andrew is 100% right and there is also a warning on that tut webpage :

    If you’re looking for how to change the “add to cart” behavior, check out this newer post.

    Do the experiments on a localhost installation next time.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Help! my sites not working anymore!’ is closed to new replies.