https://github.com/khaledalam/wordpress-woocommerce-offer-plugin
Custom wordpress plugin to add woocommerce offers/gifts for specific products' categories.
https://github.com/khaledalam/wordpress-woocommerce-offer-plugin
woocommerce woocommerce-plugin woocommerce-theme wordpress wordpress-development wordpress-plugin wordpress-theme
Last synced: 2 months ago
JSON representation
Custom wordpress plugin to add woocommerce offers/gifts for specific products' categories.
- Host: GitHub
- URL: https://github.com/khaledalam/wordpress-woocommerce-offer-plugin
- Owner: khaledalam
- License: mit
- Created: 2023-06-01T21:29:49.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2023-06-08T09:44:48.000Z (about 3 years ago)
- Last Synced: 2025-06-12T10:06:22.700Z (about 1 year ago)
- Topics: woocommerce, woocommerce-plugin, woocommerce-theme, wordpress, wordpress-development, wordpress-plugin, wordpress-theme
- Language: PHP
- Homepage:
- Size: 27.1 MB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
## ANCHOVY ∪ NIU = { 9H }
#### Custom wordpress plugin to add woocommerce offers/gifts for specific products' categories.
[README Version 1](README_v1.md)
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:
https://github.com/khaledalam/wordpress-woocommerce-offer-plugin/assets/8682067/5f512a57-bc91-4191-9704-079c2753c0b6
DB dump: [wordpress_v2.sql](./wordpress_v2.sql)
Test cases: [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
- [wordpress-docker-compose](https://github.com/kassambara/wordpress-docker-compose) used as template.
- [wppb](https://wppb.me/) used as plugin template.