[Support request] How to add this code

Home Forums Support [Support request] How to add this code

Home Forums Support How to add this code

  • This topic has 3 replies, 2 voices, and was last updated 3 years ago by Tom.
Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #564713
    Russell

    I am trying to use add to cart buttons from my cart software – they generate this code – that SHOULD work… however, the cart people say that there is an issue with the theme

    Sample code below for add to cart
    <!– Button/Link for aMember Shopping Cart –>
    <script type=”text/javascript”>
    if (typeof cart == “undefined”)
    document.write(“<scr” + “ipt src=’/membership/application/cart/views/public/js/cart.js’></scr” + “ipt>”);
    </script>
    <input type=”button” onclick=”cart.addCheckoutExternal(this,20); return false;” value=”Add to Cart”>
    <!– End Button/Link for aMember Shopping Cart –>

    Sample code for view basket:
    <!– Basket for aMember Shopping Cart –>
    <script type=”text/javascript”>
    if (typeof(cart) == “undefined”)
    document.write(“<scr” + “ipt src=’/membership/application/cart/views/public/js/cart.js’></scr” + “ipt>”);
    </script>
    <script type=”text/javascript”>
    jQuery(function(){cart.loadOnly();});
    </script>

    <!– End Basket for aMember Shopping Cart –>

    Each time I have tried to add the above… the page has been wiped of all HTML

    I have tried the standard WP Editor – which USUALLY works.

    I am using EPro to create the store pages.. and with that the page is wiped completely.

    I have been advise by my cart people that it would be best to add the following code:

    I suggest to add cart.js to header of your theme so:
    <script src=’/membership/application/cart/views/public/js/cart.js’></script>
    Then you can put to elementor only html code ie.:
    <input type=”button” onclick=”cart.addCheckoutExternal(this,4); return false;” value=”Add To Basket”>

    I have no idea how to add to the header and if I do add to the header, does that mean I need to now use a child theme etc?

    Or is there an easier fix to ensure the above code works with GP?

    Thanks in advance

    GeneratePress 2.0.2
    GP Premium 1.6.2
    #565097
    Tom
    Lead Developer
    Lead Developer

    Hi there,

    You can add the code into the wp_head hook using GP Hooks (Appearance > GP Hooks).

    Then you should be able to add the other JS inside Elementor.

    Let me know 🙂

    #566027
    Russell

    When I try to add the code to the wp-head hook I get a big 403 error come up on screen

    403
    Forbidden
    Access to this resource on the server is denied!

    #566119
    Tom
    Lead Developer
    Lead Developer

    That means your server isn’t allowing you to insert javascript into the database. This is a security measure some hosts implement to prevent bad scripts from being injected.

    Instead, you can add a function like this:

    add_action( 'wp_head', 'tu_add_head_script' );
    function tu_add_head_script() {
        ?>
        Your scripts here
        <?php
    }

    Adding PHP: https://docs.generatepress.com/article/adding-php/

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.