Changeset 3207237
- Timestamp:
- 12/12/2024 09:58:02 PM (16 months ago)
- Location:
- deliveryplus-by-invisible-dragon
- Files:
-
- 2 deleted
- 8 edited
- 1 copied
-
tags/1.6 (copied) (copied from deliveryplus-by-invisible-dragon/trunk)
-
tags/1.6/admin.js (modified) (3 diffs)
-
tags/1.6/class.DeliveryPlus_Shipping_Method.php (modified) (5 diffs)
-
tags/1.6/id-delivery.php (modified) (8 diffs)
-
tags/1.6/includes/single-options.php (deleted)
-
tags/1.6/readme.txt (modified) (1 diff)
-
trunk/admin.js (modified) (3 diffs)
-
trunk/class.DeliveryPlus_Shipping_Method.php (modified) (5 diffs)
-
trunk/id-delivery.php (modified) (8 diffs)
-
trunk/includes/single-options.php (deleted)
-
trunk/readme.txt (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
deliveryplus-by-invisible-dragon/tags/1.6/admin.js
r2786416 r3207237 106 106 e.preventDefault(); 107 107 $(this).closest("tr").remove(); 108 renderJSON(); 108 109 }); 109 110 … … 112 113 e.preventDefault(); 113 114 $(this).closest(".id-filter-set").remove(); 115 renderJSON(); 114 116 }); 115 117 … … 179 181 } 180 182 181 $(this).on("change ", "select, input[type='text']", function(){183 $(this).on("change update", "select, input[type='text']", function(){ 182 184 renderJSON(); 183 185 }); -
deliveryplus-by-invisible-dragon/tags/1.6/class.DeliveryPlus_Shipping_Method.php
r2786416 r3207237 31 31 'default' => '' 32 32 ), 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 ), 33 38 'tax_status' => array( 34 39 'title' => __( 'Tax status', 'woocommerce' ), … … 154 159 add_action( 'woocommerce_admin_field_deliveryplus_rate', array( $instance, 'admin_field_deliveryplus_rate' ) ); 155 160 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 } 156 170 } 157 171 … … 440 454 $prod = $values['data']; 441 455 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;450 456 451 457 } … … 462 468 'package' => $package, 463 469 'meta_data' => array( 464 'gform' => $this->get_option('form') 470 'gform' => $this->get_option('form'), 471 'description' => $this->get_option('description') 465 472 ) 466 473 ); 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 }485 474 486 475 $filters = json_decode($this->get_option('filter'), true); … … 493 482 $rate['cost'] = $this->evaluate_cost($this->rate, $package); 494 483 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 495 493 $this->add_rate($rate); 496 494 -
deliveryplus-by-invisible-dragon/tags/1.6/id-delivery.php
r2786416 r3207237 7 7 Author URI: https://invisibledragonltd.com/ 8 8 License: Private 9 Version: 1. 69 Version: 1.7 10 10 Requires PHP: 5.6 11 11 … … 14 14 */ 15 15 16 define('ID_DELIVERY_VERSION', '1. 6');16 define('ID_DELIVERY_VERSION', '1.8'); 17 17 18 18 add_action( 'plugins_loaded', array( 'DeliveryPlusPlugin', 'get_instance' ) ); … … 89 89 add_filter( 'woocommerce_shipping_methods', array( $this, 'add_shipping' ) ); 90 90 91 // Single Product Page92 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 95 91 // Order Page 96 92 add_action( 'woocommerce_before_order_itemmeta', array( $this, 'before_order_itemmeta' ), 10, 2 ); … … 112 108 DeliveryPlus_Filters::activate(); 113 109 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 } 127 119 } 128 120 … … 136 128 echo '<code>' . esc_html($method->internal_name) . '</code>'; 137 129 } 138 139 }140 141 /**142 * Display the single product additional options which allow selecting which delivery methods apply143 */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";150 130 151 131 } … … 283 263 add_filter( 'gform_submit_button', '__return_false' ); 284 264 265 require_once( GFCommon::get_base_path() . '/form_display.php' ); 285 266 $html = GFFormDisplay::get_form($form['id'], false, false, null, false); 286 267 $html = str_replace('<form', '<div', $html); … … 325 306 public function enqueue_acf() { 326 307 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'])) { 328 309 // Add ACF is we're trying to edit our shipping method and it's available 329 310 $method = WC_Shipping_Zones::get_shipping_method( sanitize_text_field( $_GET['instance_id'] ) ); 330 if($method ->id == 'deliveryplus') {311 if($method && $method->id == 'deliveryplus') { 331 312 $this->enqueue_admin_script(); 332 313 333 acf_enqueue_scripts(); 314 if(function_exists('get_field')) { 315 acf_enqueue_scripts(); 316 } 334 317 } 335 318 } … … 338 321 339 322 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 ); 341 325 } 342 326 -
deliveryplus-by-invisible-dragon/tags/1.6/readme.txt
r2786416 r3207237 81 81 * Precise location filter 82 82 83 = 1.7 = 84 * Add shipping method description on frontend 85 83 86 == Upgrade Notice == 84 87 -
deliveryplus-by-invisible-dragon/trunk/admin.js
r2786416 r3207237 106 106 e.preventDefault(); 107 107 $(this).closest("tr").remove(); 108 renderJSON(); 108 109 }); 109 110 … … 112 113 e.preventDefault(); 113 114 $(this).closest(".id-filter-set").remove(); 115 renderJSON(); 114 116 }); 115 117 … … 179 181 } 180 182 181 $(this).on("change ", "select, input[type='text']", function(){183 $(this).on("change update", "select, input[type='text']", function(){ 182 184 renderJSON(); 183 185 }); -
deliveryplus-by-invisible-dragon/trunk/class.DeliveryPlus_Shipping_Method.php
r2786416 r3207237 31 31 'default' => '' 32 32 ), 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 ), 33 38 'tax_status' => array( 34 39 'title' => __( 'Tax status', 'woocommerce' ), … … 154 159 add_action( 'woocommerce_admin_field_deliveryplus_rate', array( $instance, 'admin_field_deliveryplus_rate' ) ); 155 160 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 } 156 170 } 157 171 … … 440 454 $prod = $values['data']; 441 455 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;450 456 451 457 } … … 462 468 'package' => $package, 463 469 'meta_data' => array( 464 'gform' => $this->get_option('form') 470 'gform' => $this->get_option('form'), 471 'description' => $this->get_option('description') 465 472 ) 466 473 ); 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 }485 474 486 475 $filters = json_decode($this->get_option('filter'), true); … … 493 482 $rate['cost'] = $this->evaluate_cost($this->rate, $package); 494 483 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 495 493 $this->add_rate($rate); 496 494 -
deliveryplus-by-invisible-dragon/trunk/id-delivery.php
r2786416 r3207237 7 7 Author URI: https://invisibledragonltd.com/ 8 8 License: Private 9 Version: 1. 69 Version: 1.7 10 10 Requires PHP: 5.6 11 11 … … 14 14 */ 15 15 16 define('ID_DELIVERY_VERSION', '1. 6');16 define('ID_DELIVERY_VERSION', '1.8'); 17 17 18 18 add_action( 'plugins_loaded', array( 'DeliveryPlusPlugin', 'get_instance' ) ); … … 89 89 add_filter( 'woocommerce_shipping_methods', array( $this, 'add_shipping' ) ); 90 90 91 // Single Product Page92 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 95 91 // Order Page 96 92 add_action( 'woocommerce_before_order_itemmeta', array( $this, 'before_order_itemmeta' ), 10, 2 ); … … 112 108 DeliveryPlus_Filters::activate(); 113 109 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 } 127 119 } 128 120 … … 136 128 echo '<code>' . esc_html($method->internal_name) . '</code>'; 137 129 } 138 139 }140 141 /**142 * Display the single product additional options which allow selecting which delivery methods apply143 */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";150 130 151 131 } … … 283 263 add_filter( 'gform_submit_button', '__return_false' ); 284 264 265 require_once( GFCommon::get_base_path() . '/form_display.php' ); 285 266 $html = GFFormDisplay::get_form($form['id'], false, false, null, false); 286 267 $html = str_replace('<form', '<div', $html); … … 325 306 public function enqueue_acf() { 326 307 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'])) { 328 309 // Add ACF is we're trying to edit our shipping method and it's available 329 310 $method = WC_Shipping_Zones::get_shipping_method( sanitize_text_field( $_GET['instance_id'] ) ); 330 if($method ->id == 'deliveryplus') {311 if($method && $method->id == 'deliveryplus') { 331 312 $this->enqueue_admin_script(); 332 313 333 acf_enqueue_scripts(); 314 if(function_exists('get_field')) { 315 acf_enqueue_scripts(); 316 } 334 317 } 335 318 } … … 338 321 339 322 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 ); 341 325 } 342 326 -
deliveryplus-by-invisible-dragon/trunk/readme.txt
r2786416 r3207237 81 81 * Precise location filter 82 82 83 = 1.7 = 84 * Add shipping method description on frontend 85 83 86 == Upgrade Notice == 84 87
Note: See TracChangeset
for help on using the changeset viewer.