Check cart items for specific item & apply discount (WooCommerce)

I was working on a WordPress + Woocommerce store and there are special membership items, similar to a book store chain. If you buy a membership, you get a 10% discount on your purchases, including the current purchase, but only if you buy additional items.

So here is some PHP which checks your cart for the item in question, checks if there are other items in the cart, and applies the discount. If the special item is removed from the cart, the discount is removed as well.

Here is a modified version, using an array for the special items, in case you have different membership levels:

Please share!

WARGAME

Important:

This is a work in progress. I’ve been wanting something like this for a long time. I based this on another system which had some simple rules for resolving conflict, but I felt it was lacking the depth required to have large scale battles. This project is essentially ‘open source’, I invite comments and playtesting to improve upon this, so that we can all have an excellent system which is easy to learn in minutes, and completely free.

Necessary items:

  • 1d8, tho more is better
  • Miniatures, they can be toys, empty bullet shell casings, anything really.
  • Scenery objects. Abstract or precise, use anything you like.

UNIT TYPES

Infantry

Soldiers

  • Rifleman / Grenadier
  • Scout / Sniper
  • Support

Vehicles

Air

  • Jets & Planes
  • Helicopters

Land

  • Armored Personel Carriers
  • Tanks

Sea

  • Squad Boats
  • Destroyers
  • Submarine
  • Battleship
  • Carrier

WEAPON TYPES

Small Arms

Pistols

  • Semi Auto
  • Full Auto

Carbines

  • Sub-Machine Guns

Rifles

  • Combat Rifle
  • Light Machine Gun (Heavy)
  • Sniper Rifle (Heavy)

Area of Effect

  • Rocket Launcher (Anti-Vehicle, Heavy)
  • Grenade Launcher (Anti-Infantry, Heavy)
  • Heavy Machine Gun (Anti-Infantry, Heavy)

RULES

Standard unit of Measurement: 1cm

Turn Order

  • 1. Initiative
  • 2. Action Phase
  • 3. Free Actions

Initiative

Roll dice for initiative, highest roll wins.

Action Phase

Each player gets 2 actions. All players use their actions during this phase, in order of initiative.
Actions include:

  • Movement
  • Attacking
  • Using skills

Free Actions

Each player has an unlimited number of free actions. All players use their free actions during this phase, in order of initiative.
Free Actions include:

  • Entering/Exiting a vehicle
  • MOVEMENT

    Each movement point allows 10cm of travel. Rough terrain costs double, as does moving up or down. Changing direction mid-move is allowed.

    Movement Points

    • Normal Unit: 1
    • Hero Unit: 1 + Agility
    • Vehicle: 3

    COMBAT

    Attacking

    Attacker rolls 1d8. A result of 1 is an critical failure. A result of 8 is a critical success.

    Success table

    • Adjacent 2-8
    • Short 4-8
    • Long 6-8

    Defending

    Defender rolls 1d8. A result of 8 is a success. For each point of armor or agility a unit has, decrease roll target by 1. So a unit with 2 armor needs a 6 or better to deflect a hit. Cover decreases roll target by 2.

    Area of Effect

    AoE blasts count as an automatic hit wherever they land, and all spaces adjacent. In the case of a miss, roll 1d8 to determine direction of the miss, and 1d8 to determine distance in units.

    RESOLVING COMBAT

    • Critical Success – Unit is defeated
    • Hit
      • Normal unit is defeated
      • Hero unit is wounded
    • AoE Direct Hit
      • Normal Unit is Defeated
      • Hero is Defeated
      • Vehicle is Defeated
    • AoE Splash Hit
      • Normal Unit is defeated
      • Hero is wounded
      • Vehicle is unaffected

    UNIT VALUES

    Army point values should be equal or within an agreed upon handicap

    Infantry

    • Rifleman: 1pt
    • Grenadier, Sniper, Support: 3pt
    • Hero Unit: 5pt*
    • Vehicle Unit: 10pt

    Hero Buffs (Maximum of 5 points)

    • Armor+1: 1pt (Max: 2, cancels agility)
    • Agility+1: 1pt (Max: 2, cancels armor)
    • Accuracy+1: 2pt (Max: 1)
    • Morale+1: 3pt (Max: 1)

    HERO BUFFS

    Morale gives a +1 to all rolls for units within 10cm. Accuracy gives +1 to attack rolls. Agility gives +1 to movement points, and +1 to dodge rolls, but cannot be used with heavy weapons or armor, and is useless in vehicles. Armor gives +1 to deflect rolls, and cannot be combined with Agility.

    SPECIAL VEHICLE RULES

    Planes & Battleships can only perform special AoE attacks from off-map. Carriers have no weapons and are used as platforms to launch air attacks. Submarines are used for anti-vehicular sea combat. Destroyers are used to attack submarines and defend Battleships and Carriers. Squad boats carry infantry on maps with rivers, and to launch amphibious assaults from carriers.

    Squad boats have 1 heavy weapon mount and 2 light weapon mounts. Infantry can attack from the boat with a -2 penalty.

    Planes can either attack with rockets or machine guns. Helicopters move like land vehicles, and can use rockets or machine guns. Submarine torpedos and Destroyer depth charges are treated like rockets. Battleships fire a salvo of artillery.

    Machine Guns fire 5 round bursts, each shot is treated like AoE but does no splash damage. Artillery fire 3 round bursts, each shot is treated like AoE with splash damage.

    Please share!

    Philosophy & Life Eternal

    All beings of intellect share one eternal moment. The Greatest minds of the past may have lived their lives thousands of years ago, but until I learned of the product of their minds, they were as good as non-existent. Similarly, in the moments when their thoughts met my mind, they were as alive as anyone ever is.

    I am a traveler. While remaining in the confines of my mind I have visited ancient Greece, our lives taking shape with each contact. The HUMAN period was similar to pop art. As intellect coalesced and grew, our sub-conscience quietly agreed on a common form.

    I AM still in my Descartes period. I want to make this book less painful. So little of my life is solid, each day is uncertain until lived, and once passed each moment fades as quickly, as if it never was.

    You are capable of better than leaving only scars.

    I SEE REFLECTion everywhere. As with the human form, or pop art, consequence is a product of the minds of all involved. Why then, is so much time spent on death? And when it’s not death, it’s punishment, or hatred? I did not introduce these ideas. I RAN from so many, and these ideas have followed me. Does that not mean I’ve been followed by those I ran from?

    Butterflies.

    The effect of these conflicts could be complicated, distant, but this does not mean non-existent. Without knowing the extent of our meddling, the best we can do is create the best foundation. The effects could repeat, each time giving strength to the next appearance, similar to a motif in music (motive?). This could lead to greater emotional significance, our desire fed by anticipation.

    I sometimes yearn for a hands-off approach, but have mostly given up…

    Please share!