Plugin Directory

Changeset 2689830


Ignore:
Timestamp:
03/07/2022 07:21:28 AM (4 years ago)
Author:
keylorcr
Message:

Release 1.8.2

Location:
wc-pickup-store
Files:
38 added
4 edited

Legend:

Unmodified
Added
Removed
  • wc-pickup-store/trunk/includes/cpt-store.php

    r2679602 r2689830  
    273273 * Check if multicountries are allowed and return data
    274274 * Update to disable country filtering
     275 *
     276 * @since 1.6.0
     277 * @version 1.8.2
    275278 */
    276279function wps_check_countries_count($only_validate = true) {
    277     $country_filtering = (isset(WPS()->country_filtering) && WPS()->country_filtering == 'yes') ? true : false;
    278    
    279     if (apply_filters('wps_disable_country_filtering', $country_filtering)) {
    280         return;
    281     }
    282 
    283     if (count(get_option('woocommerce_specific_allowed_countries')) > 1) {
    284         if ($only_validate) {
    285             return true;
     280    if ( ! wps_is_country_filtering_disabled() ) {
     281        $specific_allowed_countries = get_option( 'woocommerce_specific_allowed_countries' );
     282
     283        if ( count( $specific_allowed_countries ) > 1 ) {
     284            if ( $only_validate ) {
     285                return true;
     286            }
     287   
     288            $allowed_countries = array();
     289            foreach ( $specific_allowed_countries as $key => $country_code ) {
     290                $allowed_countries[] = array(
     291                    'code' => $country_code,
     292                    'name' => WC()->countries->countries[ $country_code ]
     293                );
     294            }
     295
     296            return $allowed_countries;
    286297        }
    287 
    288         $allowed_countries = array();
    289         foreach (get_option('woocommerce_specific_allowed_countries') as $key => $country_code) {
    290             $allowed_countries[] = array(
    291                 'code' => $country_code,
    292                 'name' => WC()->countries->countries[$country_code]
    293             );
    294         }
    295         return $allowed_countries;
    296298    }
    297299   
     
    340342/**
    341343 * Update stores without Country
     344 *
     345 * @since 1.5.25
     346 * @version 1.8.2
    342347 */
    343348function wps_update_stores_without_country() {
    344     if (isset($_GET['update_country']) && $_GET['update_country'] == 1 && !get_option('wps_countries_updated')) {
     349    $stores_without_country = wps_check_stores_without_country();
     350
     351    if ( $stores_without_country ) {
     352        if ( isset( $_GET['update_country'] ) && $_GET['update_country'] == 1 && ! get_option( 'wps_countries_updated' ) ) {
     353            foreach ( $stores_without_country as $store_id => $store_data ) {
     354                update_post_meta( $store_id, 'store_country', wps_get_wc_default_country() );
     355            }
     356            update_option('wps_countries_updated', 1);
     357            ?>
     358            <div id="message" class="notice notice-info is-dismissible">
     359                <p><?php
     360                    printf(
     361                        __('Since version %1$s, a new Country validation was added to %2$s and all stores have been updated.', 'wc-pickup-store'),
     362                        '<strong>1.5.24</strong>',
     363                        '<strong>WC Pickup Store</strong>'
     364                    );
     365                ?></p>
     366            </div>
     367            <?php
     368        }
     369    }
     370}
     371add_action( 'init', 'wps_update_stores_without_country' );
     372
     373/**
     374 * Check if country filtering is disabled
     375 *
     376 * @version 1.8.2
     377 *
     378 * @return bool True or false if this is disabled via admin page or filter
     379 */
     380function wps_is_country_filtering_disabled() {
     381    $country_filtering = ( isset( WPS()->country_filtering ) && WPS()->country_filtering == 'yes' ) ? true : false;
     382   
     383    return apply_filters( 'wps_disable_country_filtering', $country_filtering );
     384}
     385
     386/**
     387 * Check for stores without country
     388 *
     389 * @version 1.8.2
     390 *
     391 * @return bool|array Array of stores without country or false if filtering is disabled
     392 */
     393function wps_check_stores_without_country() {
     394    if ( ! wps_is_country_filtering_disabled() ) {
    345395        $stores_without_country = wps_store_get_store_admin(true, array(
    346396            'meta_query' => array(
     
    351401                )
    352402            )
    353         ));
    354 
    355         foreach ($stores_without_country as $store_id => $store_data) {
    356             update_post_meta($store_id, 'store_country', wps_get_wc_default_country());
    357         }
    358         update_option('wps_countries_updated', 1);
    359         ?>
    360         <div id="message" class="notice notice-info is-dismissible">
    361             <p><?php
    362                 printf(
    363                     __('Since version %1$s, a new Country validation was added to %2$s and all stores have been updated.', 'wc-pickup-store'),
    364                     '<strong>1.5.24</strong>',
    365                     '<strong>WC Pickup Store</strong>'
    366                 );
    367             ?></p>
    368         </div>
    369         <?php
    370     }
    371 }
    372 add_action( 'init', 'wps_update_stores_without_country' );
     403        ) );
     404       
     405        return $stores_without_country;
     406    }
     407
     408    return false;
     409}
    373410
    374411/**
  • wc-pickup-store/trunk/includes/wps-functions.php

    r2679602 r2689830  
    2525        $ship_to_store = !empty($post_data['shipping_by_store']) ? $post_data['shipping_by_store'] : '';
    2626
    27         if (wps_check_countries_count()) {
    28             $country_to_filter = (isset($post_data['ship_to_different_address'])) ? $post_data['shipping_country'] : $post_data['billing_country'];
    29             $get_stores = wps_stores_filtering_by_country($country_to_filter);
     27        if ( wps_check_countries_count() ) {
     28            $country_to_filter = ( isset( $post_data['ship_to_different_address'] ) ) ? $post_data['shipping_country'] : ( isset( $post_data['billing_country'] ) ? $post_data['billing_country'] : wps_get_wc_default_country() );
     29            $get_stores = wps_stores_filtering_by_country( $country_to_filter );
    3030        } else {
    3131            $get_stores = wps_store_get_store_admin(true);
     
    176176/**
    177177 * Get chosen shipping method
     178 *
     179 * @since 1.5.x
     180 * @version 1.8.2
     181 *
     182 * @return array Chosen shipping methods or empty array
    178183 */
    179184function wps_get_chosen_shipping_method() {
    180     $chosen_methods = WC()->session->get('chosen_shipping_methods');
    181    
    182     return $chosen_methods[0];
     185    $chosen_methods = WC()->session->get( 'chosen_shipping_methods' );
     186   
     187    return is_array( $chosen_methods ) ? $chosen_methods[0] : array();
    183188}
    184189
     
    191196    $chosen_shipping = wps_get_chosen_shipping_method();
    192197
    193     return in_array($chosen_shipping, array(WPS()->id));
     198    return in_array( $chosen_shipping, array( WPS()->id ) );
    194199}
    195200
  • wc-pickup-store/trunk/readme.txt

    r2685521 r2689830  
    55Requires at least: 4.7
    66Tested up to: 5.9.1
    7 Stable tag: 1.8.1
     7Stable tag: 1.8.2
    88License: GPLv2
    99License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    9999View more information about tax handling in [this documentation](https://keylormendoza.com/how-to/tax-handling-by-stores/)
    100100
    101 = How can I manage tax options for this shipping method? =
    102101
    103102== Screenshots ==
     
    123122
    124123== Changelog ==
     124= 1.8.2 =
     125* Fix: Multisite validation if WC plugin is not active
     126* Improvement: Validations with country filtering notice and functionality
     127* Fix: Undefinded value in function wps_store_row_layout with variable $country_to_filter
     128* Fix: Condition to prevent undefined variable in function wps_get_chosen_shipping_method
     129
    125130= 1.8.1 =
    126131* Improvement: Admin notices for validations
     
    283288
    284289== Upgrade Notice ==
     290= 1.8.2 =
     291* Important Fix: Multisite validation if WC plugin is not active
     292
    285293= 1.8.0 =
    286294* New: Filters for admin options page
  • wc-pickup-store/trunk/wc-pickup-store.php

    r2685521 r2689830  
    44 * Plugin URI: https://www.keylormendoza.com/plugins/wc-pickup-store/
    55 * Description: Allows you to set up a custom post type for stores available to use it as shipping method Local pickup in WooCommerce. It also allows your clients to choose an store on the Checkout page and also adds the store fields to the order details and email.
    6  * Version: 1.8.1
     6 * Version: 1.8.2
    77 * Requires at least: 4.7
    88 * Tested up to: 5.9.1
     
    2222
    2323if ( !defined( 'WPS_PLUGIN_VERSION' ) ) {
    24     define( 'WPS_PLUGIN_VERSION', '1.8.1' );
     24    define( 'WPS_PLUGIN_VERSION', '1.8.2' );
    2525}
    2626
     
    3535/**
    3636 * Admin Notices
     37 *
     38 * @since 1.0.0
     39 * @version 1.8.2
    3740 */
    38 function wps_store_custom_admin_notices() {
     41if ( ! in_array( 'woocommerce/woocommerce.php', get_option( 'active_plugins' ) ) ) {
     42    add_action('admin_notices', 'wps_store_check_init_notice');
     43    return;
     44}
     45
     46function wps_store_check_init_notice() {
    3947    // Check if WooCommerce is active
    40     if ( current_user_can( 'activate_plugins') && !is_plugin_active( 'woocommerce/woocommerce.php' ) ) {
     48    if ( current_user_can( 'activate_plugins') ) {
    4149        ?>
    4250        <div id="message" class="error">
     
    5563        return;
    5664    }
     65}
    5766
     67function wps_store_country_notice() {
    5868    // Update stores Country
    59     if ( version_compare( WPS_PLUGIN_VERSION, '1.5.24' ) >= 0 ) {
     69    if ( version_compare( WPS_PLUGIN_VERSION, '1.5.24' ) >= 0 && wps_check_stores_without_country() && count( wps_check_stores_without_country() ) > 0 ) {
    6070        if ( !get_option( 'wps_countries_updated' ) ) {
    6171            ?>
     
    7888    }
    7989}
    80 add_action( 'admin_notices', 'wps_store_custom_admin_notices' );
     90add_action( 'admin_notices', 'wps_store_country_notice' );
    8191
    8292/**
Note: See TracChangeset for help on using the changeset viewer.