Support

Home Forums Event Espresso Premium Product Surcharge snippet

Product Surcharge snippet

Posted: October 11, 2017 at 6:00 am


Debbie B

October 11, 2017 at 6:00 am

For each of my events I want people to be able to buy some products (sunglasses and wrist bands).

I’ve used the snippet from here – https://github.com/eventespresso/ee-code-snippet-library/blob/master/checkout/bc_ee_add_product_surcharge.php

but it’s not quite working, it only shows the selection for the second product and nothing for the first.

I’m pretty sure I have the second product in the wrong spot but I don’t know how to fix it.

This is the bit that I think I have wrong:

$products = array(
    0 => array(
        // CHANGE NUMBER VALUE TO MATCH THE ID OF YOUR PRODUCT QUESTION
        'product_question_id'     => 54,
        // CHANGE NUMBER VALUE TO MATCH THE ID OF YOUR QUANTITY QUESTION
        'product_qty_question_id' => 56,
        // AN ARRAY THAT HOLDS DETAILS FOR EACH PRODUCT OPTION YOU ADDED AS QUESTION OPTIONS
        'product_option_details'  => array(
            // KEYS FOR THIS ARRAY SHOULD MATCH THE VALUES YOU ENTERED FOR YOUR QUESTION OPTION VALUES
            'Sunglasses'  => array(
                // THE REST OF THESE VALUES WILL BE USED FOR GENERATING LINE ITEMS
                'name'        => 'Sunglasses',
                'code'        => 'Sunglasses',
                // THE REGISTRANTS NAME WILL GET PREPENDED TO THE PRODUCT DESCRIPTION WHEN DISPLAYED IN LINE ITEMS
                // ie: Small T-shirt: for Derek Zoolander. What is this? A T-shirt for ants?"
                'description' => 'Sunglasses',
                'unit_price'  => 5.00,
                'taxable'     => false,
            ),
            
            // ADD ADDITIONAL PRODUCT OPTIONS HERE
        ),
  
    // ADD ADDITIONAL PRODUCTS HERE
         // CHANGE NUMBER VALUE TO MATCH THE ID OF YOUR PRODUCT QUESTION
        'product_question_id'     => 57,
        // CHANGE NUMBER VALUE TO MATCH THE ID OF YOUR QUANTITY QUESTION
        'product_qty_question_id' => 58,
        // AN ARRAY THAT HOLDS DETAILS FOR EACH PRODUCT OPTION YOU ADDED AS QUESTION OPTIONS
        'product_option_details'  => array(
            // KEYS FOR THIS ARRAY SHOULD MATCH THE VALUES YOU ENTERED FOR YOUR QUESTION OPTION VALUES
            'Determination'  => array(
                // THE REST OF THESE VALUES WILL BE USED FOR GENERATING LINE ITEMS
                'name'        => 'Determination H-Band',
                'code'        => 'determination-h-Band',
                'description' => 'Determination H-Band',
                'unit_price'  => 10.00,
                'taxable'     => false,
            ),
            'Perserverance' => array(
                'name'        => 'Perserverance H-Band',
                'code'        => 'perserverance-h-Band',
                'description' => 'Perserverance H-Band',
                'unit_price'  => 10.00,
                'taxable'     => false,
            ),
            'Resilience'  => array(
                'name'        => 'Resilience H-Band',
                'code'        => 'resilience-h-Band',
                'description' => 'Resilience H-Band',
                'unit_price'  => 10.00,
                'taxable'     => false,
            ),
            
            // ADD ADDITIONAL PRODUCT OPTIONS HERE
          ),
    ),
  
);


Josh

  • Support Staff

October 11, 2017 at 8:01 am

Hi there,

It looks like you’re missing a closing bracket and you need to start a second array item for the second product.

For example in your code where you have this:

// ADD ADDITIONAL PRODUCTS HERE

That should be changed to:

    ),
    // ADD ADDITIONAL PRODUCTS HERE
    1 => array(


Debbie B

October 23, 2017 at 3:18 am

I’ve added that into the code but it’s still not picking up the second lot of goods. I only get the first one.


Josh

  • Support Staff

October 23, 2017 at 6:40 pm

Can you post the entirety of the code into a pastebin or a gist, then link here? The code you’ve posted here may not be the only part that needs fixing if you fixed that one issue.


Debbie B

October 24, 2017 at 12:25 am

I have PasteBinned it (I hope this works!!!)

This is the entire snippet that I have:

https://pastebin.com/AurM7t0t


Tony

  • Support Staff

October 24, 2017 at 10:35 am

Hi Debbie,

Try this snippet:

https://pastebin.com/NYRwdE4X


Debbie B

October 25, 2017 at 3:41 am

I copied exactly what you had there and tried it – nothing happened when I selected the products. I tried changing the product_question_id and product_qty_question_id to the IDs I had created and when I did that I got the error below (I hope it shows)

or the link https://drive.google.com/file/d/0B6uqrA0HpL6qWWtweVBZX3d6eFk/view?usp=sharing


Tony

  • Support Staff

October 25, 2017 at 9:19 am

My apologies, I change the ID’s to suit my site whilst testing, I should have changed those back in the snippet for you.

I’ve created a gist so I can edit the code on the fly, try this version:

https://gist.github.com/Pebblo/51c4284d2dbedb7c0e1daff0c562f1dc

With the above error you posted, there will be an error being thrown during the request, do you have access to the server error logs? If so, see if there are any errors from the above code shown there.

The support post ‘Product Surcharge snippet’ is closed to new replies.

Have a question about this support post? Create a new support post in our support forums and include a link to this existing support post so we can help you.

Event Espresso