Plugin Directory

Changeset 3440105


Ignore:
Timestamp:
01/15/2026 08:02:07 AM (2 months ago)
Author:
wootro
Message:

Version 2.1.3: Added markup (adaos) fields for services and payment methods with percentage and/or fixed amounts. Visual highlight for enabled services, help tooltips on table headers, dynamic UI updates.

Location:
woot-ro
Files:
6 deleted
9 edited
20 copied

Legend:

Unmodified
Added
Removed
  • woot-ro/tags/2.1.3/README.txt

    r3438930 r3440105  
    44Requires at least: 4.0
    55Tested up to: 6.9
    6 Stable tag: 2.1.2
     6Stable tag: 2.1.3
    77Requires PHP: 7.0
    88License: GPLv2 or later
     
    7878
    7979== Changelog ==
     80
     81= 2.1.3 =
     82* New: Markup (adaos) fields for shipping services - percentage and/or fixed amount
     83* New: Markup (adaos) fields for payment methods - percentage from order total and/or fixed amount
     84* New: Visual highlight for enabled services in the settings table
     85* New: Help tooltips on table column headers explaining each field
     86* Improvement: Markup fields only visible when price type is "Quotation"
     87* Improvement: Dynamic UI updates when toggling service checkbox or price type
    8088
    8189= 2.1.2 =
     
    151159== Upgrade Notice ==
    152160
     161= 2.1.3 =
     162* New markup (adaos) fields for services and payment methods. Add percentage and/or fixed amount to shipping prices and payment fees.
     163
    153164= 2.1.2 =
    154165* New unified shipping method (Woot PRO - Services) with API keys authentication and quotation pricing. Legacy methods deprecated but still functional.
  • woot-ro/tags/2.1.3/includes/checkout/class-woot-checkout.php

    r3438930 r3440105  
    262262                $settings = get_option('woocommerce_woot_services_' . $instance_id . '_settings');
    263263
    264                 if (!empty($settings[$payment_id . '_fee'])) {
     264                $fee_percent = isset($settings[$payment_id . '_fee_percent']) ? floatval($settings[$payment_id . '_fee_percent']) : 0;
     265                $fee_fixed = isset($settings[$payment_id . '_fee_fixed']) ? floatval($settings[$payment_id . '_fee_fixed']) : 0;
     266
     267                if ($fee_percent > 0 || $fee_fixed > 0) {
    265268                    $gateways = WC_Payment_Gateways::instance();
    266269                    $payment = isset($gateways->payment_gateways()[$payment_id]) ? $gateways->payment_gateways()[$payment_id] : null;
    267270
    268271                    if ($payment) {
    269                         $cart->add_fee($payment->title, floatval($settings[$payment_id . '_fee']), !empty($cart->get_shipping_tax()));
     272                        $order_total = $cart->get_subtotal() + $cart->get_shipping_total();
     273                        $fee = 0;
     274
     275                        // Apply percentage first (from order total)
     276                        if ($fee_percent > 0) {
     277                            $fee = $order_total * ($fee_percent / 100);
     278                        }
     279
     280                        // Then add fixed
     281                        if ($fee_fixed > 0) {
     282                            $fee += $fee_fixed;
     283                        }
     284
     285                        if ($fee > 0) {
     286                            $cart->add_fee($payment->title, $fee, !empty($cart->get_shipping_tax()));
     287                        }
    270288                    }
    271289                }
  • woot-ro/tags/2.1.3/includes/shipping/class-woot-shipping-services.php

    r3438930 r3440105  
    247247                'default' => ''
    248248            );
     249
     250            $fields[$key . '_markup_percent'] = array(
     251                'type' => 'number',
     252                'default' => ''
     253            );
     254
     255            $fields[$key . '_markup_fixed'] = array(
     256                'type' => 'number',
     257                'default' => ''
     258            );
    249259        }
    250260
     
    254264
    255265            if ($gateways && $this->is_accessing_settings()) {
    256                 $fields['payment_fees_title'] = array(
     266                $fields['payment_fees'] = array(
    257267                    'title' => __('Payment Method Fees', 'woot-ro'),
    258                     'type' => 'title',
     268                    'type' => 'payment_fees_table',
    259269                    'description' => __('Extra charges for specific payment methods (applies to all services)', 'woot-ro'),
    260270                );
     
    264274                foreach ($gateways as $gateway) {
    265275                    if ($gateway->enabled == 'yes') {
    266                         $fields[$gateway->id . '_fee'] = array(
    267                             'title' => $this->is_accessing_settings() ? $gateway->title : '',
     276                        $fields[$gateway->id . '_fee_percent'] = array(
    268277                            'type' => 'number',
    269                             'default' => '',
    270                             'placeholder' => '0.00',
    271                             'desc_tip' => $gateway->method_description,
    272                             'custom_attributes' => array(
    273                                 'min' => '0',
    274                                 'step' => '0.01'
    275                             )
     278                            'default' => ''
     279                        );
     280
     281                        $fields[$gateway->id . '_fee_fixed'] = array(
     282                            'type' => 'number',
     283                            'default' => ''
    276284                        );
    277285                    }
     
    312320                            <th style="width: 40px;"></th>
    313321                            <th><?php esc_html_e('Service', 'woot-ro'); ?></th>
    314                             <th style="width: 200px;"><?php esc_html_e('Custom Name', 'woot-ro'); ?></th>
    315                             <th style="width: 250px;"><?php esc_html_e('Description', 'woot-ro'); ?></th>
    316                             <th style="width: 120px;"><?php esc_html_e('Price Type', 'woot-ro'); ?></th>
    317                             <th style="width: 100px;"><?php esc_html_e('Price', 'woot-ro'); ?></th>
     322                            <th style="width: 200px;"><?php esc_html_e('Custom Name', 'woot-ro'); ?> <?php echo wc_help_tip(__('Custom name displayed to customers at checkout', 'woot-ro')); ?></th>
     323                            <th style="width: 250px;"><?php esc_html_e('Description', 'woot-ro'); ?> <?php echo wc_help_tip(__('Optional description shown below the service name', 'woot-ro')); ?></th>
     324                            <th style="width: 120px;"><?php esc_html_e('Price Type', 'woot-ro'); ?> <?php echo wc_help_tip(__('Fixed: use the price you set. Quotation: get real-time price from API', 'woot-ro')); ?></th>
     325                            <th style="width: 100px;"><?php esc_html_e('Price', 'woot-ro'); ?> <?php echo wc_help_tip(__('Fixed price or fallback price if quotation fails', 'woot-ro')); ?></th>
     326                            <th style="width: 100px; white-space: nowrap;"><?php esc_html_e('Adaos %', 'woot-ro'); ?> <?php echo wc_help_tip(__('Percentage markup added to the shipping price', 'woot-ro')); ?></th>
     327                            <th style="width: 100px; white-space: nowrap;"><?php esc_html_e('Adaos Fix', 'woot-ro'); ?> <?php echo wc_help_tip(__('Fixed amount added to the shipping price', 'woot-ro')); ?></th>
    318328                        </tr>
    319329                    </thead>
     
    321331                        <?php if (empty($services)) : ?>
    322332                            <tr>
    323                                 <td colspan="6" style="text-align: center; padding: 20px;">
     333                                <td colspan="8" style="text-align: center; padding: 20px;">
    324334                                    <?php esc_html_e('No services available.', 'woot-ro'); ?>
    325335                                </td>
     
    334344                                $price_type = isset($this->instance_settings[$service_key . '_price_type']) ? $this->instance_settings[$service_key . '_price_type'] : 'fixed';
    335345                                $price = isset($this->instance_settings[$service_key . '_price']) ? $this->instance_settings[$service_key . '_price'] : '';
     346                                $markup_percent = isset($this->instance_settings[$service_key . '_markup_percent']) ? $this->instance_settings[$service_key . '_markup_percent'] : '';
     347                                $markup_fixed = isset($this->instance_settings[$service_key . '_markup_fixed']) ? $this->instance_settings[$service_key . '_markup_fixed'] : '';
    336348                                $pickup_type = isset($service['pickup']) ? $service['pickup'] : 'door';
     349                                $row_style = $enabled ? 'background-color: #e7f5e9;' : '';
    337350                            ?>
    338                                 <tr>
     351                                <tr style="<?php echo esc_attr($row_style); ?>" class="woot-service-row <?php echo $enabled ? 'woot-service-enabled' : ''; ?>">
    339352                                    <td style="text-align: center; vertical-align: middle;">
    340353                                        <input type="checkbox"
     
    388401                                               style="width: 100%;" />
    389402                                    </td>
     403                                    <td>
     404                                        <input type="number"
     405                                               name="<?php echo esc_attr($this->get_field_key($service_key . '_markup_percent')); ?>"
     406                                               id="<?php echo esc_attr($this->get_field_key($service_key . '_markup_percent')); ?>"
     407                                               class="woot-markup-input"
     408                                               data-service="<?php echo esc_attr($service_key); ?>"
     409                                               value="<?php echo esc_attr($markup_percent); ?>"
     410                                               placeholder="0"
     411                                               min="0"
     412                                               step="0.01"
     413                                               style="width: 100%;<?php echo $price_type !== 'quotation' ? ' display: none;' : ''; ?>" />
     414                                    </td>
     415                                    <td>
     416                                        <input type="number"
     417                                               name="<?php echo esc_attr($this->get_field_key($service_key . '_markup_fixed')); ?>"
     418                                               id="<?php echo esc_attr($this->get_field_key($service_key . '_markup_fixed')); ?>"
     419                                               class="woot-markup-input"
     420                                               data-service="<?php echo esc_attr($service_key); ?>"
     421                                               value="<?php echo esc_attr($markup_fixed); ?>"
     422                                               placeholder="0.00"
     423                                               min="0"
     424                                               step="0.01"
     425                                               style="width: 100%;<?php echo $price_type !== 'quotation' ? ' display: none;' : ''; ?>" />
     426                                    </td>
    390427                                </tr>
    391428                            <?php endforeach; ?>
    392429                        <?php endif; ?>
     430                    </tbody>
     431                </table>
     432                <script>
     433                jQuery(function($) {
     434                    // Toggle row highlight on checkbox change
     435                    $('.woot-services-table input[type="checkbox"]').on('change', function() {
     436                        var $row = $(this).closest('tr');
     437                        if ($(this).is(':checked')) {
     438                            $row.css('background-color', '#e7f5e9').addClass('woot-service-enabled');
     439                        } else {
     440                            $row.css('background-color', '').removeClass('woot-service-enabled');
     441                        }
     442                    });
     443
     444                    // Toggle markup fields visibility based on price type
     445                    $('.woot-price-type-select').on('change', function() {
     446                        var serviceKey = $(this).data('service');
     447                        var $markupInputs = $('.woot-markup-input[data-service="' + serviceKey + '"]');
     448                        if ($(this).val() === 'quotation') {
     449                            $markupInputs.show();
     450                        } else {
     451                            $markupInputs.hide();
     452                        }
     453                    });
     454                });
     455                </script>
     456            </td>
     457        </tr>
     458        <?php
     459        return ob_get_clean();
     460    }
     461
     462    /**
     463     * Validate services table field
     464     *
     465     * @param string $key
     466     * @param mixed $value
     467     * @return mixed
     468     */
     469    public function validate_services_table_field($key, $value)
     470    {
     471        return '';
     472    }
     473
     474    /**
     475     * Generate payment fees table HTML
     476     *
     477     * @param string $key
     478     * @param array $data
     479     * @return string
     480     */
     481    public function generate_payment_fees_table_html($key, $data)
     482    {
     483        $gateways = WC()->payment_gateways()->payment_gateways();
     484
     485        ob_start();
     486        ?>
     487        <tr valign="top">
     488            <th scope="row" class="titledesc">
     489                <label><?php echo esc_html($data['title']); ?></label>
     490                <?php if (!empty($data['description'])) : ?>
     491                    <p class="description"><?php echo esc_html($data['description']); ?></p>
     492                <?php endif; ?>
     493            </th>
     494            <td class="forminp">
     495                <table class="woot-payment-fees-table widefat striped">
     496                    <thead>
     497                        <tr>
     498                            <th style="padding: 8px;"><?php esc_html_e('Payment Method', 'woot-ro'); ?></th>
     499                            <th style="width: 120px; padding: 8px; white-space: nowrap;"><?php esc_html_e('Adaos %', 'woot-ro'); ?> <?php echo wc_help_tip(__('Percentage markup from order total (subtotal + shipping)', 'woot-ro')); ?></th>
     500                            <th style="width: 120px; padding: 8px; white-space: nowrap;"><?php esc_html_e('Adaos Fix', 'woot-ro'); ?> <?php echo wc_help_tip(__('Fixed amount added to the order', 'woot-ro')); ?></th>
     501                        </tr>
     502                    </thead>
     503                    <tbody>
     504                        <?php foreach ($gateways as $gateway) :
     505                            if ($gateway->enabled !== 'yes') continue;
     506                            $fee_percent = isset($this->instance_settings[$gateway->id . '_fee_percent']) ? $this->instance_settings[$gateway->id . '_fee_percent'] : '';
     507                            $fee_fixed = isset($this->instance_settings[$gateway->id . '_fee_fixed']) ? $this->instance_settings[$gateway->id . '_fee_fixed'] : '';
     508                        ?>
     509                            <tr>
     510                                <td style="vertical-align: middle; padding: 8px;">
     511                                    <strong><?php echo esc_html($gateway->title); ?></strong>
     512                                </td>
     513                                <td style="vertical-align: middle; padding: 8px;">
     514                                    <input type="number"
     515                                           name="<?php echo esc_attr($this->get_field_key($gateway->id . '_fee_percent')); ?>"
     516                                           id="<?php echo esc_attr($this->get_field_key($gateway->id . '_fee_percent')); ?>"
     517                                           value="<?php echo esc_attr($fee_percent); ?>"
     518                                           placeholder="0"
     519                                           min="0"
     520                                           step="0.01"
     521                                           style="width: 100%;" />
     522                                </td>
     523                                <td style="vertical-align: middle; padding: 8px;">
     524                                    <input type="number"
     525                                           name="<?php echo esc_attr($this->get_field_key($gateway->id . '_fee_fixed')); ?>"
     526                                           id="<?php echo esc_attr($this->get_field_key($gateway->id . '_fee_fixed')); ?>"
     527                                           value="<?php echo esc_attr($fee_fixed); ?>"
     528                                           placeholder="0.00"
     529                                           min="0"
     530                                           step="0.01"
     531                                           style="width: 100%;" />
     532                                </td>
     533                            </tr>
     534                        <?php endforeach; ?>
    393535                    </tbody>
    394536                </table>
     
    400542
    401543    /**
    402      * Validate services table field
     544     * Validate payment fees table field
    403545     *
    404546     * @param string $key
     
    406548     * @return mixed
    407549     */
    408     public function validate_services_table_field($key, $value)
     550    public function validate_payment_fees_table_field($key, $value)
    409551    {
    410552        return '';
     
    438580    public function generate_text_html($key, $data)
    439581    {
    440         // Hide service-specific text fields (rendered in table)
    441         if (strpos($key, 'service_') === 0 && (strpos($key, '_name') !== false || strpos($key, '_price') !== false)) {
     582        // Hide service-specific text/number fields (rendered in table)
     583        if (strpos($key, 'service_') === 0 && (
     584            strpos($key, '_name') !== false ||
     585            strpos($key, '_price') !== false ||
     586            strpos($key, '_markup_percent') !== false ||
     587            strpos($key, '_markup_fixed') !== false
     588        )) {
    442589            return '';
    443590        }
     591
     592        // Hide payment method fee fields (rendered in table)
     593        if (strpos($key, '_fee_percent') !== false || strpos($key, '_fee_fixed') !== false) {
     594            return '';
     595        }
     596
    444597        return parent::generate_text_html($key, $data);
    445598    }
     
    630783            $fallback_price = isset($this->instance_settings[$key . '_price'])
    631784                ? floatval($this->instance_settings[$key . '_price'])
     785                : 0;
     786
     787            $markup_percent = isset($this->instance_settings[$key . '_markup_percent'])
     788                ? floatval($this->instance_settings[$key . '_markup_percent'])
     789                : 0;
     790
     791            $markup_fixed = isset($this->instance_settings[$key . '_markup_fixed'])
     792                ? floatval($this->instance_settings[$key . '_markup_fixed'])
    632793                : 0;
    633794
     
    651812            }
    652813
     814            // Apply markup only for quotation pricing (percentage first, then fixed)
     815            if (!$is_free && $cost > 0 && $price_type === 'quotation') {
     816                if ($markup_percent > 0) {
     817                    $cost = $cost * (1 + $markup_percent / 100);
     818                }
     819                if ($markup_fixed > 0) {
     820                    $cost = $cost + $markup_fixed;
     821                }
     822            }
     823
    653824            // Add rate with service metadata
    654825            $this->add_rate(array(
     
    9631134     *
    9641135     * @param string $payment_method_id
     1136     * @param float $order_total Order total to calculate percentage from
    9651137     * @return float
    9661138     */
    967     public function get_payment_fee($payment_method_id)
    968     {
    969         $key = $payment_method_id . '_fee';
    970         return isset($this->instance_settings[$key]) ? floatval($this->instance_settings[$key]) : 0;
     1139    public function get_payment_fee($payment_method_id, $order_total = 0)
     1140    {
     1141        $fee_percent = isset($this->instance_settings[$payment_method_id . '_fee_percent'])
     1142            ? floatval($this->instance_settings[$payment_method_id . '_fee_percent'])
     1143            : 0;
     1144
     1145        $fee_fixed = isset($this->instance_settings[$payment_method_id . '_fee_fixed'])
     1146            ? floatval($this->instance_settings[$payment_method_id . '_fee_fixed'])
     1147            : 0;
     1148
     1149        $fee = 0;
     1150
     1151        // Apply percentage first
     1152        if ($fee_percent > 0 && $order_total > 0) {
     1153            $fee = $order_total * ($fee_percent / 100);
     1154        }
     1155
     1156        // Then add fixed
     1157        if ($fee_fixed > 0) {
     1158            $fee += $fee_fixed;
     1159        }
     1160
     1161        return $fee;
    9711162    }
    9721163}
  • woot-ro/tags/2.1.3/languages/woot-ro-ro_RO.po

    r3438930 r3440105  
    44msgid ""
    55msgstr ""
    6 "Project-Id-Version: Woot.ro 2.1.2\n"
     6"Project-Id-Version: Woot.ro 2.1.3\n"
    77"Report-Msgid-Bugs-To: https://woot.ro\n"
    88"POT-Creation-Date: 2025-01-13 00:00:00+00:00\n"
     
    399399msgid "Invalid API keys."
    400400msgstr "Chei API invalide."
     401
     402msgid "Adaos %"
     403msgstr "Adaos %"
     404
     405msgid "Adaos Fix"
     406msgstr "Adaos Fix"
     407
     408msgid "Payment Method"
     409msgstr "Metodă de plată"
     410
     411msgid "Custom name displayed to customers at checkout"
     412msgstr "Nume personalizat afișat clienților la checkout"
     413
     414msgid "Optional description shown below the service name"
     415msgstr "Descriere opțională afișată sub numele serviciului"
     416
     417msgid "Fixed: use the price you set. Quotation: get real-time price from API"
     418msgstr "Fix: folosește prețul setat. Cotație: obține prețul în timp real din API"
     419
     420msgid "Fixed price or fallback price if quotation fails"
     421msgstr "Preț fix sau preț de rezervă dacă cotația eșuează"
     422
     423msgid "Percentage markup added to the shipping price"
     424msgstr "Adaos procentual adăugat la prețul de livrare"
     425
     426msgid "Fixed amount added to the shipping price"
     427msgstr "Sumă fixă adăugată la prețul de livrare"
     428
     429msgid "Percentage markup from order total (subtotal + shipping)"
     430msgstr "Adaos procentual din totalul comenzii (subtotal + livrare)"
     431
     432msgid "Fixed amount added to the order"
     433msgstr "Sumă fixă adăugată la comandă"
  • woot-ro/tags/2.1.3/languages/woot-ro.pot

    r3438930 r3440105  
    33msgid ""
    44msgstr ""
    5 "Project-Id-Version: Woot.ro 2.1.2\n"
     5"Project-Id-Version: Woot.ro 2.1.3\n"
    66"Report-Msgid-Bugs-To: https://woot.ro\n"
    77"POT-Creation-Date: 2025-01-13 00:00:00+00:00\n"
     
    230230msgid "Drop-off at door"
    231231msgstr ""
     232
     233#: includes/shipping/class-woot-shipping-services.php
     234msgid "Adaos %"
     235msgstr ""
     236
     237#: includes/shipping/class-woot-shipping-services.php
     238msgid "Adaos Fix"
     239msgstr ""
     240
     241#: includes/shipping/class-woot-shipping-services.php
     242msgid "Payment Method"
     243msgstr ""
     244
     245#: includes/shipping/class-woot-shipping-services.php
     246msgid "Custom name displayed to customers at checkout"
     247msgstr ""
     248
     249#: includes/shipping/class-woot-shipping-services.php
     250msgid "Optional description shown below the service name"
     251msgstr ""
     252
     253#: includes/shipping/class-woot-shipping-services.php
     254msgid "Fixed: use the price you set. Quotation: get real-time price from API"
     255msgstr ""
     256
     257#: includes/shipping/class-woot-shipping-services.php
     258msgid "Fixed price or fallback price if quotation fails"
     259msgstr ""
     260
     261#: includes/shipping/class-woot-shipping-services.php
     262msgid "Percentage markup added to the shipping price"
     263msgstr ""
     264
     265#: includes/shipping/class-woot-shipping-services.php
     266msgid "Fixed amount added to the shipping price"
     267msgstr ""
     268
     269#: includes/shipping/class-woot-shipping-services.php
     270msgid "Percentage markup from order total (subtotal + shipping)"
     271msgstr ""
     272
     273#: includes/shipping/class-woot-shipping-services.php
     274msgid "Fixed amount added to the order"
     275msgstr ""
  • woot-ro/tags/2.1.3/woot.php

    r3438930 r3440105  
    1717 * Plugin URI:        https://woot.ro
    1818 * Description:       Integrates all popular couriers in Romania, providing a one-stop solution for all your delivery needs
    19  * Version:           2.1.2
     19 * Version:           2.1.3
    2020 * Author:            Woot.ro
    2121 * Author URI:        https://woot.ro
     
    3636 * Rename this for your plugin and update it as you release new versions.
    3737 */
    38 define('WOOT_VERSION', '2.1.2');
     38define('WOOT_VERSION', '2.1.3');
    3939
    4040/**
  • woot-ro/trunk/README.txt

    r3438930 r3440105  
    44Requires at least: 4.0
    55Tested up to: 6.9
    6 Stable tag: 2.1.2
     6Stable tag: 2.1.3
    77Requires PHP: 7.0
    88License: GPLv2 or later
     
    7878
    7979== Changelog ==
     80
     81= 2.1.3 =
     82* New: Markup (adaos) fields for shipping services - percentage and/or fixed amount
     83* New: Markup (adaos) fields for payment methods - percentage from order total and/or fixed amount
     84* New: Visual highlight for enabled services in the settings table
     85* New: Help tooltips on table column headers explaining each field
     86* Improvement: Markup fields only visible when price type is "Quotation"
     87* Improvement: Dynamic UI updates when toggling service checkbox or price type
    8088
    8189= 2.1.2 =
     
    151159== Upgrade Notice ==
    152160
     161= 2.1.3 =
     162* New markup (adaos) fields for services and payment methods. Add percentage and/or fixed amount to shipping prices and payment fees.
     163
    153164= 2.1.2 =
    154165* New unified shipping method (Woot PRO - Services) with API keys authentication and quotation pricing. Legacy methods deprecated but still functional.
  • woot-ro/trunk/includes/checkout/class-woot-checkout.php

    r3438930 r3440105  
    262262                $settings = get_option('woocommerce_woot_services_' . $instance_id . '_settings');
    263263
    264                 if (!empty($settings[$payment_id . '_fee'])) {
     264                $fee_percent = isset($settings[$payment_id . '_fee_percent']) ? floatval($settings[$payment_id . '_fee_percent']) : 0;
     265                $fee_fixed = isset($settings[$payment_id . '_fee_fixed']) ? floatval($settings[$payment_id . '_fee_fixed']) : 0;
     266
     267                if ($fee_percent > 0 || $fee_fixed > 0) {
    265268                    $gateways = WC_Payment_Gateways::instance();
    266269                    $payment = isset($gateways->payment_gateways()[$payment_id]) ? $gateways->payment_gateways()[$payment_id] : null;
    267270
    268271                    if ($payment) {
    269                         $cart->add_fee($payment->title, floatval($settings[$payment_id . '_fee']), !empty($cart->get_shipping_tax()));
     272                        $order_total = $cart->get_subtotal() + $cart->get_shipping_total();
     273                        $fee = 0;
     274
     275                        // Apply percentage first (from order total)
     276                        if ($fee_percent > 0) {
     277                            $fee = $order_total * ($fee_percent / 100);
     278                        }
     279
     280                        // Then add fixed
     281                        if ($fee_fixed > 0) {
     282                            $fee += $fee_fixed;
     283                        }
     284
     285                        if ($fee > 0) {
     286                            $cart->add_fee($payment->title, $fee, !empty($cart->get_shipping_tax()));
     287                        }
    270288                    }
    271289                }
  • woot-ro/trunk/includes/shipping/class-woot-shipping-services.php

    r3438930 r3440105  
    247247                'default' => ''
    248248            );
     249
     250            $fields[$key . '_markup_percent'] = array(
     251                'type' => 'number',
     252                'default' => ''
     253            );
     254
     255            $fields[$key . '_markup_fixed'] = array(
     256                'type' => 'number',
     257                'default' => ''
     258            );
    249259        }
    250260
     
    254264
    255265            if ($gateways && $this->is_accessing_settings()) {
    256                 $fields['payment_fees_title'] = array(
     266                $fields['payment_fees'] = array(
    257267                    'title' => __('Payment Method Fees', 'woot-ro'),
    258                     'type' => 'title',
     268                    'type' => 'payment_fees_table',
    259269                    'description' => __('Extra charges for specific payment methods (applies to all services)', 'woot-ro'),
    260270                );
     
    264274                foreach ($gateways as $gateway) {
    265275                    if ($gateway->enabled == 'yes') {
    266                         $fields[$gateway->id . '_fee'] = array(
    267                             'title' => $this->is_accessing_settings() ? $gateway->title : '',
     276                        $fields[$gateway->id . '_fee_percent'] = array(
    268277                            'type' => 'number',
    269                             'default' => '',
    270                             'placeholder' => '0.00',
    271                             'desc_tip' => $gateway->method_description,
    272                             'custom_attributes' => array(
    273                                 'min' => '0',
    274                                 'step' => '0.01'
    275                             )
     278                            'default' => ''
     279                        );
     280
     281                        $fields[$gateway->id . '_fee_fixed'] = array(
     282                            'type' => 'number',
     283                            'default' => ''
    276284                        );
    277285                    }
     
    312320                            <th style="width: 40px;"></th>
    313321                            <th><?php esc_html_e('Service', 'woot-ro'); ?></th>
    314                             <th style="width: 200px;"><?php esc_html_e('Custom Name', 'woot-ro'); ?></th>
    315                             <th style="width: 250px;"><?php esc_html_e('Description', 'woot-ro'); ?></th>
    316                             <th style="width: 120px;"><?php esc_html_e('Price Type', 'woot-ro'); ?></th>
    317                             <th style="width: 100px;"><?php esc_html_e('Price', 'woot-ro'); ?></th>
     322                            <th style="width: 200px;"><?php esc_html_e('Custom Name', 'woot-ro'); ?> <?php echo wc_help_tip(__('Custom name displayed to customers at checkout', 'woot-ro')); ?></th>
     323                            <th style="width: 250px;"><?php esc_html_e('Description', 'woot-ro'); ?> <?php echo wc_help_tip(__('Optional description shown below the service name', 'woot-ro')); ?></th>
     324                            <th style="width: 120px;"><?php esc_html_e('Price Type', 'woot-ro'); ?> <?php echo wc_help_tip(__('Fixed: use the price you set. Quotation: get real-time price from API', 'woot-ro')); ?></th>
     325                            <th style="width: 100px;"><?php esc_html_e('Price', 'woot-ro'); ?> <?php echo wc_help_tip(__('Fixed price or fallback price if quotation fails', 'woot-ro')); ?></th>
     326                            <th style="width: 100px; white-space: nowrap;"><?php esc_html_e('Adaos %', 'woot-ro'); ?> <?php echo wc_help_tip(__('Percentage markup added to the shipping price', 'woot-ro')); ?></th>
     327                            <th style="width: 100px; white-space: nowrap;"><?php esc_html_e('Adaos Fix', 'woot-ro'); ?> <?php echo wc_help_tip(__('Fixed amount added to the shipping price', 'woot-ro')); ?></th>
    318328                        </tr>
    319329                    </thead>
     
    321331                        <?php if (empty($services)) : ?>
    322332                            <tr>
    323                                 <td colspan="6" style="text-align: center; padding: 20px;">
     333                                <td colspan="8" style="text-align: center; padding: 20px;">
    324334                                    <?php esc_html_e('No services available.', 'woot-ro'); ?>
    325335                                </td>
     
    334344                                $price_type = isset($this->instance_settings[$service_key . '_price_type']) ? $this->instance_settings[$service_key . '_price_type'] : 'fixed';
    335345                                $price = isset($this->instance_settings[$service_key . '_price']) ? $this->instance_settings[$service_key . '_price'] : '';
     346                                $markup_percent = isset($this->instance_settings[$service_key . '_markup_percent']) ? $this->instance_settings[$service_key . '_markup_percent'] : '';
     347                                $markup_fixed = isset($this->instance_settings[$service_key . '_markup_fixed']) ? $this->instance_settings[$service_key . '_markup_fixed'] : '';
    336348                                $pickup_type = isset($service['pickup']) ? $service['pickup'] : 'door';
     349                                $row_style = $enabled ? 'background-color: #e7f5e9;' : '';
    337350                            ?>
    338                                 <tr>
     351                                <tr style="<?php echo esc_attr($row_style); ?>" class="woot-service-row <?php echo $enabled ? 'woot-service-enabled' : ''; ?>">
    339352                                    <td style="text-align: center; vertical-align: middle;">
    340353                                        <input type="checkbox"
     
    388401                                               style="width: 100%;" />
    389402                                    </td>
     403                                    <td>
     404                                        <input type="number"
     405                                               name="<?php echo esc_attr($this->get_field_key($service_key . '_markup_percent')); ?>"
     406                                               id="<?php echo esc_attr($this->get_field_key($service_key . '_markup_percent')); ?>"
     407                                               class="woot-markup-input"
     408                                               data-service="<?php echo esc_attr($service_key); ?>"
     409                                               value="<?php echo esc_attr($markup_percent); ?>"
     410                                               placeholder="0"
     411                                               min="0"
     412                                               step="0.01"
     413                                               style="width: 100%;<?php echo $price_type !== 'quotation' ? ' display: none;' : ''; ?>" />
     414                                    </td>
     415                                    <td>
     416                                        <input type="number"
     417                                               name="<?php echo esc_attr($this->get_field_key($service_key . '_markup_fixed')); ?>"
     418                                               id="<?php echo esc_attr($this->get_field_key($service_key . '_markup_fixed')); ?>"
     419                                               class="woot-markup-input"
     420                                               data-service="<?php echo esc_attr($service_key); ?>"
     421                                               value="<?php echo esc_attr($markup_fixed); ?>"
     422                                               placeholder="0.00"
     423                                               min="0"
     424                                               step="0.01"
     425                                               style="width: 100%;<?php echo $price_type !== 'quotation' ? ' display: none;' : ''; ?>" />
     426                                    </td>
    390427                                </tr>
    391428                            <?php endforeach; ?>
    392429                        <?php endif; ?>
     430                    </tbody>
     431                </table>
     432                <script>
     433                jQuery(function($) {
     434                    // Toggle row highlight on checkbox change
     435                    $('.woot-services-table input[type="checkbox"]').on('change', function() {
     436                        var $row = $(this).closest('tr');
     437                        if ($(this).is(':checked')) {
     438                            $row.css('background-color', '#e7f5e9').addClass('woot-service-enabled');
     439                        } else {
     440                            $row.css('background-color', '').removeClass('woot-service-enabled');
     441                        }
     442                    });
     443
     444                    // Toggle markup fields visibility based on price type
     445                    $('.woot-price-type-select').on('change', function() {
     446                        var serviceKey = $(this).data('service');
     447                        var $markupInputs = $('.woot-markup-input[data-service="' + serviceKey + '"]');
     448                        if ($(this).val() === 'quotation') {
     449                            $markupInputs.show();
     450                        } else {
     451                            $markupInputs.hide();
     452                        }
     453                    });
     454                });
     455                </script>
     456            </td>
     457        </tr>
     458        <?php
     459        return ob_get_clean();
     460    }
     461
     462    /**
     463     * Validate services table field
     464     *
     465     * @param string $key
     466     * @param mixed $value
     467     * @return mixed
     468     */
     469    public function validate_services_table_field($key, $value)
     470    {
     471        return '';
     472    }
     473
     474    /**
     475     * Generate payment fees table HTML
     476     *
     477     * @param string $key
     478     * @param array $data
     479     * @return string
     480     */
     481    public function generate_payment_fees_table_html($key, $data)
     482    {
     483        $gateways = WC()->payment_gateways()->payment_gateways();
     484
     485        ob_start();
     486        ?>
     487        <tr valign="top">
     488            <th scope="row" class="titledesc">
     489                <label><?php echo esc_html($data['title']); ?></label>
     490                <?php if (!empty($data['description'])) : ?>
     491                    <p class="description"><?php echo esc_html($data['description']); ?></p>
     492                <?php endif; ?>
     493            </th>
     494            <td class="forminp">
     495                <table class="woot-payment-fees-table widefat striped">
     496                    <thead>
     497                        <tr>
     498                            <th style="padding: 8px;"><?php esc_html_e('Payment Method', 'woot-ro'); ?></th>
     499                            <th style="width: 120px; padding: 8px; white-space: nowrap;"><?php esc_html_e('Adaos %', 'woot-ro'); ?> <?php echo wc_help_tip(__('Percentage markup from order total (subtotal + shipping)', 'woot-ro')); ?></th>
     500                            <th style="width: 120px; padding: 8px; white-space: nowrap;"><?php esc_html_e('Adaos Fix', 'woot-ro'); ?> <?php echo wc_help_tip(__('Fixed amount added to the order', 'woot-ro')); ?></th>
     501                        </tr>
     502                    </thead>
     503                    <tbody>
     504                        <?php foreach ($gateways as $gateway) :
     505                            if ($gateway->enabled !== 'yes') continue;
     506                            $fee_percent = isset($this->instance_settings[$gateway->id . '_fee_percent']) ? $this->instance_settings[$gateway->id . '_fee_percent'] : '';
     507                            $fee_fixed = isset($this->instance_settings[$gateway->id . '_fee_fixed']) ? $this->instance_settings[$gateway->id . '_fee_fixed'] : '';
     508                        ?>
     509                            <tr>
     510                                <td style="vertical-align: middle; padding: 8px;">
     511                                    <strong><?php echo esc_html($gateway->title); ?></strong>
     512                                </td>
     513                                <td style="vertical-align: middle; padding: 8px;">
     514                                    <input type="number"
     515                                           name="<?php echo esc_attr($this->get_field_key($gateway->id . '_fee_percent')); ?>"
     516                                           id="<?php echo esc_attr($this->get_field_key($gateway->id . '_fee_percent')); ?>"
     517                                           value="<?php echo esc_attr($fee_percent); ?>"
     518                                           placeholder="0"
     519                                           min="0"
     520                                           step="0.01"
     521                                           style="width: 100%;" />
     522                                </td>
     523                                <td style="vertical-align: middle; padding: 8px;">
     524                                    <input type="number"
     525                                           name="<?php echo esc_attr($this->get_field_key($gateway->id . '_fee_fixed')); ?>"
     526                                           id="<?php echo esc_attr($this->get_field_key($gateway->id . '_fee_fixed')); ?>"
     527                                           value="<?php echo esc_attr($fee_fixed); ?>"
     528                                           placeholder="0.00"
     529                                           min="0"
     530                                           step="0.01"
     531                                           style="width: 100%;" />
     532                                </td>
     533                            </tr>
     534                        <?php endforeach; ?>
    393535                    </tbody>
    394536                </table>
     
    400542
    401543    /**
    402      * Validate services table field
     544     * Validate payment fees table field
    403545     *
    404546     * @param string $key
     
    406548     * @return mixed
    407549     */
    408     public function validate_services_table_field($key, $value)
     550    public function validate_payment_fees_table_field($key, $value)
    409551    {
    410552        return '';
     
    438580    public function generate_text_html($key, $data)
    439581    {
    440         // Hide service-specific text fields (rendered in table)
    441         if (strpos($key, 'service_') === 0 && (strpos($key, '_name') !== false || strpos($key, '_price') !== false)) {
     582        // Hide service-specific text/number fields (rendered in table)
     583        if (strpos($key, 'service_') === 0 && (
     584            strpos($key, '_name') !== false ||
     585            strpos($key, '_price') !== false ||
     586            strpos($key, '_markup_percent') !== false ||
     587            strpos($key, '_markup_fixed') !== false
     588        )) {
    442589            return '';
    443590        }
     591
     592        // Hide payment method fee fields (rendered in table)
     593        if (strpos($key, '_fee_percent') !== false || strpos($key, '_fee_fixed') !== false) {
     594            return '';
     595        }
     596
    444597        return parent::generate_text_html($key, $data);
    445598    }
     
    630783            $fallback_price = isset($this->instance_settings[$key . '_price'])
    631784                ? floatval($this->instance_settings[$key . '_price'])
     785                : 0;
     786
     787            $markup_percent = isset($this->instance_settings[$key . '_markup_percent'])
     788                ? floatval($this->instance_settings[$key . '_markup_percent'])
     789                : 0;
     790
     791            $markup_fixed = isset($this->instance_settings[$key . '_markup_fixed'])
     792                ? floatval($this->instance_settings[$key . '_markup_fixed'])
    632793                : 0;
    633794
     
    651812            }
    652813
     814            // Apply markup only for quotation pricing (percentage first, then fixed)
     815            if (!$is_free && $cost > 0 && $price_type === 'quotation') {
     816                if ($markup_percent > 0) {
     817                    $cost = $cost * (1 + $markup_percent / 100);
     818                }
     819                if ($markup_fixed > 0) {
     820                    $cost = $cost + $markup_fixed;
     821                }
     822            }
     823
    653824            // Add rate with service metadata
    654825            $this->add_rate(array(
     
    9631134     *
    9641135     * @param string $payment_method_id
     1136     * @param float $order_total Order total to calculate percentage from
    9651137     * @return float
    9661138     */
    967     public function get_payment_fee($payment_method_id)
    968     {
    969         $key = $payment_method_id . '_fee';
    970         return isset($this->instance_settings[$key]) ? floatval($this->instance_settings[$key]) : 0;
     1139    public function get_payment_fee($payment_method_id, $order_total = 0)
     1140    {
     1141        $fee_percent = isset($this->instance_settings[$payment_method_id . '_fee_percent'])
     1142            ? floatval($this->instance_settings[$payment_method_id . '_fee_percent'])
     1143            : 0;
     1144
     1145        $fee_fixed = isset($this->instance_settings[$payment_method_id . '_fee_fixed'])
     1146            ? floatval($this->instance_settings[$payment_method_id . '_fee_fixed'])
     1147            : 0;
     1148
     1149        $fee = 0;
     1150
     1151        // Apply percentage first
     1152        if ($fee_percent > 0 && $order_total > 0) {
     1153            $fee = $order_total * ($fee_percent / 100);
     1154        }
     1155
     1156        // Then add fixed
     1157        if ($fee_fixed > 0) {
     1158            $fee += $fee_fixed;
     1159        }
     1160
     1161        return $fee;
    9711162    }
    9721163}
  • woot-ro/trunk/languages/woot-ro-ro_RO.po

    r3438930 r3440105  
    44msgid ""
    55msgstr ""
    6 "Project-Id-Version: Woot.ro 2.1.2\n"
     6"Project-Id-Version: Woot.ro 2.1.3\n"
    77"Report-Msgid-Bugs-To: https://woot.ro\n"
    88"POT-Creation-Date: 2025-01-13 00:00:00+00:00\n"
     
    399399msgid "Invalid API keys."
    400400msgstr "Chei API invalide."
     401
     402msgid "Adaos %"
     403msgstr "Adaos %"
     404
     405msgid "Adaos Fix"
     406msgstr "Adaos Fix"
     407
     408msgid "Payment Method"
     409msgstr "Metodă de plată"
     410
     411msgid "Custom name displayed to customers at checkout"
     412msgstr "Nume personalizat afișat clienților la checkout"
     413
     414msgid "Optional description shown below the service name"
     415msgstr "Descriere opțională afișată sub numele serviciului"
     416
     417msgid "Fixed: use the price you set. Quotation: get real-time price from API"
     418msgstr "Fix: folosește prețul setat. Cotație: obține prețul în timp real din API"
     419
     420msgid "Fixed price or fallback price if quotation fails"
     421msgstr "Preț fix sau preț de rezervă dacă cotația eșuează"
     422
     423msgid "Percentage markup added to the shipping price"
     424msgstr "Adaos procentual adăugat la prețul de livrare"
     425
     426msgid "Fixed amount added to the shipping price"
     427msgstr "Sumă fixă adăugată la prețul de livrare"
     428
     429msgid "Percentage markup from order total (subtotal + shipping)"
     430msgstr "Adaos procentual din totalul comenzii (subtotal + livrare)"
     431
     432msgid "Fixed amount added to the order"
     433msgstr "Sumă fixă adăugată la comandă"
  • woot-ro/trunk/languages/woot-ro.pot

    r3438930 r3440105  
    33msgid ""
    44msgstr ""
    5 "Project-Id-Version: Woot.ro 2.1.2\n"
     5"Project-Id-Version: Woot.ro 2.1.3\n"
    66"Report-Msgid-Bugs-To: https://woot.ro\n"
    77"POT-Creation-Date: 2025-01-13 00:00:00+00:00\n"
     
    230230msgid "Drop-off at door"
    231231msgstr ""
     232
     233#: includes/shipping/class-woot-shipping-services.php
     234msgid "Adaos %"
     235msgstr ""
     236
     237#: includes/shipping/class-woot-shipping-services.php
     238msgid "Adaos Fix"
     239msgstr ""
     240
     241#: includes/shipping/class-woot-shipping-services.php
     242msgid "Payment Method"
     243msgstr ""
     244
     245#: includes/shipping/class-woot-shipping-services.php
     246msgid "Custom name displayed to customers at checkout"
     247msgstr ""
     248
     249#: includes/shipping/class-woot-shipping-services.php
     250msgid "Optional description shown below the service name"
     251msgstr ""
     252
     253#: includes/shipping/class-woot-shipping-services.php
     254msgid "Fixed: use the price you set. Quotation: get real-time price from API"
     255msgstr ""
     256
     257#: includes/shipping/class-woot-shipping-services.php
     258msgid "Fixed price or fallback price if quotation fails"
     259msgstr ""
     260
     261#: includes/shipping/class-woot-shipping-services.php
     262msgid "Percentage markup added to the shipping price"
     263msgstr ""
     264
     265#: includes/shipping/class-woot-shipping-services.php
     266msgid "Fixed amount added to the shipping price"
     267msgstr ""
     268
     269#: includes/shipping/class-woot-shipping-services.php
     270msgid "Percentage markup from order total (subtotal + shipping)"
     271msgstr ""
     272
     273#: includes/shipping/class-woot-shipping-services.php
     274msgid "Fixed amount added to the order"
     275msgstr ""
  • woot-ro/trunk/woot.php

    r3438930 r3440105  
    1717 * Plugin URI:        https://woot.ro
    1818 * Description:       Integrates all popular couriers in Romania, providing a one-stop solution for all your delivery needs
    19  * Version:           2.1.2
     19 * Version:           2.1.3
    2020 * Author:            Woot.ro
    2121 * Author URI:        https://woot.ro
     
    3636 * Rename this for your plugin and update it as you release new versions.
    3737 */
    38 define('WOOT_VERSION', '2.1.2');
     38define('WOOT_VERSION', '2.1.3');
    3939
    4040/**
Note: See TracChangeset for help on using the changeset viewer.