• Hi all, just wondering if anyone would know how to make it so discount codes only work on one ticket per order, rather than every ticket?

    I’ve tried many different routes, including inserting this code within stageshow-wp-config.php file, as well as various other files, but can’t seem to find where to edit the trolley’s code:

    function StageshowFilterDiscount($unused, $cartContents)
    {
    $discount = 0;

    // Loop round all Trolley Entries
    foreach ($cartContents->rows as $cartEntry)
    {
    $showName = $cartEntry->showName; // Show Name
    $qty = $cartEntry->qty; // Number of tickets
    $cost = $cartEntry->price; // Price per ticket

    // Apply discount only to the first ticket of each show
    if ($qty > 0) {
    // Calculate 33.36% discount for the first ticket
    $discountAmount = $cost * 0.3336;
    $discount += $discountAmount;

    // Display the discount details for the user (optional)
    define('STAGESHOWLIB_TROLLEYHTML_ABOVEBUTTONS', '<tr><td><br></td></tr><tr>
    <td colspan="6" style="text-align:left"><h2>A DISCOUNT HAS BEEN APPLIED TO YOUR ORDER!</h2></td>
    </tr>
    <tr>
    <td colspan="6" style="text-align:left">You have received a 33.36% discount on the first ticket for each show in your order.</td>
    </tr>
    <tr><td><br></td></tr>');
    }
    }

    // Uncomment the line below to show the discount amount in the trolley
    // echo "Total Discount: $discount <br>\n";

    return $discount;
    }

    add_filter('stageshow_filter_discount', 'StageshowFilterDiscount', 1, 2);

    This code works, but applies to the cart regardless of whether a discount code has been used (and when a discount code is submitted, it removes this anyway).

    Any help would be greatly appreciated! Thankyou.

Viewing 3 replies - 1 through 3 (of 3 total)
  • I had a similar issue and resolved it in a different way.
    we have sponsors that receive a discount for 1 ticket.
    so I made a user roll in do as sponsor.
    Than I made an extra discounted price limited to 1 per sale.
    rhis price is only shown to the users that I elevated to sponsor.

    Thread Starter filmreeves

    (@filmreeves)

    Thanks for your reply, can I ask how you did all of this?

    Thread Starter filmreeves

    (@filmreeves)

    I managed to FINALLY find a solution with the code, so I’ll post it here to save anyone else in the same situation hours of suffering:

    <?php

    function StageshowFilterDiscount($unused, $cartContents)
    {
    $discount = 0;
    $discountedShows = []; // Array to track shows with discounted tickets

    // Check if a discount code has been applied
    if (!empty($cartContents->disCode)) { // Assuming 'disCode' contains the discount code entered by the user

    // Loop through all trolley entries
    foreach ($cartContents->rows as $cartEntry) {
    $showName = $cartEntry->showName; // Show Name
    $qty = $cartEntry->qty; // Number of tickets
    $cost = $cartEntry->price; // Price per ticket

    // Check if this is the first ticket for this show
    if (!isset($discountedShows[$showName]) && $qty > 0) {
    // Calculate 33.36% discount for the first ticket
    $discountAmount = $cost * 0.3336;
    $discount += $discountAmount;

    // Mark this show as discounted
    $discountedShows[$showName] = true;
    }
    }

    // Display the discount details for the user
    if ($discount > 0) {
    define('STAGESHOWLIB_TROLLEYHTML_ABOVEBUTTONS', '<tr><td><br></td></tr><tr>
    <td colspan="6" style="text-align:left"><h4>THANKYOU FOR BEING A SUBSCRIBER!</h4></td>
    </tr>
    <tr>
    <td colspan="6" style="text-align:left">You have received a discount on the first ticket for each show in your order.</td>
    </tr>
    <tr><td><br></td></tr>');
    } else {
    define('STAGESHOWLIB_TROLLEYHTML_ABOVEBUTTONS', '<tr><td><br></td></tr><tr>
    <td colspan="6" style="text-align:left"><h2>DISCOUNTS AVAILABLE</h2></td>
    </tr>
    <tr>
    <td colspan="6" style="text-align:left">By purchasing 6+ tickets you can get up to 10% off your order.</td>
    </tr>
    <tr><td><br></td></tr>');
    }

    // Uncomment the line below to show the discount amount in the trolley
    // echo "Total Discount: $discount <br>\n";

    return $discount;
    }
    }
    add_filter('stageshow_filter_discount', 'StageshowFilterDiscount', 1, 2);

    Add that to stageshow-wp-config.php, tailor the amounts used for the discount, then make a discount code that changes the price to the same value as the normal price.

    Phew!

    • This reply was modified 1 month, 1 week ago by filmreeves.
Viewing 3 replies - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.