Version Description
Download this release
Release Info
| Developer | quadlayers |
| Plugin | |
| Version | 6.0.7.6 |
| Comparing to | |
| See all releases | |
Code changes from version 6.0.7.5 to 6.0.7.6
includes/view/frontend/class-wooccm-fields-conditional.php
CHANGED
|
@@ -1,79 +1,118 @@
|
|
| 1 |
<?php
|
| 2 |
|
| 3 |
-
class WOOCCM_Fields_Conditional
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 77 |
}
|
| 78 |
|
| 79 |
WOOCCM_Fields_Conditional::instance();
|
| 1 |
<?php
|
| 2 |
|
| 3 |
+
class WOOCCM_Fields_Conditional {
|
| 4 |
+
|
| 5 |
+
protected static $_instance;
|
| 6 |
+
|
| 7 |
+
public function __construct() {
|
| 8 |
+
// Add field attributes
|
| 9 |
+
add_filter( 'wooccm_checkout_field_filter', array( $this, 'add_field_attributes' ) );
|
| 10 |
+
add_action( 'wooccm_billing_fields', array( $this, 'remove_required' ) );
|
| 11 |
+
add_action( 'wooccm_shipping_fields', array( $this, 'remove_required' ) );
|
| 12 |
+
add_action( 'wooccm_additional_fields', array( $this, 'remove_required' ) );
|
| 13 |
+
}
|
| 14 |
+
|
| 15 |
+
public static function instance() {
|
| 16 |
+
if ( is_null( self::$_instance ) ) {
|
| 17 |
+
self::$_instance = new self();
|
| 18 |
+
}
|
| 19 |
+
return self::$_instance;
|
| 20 |
+
}
|
| 21 |
+
|
| 22 |
+
public function remove_required( $fields ) {
|
| 23 |
+
foreach ( $fields as $field_id => $field ) {
|
| 24 |
+
|
| 25 |
+
/**
|
| 26 |
+
* Continue if it's not a conditional field
|
| 27 |
+
*/
|
| 28 |
+
if ( empty( $field['conditional'] ) ) {
|
| 29 |
+
continue;
|
| 30 |
+
}
|
| 31 |
+
/**
|
| 32 |
+
* Continue if it doesn't have the conditional parent key
|
| 33 |
+
*/
|
| 34 |
+
if ( empty( $field['conditional_parent_key'] ) ) {
|
| 35 |
+
continue;
|
| 36 |
+
}
|
| 37 |
+
/**
|
| 38 |
+
* Continue if it's parent of self
|
| 39 |
+
*/
|
| 40 |
+
if ( $field['conditional_parent_key'] == $field['key'] ) {
|
| 41 |
+
continue;
|
| 42 |
+
}
|
| 43 |
+
/**
|
| 44 |
+
* Continue if parent dosen't exists
|
| 45 |
+
*/
|
| 46 |
+
if ( empty( $fields[ $field['conditional_parent_key'] ] ) ) {
|
| 47 |
+
continue;
|
| 48 |
+
}
|
| 49 |
+
|
| 50 |
+
$action = $this->get_checkout_action();
|
| 51 |
+
|
| 52 |
+
switch ( $action ) {
|
| 53 |
+
case 'save':
|
| 54 |
+
$is_valid_conditional_field = $this->is_valid_conditional_field( $_POST, $field );
|
| 55 |
+
if ( ! $is_valid_conditional_field ) {
|
| 56 |
+
$fields[ $field['key'] ]['required'] = false;
|
| 57 |
+
}
|
| 58 |
+
break;
|
| 59 |
+
case 'update':
|
| 60 |
+
$post_data = array();
|
| 61 |
+
parse_str( $_REQUEST['post_data'], $post_data );
|
| 62 |
+
$is_valid_conditional_field = $this->is_valid_conditional_field( $post_data, $field );
|
| 63 |
+
if ( ! $is_valid_conditional_field ) {
|
| 64 |
+
$fields[ $field['key'] ]['required'] = false;
|
| 65 |
+
}
|
| 66 |
+
break;
|
| 67 |
+
}
|
| 68 |
+
}
|
| 69 |
+
|
| 70 |
+
return $fields;
|
| 71 |
+
}
|
| 72 |
+
|
| 73 |
+
public function is_valid_conditional_field( $post_data, $field ) {
|
| 74 |
+
/**
|
| 75 |
+
* Don't remove field if parent dosen't exists in the current form posts
|
| 76 |
+
*/
|
| 77 |
+
|
| 78 |
+
if ( ! isset( $post_data[ $field['conditional_parent_key'] ] ) ) {
|
| 79 |
+
return true;
|
| 80 |
+
}
|
| 81 |
+
/**
|
| 82 |
+
* Don't remove field if conditional parent value is undefined
|
| 83 |
+
*/
|
| 84 |
+
if ( ! isset( $field['conditional_parent_value'] ) ) {
|
| 85 |
+
return true;
|
| 86 |
+
}
|
| 87 |
+
|
| 88 |
+
$posted_conditional_parent_value = (array) $post_data[ $field['conditional_parent_key'] ];
|
| 89 |
+
$conditional_parent_value = (array) $field['conditional_parent_value'];
|
| 90 |
+
/**
|
| 91 |
+
* Don't remove field if conditional parent value is valid
|
| 92 |
+
*/
|
| 93 |
+
if ( array_intersect( $conditional_parent_value, $posted_conditional_parent_value ) ) {
|
| 94 |
+
return true;
|
| 95 |
+
}
|
| 96 |
+
|
| 97 |
+
return false;
|
| 98 |
+
}
|
| 99 |
+
|
| 100 |
+
public function get_checkout_action() {
|
| 101 |
+
if ( isset( $_REQUEST['woocommerce-process-checkout-nonce'] ) ) {
|
| 102 |
+
return 'save';
|
| 103 |
+
} elseif ( isset( $_REQUEST['post_data'] ) && isset( $_REQUEST['wc-ajax'] ) && $_REQUEST['wc-ajax'] == 'update_order_review' ) {
|
| 104 |
+
return 'update';
|
| 105 |
+
}
|
| 106 |
+
}
|
| 107 |
+
|
| 108 |
+
public function add_field_attributes( $field ) {
|
| 109 |
+
if ( ! empty( $field['conditional'] ) && ! empty( $field['conditional_parent_key'] ) && isset( $field['conditional_parent_value'] ) && ( $field['conditional_parent_key'] != $field['name'] ) ) {
|
| 110 |
+
$field['class'][] = 'wooccm-conditional-child';
|
| 111 |
+
$field['custom_attributes']['data-conditional-parent'] = $field['conditional_parent_key'];
|
| 112 |
+
$field['custom_attributes']['data-conditional-parent-value'] = $field['conditional_parent_value'];
|
| 113 |
+
}
|
| 114 |
+
return $field;
|
| 115 |
+
}
|
| 116 |
}
|
| 117 |
|
| 118 |
WOOCCM_Fields_Conditional::instance();
|
readme.txt
CHANGED
|
@@ -5,7 +5,7 @@ Tags: checkout field editor, woocommerce checkout field editor, checkout manager
|
|
| 5 |
Requires at least: 4.9
|
| 6 |
Tested up to: 6.0.1
|
| 7 |
Requires PHP: 5.6
|
| 8 |
-
Stable tag: 6.0.7.
|
| 9 |
WC requires at least: 3.1.0
|
| 10 |
WC tested up to: 6.6.1
|
| 11 |
License: GPLv3
|
|
@@ -149,6 +149,9 @@ Your Order data can be reviewed in each order within the default WooCommerce Ord
|
|
| 149 |
|
| 150 |
== Changelog ==
|
| 151 |
|
|
|
|
|
|
|
|
|
|
| 152 |
= 6.0.7.5
|
| 153 |
* Fix. WooCommerce Checkout billing fields
|
| 154 |
|
| 5 |
Requires at least: 4.9
|
| 6 |
Tested up to: 6.0.1
|
| 7 |
Requires PHP: 5.6
|
| 8 |
+
Stable tag: 6.0.7.6
|
| 9 |
WC requires at least: 3.1.0
|
| 10 |
WC tested up to: 6.6.1
|
| 11 |
License: GPLv3
|
| 149 |
|
| 150 |
== Changelog ==
|
| 151 |
|
| 152 |
+
= 6.0.7.6
|
| 153 |
+
* Fix. WooCommerce Checkout conditional fields
|
| 154 |
+
|
| 155 |
= 6.0.7.5
|
| 156 |
* Fix. WooCommerce Checkout billing fields
|
| 157 |
|
woocommerce-checkout-manager.php
CHANGED
|
@@ -4,7 +4,7 @@
|
|
| 4 |
* Plugin Name: Checkout Fields Manager for WooCommerce
|
| 5 |
* Plugin URI: https://quadlayers.com/portfolio/woocommerce-checkout-manager/
|
| 6 |
* Description: Manage and customize WooCommerce Checkout fields (Add, Edit, Delete or re-order fields).
|
| 7 |
-
* Version: 6.0.7.
|
| 8 |
* Author: QuadLayers
|
| 9 |
* Author URI: https://quadlayers.com
|
| 10 |
* License: GPLv3
|
|
@@ -20,7 +20,7 @@ if ( ! defined( 'WOOCCM_PLUGIN_NAME' ) ) {
|
|
| 20 |
define( 'WOOCCM_PLUGIN_NAME', 'Checkout Fields Manager for WooCommerce' );
|
| 21 |
}
|
| 22 |
if ( ! defined( 'WOOCCM_PLUGIN_VERSION' ) ) {
|
| 23 |
-
define( 'WOOCCM_PLUGIN_VERSION', '6.0.7.
|
| 24 |
}
|
| 25 |
if ( ! defined( 'WOOCCM_PLUGIN_FILE' ) ) {
|
| 26 |
define( 'WOOCCM_PLUGIN_FILE', __FILE__ );
|
| 4 |
* Plugin Name: Checkout Fields Manager for WooCommerce
|
| 5 |
* Plugin URI: https://quadlayers.com/portfolio/woocommerce-checkout-manager/
|
| 6 |
* Description: Manage and customize WooCommerce Checkout fields (Add, Edit, Delete or re-order fields).
|
| 7 |
+
* Version: 6.0.7.6
|
| 8 |
* Author: QuadLayers
|
| 9 |
* Author URI: https://quadlayers.com
|
| 10 |
* License: GPLv3
|
| 20 |
define( 'WOOCCM_PLUGIN_NAME', 'Checkout Fields Manager for WooCommerce' );
|
| 21 |
}
|
| 22 |
if ( ! defined( 'WOOCCM_PLUGIN_VERSION' ) ) {
|
| 23 |
+
define( 'WOOCCM_PLUGIN_VERSION', '6.0.7.6' );
|
| 24 |
}
|
| 25 |
if ( ! defined( 'WOOCCM_PLUGIN_FILE' ) ) {
|
| 26 |
define( 'WOOCCM_PLUGIN_FILE', __FILE__ );
|
