SAWE Membership Store Credits
SAWE Store Credit Plugin - Coded by Claude ai
by Society of Allied Weight Engineers, Inc. · github.com/apbrook5/wordpress-sawe-store-credit-plugin · website
Install
No release zip yet. The repository archive installs, but the folder name will carry the branch suffix and updates will not flow:
wp plugin install https://github.com/apbrook5/wordpress-sawe-store-credit-plugin/archive/refs/heads/main.zipVersion: 1.2.3
Requires WordPress: 6.4+
Requires WooCommerce: 8.0+
Requires PHP: 8.0+
Overview
SAWE Membership Store Credits gives eligible members a renewable store credit that auto-applies to qualifying products at checkout. Credits are role-based, product-scoped, and renew annually on a configurable date.
Installation
- Upload the
sawe-membership-store-creditsfolder to/wp-content/plugins/. - Activate the plugin through Plugins → Installed Plugins.
- Navigate to Store Credits → Settings and configure the uninstall option.
- Create a credit definition under Store Credits → Add New.
Creating a Store Credit
| Field | Description |
|---|---|
| Title | Shown to the member in checkout and account pages |
| Description (body) | Shown to the member below the title |
| Admin Notes | Internal only; never shown to members |
| Credit Amount ($) | Dollar value awarded / renewed each cycle |
| Renewal Date | Month + Day when the credit resets to full value each year |
| Eligible Roles | WP user roles that receive this credit |
| Qualifying Categories | Product categories whose products the credit can pay for |
| Qualifying Products | Individual products the credit can pay for |
Set post status to Published to activate. Drafts and pending posts are ignored.
How Credits Work
Award
When a logged-in user visits the store, the plugin checks every published credit definition. If the user holds a matching role and has no existing row, they are awarded the full credit amount.
Display
- Checkout – A styled box (light blue background, gold border) appears above the checkout form listing each active credit, its remaining balance, how much will be applied to the current order, and the renewal date.
- My Account → Available Store Credits – A dedicated account tab shows all credits.
Applying the Discount
The discount is injected as a WooCommerce fee (negative amount) after all other coupons. It is limited to:
- The user's remaining balance, AND
- The combined subtotal of qualifying items in the cart.
Removing / Restoring
Members can click Remove Store Credit to exclude it from the current order. The button changes to Re-apply Store Credit to allow reversal before checkout.
Finalisation
The deduction is only committed to the database when the order is placed (woocommerce_checkout_order_created). If the order is cancelled or refunded, the deducted amount is restored automatically.
Renewal (Cron)
A daily WP-Cron job runs at midnight. On the configured Month/Day it resets every eligible user's balance back to the full initial amount.
Role Removal
If a user no longer holds any of the required roles, their balance is zeroed the next time they visit the store.
Uninstall
Go to Store Credits → Settings and check Remove database tables on uninstall before deleting the plugin if you want the wp_sawe_msc_user_credits table removed.
CSS Customisation
Override styles in your child theme or via Appearance → Customize → Additional CSS:
/* Example: change border colour */
.sawe-msc-credit-box {
border-color: #005a9c;
}
/* Example: change background */
.sawe-msc-credit-box {
background-color: #f0f8ee;
}
File Structure
sawe-membership-store-credits/
├── sawe-membership-store-credits.php Main plugin file
├── uninstall.php Cleanup on delete
├── includes/
│ ├── class-sawe-msc-db.php Database layer (tables + CRUD)
│ ├── class-sawe-msc-credit-post-type.php CPT + meta registration
│ ├── class-sawe-msc-user-credits.php Award / revoke / renewal logic
│ ├── class-sawe-msc-cart.php Cart discount injection
│ ├── class-sawe-msc-checkout.php Checkout notice + order finalisation
│ └── class-sawe-msc-account.php My Account tab
├── admin/
│ ├── class-sawe-msc-admin.php Admin menus, meta boxes, columns
│ ├── css/sawe-msc-admin.css
│ └── js/sawe-msc-admin.js
└── public/
├── css/sawe-msc-public.css
└── js/
├── sawe-msc-cart.js
└── sawe-msc-account.js
Creating a Release
Releases are built automatically by a GitHub Actions workflow whenever a version tag is pushed. The workflow produces a correctly named .zip file and attaches it to a GitHub Release as a downloadable asset.
Pre-release checklist
Before tagging, make sure the following are in sync with the new version number:
Version:header insawe-membership-store-credits.phpSAWE_MSC_VERSIONconstant insawe-membership-store-credits.php**Version:**inREADME.md> **Plugin version documented:**indocs/DEVELOPER-GUIDE.md- New entry added to
docs/CHANGELOG.md
Option A — tag push (command line)
The tag must start with v (e.g. v1.1.5, not 1.1.5) — the workflow only triggers on tags matching v*.
git tag v1.1.5
git push origin v1.1.5
GitHub Actions will automatically:
- Build a clean plugin zip (
sawe-membership-store-credits-1.1.5.zip) - Create a GitHub Release named "Release v1.1.5" with auto-generated notes
- Attach the zip as a downloadable asset
Option B — GitHub website
- Go to the repository on GitHub and click Releases → Draft a new release.
- In the Choose a tag field, type the new tag — it must start with
v(e.g.v1.1.5) — and select Create new tag on publish. - Fill in a release title and description, then click Publish release.
- GitHub Actions will detect the published release, build the zip, and attach it automatically.
Installing the release zip in WordPress
- Download
sawe-membership-store-credits-{version}.zipfrom the GitHub Release page. - In the WordPress admin go to Plugins → Add New → Upload Plugin.
- Choose the zip file and click Install Now, then Activate.
Note: The zip contains the plugin in a folder named
sawe-membership-store-credits/— the exact name WordPress expects. Uploading via the admin will replace any existing installation cleanly.
Changelog
See docs/CHANGELOG.md for the full history.
1.2.3
- Version bump only — synced with SAWE MembershipWorks Role Sync v1.2.3, tagged together as
v1.2.3. No functional changes to this plugin.
1.2.2
- Page-cache safety guards added to the cart, checkout, and My Account pages (
nocache_headers()+DONOTCACHEPAGE) so a full-page cache can't serve one member's credit balance to another.
1.2.0
- Version bump released alongside the new companion plugin SAWE MembershipWorks Role Sync (also v1.2.0), tagged and released together.
1.1.5
- Added real-time search box to the "Available Store Credits" My Account tab
1.0.0
- Initial release