Plugin Directory

Changeset 3207237


Ignore:
Timestamp:
12/12/2024 09:58:02 PM (16 months ago)
Author:
invisibledragonltd
Message:

Update to version 1.6 from GitLab (https://gitlab.com/invisibledragon/id-delivery; https://gitlab.com/invisibledragon/id-delivery/-/jobs/8629390721)

Location:
deliveryplus-by-invisible-dragon
Files:
2 deleted
8 edited
1 copied

Legend:

Unmodified
Added
Removed
  • deliveryplus-by-invisible-dragon/tags/1.6/admin.js

    r2786416 r3207237  
    106106                e.preventDefault();
    107107                $(this).closest("tr").remove();
     108                renderJSON();
    108109            });
    109110
     
    112113                e.preventDefault();
    113114                $(this).closest(".id-filter-set").remove();
     115                renderJSON();
    114116            });
    115117
     
    179181            }
    180182
    181             $(this).on("change", "select, input[type='text']", function(){
     183            $(this).on("change update", "select, input[type='text']", function(){
    182184                renderJSON();
    183185            });
  • deliveryplus-by-invisible-dragon/tags/1.6/class.DeliveryPlus_Shipping_Method.php

    r2786416 r3207237  
    3131                'default'       => ''
    3232            ),
     33            'description' => array(
     34                'title' => __('Description'),
     35                'type' => 'text',
     36                'description' => __('If specified, this additional information is displayed alongside the title in the checkout')
     37            ),
    3338            'tax_status' => array(
    3439                'title'         => __( 'Tax status', 'woocommerce' ),
     
    154159        add_action( 'woocommerce_admin_field_deliveryplus_rate', array( $instance, 'admin_field_deliveryplus_rate' ) );
    155160        add_action( 'woocommerce_admin_field_deliveryplus_filter', array( $instance, 'admin_field_deliveryplus_filter' ) );
     161
     162        add_action( 'woocommerce_after_shipping_rate', [ static::class, 'after_shipping_rate' ] );
     163    }
     164
     165    public static function after_shipping_rate($rate) {
     166        $current_shipping_method = WC()->session->get( 'chosen_shipping_methods' );
     167        if($rate->method_id === 'deliveryplus' && in_array($rate->id, $current_shipping_method) && $rate->meta_data['description']) {
     168            echo '<p class="id-delivery-selected-description">' . esc_html($rate->meta_data['description']) . '</p>';
     169        }
    156170    }
    157171
     
    440454            $prod = $values['data'];
    441455
    442             if(method_exists($prod, 'get_meta')) {
    443                 $skip = $prod->get_meta('idd_options');
    444                 if(is_array($skip) && in_array($this->instance_id, $skip)) {
    445                     continue;
    446                 }
    447             }
    448 
    449             return false;
    450456
    451457        }
     
    462468            'package' => $package,
    463469            'meta_data' => array(
    464                 'gform' => $this->get_option('form')
     470                'gform' => $this->get_option('form'),
     471                'description' => $this->get_option('description')
    465472            )
    466473        );
    467 
    468         foreach ( $package['contents'] as $item_id => $values ) {
    469             $prod = $values['data'];
    470 
    471             if(method_exists($prod, 'get_meta')) {
    472                 $skip = $prod->get_meta('idd_options');
    473                 if(is_array($skip)) {
    474                     if (in_array($this->instance_id, $skip)) {
    475                         if(!apply_filters('idd_override_apply_filters', false)) {
    476                             unset($package['contents'][$item_id]);
    477                         }
    478                     } else {
    479                         return;
    480                     }
    481                 }
    482             }
    483 
    484         }
    485474
    486475        $filters = json_decode($this->get_option('filter'), true);
     
    493482        $rate['cost'] = $this->evaluate_cost($this->rate, $package);
    494483
     484        if($rate['cost'] < 0 && $this->is_taxable()) {
     485            // Calculate negative tax rate if the amount is negative as WooCommerce doesn't support this
     486            // out of the box
     487            $rate['taxes'] = WC_Tax::calc_shipping_tax( abs($rate['cost']), WC_Tax::get_shipping_tax_rates() );
     488            foreach($rate['taxes'] as &$tax) {
     489                $tax = 0 - $tax;
     490            }
     491        }
     492
    495493        $this->add_rate($rate);
    496494
  • deliveryplus-by-invisible-dragon/tags/1.6/id-delivery.php

    r2786416 r3207237  
    77Author URI: https://invisibledragonltd.com/
    88License: Private
    9 Version: 1.6
     9Version: 1.7
    1010Requires PHP: 5.6
    1111
     
    1414*/
    1515
    16 define('ID_DELIVERY_VERSION', '1.6');
     16define('ID_DELIVERY_VERSION', '1.8');
    1717
    1818add_action( 'plugins_loaded', array( 'DeliveryPlusPlugin', 'get_instance' ) );
     
    8989        add_filter( 'woocommerce_shipping_methods', array( $this, 'add_shipping' ) );
    9090
    91         // Single Product Page
    92         add_action( 'woocommerce_product_options_shipping', array( $this, 'single_deliveryplus_options' ) );
    93         add_action( 'woocommerce_admin_process_product_object', array( $this, 'set_additional_product_options' ), 10, 1 );
    94 
    9591        // Order Page
    9692        add_action( 'woocommerce_before_order_itemmeta', array( $this, 'before_order_itemmeta' ), 10, 2 );
     
    112108        DeliveryPlus_Filters::activate();
    113109
    114     }
    115 
    116     public function set_additional_product_options($product) {
    117 
    118         $value = null;
    119         if($_POST['_idd_enable_options']) {
    120             $value = [];
    121             foreach($_POST['_idd_options'] as $key => $v) {
    122                 $value[] = $key;
    123             }
    124         }
    125         $product->update_meta_data('idd_options', $value);
    126 
     110        add_action( 'before_woocommerce_init', [ $this, 'before_woocommerce_init' ] );
     111
     112    }
     113
     114    public function before_woocommerce_init() {
     115        if ( class_exists( \Automattic\WooCommerce\Utilities\FeaturesUtil::class ) ) {
     116            \Automattic\WooCommerce\Utilities\FeaturesUtil::declare_compatibility( 'custom_order_tables', __FILE__, false );
     117            \Automattic\WooCommerce\Utilities\FeaturesUtil::declare_compatibility( 'remote_logging', __FILE__, false );
     118        }
    127119    }
    128120
     
    136128            echo '<code>' . esc_html($method->internal_name) . '</code>';
    137129        }
    138 
    139     }
    140 
    141     /**
    142      * Display the single product additional options which allow selecting which delivery methods apply
    143      */
    144     public function single_deliveryplus_options() {
    145 
    146         global $product_object;
    147         echo '</div><!-- Seems odd, but other Woo plugins behave this way -->';
    148         echo '<div class="options_group">';
    149         require "includes/single-options.php";
    150130
    151131    }
     
    283263        add_filter( 'gform_submit_button', '__return_false' );
    284264
     265        require_once( GFCommon::get_base_path() . '/form_display.php' );
    285266        $html = GFFormDisplay::get_form($form['id'], false, false, null, false);
    286267        $html = str_replace('<form', '<div', $html);
     
    325306    public function enqueue_acf() {
    326307
    327         if(function_exists('get_field') && $_GET['page'] == 'wc-settings' && $_GET['tab'] == 'shipping') {
     308        if(isset($_GET['page']) && $_GET['page'] == 'wc-settings' && isset($_GET['tab']) && $_GET['tab'] == 'shipping' && isset($_GET['instance_id'])) {
    328309            // Add ACF is we're trying to edit our shipping method and it's available
    329310            $method = WC_Shipping_Zones::get_shipping_method( sanitize_text_field( $_GET['instance_id'] ) );
    330             if($method->id == 'deliveryplus') {
     311            if($method && $method->id == 'deliveryplus') {
    331312                $this->enqueue_admin_script();
    332313
    333                 acf_enqueue_scripts();
     314                if(function_exists('get_field')) {
     315                    acf_enqueue_scripts();
     316                }
    334317            }
    335318        }
     
    338321
    339322    public function enqueue_admin_script() {
    340         wp_enqueue_script( 'deliveryplus_admin', plugin_dir_url( __FILE__ ) . '/admin.js', array( 'jquery' ), '1.0', true );
     323        wp_enqueue_script( 'deliveryplus_admin', plugin_dir_url( __FILE__ ) . '/admin.js', array( 'jquery' ), '1.0.1',
     324            true );
    341325    }
    342326
  • deliveryplus-by-invisible-dragon/tags/1.6/readme.txt

    r2786416 r3207237  
    8181* Precise location filter
    8282
     83= 1.7 =
     84* Add shipping method description on frontend
     85
    8386== Upgrade Notice ==
    8487
  • deliveryplus-by-invisible-dragon/trunk/admin.js

    r2786416 r3207237  
    106106                e.preventDefault();
    107107                $(this).closest("tr").remove();
     108                renderJSON();
    108109            });
    109110
     
    112113                e.preventDefault();
    113114                $(this).closest(".id-filter-set").remove();
     115                renderJSON();
    114116            });
    115117
     
    179181            }
    180182
    181             $(this).on("change", "select, input[type='text']", function(){
     183            $(this).on("change update", "select, input[type='text']", function(){
    182184                renderJSON();
    183185            });
  • deliveryplus-by-invisible-dragon/trunk/class.DeliveryPlus_Shipping_Method.php

    r2786416 r3207237  
    3131                'default'       => ''
    3232            ),
     33            'description' => array(
     34                'title' => __('Description'),
     35                'type' => 'text',
     36                'description' => __('If specified, this additional information is displayed alongside the title in the checkout')
     37            ),
    3338            'tax_status' => array(
    3439                'title'         => __( 'Tax status', 'woocommerce' ),
     
    154159        add_action( 'woocommerce_admin_field_deliveryplus_rate', array( $instance, 'admin_field_deliveryplus_rate' ) );
    155160        add_action( 'woocommerce_admin_field_deliveryplus_filter', array( $instance, 'admin_field_deliveryplus_filter' ) );
     161
     162        add_action( 'woocommerce_after_shipping_rate', [ static::class, 'after_shipping_rate' ] );
     163    }
     164
     165    public static function after_shipping_rate($rate) {
     166        $current_shipping_method = WC()->session->get( 'chosen_shipping_methods' );
     167        if($rate->method_id === 'deliveryplus' && in_array($rate->id, $current_shipping_method) && $rate->meta_data['description']) {
     168            echo '<p class="id-delivery-selected-description">' . esc_html($rate->meta_data['description']) . '</p>';
     169        }
    156170    }
    157171
     
    440454            $prod = $values['data'];
    441455
    442             if(method_exists($prod, 'get_meta')) {
    443                 $skip = $prod->get_meta('idd_options');
    444                 if(is_array($skip) && in_array($this->instance_id, $skip)) {
    445                     continue;
    446                 }
    447             }
    448 
    449             return false;
    450456
    451457        }
     
    462468            'package' => $package,
    463469            'meta_data' => array(
    464                 'gform' => $this->get_option('form')
     470                'gform' => $this->get_option('form'),
     471                'description' => $this->get_option('description')
    465472            )
    466473        );
    467 
    468         foreach ( $package['contents'] as $item_id => $values ) {
    469             $prod = $values['data'];
    470 
    471             if(method_exists($prod, 'get_meta')) {
    472                 $skip = $prod->get_meta('idd_options');
    473                 if(is_array($skip)) {
    474                     if (in_array($this->instance_id, $skip)) {
    475                         if(!apply_filters('idd_override_apply_filters', false)) {
    476                             unset($package['contents'][$item_id]);
    477                         }
    478                     } else {
    479                         return;
    480                     }
    481                 }
    482             }
    483 
    484         }
    485474
    486475        $filters = json_decode($this->get_option('filter'), true);
     
    493482        $rate['cost'] = $this->evaluate_cost($this->rate, $package);
    494483
     484        if($rate['cost'] < 0 && $this->is_taxable()) {
     485            // Calculate negative tax rate if the amount is negative as WooCommerce doesn't support this
     486            // out of the box
     487            $rate['taxes'] = WC_Tax::calc_shipping_tax( abs($rate['cost']), WC_Tax::get_shipping_tax_rates() );
     488            foreach($rate['taxes'] as &$tax) {
     489                $tax = 0 - $tax;
     490            }
     491        }
     492
    495493        $this->add_rate($rate);
    496494
  • deliveryplus-by-invisible-dragon/trunk/id-delivery.php

    r2786416 r3207237  
    77Author URI: https://invisibledragonltd.com/
    88License: Private
    9 Version: 1.6
     9Version: 1.7
    1010Requires PHP: 5.6
    1111
     
    1414*/
    1515
    16 define('ID_DELIVERY_VERSION', '1.6');
     16define('ID_DELIVERY_VERSION', '1.8');
    1717
    1818add_action( 'plugins_loaded', array( 'DeliveryPlusPlugin', 'get_instance' ) );
     
    8989        add_filter( 'woocommerce_shipping_methods', array( $this, 'add_shipping' ) );
    9090
    91         // Single Product Page
    92         add_action( 'woocommerce_product_options_shipping', array( $this, 'single_deliveryplus_options' ) );
    93         add_action( 'woocommerce_admin_process_product_object', array( $this, 'set_additional_product_options' ), 10, 1 );
    94 
    9591        // Order Page
    9692        add_action( 'woocommerce_before_order_itemmeta', array( $this, 'before_order_itemmeta' ), 10, 2 );
     
    112108        DeliveryPlus_Filters::activate();
    113109
    114     }
    115 
    116     public function set_additional_product_options($product) {
    117 
    118         $value = null;
    119         if($_POST['_idd_enable_options']) {
    120             $value = [];
    121             foreach($_POST['_idd_options'] as $key => $v) {
    122                 $value[] = $key;
    123             }
    124         }
    125         $product->update_meta_data('idd_options', $value);
    126 
     110        add_action( 'before_woocommerce_init', [ $this, 'before_woocommerce_init' ] );
     111
     112    }
     113
     114    public function before_woocommerce_init() {
     115        if ( class_exists( \Automattic\WooCommerce\Utilities\FeaturesUtil::class ) ) {
     116            \Automattic\WooCommerce\Utilities\FeaturesUtil::declare_compatibility( 'custom_order_tables', __FILE__, false );
     117            \Automattic\WooCommerce\Utilities\FeaturesUtil::declare_compatibility( 'remote_logging', __FILE__, false );
     118        }
    127119    }
    128120
     
    136128            echo '<code>' . esc_html($method->internal_name) . '</code>';
    137129        }
    138 
    139     }
    140 
    141     /**
    142      * Display the single product additional options which allow selecting which delivery methods apply
    143      */
    144     public function single_deliveryplus_options() {
    145 
    146         global $product_object;
    147         echo '</div><!-- Seems odd, but other Woo plugins behave this way -->';
    148         echo '<div class="options_group">';
    149         require "includes/single-options.php";
    150130
    151131    }
     
    283263        add_filter( 'gform_submit_button', '__return_false' );
    284264
     265        require_once( GFCommon::get_base_path() . '/form_display.php' );
    285266        $html = GFFormDisplay::get_form($form['id'], false, false, null, false);
    286267        $html = str_replace('<form', '<div', $html);
     
    325306    public function enqueue_acf() {
    326307
    327         if(function_exists('get_field') && $_GET['page'] == 'wc-settings' && $_GET['tab'] == 'shipping') {
     308        if(isset($_GET['page']) && $_GET['page'] == 'wc-settings' && isset($_GET['tab']) && $_GET['tab'] == 'shipping' && isset($_GET['instance_id'])) {
    328309            // Add ACF is we're trying to edit our shipping method and it's available
    329310            $method = WC_Shipping_Zones::get_shipping_method( sanitize_text_field( $_GET['instance_id'] ) );
    330             if($method->id == 'deliveryplus') {
     311            if($method && $method->id == 'deliveryplus') {
    331312                $this->enqueue_admin_script();
    332313
    333                 acf_enqueue_scripts();
     314                if(function_exists('get_field')) {
     315                    acf_enqueue_scripts();
     316                }
    334317            }
    335318        }
     
    338321
    339322    public function enqueue_admin_script() {
    340         wp_enqueue_script( 'deliveryplus_admin', plugin_dir_url( __FILE__ ) . '/admin.js', array( 'jquery' ), '1.0', true );
     323        wp_enqueue_script( 'deliveryplus_admin', plugin_dir_url( __FILE__ ) . '/admin.js', array( 'jquery' ), '1.0.1',
     324            true );
    341325    }
    342326
  • deliveryplus-by-invisible-dragon/trunk/readme.txt

    r2786416 r3207237  
    8181* Precise location filter
    8282
     83= 1.7 =
     84* Add shipping method description on frontend
     85
    8386== Upgrade Notice ==
    8487
Note: See TracChangeset for help on using the changeset viewer.