WooCommerce Germanized - Version 1.2.1

Version Description

  • Fix - Variations admin edit custom attributes (unit price etc.)
  • Fix - Fallback for non-wc-compliant Plugins to inject gzd_product
Download this release

Release Info

Developer vendidero
Plugin Icon 128x128 WooCommerce Germanized
Version 1.2.1
Comparing to
See all releases

Code changes from version 1.2.0 to 1.2.1

assets/css/woocommerce-gzd-admin.css CHANGED
@@ -3,7 +3,11 @@ table.data_table tr td p.form-field {
3
  padding: 0 !important;
4
  }
5
 
6
- #wp-wc_gzd_product_mini_desc-wrap {
 
 
 
 
7
  margin-top: -2em;
8
  }
9
 
3
  padding: 0 !important;
4
  }
5
 
6
+ .variable_cart_mini_desc .wp-editor-tools {
7
+ margin-top: -3em;
8
+ }
9
+
10
+ .variable_cart_mini_desc_pre .wp-editor-tools {
11
  margin-top: -2em;
12
  }
13
 
assets/css/woocommerce-gzd-layout.css CHANGED
@@ -85,10 +85,14 @@ p.footer-info {
85
  }
86
  table.product-details-inner {
87
  table-layout:fixed;
 
 
88
  }
89
  table.product-details-inner, table.product-details-inner tr, table.product-details-inner td {
90
- padding: 0;
91
- margin: 0;
 
 
92
  border: none;
93
  background: transparent;
94
  }
85
  }
86
  table.product-details-inner {
87
  table-layout:fixed;
88
+ margin: 0;
89
+ padding: 0;
90
  }
91
  table.product-details-inner, table.product-details-inner tr, table.product-details-inner td {
92
+ padding-top: 0;
93
+ padding-bottom: 0;
94
+ margin-top: 0;
95
+ margin-bottom: 0;
96
  border: none;
97
  background: transparent;
98
  }
includes/abstracts/abstract-wc-gzd-product.php CHANGED
@@ -26,6 +26,8 @@ class WC_GZD_Product {
26
  * @param WC_Product $product
27
  */
28
  public function __construct( $product ) {
 
 
29
  $this->child = $product;
30
  }
31
 
26
  * @param WC_Product $product
27
  */
28
  public function __construct( $product ) {
29
+ if ( is_numeric( $product ) )
30
+ $product = WC()->product_factory->get_product_standalone( get_post( $product ) );
31
  $this->child = $product;
32
  }
33
 
includes/admin/meta-boxes/class-wc-gzd-meta-box-product-data-variable.php CHANGED
@@ -20,12 +20,81 @@ if ( ! defined( 'ABSPATH' ) ) {
20
  class WC_Germanized_Meta_Box_Product_Data_Variable {
21
 
22
  public static function init() {
23
- add_action( 'woocommerce_product_after_variable_attributes', array( __CLASS__, 'output' ), 20, 2 );
24
  add_action( 'woocommerce_process_product_meta_variable', array( __CLASS__, 'save' ) , 10, 1 );
25
  }
26
 
27
- public static function output( $loop, $variation_data ) {
28
- $variation_id = isset( $variation_data[ 'variation_post_id' ] ) ? $variation_data[ 'variation_post_id' ] : -1;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
29
  $delivery_times = get_the_terms( $variation_id, 'product_delivery_time' );
30
  $delivery_time = ( $delivery_times && ! is_wp_error( $delivery_times ) ) ? current( $delivery_times )->term_id : '';
31
  ?>
@@ -41,17 +110,17 @@ class WC_Germanized_Meta_Box_Product_Data_Variable {
41
  </td>
42
  <td>
43
  <label for="variable_unit_base"><?php echo __( 'Unit Base', 'woocommerce-germanized' );?>:</label>
44
- <input class="input-text wc_input_decimal" size="6" type="text" name="variable_unit_base[<?php echo $loop; ?>]" value="<?php echo ( isset( $variation_data['_unit_base'][0] ) ? $variation_data['_unit_base'][0] : '' );?>" placeholder="" />
45
  </td>
46
  </tr>
47
  <tr>
48
  <td>
49
  <label for="variable_unit_price_regular"><?php echo __( 'Regular Unit Price', 'woocommerce-germanized' ) . ' (' . get_woocommerce_currency_symbol() . ')'; ?>:</label>
50
- <input class="input-text wc_input_price" size="5" type="text" name="variable_unit_price_regular[<?php echo $loop; ?>]" value="<?php echo ( isset( $variation_data['_unit_price_regular'][0] ) ? $variation_data['_unit_price_regular'][0] : '' );?>" placeholder="" />
51
  </td>
52
  <td>
53
  <label for="variable_unit_price_sale"><?php echo __( 'Sale Unit Price', 'woocommerce-germanized' ) . ' (' . get_woocommerce_currency_symbol() . ')'; ?>:</label>
54
- <input class="input-text wc_input_price" size="5" type="text" name="variable_unit_price_sale[<?php echo $loop; ?>]" value="<?php echo ( isset( $variation_data['_unit_price_sale'][0] ) ? $variation_data['_unit_price_sale'][0] : '' );?>" placeholder="" />
55
  </td>
56
  </tr>
57
  <tr>
@@ -72,7 +141,7 @@ class WC_Germanized_Meta_Box_Product_Data_Variable {
72
  </td>
73
  </tr>
74
  <tr>
75
- <td colspan="2">
76
  <label for="variable_product_mini_desc"><?php echo __( 'Optional Mini Description', 'woocommerce-germanized' ); ?>:</label>
77
  <?php wp_editor( htmlspecialchars_decode( ( isset( $variation_data['_mini_desc'][0] ) ? $variation_data['_mini_desc'][0] : '' ) ), 'wc_gzd_product_mini_desc_' . $loop, array( 'textarea_name' => 'variable_product_mini_desc[' . $loop . ']', 'textarea_rows' => 5, 'media_buttons' => false, 'teeny' => true ) ); ?>
78
  </td>
20
  class WC_Germanized_Meta_Box_Product_Data_Variable {
21
 
22
  public static function init() {
23
+ add_action( 'woocommerce_product_after_variable_attributes', array( __CLASS__, 'output' ), 20, 3 );
24
  add_action( 'woocommerce_process_product_meta_variable', array( __CLASS__, 'save' ) , 10, 1 );
25
  }
26
 
27
+ public static function output( $loop, $variation_data, $variation ) {
28
+ if ( version_compare( WC()->version, '2.3', '<' ) )
29
+ return self::output_pre( $loop, $variation_data );
30
+ $_product = wc_get_product( $variation );
31
+ $variation_id = $_product->variation_id;
32
+ $variation_meta = get_post_meta( $variation_id );
33
+ $variation_meta_level = $_product->get_level_meta_data();
34
+ if ( ! empty( $variation_meta_level ) ) {
35
+ foreach ( $variation_meta_level as $key => $value ) {
36
+ $key = '_' . $key;
37
+ if ( ! isset( $variation_data[ $key ] ) )
38
+ $variation_data[ $key ] = isset( $variation_meta[ $key ][0] ) ? maybe_unserialize( $variation_meta[ $key ][0] ) : $value;
39
+ }
40
+ }
41
+ $delivery_times = get_the_terms( $variation_id, 'product_delivery_time' );
42
+ $delivery_time = ( $delivery_times && ! is_wp_error( $delivery_times ) ) ? current( $delivery_times )->term_id : '';
43
+ ?>
44
+ <div class="variable_pricing_unit">
45
+ <p class="form-row form-row-first">
46
+ <label><?php _e( 'Unit', 'woocommerce-germanized' ); ?>:</label>
47
+ <select name="variable_unit[<?php echo $loop; ?>]">
48
+ <option value="parent" <?php selected( is_null( isset( $variation_data['_unit'] ) ? $variation_data['_unit'] : null ), true ); ?>><?php _e( 'None', 'woocommerce-germanized' ); ?></option>
49
+ <?php
50
+ foreach ( WC_germanized()->units->get_units() as $key => $value )
51
+ echo '<option value="' . esc_attr( $key ) . '" ' . selected( $key === ( isset( $variation_data['_unit'] ) ? $variation_data['_unit'] : '' ) , true, false ) . '>' . esc_html( $value ) . '</option>';
52
+ ?></select>
53
+ </p>
54
+ <p class="form-row form-row-last">
55
+ <label for="variable_unit_base"><?php echo __( 'Unit Base', 'woocommerce-germanized' );?>:</label>
56
+ <input class="input-text wc_input_decimal" size="6" type="text" name="variable_unit_base[<?php echo $loop; ?>]" value="<?php echo ( isset( $variation_data['_unit_base'] ) ? esc_attr( wc_format_localized_decimal( $variation_data['_unit_base'] ) ) : '' );?>" placeholder="" />
57
+ </p>
58
+ <p class="form-row form-row-first">
59
+ <label for="variable_unit_price_regular"><?php echo __( 'Regular Unit Price', 'woocommerce-germanized' ) . ' (' . get_woocommerce_currency_symbol() . ')'; ?>:</label>
60
+ <input class="input-text wc_input_price" size="5" type="text" name="variable_unit_price_regular[<?php echo $loop; ?>]" value="<?php echo ( isset( $variation_data['_unit_price_regular'] ) ? esc_attr( wc_format_localized_price( $variation_data['_unit_price_regular'] ) ) : '' );?>" placeholder="" />
61
+ </p>
62
+ <p class="form-row form-row-last">
63
+ <label for="variable_unit_price_sale"><?php echo __( 'Sale Unit Price', 'woocommerce-germanized' ) . ' (' . get_woocommerce_currency_symbol() . ')'; ?>:</label>
64
+ <input class="input-text wc_input_price" size="5" type="text" name="variable_unit_price_sale[<?php echo $loop; ?>]" value="<?php echo ( isset( $variation_data['_unit_price_sale'] ) ? esc_attr( wc_format_localized_price( $variation_data['_unit_price_sale'] ) ) : '' );?>" placeholder="" />
65
+ </p>
66
+ </div>
67
+ <div class="variable_shipping_time hide_if_variation_virtual">
68
+ <p class="form-row form-row-full">
69
+ <label><?php _e( 'Delivery Time', 'woocommerce-germanized' ); ?>:</label>
70
+ <?php
71
+ $args = array(
72
+ 'taxonomy' => 'product_delivery_time',
73
+ 'hide_empty' => 0,
74
+ 'show_option_none' => __( 'None', 'woocommerce-germanized' ),
75
+ 'name' => 'variable_delivery_time[' . $loop . ']',
76
+ 'id' => '',
77
+ 'selected' => isset( $delivery_time ) ? esc_attr( $delivery_time ) : '',
78
+ 'echo' => 0
79
+ );
80
+ echo wp_dropdown_categories( $args );
81
+ ?>
82
+ </p>
83
+ </div>
84
+ <div class="variable_cart_mini_desc">
85
+ <p class="form-row form-row-full">
86
+ <label for="variable_product_mini_desc"><?php echo __( 'Optional Mini Description', 'woocommerce-germanized' ); ?>:</label>
87
+ <?php wp_editor( htmlspecialchars_decode( ( isset( $variation_data['_mini_desc'] ) ? $variation_data['_mini_desc'] : '' ) ), 'wc_gzd_product_mini_desc_' . $loop, array( 'textarea_name' => 'variable_product_mini_desc[' . $loop . ']', 'textarea_rows' => 5, 'media_buttons' => false, 'teeny' => true ) ); ?>
88
+ </p>
89
+ </div>
90
+ <?php
91
+ }
92
+
93
+ /**
94
+ * Variable Products meta for WC pre 2.3
95
+ */
96
+ public static function output_pre( $loop, $variation_data ) {
97
+ $variation_id = isset( $variation_data[ 'variation_post_id' ] ) ? $variation_data[ 'variation_post_id' ] : -1;
98
  $delivery_times = get_the_terms( $variation_id, 'product_delivery_time' );
99
  $delivery_time = ( $delivery_times && ! is_wp_error( $delivery_times ) ) ? current( $delivery_times )->term_id : '';
100
  ?>
110
  </td>
111
  <td>
112
  <label for="variable_unit_base"><?php echo __( 'Unit Base', 'woocommerce-germanized' );?>:</label>
113
+ <input class="input-text wc_input_decimal" size="6" type="text" name="variable_unit_base[<?php echo $loop; ?>]" value="<?php echo ( isset( $variation_data['_unit_base'][0] ) ? esc_attr( wc_format_localized_decimal( $variation_data['_unit_base'][0] ) ) : '' );?>" placeholder="" />
114
  </td>
115
  </tr>
116
  <tr>
117
  <td>
118
  <label for="variable_unit_price_regular"><?php echo __( 'Regular Unit Price', 'woocommerce-germanized' ) . ' (' . get_woocommerce_currency_symbol() . ')'; ?>:</label>
119
+ <input class="input-text wc_input_price" size="5" type="text" name="variable_unit_price_regular[<?php echo $loop; ?>]" value="<?php echo ( isset( $variation_data['_unit_price_regular'][0] ) ? esc_attr( wc_format_localized_price( $variation_data['_unit_price_regular'][0] ) ) : '' );?>" placeholder="" />
120
  </td>
121
  <td>
122
  <label for="variable_unit_price_sale"><?php echo __( 'Sale Unit Price', 'woocommerce-germanized' ) . ' (' . get_woocommerce_currency_symbol() . ')'; ?>:</label>
123
+ <input class="input-text wc_input_price" size="5" type="text" name="variable_unit_price_sale[<?php echo $loop; ?>]" value="<?php echo ( isset( $variation_data['_unit_price_sale'][0] ) ? esc_attr( wc_format_localized_price( $variation_data['_unit_price_sale'][0] ) ) : '' );?>" placeholder="" />
124
  </td>
125
  </tr>
126
  <tr>
141
  </td>
142
  </tr>
143
  <tr>
144
+ <td colspan="2" class="variable_cart_mini_desc_pre">
145
  <label for="variable_product_mini_desc"><?php echo __( 'Optional Mini Description', 'woocommerce-germanized' ); ?>:</label>
146
  <?php wp_editor( htmlspecialchars_decode( ( isset( $variation_data['_mini_desc'][0] ) ? $variation_data['_mini_desc'][0] : '' ) ), 'wc_gzd_product_mini_desc_' . $loop, array( 'textarea_name' => 'variable_product_mini_desc[' . $loop . ']', 'textarea_rows' => 5, 'media_buttons' => false, 'teeny' => true ) ); ?>
147
  </td>
includes/class-wc-gzd-product-factory.php CHANGED
@@ -20,10 +20,21 @@ class WC_GZD_Product_Factory extends WC_Product_Factory {
20
  * @return WC_Product|bool false if the product cannot be loaded
21
  */
22
  public function get_product( $the_product = false, $args = array() ) {
23
- $product = parent::get_product( $the_product, $args );
24
  if ( is_object( $product ) )
25
  $product->gzd_product = new WC_GZD_Product( $product );
26
  return $product;
27
  }
28
 
 
 
 
 
 
 
 
 
 
 
 
29
  }
20
  * @return WC_Product|bool false if the product cannot be loaded
21
  */
22
  public function get_product( $the_product = false, $args = array() ) {
23
+ $product = $this->get_product_standalone( $the_product, $args );
24
  if ( is_object( $product ) )
25
  $product->gzd_product = new WC_GZD_Product( $product );
26
  return $product;
27
  }
28
 
29
+ /**
30
+ * Gets product without injecting gzd_product. Only available as fallback
31
+ *
32
+ * @param bool $the_product (default: false)
33
+ * @param array $args (default: array())
34
+ * @return WC_Product|bool false if the product cannot be loaded
35
+ */
36
+ public function get_product_standalone( $the_product = false, $args = array() ) {
37
+ return parent::get_product( $the_product, $args );
38
+ }
39
+
40
  }
includes/class-wc-gzd-product-variation.php CHANGED
@@ -28,6 +28,10 @@ class WC_GZD_Product_Variation extends WC_Product_Variation {
28
  $this->variation_level_meta_data[ 'gzd_product' ] = NULL;
29
  }
30
 
 
 
 
 
31
  /**
32
  * Returns the current products delivery time term without falling back to default terms
33
  *
28
  $this->variation_level_meta_data[ 'gzd_product' ] = NULL;
29
  }
30
 
31
+ public function get_level_meta_data() {
32
+ return $this->variation_level_meta_data;
33
+ }
34
+
35
  /**
36
  * Returns the current products delivery time term without falling back to default terms
37
  *
readme.txt CHANGED
@@ -4,7 +4,7 @@ Tags: woocommerce, german market, german, germany, deutsch, deutschland, de, de_
4
  Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_xclick&business=info@vendidero.de&item_name=Donation+for+WooCommerce+Germanized
5
  Requires at least: 3.8
6
  Tested up to: 4.1
7
- Stable tag: 1.2.0
8
  License: GPLv3
9
  License URI: http://www.gnu.org/licenses/gpl-3.0.html
10
 
@@ -130,6 +130,10 @@ Bugs sowie Hilfe bei der Arbeit an WooCommerce Germanized werden gerne über uns
130
 
131
  == Changelog ==
132
 
 
 
 
 
133
  = 1.2.0 =
134
  * Feature - Better shipping and fee taxation
135
  * Feature - Now supporting WooCommerce 2.3
4
  Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_xclick&business=info@vendidero.de&item_name=Donation+for+WooCommerce+Germanized
5
  Requires at least: 3.8
6
  Tested up to: 4.1
7
+ Stable tag: 1.2.1
8
  License: GPLv3
9
  License URI: http://www.gnu.org/licenses/gpl-3.0.html
10
 
130
 
131
  == Changelog ==
132
 
133
+ = 1.2.1 =
134
+ * Fix - Variations admin edit custom attributes (unit price etc.)
135
+ * Fix - Fallback for non-wc-compliant Plugins to inject gzd_product
136
+
137
  = 1.2.0 =
138
  * Feature - Better shipping and fee taxation
139
  * Feature - Now supporting WooCommerce 2.3
woocommerce-germanized.php CHANGED
@@ -3,7 +3,7 @@
3
  * Plugin Name: WooCommerce Germanized
4
  * Plugin URI: http://www.vendidero.de/woocommerce-germanized
5
  * Description: Extends WooCommerce to become a legally compliant store for the german market.
6
- * Version: 1.2.0
7
  * Author: Vendidero
8
  * Author URI: http://vendidero.de
9
  * Requires at least: 3.8
@@ -26,7 +26,7 @@ final class WooCommerce_Germanized {
26
  *
27
  * @var string
28
  */
29
- public $version = '1.2.0';
30
 
31
  /**
32
  * Single instance of WooCommerce Germanized Main Class
@@ -186,6 +186,8 @@ final class WooCommerce_Germanized {
186
 
187
  // Adjust virtual Product Price and tax class
188
  add_filter( 'woocommerce_get_price_including_tax', array( $this, 'set_virtual_product_price' ), PHP_INT_MAX, 3 );
 
 
189
 
190
  // Hide cart estimated text if chosen
191
  add_action( 'woocommerce_cart_totals_after_order_total', array( $this, 'hide_cart_estimated_text' ) );
@@ -434,6 +436,21 @@ final class WooCommerce_Germanized {
434
  return $templates;
435
  }
436
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
437
  /**
438
  * Replace the default WC_Cart by WC_GZD_Cart for EU virtual VAT rules.
439
  */
3
  * Plugin Name: WooCommerce Germanized
4
  * Plugin URI: http://www.vendidero.de/woocommerce-germanized
5
  * Description: Extends WooCommerce to become a legally compliant store for the german market.
6
+ * Version: 1.2.1
7
  * Author: Vendidero
8
  * Author URI: http://vendidero.de
9
  * Requires at least: 3.8
26
  *
27
  * @var string
28
  */
29
+ public $version = '1.2.1';
30
 
31
  /**
32
  * Single instance of WooCommerce Germanized Main Class
186
 
187
  // Adjust virtual Product Price and tax class
188
  add_filter( 'woocommerce_get_price_including_tax', array( $this, 'set_virtual_product_price' ), PHP_INT_MAX, 3 );
189
+ // Fallback gzd_product injection if not using wc_get_product
190
+ add_filter( 'get_post_metadata', array( $this, 'inject_gzd_product' ), 0, 4 );
191
 
192
  // Hide cart estimated text if chosen
193
  add_action( 'woocommerce_cart_totals_after_order_total', array( $this, 'hide_cart_estimated_text' ) );
436
  return $templates;
437
  }
438
 
439
+ /**
440
+ * Inject WC_GZD_Product into WC_Product by filtering postmeta - fallback if not using wc_get_product
441
+ *
442
+ * @param mixed $metadata
443
+ * @param int $object_id
444
+ * @param string $meta_key
445
+ * @param boolean $single
446
+ * @return mixed
447
+ */
448
+ public function inject_gzd_product( $metadata, $object_id, $meta_key, $single ) {
449
+ if ( $meta_key == '_gzd_product' && in_array( get_post_type( $object_id ), array( 'product', 'product_variation' ) ) )
450
+ return new WC_GZD_Product( $object_id );
451
+ return $metadata;
452
+ }
453
+
454
  /**
455
  * Replace the default WC_Cart by WC_GZD_Cart for EU virtual VAT rules.
456
  */