Plugin Directory

Changeset 3329484


Ignore:
Timestamp:
07/17/2025 08:07:35 AM (9 months ago)
Author:
olivery
Message:

version 1.0.26 , add address mapping

Location:
connect-plus-for-woocommerce
Files:
38 added
7 edited

Legend:

Unmodified
Added
Removed
  • connect-plus-for-woocommerce/trunk/README.txt

    r3327337 r3329484  
    99Tested up to: 6.8
    1010
    11 Stable tag: 1.0.25
     11Stable tag: 1.0.26
    1212
    1313Requires PHP: 7.0
  • connect-plus-for-woocommerce/trunk/admin/cpfw-connect-admin.php

    r3327337 r3329484  
    269269            'sanitize_callback' => 'absint',
    270270            'default' => 1,
     271        ]);
     272
     273        register_setting('olivery_options_group', 'olivery_connect_field_mapping', [
     274            'type' => 'array',
     275            'sanitize_callback' => function ($input) {
     276                return is_array($input)
     277                    ? array_map('sanitize_text_field', $input)
     278                    : [];
     279            },
     280            'default' => [],
    271281        ]);
    272282
  • connect-plus-for-woocommerce/trunk/admin/js/cpfw-connect-admin.js

    r3288066 r3329484  
    133133            .replace(/customer_name/g, 'Customer Name')
    134134            .replace(/customer_mobile/g, 'Phone')
    135             .replace(/sub_area/g, 'Address 1')
    136             .replace(/sub area/g, 'Address 1')
     135            .replace(/sub_area/g, 'Address')
     136            .replace(/sub area/g, 'Address')
    137137            .replace(/area/g, 'City')
    138138            .replace(/address/g, 'Customer Address');
  • connect-plus-for-woocommerce/trunk/admin/views/cpfw-connect-admin-settings.php

    r3321453 r3329484  
    5353    "Completed Returned" => __("Completed Returned", 'connect-plus-for-woocommerce'),
    5454];
     55
     56$connect_fields = [
     57    'customer_name' => __('Customer First Name', 'connect-plus-for-woocommerce'),
     58    'customer_mobile' => __('Customer Mobile', 'connect-plus-for-woocommerce'),
     59    'customer_area' => __('Customer Area', 'connect-plus-for-woocommerce'),
     60    'customer_sub_area' => __('Customer Sub Area', 'connect-plus-for-woocommerce'),
     61];
     62
     63$available_name_fields = [
     64    // Billing
     65    'billing_name' => __('Billing Name', 'connect-plus-for-woocommerce'),
     66    // Shipping
     67    'shipping_name' => __('Shipping Name', 'connect-plus-for-woocommerce'),
     68];
     69
     70$available_phone_fields = [
     71    // Billing
     72    'billing_phone' => __('Billing Phone', 'connect-plus-for-woocommerce'),
     73    // Shipping
     74    'shipping_phone' => __('Shipping Phone', 'connect-plus-for-woocommerce'),
     75];
     76
     77$available_fields = [
     78    // Billing
     79    'billing_address_1' => __('Billing Address 1', 'connect-plus-for-woocommerce'),
     80    'billing_address_2' => __('Billing Address 2', 'connect-plus-for-woocommerce'),
     81    'billing_city' => __('Billing City', 'connect-plus-for-woocommerce'),
     82    'billing_state' => __('Billing State/County', 'connect-plus-for-woocommerce'),
     83
     84    // Shipping
     85    'shipping_address_1' => __('Shipping Address 1', 'connect-plus-for-woocommerce'),
     86    'shipping_address_2' => __('Shipping Address 2', 'connect-plus-for-woocommerce'),
     87    'shipping_city' => __('Shipping City', 'connect-plus-for-woocommerce'),
     88    'shipping_state' => __('Shipping State/County', 'connect-plus-for-woocommerce'),
     89];
     90
     91
     92$field_mapping = get_option('olivery_connect_field_mapping', []);
     93
    5594
    5695$available_gateways = WC()->payment_gateways->get_available_payment_gateways();
     
    173212       
    174213        <div class="connect-plus-settings-section">
     214            <h2><?php esc_html_e('Order Fields Mapping to Connect Plus', 'connect-plus-for-woocommerce'); ?></h2>
     215            <p><?php esc_html_e('Map WooCommerce billing/shipping fields to required Connect Plus fields. Custom fields are supported.', 'connect-plus-for-woocommerce'); ?></p>
     216
     217            <table class="wp-list-table widefat fixed striped">
     218                <thead>
     219                    <tr>
     220                        <th><?php esc_html_e('Connect Fields', 'connect-plus-for-woocommerce'); ?></th>
     221                        <th><?php esc_html_e('WooCommerce Fields', 'connect-plus-for-woocommerce'); ?></th>
     222                    </tr>
     223                </thead>
     224                <tbody>
     225                    <?php foreach ($connect_fields as $connect_key => $label) : ?>
     226                        <?php
     227                            if (in_array($connect_key, ['customer_name'])) {
     228                                $field_group = $available_name_fields;
     229                            } elseif (in_array($connect_key, ['customer_mobile'])) {
     230                                $field_group = $available_phone_fields;
     231                            }
     232                        ?>
     233                        <tr>
     234                            <td><?php echo esc_html($label); ?></td>
     235                            <td>
     236                                <select name="olivery_connect_field_mapping[<?php echo esc_attr($connect_key); ?>]" class="regular-text">
     237                                    <option value=""><?php esc_html_e('-- Use Default Mapping Field --', 'connect-plus-for-woocommerce'); ?></option>
     238
     239                                    <?php
     240                                    if (stripos($connect_key, 'name') !== false) : ?>
     241                                        <?php foreach ($available_name_fields as $wc_key => $wc_label) : ?>
     242                                            <option value="<?php echo esc_attr($wc_key); ?>" <?php selected($field_mapping[$connect_key] ?? '', $wc_key); ?>>
     243                                                <?php echo esc_html($wc_label); ?>
     244                                            </option>
     245                                        <?php endforeach; ?>
     246
     247                                    <?php elseif (stripos($connect_key, 'mobile') !== false) : ?>
     248                                        <?php foreach ($available_phone_fields as $wc_key => $wc_label) : ?>
     249                                            <option value="<?php echo esc_attr($wc_key); ?>" <?php selected($field_mapping[$connect_key] ?? '', $wc_key); ?>>
     250                                                <?php echo esc_html($wc_label); ?>
     251                                            </option>
     252                                        <?php endforeach; ?>
     253
     254                                    <?php else : ?>
     255                                        <option value="" disabled>--- Billing Fields ---</option>
     256                                        <?php foreach ($available_fields as $wc_key => $wc_label) :
     257                                            if (strpos($wc_key, 'billing_') === 0) : ?>
     258                                                <option value="<?php echo esc_attr($wc_key); ?>" <?php selected($field_mapping[$connect_key] ?? '', $wc_key); ?>>
     259                                                    <?php echo esc_html($wc_label); ?>
     260                                                </option>
     261                                        <?php endif; endforeach; ?>
     262
     263                                        <option value="" disabled>--- Shipping Fields ---</option>
     264                                        <?php foreach ($available_fields as $wc_key => $wc_label) :
     265                                            if (strpos($wc_key, 'shipping_') === 0) : ?>
     266                                                <option value="<?php echo esc_attr($wc_key); ?>" <?php selected($field_mapping[$connect_key] ?? '', $wc_key); ?>>
     267                                                    <?php echo esc_html($wc_label); ?>
     268                                                </option>
     269                                        <?php endif; endforeach; ?>
     270                                    <?php endif; ?>
     271                                </select>
     272                            </td>
     273                        </tr>
     274                    <?php endforeach; ?>
     275                </tbody>
     276            </table>
     277        </div>
     278
     279
     280        <div class="connect-plus-settings-section">
    175281            <h2><?php esc_html_e('Delviery Status Mapping', 'connect-plus-for-woocommerce'); ?></h2>
    176282            <p><?php esc_html_e('Map Connect Plus delivery statuses to WooCommerce order statuses.', 'connect-plus-for-woocommerce'); ?></p>
  • connect-plus-for-woocommerce/trunk/connect-plus-for-woocommerce.php

    r3327337 r3329484  
    1717 * Plugin URI:        https://website.olivery.app/
    1818 * Description:       Plugin to help you connect WooCommerce with Connect Plus application
    19  * Version:           1.0.25
     19 * Version:           1.0.26
    2020 * Author:            Olivery dev
    2121 * Text Domain:       connect-plus-for-woocommerce
     
    4040define('CPFW_PLUGIN_DIR', __DIR__);
    4141
    42 define('PLUGIN_VERSION','1.0.25');
     42define('PLUGIN_VERSION','1.0.26');
    4343/**
    4444 * The code that runs during plugin activation.
  • connect-plus-for-woocommerce/trunk/includes/services/cpfw-connect-api.php

    r3321453 r3329484  
    3434       
    3535        $cpfw_the_order = !is_object($cpfw_the_order) ? wc_get_order($cpfw_the_order) : $cpfw_the_order;
    36         $cpfw_customer_area = $cpfw_customer_name = $cpfw_customer_phone = $cpfw_customer_postcode = "";
     36        $cpfw_customer_area = $cpfw_customer_name = $cpfw_customer_phone = $cpfw_customer_postcode =  $cpfw_customer_sub_area = "";
    3737        $cpfw_customer_address = [];
    38 
    39 
    40         switch (true) {
    41             case (bool) ($cpfw_temp = $this->cpfw_get_meta_key_from_option($cpfw_the_order, 'cpfw_customer_area', true)):
    42                 $cpfw_customer_area = $cpfw_temp;
    43                 break;
    44             case (bool) ($cpfw_temp = sanitize_text_field($cpfw_the_order->get_shipping_city())):
    45                 $cpfw_customer_area = $cpfw_temp;
    46                 break;
    47             case (bool) ($cpfw_temp = sanitize_text_field($cpfw_the_order->get_billing_city())) :
    48                 $cpfw_customer_area = $cpfw_temp;
    49                 break;
    50             default:
    51                 $cpfw_customer_area ;
    52                 break;
    53         }
    54 
    55         switch (true) {
    56             case (bool) ($cpfw_temp = preg_replace('/[^0-9]/', '', $this->cpfw_get_meta_key_from_option($cpfw_the_order, 'cpfw_customer_phone', true))):
    57                 $cpfw_customer_phone = $cpfw_temp;
    58                 break;
    59             case (bool) ($cpfw_temp = preg_replace('/[^0-9]/', '', $cpfw_the_order->get_shipping_phone())):
    60                 $cpfw_customer_phone = $cpfw_temp;
    61                 break;
    62             case (bool) ($cpfw_temp = preg_replace('/[^0-9]/', '', $cpfw_the_order->get_billing_phone())):
    63                 $cpfw_customer_phone = $cpfw_temp;
    64                 break;
    65             default:
    66                 $cpfw_customer_phone;
    67                 break;
    68         }
    69 
     38        $field_mapping = get_option('olivery_connect_field_mapping', []);
     39
     40        // area
     41        if (!empty($field_mapping['customer_area'])) {
     42            $mapped_field = $field_mapping['customer_area'];
     43
     44            // Build method name: get_billing_city()
     45            $getter = 'get_' . $mapped_field;
     46
     47            if (method_exists($cpfw_the_order, $getter)) {
     48                $cpfw_customer_area = sanitize_text_field($cpfw_the_order->$getter());
     49            }
     50        }
     51        else{
     52            switch (true) {
     53                case (bool) ($cpfw_temp = $this->cpfw_get_meta_key_from_option($cpfw_the_order, 'cpfw_customer_area', true)):
     54                    $cpfw_customer_area = $cpfw_temp;
     55                    break;
     56                case (bool) ($cpfw_temp = sanitize_text_field($cpfw_the_order->get_shipping_city())):
     57                    $cpfw_customer_area = $cpfw_temp;
     58                    break;
     59                case (bool) ($cpfw_temp = sanitize_text_field($cpfw_the_order->get_billing_city())) :
     60                    $cpfw_customer_area = $cpfw_temp;
     61                    break;
     62                default:
     63                    $cpfw_customer_area ;
     64                    break;
     65            }
     66        }
     67
     68        // sub_area
     69        if (!empty($field_mapping['customer_sub_area'])) {
     70            $mapped_field = $field_mapping['customer_sub_area'];
     71            $getter = 'get_' . $mapped_field;
     72            if (method_exists($cpfw_the_order, $getter)) {
     73                $cpfw_customer_sub_area = sanitize_text_field($cpfw_the_order->$getter());
     74            }
     75        }
     76        else{
     77            switch (true) {
     78                case (bool) ($cpfw_temp = $this->cpfw_get_meta_key_from_option($cpfw_the_order, 'cpfw_customer_sub_area', true)):
     79                    $cpfw_customer_sub_area = $cpfw_temp;
     80                    break;
     81                case (bool) ($cpfw_temp = sanitize_text_field($cpfw_the_order->get_shipping_address_1() ?: $cpfw_the_order->get_shipping_address_2())):
     82                    $cpfw_customer_sub_area = $cpfw_temp;
     83                    break;
     84                case (bool) ($cpfw_temp = sanitize_text_field($cpfw_the_order->get_billing_address_1() ?: $cpfw_the_order->get_billing_address_2())):
     85                    $cpfw_customer_sub_area = $cpfw_temp;
     86                    break;
     87                default:
     88                    $cpfw_customer_sub_area = '' ;
     89                    break;
     90            }
     91        }
     92
     93        // mobile
     94        if (!empty($field_mapping['customer_mobile'])) {
     95            $mapped_field = $field_mapping['customer_mobile'];
     96            $getter = 'get_' . $mapped_field;
     97
     98            if (method_exists($cpfw_the_order, $getter)) {
     99                $cpfw_customer_phone = preg_replace('/[^0-9]/', '', $cpfw_the_order->$getter());
     100            }
     101        }else{
     102            switch (true) {
     103                case (bool) ($cpfw_temp = preg_replace('/[^0-9]/', '', $this->cpfw_get_meta_key_from_option($cpfw_the_order, 'cpfw_customer_phone', true))):
     104                    $cpfw_customer_phone = $cpfw_temp;
     105                    break;
     106                case (bool) ($cpfw_temp = preg_replace('/[^0-9]/', '', $cpfw_the_order->get_shipping_phone())):
     107                    $cpfw_customer_phone = $cpfw_temp;
     108                    break;
     109                case (bool) ($cpfw_temp = preg_replace('/[^0-9]/', '', $cpfw_the_order->get_billing_phone())):
     110                    $cpfw_customer_phone = $cpfw_temp;
     111                    break;
     112                default:
     113                    $cpfw_customer_phone;
     114                    break;
     115            }
     116        }
     117
     118        // address
    70119        if ($cpfw_temp = sanitize_text_field($this->cpfw_get_meta_key_from_option($cpfw_the_order, 'cpfw_customer_address', true))) {
    71120            $cpfw_customer_address = $cpfw_temp;
     
    85134        }
    86135
    87         switch (true) {
    88             case (bool) ($cpfw_temp = sanitize_text_field($this->cpfw_get_meta_key_from_option($cpfw_the_order, 'cpfw_customer_full_name', true))):
    89                 $cpfw_customer_name = $cpfw_temp;
    90                 break;
    91             case (bool) ($cpfw_temp = sanitize_text_field($cpfw_the_order->get_formatted_shipping_full_name())):
    92                 $cpfw_customer_name = $cpfw_temp;
    93                 break;
    94             case (bool) ($cpfw_temp = sanitize_text_field($cpfw_the_order->get_formatted_billing_full_name())):
    95                 $cpfw_customer_name = $cpfw_temp;
    96                 break;
    97             default:
    98                 $cpfw_customer_name;
    99                 break;
    100         }
    101 
     136        // name
     137        if (!empty($field_mapping['customer_name'])) {
     138            switch ($field_mapping['customer_name']) {
     139                case 'billing_name':
     140                    $cpfw_customer_name = sanitize_text_field($cpfw_the_order->get_formatted_billing_full_name());
     141                    break;
     142                case 'shipping_name':
     143                    $cpfw_customer_name = sanitize_text_field($cpfw_the_order->get_formatted_shipping_full_name());
     144                    break;
     145            }
     146        }
     147        else{
     148            switch (true) {
     149                case (bool) ($cpfw_temp = sanitize_text_field($this->cpfw_get_meta_key_from_option($cpfw_the_order, 'cpfw_customer_full_name', true))):
     150                    $cpfw_customer_name = $cpfw_temp;
     151                    break;
     152                case (bool) ($cpfw_temp = sanitize_text_field($cpfw_the_order->get_formatted_shipping_full_name())):
     153                    $cpfw_customer_name = $cpfw_temp;
     154                    break;
     155                case (bool) ($cpfw_temp = sanitize_text_field($cpfw_the_order->get_formatted_billing_full_name())):
     156                    $cpfw_customer_name = $cpfw_temp;
     157                    break;
     158                default:
     159                    $cpfw_customer_name;
     160                    break;
     161            }
     162        }
     163       
     164        // postcode
    102165        switch (true) {
    103166            case (bool) ($cpfw_temp = $this->cpfw_get_meta_key_from_option($cpfw_the_order, 'cpfw_customer_postcode', true)):
     
    183246                    "customer_name": "' . sanitize_text_field($cpfw_customer_name) . '",
    184247                    "area": "' .($cpfw_customer_area?:'').'",
    185                     "sub_area": "' . sanitize_text_field($cpfw_the_order->get_billing_address_1() ?: $cpfw_the_order->get_shipping_address_1()). '",
     248                    "sub_area": "' .($cpfw_customer_sub_area?:'').'",
    186249                    "country": "' .sanitize_text_field($cpfw_the_order->get_billing_country() ?: $cpfw_the_order->get_shipping_country()) . '",
    187250                    "country_code": "",
  • connect-plus-for-woocommerce/trunk/languages/connect-plus-for-woocommerce.pot

    r3327337 r3329484  
    33msgid ""
    44msgstr ""
    5 "Project-Id-Version: Connect Plus for WooCommerce 1.0.25\n"
     5"Project-Id-Version: Connect Plus for WooCommerce 1.0.26\n"
    66"Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/connect-plus-for-woocommerce\n"
    77"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
Note: See TracChangeset for help on using the changeset viewer.