Skip to content

Commit

Permalink
4.2.0 - Make plugin compatible with HPOS
Browse files Browse the repository at this point in the history
  • Loading branch information
CharlieEtienne committed Feb 21, 2024
1 parent 9dbf0d4 commit b35b9c5
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 15 deletions.
7 changes: 5 additions & 2 deletions readme.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
=== Wash Care Symbols for WooCommerce ===
Contributors: charlieetienne
Tags: woocommerce, wash, care, symbols, clothes
Stable tag: 4.1.0
Stable tag: 4.2.0
Requires at least: 5.2
Tested up to: 6.1
Tested up to: 6.4
Requires PHP: 7.2
License: GPLv2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html
Expand Down Expand Up @@ -221,6 +221,9 @@ If you like my work, you can donate here: [https://paypal.me/webnancy](https://p

== Changelog ==

= 4.2.0 =
* Make plugin compatible with WooCommerce HPOS

= 4.1.0 =
* [FIX] Fix tooltip overlap in some cases
* [FIX] Fix tooltip being hidden in elementor in some cases
Expand Down
13 changes: 8 additions & 5 deletions src/Fields.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,20 @@ class Fields {
* @param $post_id
*/
public static function save( $post_id ) {
$product = wc_get_product( $post_id );

foreach ( Values::get() as $fieldkey => $field ) {
if ( isset( $_POST[ '_' . $fieldkey ] ) && is_array( $_POST[ '_' . $fieldkey ] ) ) {
$clean_values = [];
foreach ( $_POST[ '_' . $fieldkey ] as $item ) {
$clean_values[] = sanitize_key( $item );
}
update_post_meta( $post_id, '_' . $fieldkey, $clean_values ?? null );
} else {
delete_post_meta( $post_id, '_' . $fieldkey );
}
}
$product->update_meta_data('_' . $fieldkey, $clean_values ?? null);
} else {
$product->delete_meta_data( '_' . $fieldkey );
}
$product->save();
}
}

/**
Expand Down
8 changes: 5 additions & 3 deletions src/Utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,18 @@ class Utils {
public static function multiple_select( $field ) {
global $thepostid, $post;

$thepostid = empty( $thepostid ) ? $post->ID : $thepostid;
$field[ 'class' ] = $field[ 'class' ] ?? 'select short';
$thepostid = empty( $thepostid ) ? $post->ID : $thepostid;
$product = wc_get_product( $thepostid );
$field[ 'class' ] = $field[ 'class' ] ?? 'select short';
$field[ 'wrapper_class' ] = $field[ 'wrapper_class' ] ?? '';
$field[ 'name' ] = $field[ 'name' ] ?? $field[ 'id' ];
if (self::is_product_category()){
$term_id = absint( $_GET['tag_ID'] );
$field[ 'value' ] = $field[ 'value' ] ?? ( get_term_meta( $term_id, '_' . $field[ 'id' ], true ) ? get_term_meta( $term_id, '_' . $field[ 'id' ], true ) : array() );
}
else {
$field[ 'value' ] = $field[ 'value' ] ?? ( get_post_meta( $thepostid, '_' . $field[ 'id' ], true ) ? get_post_meta( $thepostid, '_' . $field[ 'id' ], true ) : array() );
$product_meta = $product->get_meta('_' . $field['id']);
$field[ 'value' ] = $field[ 'value' ] ?? ( $product_meta ? $product_meta : array() );
}

printf( '<p class="form-field %s_field %s">',
Expand Down
17 changes: 12 additions & 5 deletions wash-care-symbols-for-woocommerce.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
/**
* Plugin Name: Wash Care Symbols for WooCommerce
* Description: Display wash/care symbols in WooCommerce products
* Version: 4.1.0
* Version: 4.2.0
* Requires at least: 5.2
* Requires PHP: 7.2
* WC requires at least: 4.0
* WC tested up to: 7.5
* WC tested up to: 8.6
* Author: Charlie Etienne
* Author URI: https://web-nancy.fr
* License: GPL v2 or later
Expand Down Expand Up @@ -245,11 +245,12 @@ public function force_tab_to_display( $tabs ) {
*/
public function get_product_values( int $product = null) {
if( empty($product) ) {$product = get_the_ID();}
$product_obj = wc_get_product($product);
$values = [];
foreach ( $this->values as $fieldkey => $field ) {
$option = get_post_meta( $product, '_' . $fieldkey, true );
$option = $product_obj->get_meta('_' . $fieldkey);
if($option){
$values[$fieldkey] = get_post_meta( $product, '_' . $fieldkey, true );
$values[$fieldkey] = $product_obj->get_meta('_' . $fieldkey);
}
}
if( !empty($values) ){
Expand Down Expand Up @@ -279,4 +280,10 @@ public function get_product_values( int $product = null) {

}

WashCareSymbolsForWooCommerce::get_instance()->init();
WashCareSymbolsForWooCommerce::get_instance()->init();

add_action( 'before_woocommerce_init', function() {
if ( class_exists( \Automattic\WooCommerce\Utilities\FeaturesUtil::class ) ) {
\Automattic\WooCommerce\Utilities\FeaturesUtil::declare_compatibility( 'custom_order_tables', __FILE__, true );
}
} );

0 comments on commit b35b9c5

Please sign in to comment.