Skip to content

Commit

Permalink
v3.1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
algoritmika committed Nov 9, 2024
1 parent d65027d commit 3840f5f
Show file tree
Hide file tree
Showing 4 changed files with 257 additions and 241 deletions.
238 changes: 29 additions & 209 deletions eu-vat-for-woocommerce.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Plugin Name: EU/UK VAT for WooCommerce
Plugin URI: https://wpfactory.com/item/eu-vat-for-woocommerce/
Description: Manage EU VAT in WooCommerce. Beautifully.
Version: 3.1.0
Version: 3.1.1
Author: WPFactory
Author URI: https://wpfactory.com/
Text Domain: eu-vat-for-woocommerce
Expand All @@ -22,7 +22,7 @@
* Main Alg_WC_EU_VAT Class
*
* @class Alg_WC_EU_VAT
* @version 3.1.0
* @version 3.1.1
* @since 1.0.0
*/
final class Alg_WC_EU_VAT {
Expand All @@ -33,7 +33,7 @@ final class Alg_WC_EU_VAT {
* @var string
* @since 1.0.0
*/
public $version = '3.1.0';
public $version = '3.1.1';

/**
* core object.
Expand Down Expand Up @@ -78,13 +78,16 @@ public static function instance() {
/**
* Alg_WC_EU_VAT Constructor.
*
* @version 3.1.0
* @version 3.1.1
* @since 1.0.0
*
* @access public
*/
function __construct() {

// Declare compatibility with custom order tables for WooCommerce
add_action( 'before_woocommerce_init', array( $this, 'wc_declare_compatibility' ) );

// Check for active plugins
if (
! $this->is_plugin_active( 'woocommerce/woocommerce.php' ) ||
Expand Down Expand Up @@ -122,6 +125,24 @@ function __construct() {

}

/**
* wc_declare_compatibility.
*
* @version 3.1.1
* @since 2.9.12
*
* @see https://github.com/woocommerce/woocommerce/wiki/High-Performance-Order-Storage-Upgrade-Recipe-Book#declaring-extension-incompatibility
*/
function wc_declare_compatibility() {
if ( class_exists( \Automattic\WooCommerce\Utilities\FeaturesUtil::class ) ) {
\Automattic\WooCommerce\Utilities\FeaturesUtil::declare_compatibility(
'custom_order_tables',
dirname( __FILE__ ),
true
);
}
}

/**
* is_plugin_active.
*
Expand Down Expand Up @@ -330,209 +351,8 @@ function alg_wc_eu_vat() {
}

/**
* alg_wc_eu_vat.
*/
alg_wc_eu_vat();

/**
* alg_wc_eu_vat_admin_js_field_control.
*/
if ( ! function_exists( 'alg_wc_eu_vat_admin_js_field_control' ) ) {
function alg_wc_eu_vat_admin_js_field_control() {
?>
<script>
jQuery( document ).ready( function () {

var eu_vat_required = jQuery( '#alg_wc_eu_vat_field_required' );

if ( 'yes_for_countries' == eu_vat_required.val() ) {
toogle_required_countries( 2 );
} else if( 'no_for_countries' == eu_vat_required.val() ) {
toogle_required_countries( 2 );
} else {
toogle_required_countries( 1 );
}

eu_vat_required.change( function () {

if ( 'yes_for_countries' == jQuery(this).val() ){
toogle_required_countries( 2 );
}else if ( 'no_for_countries' == jQuery(this).val() ) {
toogle_required_countries( 2 );
}else{
toogle_required_countries( 1 );
}

} );

} );

function toogle_customer_decide( flag = 1 ) {
var customer_decide = jQuery( '#alg_wc_eu_vat_field_let_customer_decide' );
var customer_decide_label = jQuery( '#alg_wc_eu_vat_field_let_customer_decide_label' );

if ( 1 == flag ) {
customer_decide.attr( 'disabled', 'disabled' );
customer_decide_label.attr( 'disabled', 'disabled' );
} else {
customer_decide.removeAttr( 'disabled' );
customer_decide_label.removeAttr( 'disabled' );
}
}

function toogle_required_countries( flag = 1 ) {
var field_required_countries = jQuery( '#alg_wc_eu_vat_field_required_countries' );

if ( 1 == flag ) {
field_required_countries.attr( 'disabled', 'disabled' );
} else {
field_required_countries.removeAttr( 'disabled' );
}
}
</script>
<?php
}
}
add_action( 'admin_footer', 'alg_wc_eu_vat_admin_js_field_control' );

add_action( 'wp_ajax_alg_wc_eu_vat_update_closedate', 'alg_wc_eu_vat_update_closedate' );
add_action( 'wp_ajax_nopriv_alg_wc_eu_vat_update_closedate', 'alg_wc_eu_vat_update_closedate' );
/**
* alg_wc_eu_vat_update_closedate.
*/
if ( ! function_exists( 'alg_wc_eu_vat_update_closedate' ) ) {
function alg_wc_eu_vat_update_closedate(){
$user_id = get_current_user_id();
if ( $user_id > 0 ) {
$phpdatetime = time();
update_user_meta( $user_id, 'alg_wc_eu_vat_closedate', $phpdatetime );
}
echo "ok";
die;
}
}

/**
* alg_wc_eu_vat_admin_footer_js.
*/
if ( ! function_exists( 'alg_wc_eu_vat_admin_footer_js' ) ) {
add_action( 'admin_footer', 'alg_wc_eu_vat_admin_footer_js' );
function alg_wc_eu_vat_admin_footer_js( $data ) {
?>
<script>
jQuery( document ).ready( function () {
jQuery( ".alg_wc_eu_vat_close" ).on( 'click', function () {
var closeData = {
'action' : 'alg_wc_eu_vat_update_closedate'
};

jQuery.ajax( {
type : 'POST',
url : <?php echo "'" . admin_url( 'admin-ajax.php' ) . "'"; ?>,
data : closeData,
async : true,
success: function ( response ) {
if ( 'ok' == response ) {
jQuery( ".alg_wc_eu_vat_right_ad" ).remove();
}
},
} );
} );
} );
</script>
<style>
.alg_wc_eu_vat_close {
position: absolute;
right:-13px;
top: -26px;
cursor: pointer;
color: white;
background: #000;
width: 25px;
height: 25px;
text-align: center;
border-radius: 50%;
font-size: 32px;
}

.alg_wc_eu_vat_name_heading {
position: relative;
}
.alg_wc_eu_vat_right_ad {
position: absolute;
right:20px;
padding: 16px;
box-shadow: 0 1px 6px 0 rgb(0 0 0 / 30%);
border: 1px solid #dcdcdc;
background-color: #fff;
margin: 0px 0 20px;
width: 25em;
z-index: 99;
font-weight: 600;
border-radius: 10px;

}
.alg_wc_eu_vat-button-upsell {
display:inline-flex;
align-items:center;
justify-content:center;
box-sizing:border-box;
min-height:48px;
padding:8px 1em;
font-size:16px;
line-height:1.5;
font-family:Arial,sans-serif;
color:#000;
border-radius:4px;
box-shadow:inset 0 -4px 0 rgba(0,0,0,.2);
filter:drop-shadow(0 2px 4px rgba(0,0,0,.2));
text-decoration:none;
background-color:#7ce577;
font-weight: 600;
}
.alg_wc_eu_vat-button-upsell:hover {
background-color:#7ce577;
color:#000;
font-weight: 600;
}
.alg_wc_eu_vat-sidebar__section li:before {
content:"+";
position:absolute;
left:0;
font-weight:700
}
.alg_wc_eu_vat-sidebar__section li {
list-style:none;
margin-left:20px
}
.alg_wc_eu_vat-sidebar__section {
position: relative;
}
img.alg_wc_eu_vat_resize {
width: 60px;
float: right;
position: absolute;
right: 0px;
top: -15px;
padding-left: 10px;
}
.alg_wc_eu_vat_text {
margin-right: 18%;
}
</style>
<?php
}
}

/**
* before_woocommerce_init.
* plugins_loaded.
*
* @version 3.1.1
*/
add_action( 'before_woocommerce_init', function() {
if ( class_exists( \Automattic\WooCommerce\Utilities\FeaturesUtil::class ) ) {
\Automattic\WooCommerce\Utilities\FeaturesUtil::declare_compatibility(
'custom_order_tables',
dirname(__FILE__),
true
);
}
} );
add_action( 'plugins_loaded', 'alg_wc_eu_vat' );
Loading

0 comments on commit 3840f5f

Please sign in to comment.