Plugin Directory

Changeset 3445720


Ignore:
Timestamp:
01/23/2026 04:33:05 PM (4 weeks ago)
Author:
digitallychee
Message:

Release 1.0.3

Location:
dl-gift-wallet/trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • dl-gift-wallet/trunk/changelog.txt

    r3432896 r3445720  
    11*** DL Gift Wallet ***
     2
     32026-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.
    27
    382025-12-29 - version 1.0.2
  • dl-gift-wallet/trunk/dl-gift-wallet.php

    r3432896 r3445720  
    33 * Plugin Name: DL Gift Wallet
    44 * Description: Allow customers to purchase gift credit that is automatically added to a recipient’s store account as balance.
    5  * Version: 1.0.2
     5 * Version: 1.0.3
    66 * Requires at least: 6.0
    7  * Requires PHP: 7.4
     7 * Requires PHP: 8.3
    88 * WC requires at least: 8.0
    99 * WC tested up to: 10.4.3
     
    6060
    6161    // Pro upgrade URL (Freemius etc).
    62     $upgrade_url = 'https://digitallycheeplugins.com/wordpress-plugins/';
     62    $upgrade_url = 'https://woocommerce.com/products/dl-gift-wallet-pro';
    6363
    6464    $upgrade_link = sprintf(
     
    9696        }
    9797
    98         $install_url = esc_url('https://digitallycheeplugins.com/wordpress-plugins/');
     98        $install_url = esc_url('https://digitallycheeplugins.com/wordpress-plugins/gift-wallet/');
    9999
    100100        echo '<tr class="plugin-update-tr"><td colspan="3" class="plugin-update colspanchange">';
     
    197197        add_action('wp_enqueue_scripts', [$this, 'enqueue_frontend_styles']);
    198198
     199        // Autocompleting gift wallet orders
     200        add_action('woocommerce_payment_complete', [$this, 'maybe_autocomplete_giftwallet_order'], 20);
    199201    }
    200202
     
    11661168     * --------------------------------------------------------------------- */
    11671169
    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)) {
     1170public 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                );
    11771218                continue;
    11781219            }
    11791220
    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
     1265public 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}
    12251289
    12261290    /* -------------------------------------------------------------------------
  • dl-gift-wallet/trunk/readme.txt

    r3432896 r3445720  
    44Requires at least: 6.0
    55Tested up to: 6.9
    6 Requires PHP: 7.4
    7 Stable tag: 1.0.2
     6Requires PHP: 8.3
     7Stable tag: 1.0.3
    88License: GPLv3
    99License URI: https://www.gnu.org/licenses/gpl-3.0.html
     
    250250
    251251== 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.
    252257
    253258= 1.0.2 =
     
    274279= Upgrade Notice =
    275280
    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 =
     282Gift 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.