1. Go to this page and download the library: Download daikazu/flexicart library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
// Remove a specific item
Cart::removeItem('item_id');
// Clear all items from the cart
Cart::clear();
// Clear all items and conditions from cart
Cart::reset();
// Get all items
$items = Cart::items();
// Get a specific item
$item = Cart::item('item_id');
// Get cart counts
$totalItems = Cart::count(); // Total quantity of all items
$uniqueItems = Cart::uniqueCount(); // Number of unique items
// Check if cart is empty
$isEmpty = Cart::isEmpty();
// Get cart totals
$subtotal = Cart::subtotal(); // Subtotal before conditions
$total = Cart::total(); // Final total after all conditions
$taxableSubtotal = Cart::getTaxableSubtotal(); // Subtotal of taxable items only
use Daikazu\Flexicart\Conditions\Types\PercentageCondition;
use Daikazu\Flexicart\Conditions\Types\FixedCondition;
use Daikazu\Flexicart\Enums\ConditionTarget;
// Add a 10% discount to the cart
$discount = new PercentageCondition(
name: '10% Off Sale',
value: -10, // Negative for discount
target: ConditionTarget::SUBTOTAL
);
Cart::addCondition($discount);
// Add a $5 shipping fee
$shipping = new FixedCondition(
name: 'Shipping Fee',
value: 5.00,
target: ConditionTarget::SUBTOTAL
);
Cart::addCondition($shipping);
// Add condition to a specific item
$itemDiscount = new PercentageCondition(
name: 'Item Discount',
value: -20,
target: ConditionTarget::ITEM
);
Cart::addItemCondition('item_id', $itemDiscount);
// Remove a specific condition from the cart
Cart::removeCondition('10% Off Sale');
// Remove a condition from a specific item
Cart::removeItemCondition('item_id', 'Item Discount');
// Clear all cart conditions
Cart::clearConditions();
use Daikazu\Flexicart\Conditions\Types\FixedCondition;
use Daikazu\Flexicart\Conditions\Types\PercentageCondition;
use Daikazu\Flexicart\Conditions\Types\PercentageTaxCondition;
// Non-taxable shipping — added to total, NOT added to the tax base.
$shipping = new FixedCondition(
name: 'Shipping',
value: 10.00,
taxable: false // default
);
// Taxable shipping — added to total AND added to the tax base.
$taxableShipping = new FixedCondition(
name: 'Shipping',
value: 10.00,
taxable: true
);
// Discount that does NOT reduce the tax base (tax is calculated on the pre-discount amount).
$discount = new PercentageCondition(
name: 'Discount',
value: -10,
taxable: false // default
);
// Discount that DOES reduce the tax base by its full amount (tax is calculated on the post-discount amount).
$discountReducingTax = new PercentageCondition(
name: 'Discount',
value: -10,
taxable: true
);
// Apply sales tax. The tax is computed against the tax base described above.
$tax = new PercentageTaxCondition(name: 'Sales Tax', value: 8.25);
Cart::addCondition($shipping);
Cart::addCondition($discount);
Cart::addCondition($tax);