Plugin Directory

Changeset 3310856


Ignore:
Timestamp:
06/13/2025 06:58:37 AM (7 months ago)
Author:
biggidroid
Message:

Added support for the latest Wordpress version

Location:
ade-custom-shipping/trunk
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • ade-custom-shipping/trunk/README.md

    r3297454 r3310856  
    77Requires PHP: 7.0
    88Tested up to: 6.8
    9 Stable tag: 4.1.9
     9Stable tag: 4.2.0
    1010License: GPLv2 or later
    1111License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    5353
    5454== Changelog ==
     55
     56= 4.2.0 =
     57
     58- Added support for latest version of WooCommerce.
     59- Added new action to remove all cities.
     60- Added new action to append to existing cities.
     61- Added new action to replace existing cities.
    5562
    5663= 4.1.9 =
  • ade-custom-shipping/trunk/ade-custom-shipping.php

    r3297454 r3310856  
    77 * Author URI: https://adeleyeayodeji.com
    88 * Description: Add shipping zones 3 levels deep for ecommerce.
    9  * Version: 4.1.9
     9 * Version: 4.2.0
    1010 * License: GPL2
    1111 * License URL: http://www.gnu.org/licenses/gpl-2.0.txt
  • ade-custom-shipping/trunk/assets/js/ade-custom-js.js

    r3043344 r3310856  
    5353                <th scope="row" class="titledesc">
    5454                    <label for="zone_name">
    55                         Ade Custom Shipping Selections
     55                        Custom Selections
    5656                    </label>
     57          <p class="wc-shipping-zone-help-text">
     58            Select all cities within a state
     59          </p>
    5760                </th>
    5861                <td class="forminp">
    59                     <div class="ade-custom-shipping-selections" id="ade-custom-shipping-selections">Loading...</div>
     62                    <div class="ade-custom-shipping-wc-selections" id="ade-custom-shipping-wc-selections" style="display: flex; flex-direction: column; gap: 10px;">
     63            Loading selections...
     64          </div>
    6065                </td>
    6166            </tr>
     
    116121  }, 500);
    117122
    118   // update_wc_shipping_fields();
     123  update_wc_shipping_fields();
    119124});
  • ade-custom-shipping/trunk/build/ade-core.asset.php

    r3043344 r3310856  
    1 <?php return array('dependencies' => array('react', 'wp-components'), 'version' => 'c8f1937fc9c336c08293');
     1<?php return array('dependencies' => array('react', 'wp-components', 'wp-html-entities'), 'version' => 'c7c23441aa21b1034bba');
  • ade-custom-shipping/trunk/build/ade-core.css

    r3043344 r3310856  
    1 .ade-custom-shipping-select-container{align-items:center;display:flex;flex-direction:column;gap:18px;justify-content:center;margin:16px 0}.ade-custom-shipping-select-container #ade_custom_shipping_selections{width:100%}.ade-custom-shipping-select-container .ade-custom-shipping-action-type{align-items:center;display:flex;flex-direction:row;gap:5px;justify-content:center}
     1.ade-custom-shipping-select-container{align-items:center;display:flex;flex-direction:column;gap:18px;justify-content:center;margin:16px 0}.ade-custom-shipping-select-container #ade_custom_shipping_selections{width:100%}.ade-custom-shipping-select-container .ade-custom-shipping-action-type{align-items:center;display:flex;flex-direction:row;gap:5px;justify-content:center}.ade-custom-shipping-woocommerce-selections-wrapper{display:flex;flex-direction:column;gap:10px}.ade-custom-shipping-woocommerce-selections-wrapper .select2-container{max-width:600px!important;width:100%!important}
  • ade-custom-shipping/trunk/build/ade-core.js

    r3043344 r3310856  
    1 (()=>{"use strict";var e={n:t=>{var o=t&&t.__esModule?()=>t.default:()=>t;return e.d(o,{a:o}),o},d:(t,o)=>{for(var n in o)e.o(o,n)&&!e.o(t,n)&&Object.defineProperty(t,n,{enumerable:!0,get:o[n]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t)};const t=window.React;var o=e.n(t);const n=window.wp.components;class s extends o().Component{constructor(e){super(e),this.state={popup:!1,woocommerce_states:{},formatted:[]}}componentWillMount(){const e=ade_custom_params.woocommerce_states;this.setState({woocommerce_states:e})}componentDidMount(){this.update_wc_states()}componentDidUpdate(){this.state.popup&&this.initSelect2()}update_wc_states=()=>{const e=this.state.woocommerce_states;let t=[];for(let n in e){let e=n.split(","),s=e[e.length-1];var o=s.split(" ");s=o.slice(1).join(" "),t.push(s)}t=[...new Set(t)],this.setState({formatted:t})};loadpopup=e=>{e.preventDefault(),this.setState({popup:!0})};initSelect2=()=>{void 0!==jQuery.fn.select2&&(jQuery("#ade_custom_shipping_selections").hasClass("select2-hidden-accessible")||jQuery("#ade_custom_shipping_selections").select2())};selectGroupRegions=e=>{e.preventDefault();let t=jQuery("#ade_custom_shipping_selections").val(),o=jQuery("#ade_custom_shipping_action_type").val();jQuery("select[name='zone_locations']").length&&(jQuery("select[name='zone_locations'] option").each((function(){jQuery(this).text().includes(t)&&jQuery(this).text().includes("Nigeria")&&jQuery(this).prop("selected","add"===o)})),jQuery("select[name='zone_locations']").trigger("change")),jQuery("select[data-placeholder='Select locations']").length&&(jQuery("select[data-placeholder='Select locations'] option").each((function(){jQuery(this).text().includes(t)&&jQuery(this).text().includes("Nigeria")&&jQuery(this).prop("selected","add"===o)})),jQuery("select[data-placeholder='Select locations']").trigger("change")),jQuery("#woocommerce-tree-select-control-0__control-input").length&&(jQuery("#woocommerce-tree-select-control-0__control-input").trigger("focus"),jQuery("#woocommerce-tree-select-control-0__control-input").val("Nigeria"),jQuery("#woocommerce-tree-select-control-0__control-input").trigger("change")),jQuery(".components-base-control.woocommerce-tree-select-control__option").length?jQuery(".components-base-control.woocommerce-tree-select-control__option").each((function(){console.log("get all elements");let e=$(this).find("label").text();console.log(e)})):console.log("no elements found");try{jQuery(".components-snackbar-list__notice-container").each((function(e,t){0!==e&&jquery(t).remove()})),wp.data.dispatch("core/notices").createNotice("success","Group Regions Updated",{type:"snackbar",isDismissible:!0,timeout:100})}catch(e){}};render(){const{popup:e,formatted:o}=this.state;return(0,t.createElement)(t.Fragment,null,e&&(0,t.createElement)(n.Modal,{title:"Select Group Regions",onRequestClose:()=>this.setState({popup:!1}),className:"ade-custom-shipping-selections"},(0,t.createElement)("div",{className:"ade-custom-shipping-select-container"},(0,t.createElement)("select",{name:"ade_custom_shipping_selections",id:"ade_custom_shipping_selections"},o.map(((e,o)=>(0,t.createElement)("option",{key:o,value:e},e)))),(0,t.createElement)("div",{className:"ade-custom-shipping-action-type"},(0,t.createElement)("label",null,"Action Type:"),(0,t.createElement)("select",{name:"ade_custom_shipping_action_type",id:"ade_custom_shipping_action_type"},(0,t.createElement)("option",{value:"add"},"Add"),(0,t.createElement)("option",{value:"remove"},"Remove"))),(0,t.createElement)("button",{onClick:this.selectGroupRegions,className:"button button-primary"},"Set Group Regions"),(0,t.createElement)("p",{style:{textAlign:"center"}},(0,t.createElement)("small",null,(0,t.createElement)("strong",null,"Note:")," This will group the selected regions to Nigeria",(0,t.createElement)("br",null),(0,t.createElement)("a",{href:"https://www.adeleyeayodeji.com",target:"_blank"},"Learn More"))))),(0,t.createElement)("button",{onClick:this.loadpopup,className:"button button-primary"},"Select Group Regions"))}}const c=s;jQuery(document).ready((function(e){setInterval((()=>{(()=>{if(e("#ade-custom-shipping-selections").length){let e=document.getElementById("ade-custom-shipping-selections");if(!e.hasChildNodes())return;ReactDOM.render((0,t.createElement)(c,null),e)}})()}),1e3)}))})();
     1(()=>{"use strict";var e={n:t=>{var o=t&&t.__esModule?()=>t.default:()=>t;return e.d(o,{a:o}),o},d:(t,o)=>{for(var n in o)e.o(o,n)&&!e.o(t,n)&&Object.defineProperty(t,n,{enumerable:!0,get:o[n]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t)};const t=window.React;var o=e.n(t);const n=window.wp.components;class l extends o().Component{constructor(e){super(e),this.state={popup:!1,woocommerce_states:{},formatted:[]}}componentWillMount(){const e=ade_custom_params.woocommerce_states;this.setState({woocommerce_states:e})}componentDidMount(){this.update_wc_states()}componentDidUpdate(){this.state.popup&&this.initSelect2()}update_wc_states=()=>{const e=this.state.woocommerce_states;let t=[];for(let n in e){let e=n.split(","),l=e[e.length-1];var o=l.split(" ");l=o.slice(1).join(" "),t.push(l)}t=[...new Set(t)],this.setState({formatted:t})};loadpopup=e=>{e.preventDefault(),this.setState({popup:!0})};initSelect2=()=>{void 0!==jQuery.fn.select2&&(jQuery("#ade_custom_shipping_selections").hasClass("select2-hidden-accessible")||jQuery("#ade_custom_shipping_selections").select2())};selectGroupRegions=e=>{e.preventDefault();let t=jQuery("#ade_custom_shipping_selections").val(),o=jQuery("#ade_custom_shipping_action_type").val();jQuery("select[name='zone_locations']").length&&(jQuery("select[name='zone_locations'] option").each((function(){jQuery(this).text().includes(t)&&jQuery(this).text().includes("Nigeria")&&jQuery(this).prop("selected","add"===o)})),jQuery("select[name='zone_locations']").trigger("change")),jQuery("select[data-placeholder='Select locations']").length&&(jQuery("select[data-placeholder='Select locations'] option").each((function(){jQuery(this).text().includes(t)&&jQuery(this).text().includes("Nigeria")&&jQuery(this).prop("selected","add"===o)})),jQuery("select[data-placeholder='Select locations']").trigger("change")),jQuery("#woocommerce-tree-select-control-0__control-input").length&&(jQuery("#woocommerce-tree-select-control-0__control-input").trigger("focus"),jQuery("#woocommerce-tree-select-control-0__control-input").val("Nigeria"),jQuery("#woocommerce-tree-select-control-0__control-input").trigger("change")),jQuery(".components-base-control.woocommerce-tree-select-control__option").length?jQuery(".components-base-control.woocommerce-tree-select-control__option").each((function(){console.log("get all elements");let e=$(this).find("label").text();console.log(e)})):console.log("no elements found");try{jQuery(".components-snackbar-list__notice-container").each((function(e,t){0!==e&&jquery(t).remove()})),wp.data.dispatch("core/notices").createNotice("success","Group Regions Updated",{type:"snackbar",isDismissible:!0,timeout:100})}catch(e){}};render(){const{popup:e,formatted:o}=this.state;return(0,t.createElement)(t.Fragment,null,e&&(0,t.createElement)(n.Modal,{title:"Select Group Regions",onRequestClose:()=>this.setState({popup:!1}),className:"ade-custom-shipping-selections"},(0,t.createElement)("div",{className:"ade-custom-shipping-select-container"},(0,t.createElement)("select",{name:"ade_custom_shipping_selections",id:"ade_custom_shipping_selections"},o.map(((e,o)=>(0,t.createElement)("option",{key:o,value:e},e)))),(0,t.createElement)("div",{className:"ade-custom-shipping-action-type"},(0,t.createElement)("label",null,"Action Type:"),(0,t.createElement)("select",{name:"ade_custom_shipping_action_type",id:"ade_custom_shipping_action_type"},(0,t.createElement)("option",{value:"add"},"Add"),(0,t.createElement)("option",{value:"remove"},"Remove"))),(0,t.createElement)("button",{onClick:this.selectGroupRegions,className:"button button-primary"},"Set Group Regions"),(0,t.createElement)("p",{style:{textAlign:"center"}},(0,t.createElement)("small",null,(0,t.createElement)("strong",null,"Note:")," This will group the selected regions to Nigeria",(0,t.createElement)("br",null),(0,t.createElement)("a",{href:"https://www.adeleyeayodeji.com",target:"_blank"},"Learn More"))))),(0,t.createElement)("button",{onClick:this.loadpopup,className:"button button-primary"},"Select Group Regions"))}}const c=l,a=window.wp.htmlEntities;function s(){const[e,o]=(0,t.useState)(!1),[l,c]=(0,t.useState)([]),[s,i]=(0,t.useState)(!1),[r,p]=(0,t.useState)("replace");var u=Object.keys(ade_custom_params.woocommerce_formatted_states).map((e=>({label:e,value:e})));const m=(e,t)=>Array.isArray(e)?e.map((e=>m(e,t))):(e.label&&(e.label=t(e.label)),e.children&&(e.children=m(e.children,t)),e);return(0,t.useEffect)((()=>{jQuery("#ade-custom-shipping-woocommerce-selections").select2({width:"resolve",placeholder:"Select a state or action",allowClear:!0}),jQuery("#ade-custom-shipping-woocommerce-selections").on("change",(e=>{(e=>{var t;const n=e.target.value,l=null!==(t=m(window.shippingZoneMethodsLocalizeScript?.region_options,a.decodeEntities))&&void 0!==t?t:[];if("remove-all"===n)return c([]),void o(!0);const s=l.find((e=>"Africa"===e.label)).children.find((e=>"Nigeria"===e.label)).children.filter((e=>e.value.includes(n))).map((e=>e.value));c(s),o(!0)})(e)}))}),[]),(0,t.createElement)("div",{className:"ade-custom-shipping-woocommerce-selections-wrapper"},e&&(0,t.createElement)(n.Modal,{title:"Page Reload Required",onRequestClose:()=>{o(!1)}},(0,t.createElement)("p",{style:{marginTop:0}},"A page reload is required to apply the changes.",(0,t.createElement)("br",null),"Please select an action to proceed."),l.length>0&&(0,t.createElement)("select",{value:r,style:{width:"100%",marginBottom:"20px"},onChange:e=>{p(e.target.value)}},(0,t.createElement)("option",{value:"append"},"Append to existing cities"),(0,t.createElement)("option",{value:"replace"},"Replace existing cities")),s?(0,t.createElement)(n.Spinner,null):(0,t.createElement)(n.Button,{onClick:()=>{var e;i(!0);let t=null!==(e=window.shippingZoneMethodsLocalizeScript?.locations)&&void 0!==e?e:[];"append"===r?t.push(...l):t=l,document.body.dispatchEvent(new CustomEvent("wc_region_picker_update",{detail:t}));const o=document.querySelector("button.wc-shipping-zone-method-save");o&&o.click(),setTimeout((()=>{window.location.reload()}),2e3)},isPrimary:!0},"Reload Page")),(0,t.createElement)("select",{id:"ade-custom-shipping-woocommerce-selections",style:{width:"100%",maxWidth:"600px"}},(0,t.createElement)("option",{value:""},"Select a state or action"),(0,t.createElement)("option",{value:"remove-all"},"Remove all cities - action"),u.map((e=>(0,t.createElement)("option",{value:e.value},e.label)))),(0,t.createElement)("small",{className:"wc-shipping-zone-help-text"},"Select all cities within the state.",(0,t.createElement)("br",null),(0,t.createElement)("strong",null,"Note:")," this will replace any previously selected default cities."))}jQuery(document).ready((function(e){setInterval((()=>{(()=>{if(e("#ade-custom-shipping-selections").length){let e=document.getElementById("ade-custom-shipping-selections");if(!e.hasChildNodes())return;ReactDOM.render((0,t.createElement)(c,null),e)}})(),(()=>{if(e("#ade-custom-shipping-wc-selections").length){let e=document.getElementById("ade-custom-shipping-wc-selections");if(!e.hasChildNodes())return;ReactDOM.render((0,t.createElement)(s,null),e)}})()}),1e3)}))})();
  • ade-custom-shipping/trunk/inc/AdeCustomClass.php

    r3043344 r3310856  
    2727
    2828    /**
     29     * Get formatted states
     30     *
     31     * @since 4.1.5
     32     */
     33    public function get_formatted_states()
     34    {
     35        $states = WC()->countries->get_states('NG');
     36        //check if states is not empty
     37        if (empty($states)) {
     38            return array();
     39        }
     40        $formatted_states = array();
     41        //loop through states
     42        foreach ($states as $state => $city) {
     43            //explode the city by comma
     44            $city_exploded = explode(',', $city);
     45            //get the last item
     46            $last_item = end($city_exploded);
     47            //remove the first whitespace
     48            $last_item = ltrim($last_item);
     49            //set the state
     50            $formatted_states[$last_item] = $last_item;
     51        }
     52        //return formatted states
     53        return $formatted_states;
     54    }
     55
     56    /**
    2957     * Enqueue admin script
    3058     *
     
    4775            //Nigeria states
    4876            'woocommerce_states' => WC()->countries->get_states('NG'),
     77            'woocommerce_formatted_states' => $this->get_formatted_states(),
    4978        );
    5079        wp_localize_script('ade-custom-build-js', 'ade_custom_params', $ade_custom_params);
Note: See TracChangeset for help on using the changeset viewer.