Changeset 3445720
- Timestamp:
- 01/23/2026 04:33:05 PM (4 weeks ago)
- Location:
- dl-gift-wallet/trunk
- Files:
-
- 3 edited
-
changelog.txt (modified) (1 diff)
-
dl-gift-wallet.php (modified) (5 diffs)
-
readme.txt (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
dl-gift-wallet/trunk/changelog.txt
r3432896 r3445720 1 1 *** DL Gift Wallet *** 2 3 2026-01-23 - version 1.0.3 4 * Improved Gift Wallet order handling so gift-only orders are automatically completed after successful payment. 5 * Gift credit is now applied immediately without requiring manual order completion. 6 * Added safeguards to prevent gift credit from being applied more than once per order. 2 7 3 8 2025-12-29 - version 1.0.2 -
dl-gift-wallet/trunk/dl-gift-wallet.php
r3432896 r3445720 3 3 * Plugin Name: DL Gift Wallet 4 4 * Description: Allow customers to purchase gift credit that is automatically added to a recipient’s store account as balance. 5 * Version: 1.0. 25 * Version: 1.0.3 6 6 * Requires at least: 6.0 7 * Requires PHP: 7.47 * Requires PHP: 8.3 8 8 * WC requires at least: 8.0 9 9 * WC tested up to: 10.4.3 … … 60 60 61 61 // Pro upgrade URL (Freemius etc). 62 $upgrade_url = 'https:// digitallycheeplugins.com/wordpress-plugins/';62 $upgrade_url = 'https://woocommerce.com/products/dl-gift-wallet-pro'; 63 63 64 64 $upgrade_link = sprintf( … … 96 96 } 97 97 98 $install_url = esc_url('https://digitallycheeplugins.com/wordpress-plugins/ ');98 $install_url = esc_url('https://digitallycheeplugins.com/wordpress-plugins/gift-wallet/'); 99 99 100 100 echo '<tr class="plugin-update-tr"><td colspan="3" class="plugin-update colspanchange">'; … … 197 197 add_action('wp_enqueue_scripts', [$this, 'enqueue_frontend_styles']); 198 198 199 // Autocompleting gift wallet orders 200 add_action('woocommerce_payment_complete', [$this, 'maybe_autocomplete_giftwallet_order'], 20); 199 201 } 200 202 … … 1166 1168 * --------------------------------------------------------------------- */ 1167 1169 1168 public function handle_order_completed($order_id) 1169 { 1170 $order = wc_get_order($order_id); 1171 if (!$order) 1172 return; 1173 1174 foreach ($order->get_items() as $item) { 1175 $product = $item->get_product(); 1176 if (!$product || !$this->is_gift_product($product)) { 1170 public function handle_order_completed($order_id) 1171 { 1172 $order = wc_get_order($order_id); 1173 if (!$order) { 1174 return; 1175 } 1176 1177 // Prevent double-crediting (e.g. if status changes trigger this again) 1178 if ($order->get_meta('_giftwallet_credited') === 'yes') { 1179 return; 1180 } 1181 1182 $did_credit_any = false; 1183 1184 foreach ($order->get_items() as $item) { 1185 $product = $item->get_product(); 1186 if (!$product || !$this->is_gift_product($product)) { 1187 continue; 1188 } 1189 1190 $recipient_email = $item->get_meta('giftwallet_recipient_email', true); 1191 if (empty($recipient_email) || !is_email($recipient_email)) { 1192 continue; 1193 } 1194 1195 $from_name = $item->get_meta('giftwallet_from_name', true); 1196 $message = $item->get_meta('giftwallet_message', true); 1197 $gift_total = floatval($item->get_total()); 1198 1199 if ($gift_total <= 0) { 1200 continue; 1201 } 1202 1203 $user = get_user_by('email', $recipient_email); 1204 1205 if (!$user) { 1206 $username = sanitize_user(current(explode('@', $recipient_email)), true); 1207 if (username_exists($username)) { 1208 $username .= '_' . wp_generate_password(4, false); 1209 } 1210 1211 $password = wp_generate_password(12, true); 1212 $user_id = wp_create_user($username, $password, $recipient_email); 1213 1214 if (is_wp_error($user_id)) { 1215 $order->add_order_note( 1216 'Gift Wallet: Failed to create user for ' . sanitize_email($recipient_email) 1217 ); 1177 1218 continue; 1178 1219 } 1179 1220 1180 $recipient_email = $item->get_meta('giftwallet_recipient_email', true); 1181 if (empty($recipient_email) || !is_email($recipient_email)) { 1182 continue; 1183 } 1184 1185 $from_name = $item->get_meta('giftwallet_from_name', true); 1186 $message = $item->get_meta('giftwallet_message', true); 1187 $gift_total = floatval($item->get_total()); 1188 if ($gift_total <= 0) { 1189 continue; 1190 } 1191 1192 $user = get_user_by('email', $recipient_email); 1193 if (!$user) { 1194 $username = sanitize_user(current(explode('@', $recipient_email)), true); 1195 if (username_exists($username)) { 1196 $username .= '_' . wp_generate_password(4, false); 1197 } 1198 $password = wp_generate_password(12, true); 1199 $user_id = wp_create_user($username, $password, $recipient_email); 1200 1201 if (is_wp_error($user_id)) { 1202 $order->add_order_note( 1203 'Gift Wallet: Failed to create user for ' . sanitize_email($recipient_email) 1204 ); 1205 continue; 1206 } 1207 1208 wp_new_user_notification($user_id, null, 'user'); 1209 } else { 1210 $user_id = $user->ID; 1211 } 1212 1213 $this->add_credit($user_id, $gift_total); 1214 1215 $order->add_order_note(sprintf( 1216 'Gift Wallet: Credited %s to %s (user ID %d).', 1217 wp_strip_all_tags(wc_price($gift_total)), 1218 sanitize_email($recipient_email), 1219 absint($user_id) 1220 )); 1221 1222 $this->send_gift_email($recipient_email, $from_name, $message, $gift_total, false); 1223 } 1224 } 1221 // Send standard WP account email 1222 wp_new_user_notification($user_id, null, 'user'); 1223 } else { 1224 $user_id = $user->ID; 1225 } 1226 1227 // Apply credit 1228 $this->add_credit($user_id, $gift_total); 1229 $did_credit_any = true; 1230 1231 // Log 1232 $order->add_order_note(sprintf( 1233 'Gift Wallet: Credited %s to %s (user ID %d).', 1234 wp_strip_all_tags(wc_price($gift_total)), 1235 sanitize_email($recipient_email), 1236 absint($user_id) 1237 )); 1238 1239 // Email recipient 1240 $this->send_gift_email($recipient_email, $from_name, $message, $gift_total, false); 1241 } 1242 1243 // Only mark the order as credited if we actually credited something 1244 if ($did_credit_any) { 1245 $order->update_meta_data('_giftwallet_credited', 'yes'); 1246 $order->save(); 1247 } 1248 } 1249 1250 1251 private function order_is_all_giftwallet( WC_Order $order ): bool 1252 { 1253 $items = $order->get_items(); 1254 if (empty($items)) return false; 1255 1256 foreach ($items as $item) { 1257 $product = $item->get_product(); 1258 if (!$product || !$this->is_gift_product($product)) { 1259 return false; // contains something else 1260 } 1261 } 1262 return true; 1263 } 1264 1265 public function maybe_autocomplete_giftwallet_order( $order_id ) 1266 { 1267 $order = wc_get_order($order_id); 1268 if (!$order instanceof WC_Order) return; 1269 1270 // Only for orders that are *entirely* gift wallet products 1271 if (!$this->order_is_all_giftwallet($order)) return; 1272 1273 // Don't touch terminal statuses 1274 if ($order->has_status(['completed','cancelled','refunded','failed'])) return; 1275 1276 // Prevent repeated status updates if gateway calls payment_complete more than once 1277 if ($order->get_meta('_giftwallet_autocompleted') === 'yes') return; 1278 1279 $order->update_meta_data('_giftwallet_autocompleted', 'yes'); 1280 $order->save(); 1281 1282 // Mark completed (this will trigger your existing order_status_completed hook) 1283 $order->update_status( 1284 'completed', 1285 __('Gift Wallet: Auto-completed after successful payment.', 'dl-gift-wallet'), 1286 true 1287 ); 1288 } 1225 1289 1226 1290 /* ------------------------------------------------------------------------- -
dl-gift-wallet/trunk/readme.txt
r3432896 r3445720 4 4 Requires at least: 6.0 5 5 Tested up to: 6.9 6 Requires PHP: 7.47 Stable tag: 1.0. 26 Requires PHP: 8.3 7 Stable tag: 1.0.3 8 8 License: GPLv3 9 9 License URI: https://www.gnu.org/licenses/gpl-3.0.html … … 250 250 251 251 == Changelog == 252 253 = 1.0.3 = 254 * Improved Gift Wallet order handling so gift-only orders are automatically completed after successful payment. 255 * Gift credit is now applied immediately without requiring manual order completion. 256 * Added safeguards to prevent gift credit from being applied more than once per order. 252 257 253 258 = 1.0.2 = … … 274 279 = Upgrade Notice = 275 280 276 = 1.0. 2=277 This update improves the presentation of Gift Wallet fields on product pages and includes small frontend refinements. No changes to how gift credit or checkout logic works.281 = 1.0.3 = 282 Gift Wallet orders are now automatically completed after successful payment, ensuring store credit is applied instantly. This prevents gift credits from being delayed when orders remain in “Processing”.
Note: See TracChangeset
for help on using the changeset viewer.