Embed Snippet on Your Site
Allow Admin to Redeem Customer’s Loyalty Points to Store Credits
1. Add it to your site using one of the following methods:
- Option A: Add it to your child theme's functions.php file (recommended for developers).
- Option B: Use a custom plugin for snippets (like Code Snippets) and paste the code there.
Then, save and activate the snippet.
2. It creates a custom AJAX action (migrate_loyalty_to_credits) that:
- Loops through all loyalty points entries.
- Calculates remaining points per user (earned minus redeemed).
- Converts points to store credits using the points-to-credits conversion ratio (acfw_loyalprog_cost_points_ratio).
- Inserts store credits into the acfw_store_credits table.
- Marks the loyalty points as redeemed (to prevent duplicate conversion).
- Stores a flag in user meta to track migrated credits.
3. After adding the snippet, you need to call the AJAX action. Two ways to do it:
- Option A: Use CURL (from the snippet)
Run this command in your terminal (replace acfwp.local and credentials with your site info):
curl -X POST "https://acfwp.local/wp-admin/admin-ajax.php"
-u "admin:yourpassword"
-d "action=migrate_loyalty_to_credits"
Option B: Use the Browser (Quick Method)
While logged in as an admin, go to: https://acfwp.local/wp-admin/admin-ajax.php?action=migrate_loyalty_to_credits
This will execute the migration and return a JSON response.
4. After that, check the response for:
message: should say "Loyalty points successfully migrated to store credits."
migrated_users: shows user IDs, loyalty points converted, and store credits.
You can also verify in the database:
Table: wp_acfw_store_credits
Look for new entries with entry_action = 'loyalty_points'.
5. Important Notes:
- Backup before running this: It modifies your database by adding store credits and marking points as redeemed.
- This runs once per user; it won’t duplicate credits because of the acfw_imported_store_credits_from_lpfw meta check.
- Conversion ratio is pulled from plugin settings (acfw_loyalprog_cost_points_ratio).
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
Comments