khaledalam / wordpress-woocommerce-offer-plugin

Custom wordpress plugin to add woocommerce offers/gifts for specific products' categories.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

ANCHOVY ∪ NIU = { 9H }

Custom wordpress plugin to add woocommerce offers/gifts for specific products' categories.

README Version 1
README Version 2 [current]

TODOs:

  • This is POC, some corner test cases not handled such as change offer product id, or eligible category id of the offer while there are some carts with old offer products..
  • Populate products in the select menu of offer product wc config and add validations for incorrect inputs
  • Validate preventing adding single offer product via [backend] e.g. curl or api call
  • Improve add&remove item to cart logic (regarding update offers items)
  • Cover translations
  • Clean DB and remove any debugging or old unused wp options
  • Add Unit testing (e.g. PHPUnit)
  • Handle senario such as: delete offer -> add eligable product to cart -> restore offer -> add another eligable product to cart (add/remove cart logic)

V1 Demo video:

screencast.mp4

DB dump: wordpress_v2.sql

Test cases: test_cases


Problem/requirements

  • Ability to auto-add offer products(gifts) to wordpress woocommerce cart when user try to add any products from specific categories.
  • Ability to set the allowed categories <-> gifts from admin dashboard.
  • Restrict cart CRUD operations for this kind of "offer" products.

Example

  • 3 t-shirt products => belongs to [Special Category] => add gift product(Clothes Hanger) for each item.
  • 2 short products => belongs to [Uncategorized] => add no gifts.



Approach/solution/technical

  • Create custom woocommerce product settings section "Offers Products" that will allow the admin & shop manager to manage/set categories <-> gifts association in the dashboard.
  • Use filters/actions hooks:
    • Actions:
      • carbon_fields_register_fields
      • after_setup_theme
      • woocommerce_add_cart_item_data
      • woocommerce_update_cart_action_cart_updated
      • woocommerce_remove_cart_item
      • wp
    • Filters:
      • woocommerce_get_sections_products
      • woocommerce_get_settings_products
      • woocommerce_cart_item_remove_link
      • woocommerce_cart_item_quantity
  • No hard-coded
  • "Offer" product marking depends set product id in woocommerce product settings section "Offers Products"
  • Relation between product's category<->"offer" product depends on wc options product_offer_cat_term_id and product_offer_id.

Auth:

admin:
user: 9Huser
pass: 9Hpassword9H

shop manager:
user: 9hshopmanager
pass: shopmanager9H

PMA:
user: root
pass: password

$ docker-compose up -d --build


References

About

Custom wordpress plugin to add woocommerce offers/gifts for specific products' categories.

License:MIT License


Languages

Language:PHP 69.3%Language:JavaScript 16.9%Language:CSS 7.7%Language:TypeScript 4.3%Language:SCSS 1.6%Language:Less 0.2%Language:HTML 0.0%Language:Shell 0.0%Language:Makefile 0.0%Language:Dockerfile 0.0%