Plugin Directory

Changeset 3300885


Ignore:
Timestamp:
05/26/2025 04:02:49 PM (10 months ago)
Author:
mgplugin
Message:

new version alive

Location:
toggle-tax-for-woocommerce/trunk
Files:
4 added
3 deleted
3 edited

Legend:

Unmodified
Added
Removed
  • toggle-tax-for-woocommerce/trunk/frontend/frontend.php

    r3203723 r3300885  
    11<?php
    22
    3 if( ! defined ( 'ABSPATH' ) ){
     3if ( ! defined( 'ABSPATH' ) ) {
    44    exit;
    55}
    66
    7 if( ! class_exists ('Gt_frontend') ){
     7// Add actions and filters to initialize the functionality
     8add_action( 'wp_footer', 'gt_add_floating_button' );
     9add_filter( 'woocommerce_get_price_html', 'gt_add_prices_data_attributes', 10, 2 );
     10add_action( 'wp_head', 'gt_style_head' );
     11add_shortcode( 'gt_toogle_tax', 'gt_toogle_tax' );
    812
    9     class Gt_frontend {   
    10        
    11         public function __construct()
    12         {
    13             add_action( 'wp_footer', array($this, 'gt_add_floating_button') );
    14             add_filter( 'woocommerce_get_price_html', array($this, 'gt_add_prices_data_attributes'), 10, 2 );
    15             add_action( 'wp_head', array($this, 'gt_style_head') );
    16             add_shortcode('gt_toogle_tax',  array($this, 'gt_toogle_tax'));
    17         }
    18        
    19         function gt_add_floating_button () {
    20             $gt_btn_state = get_option('gt_tax_btn_state') ? get_option('gt_tax_btn_state') : 'show';
    21             $gt_bg_color = get_option('gt_tax_bg_color') ? get_option('gt_tax_bg_color') : '#333333';
    22             $gt_text_color = get_option('gt_tax_text_color') ?  get_option('gt_tax_text_color') : '#ffffff';
    23             $gt_tax_btn_text = get_option('gt_tax_btn_text') ? get_option('gt_tax_btn_text') : 'incl. tax';
    24             $gt_tax_btn_toggle_text = get_option('gt_tax_btn_toggle_text') ? get_option('gt_tax_btn_toggle_text') : 'excl. tax';
    25        
    26             if(wc_tax_enabled() && $gt_btn_state == 'show'){
    27                 if(is_shop() || is_product_category() || is_product() || is_front_page() || is_cart()) {
    28                     echo '<div class="sticky-slider tax-toggle-prices gt-toggle-button" style = "background-color : '.esc_attr($gt_bg_color).'; color : '.esc_attr($gt_text_color).' ">
    29                             <span class="price-including-tax">'.esc_html($gt_tax_btn_text).'</span>
    30                             <span class="price-excluding-tax">'.esc_html($gt_tax_btn_toggle_text).'</span>
    31                         </div>';
    32                 }   
    33             }
     13// Add the floating button to the footer
     14function gt_add_floating_button() {
     15    $gt_btn_state = get_option( 'gt_tax_btn_state' ) ? get_option( 'gt_tax_btn_state' ) : 'show';
     16    $gt_bg_color = get_option( 'gt_tax_bg_color' ) ? get_option( 'gt_tax_bg_color' ) : '#333333';
     17    $gt_text_color = get_option( 'gt_tax_text_color' ) ? get_option( 'gt_tax_text_color' ) : '#ffffff';
     18    $gt_tax_btn_text = get_option( 'gt_tax_btn_text' ) ? get_option( 'gt_tax_btn_text' ) : 'incl. tax';
     19    $gt_tax_btn_toggle_text = get_option( 'gt_tax_btn_toggle_text' ) ? get_option( 'gt_tax_btn_toggle_text' ) : 'excl. tax';
    3420
     21    if ( wc_tax_enabled() && $gt_btn_state == 'show' ) {
     22        if ( is_shop() || is_product_category() || is_product() || is_front_page() || is_cart() ) {
     23            echo '<div class="gt-sticky-slider tax-toggle-prices gt-toggle-button" style="background-color: ' . esc_attr( $gt_bg_color ) . '; color: ' . esc_attr( $gt_text_color ) . '">
     24                    <span class="price-including-tax">' . esc_html( $gt_tax_btn_text ) . '</span>
     25                    <span class="price-excluding-tax">' . esc_html( $gt_tax_btn_toggle_text ) . '</span>
     26                </div>';
    3527        }
    36         function gt_toogle_tax () {
    37             ob_start();
    38             $gt_btn_state = get_option('gt_tax_btn_state') ? get_option('gt_tax_btn_state') : 'show';
    39             $gt_bg_color = get_option('gt_tax_bg_color') ? get_option('gt_tax_bg_color') : '#333333';
    40             $gt_text_color = get_option('gt_tax_text_color') ?  get_option('gt_tax_text_color') : '#ffffff';
    41             $gt_tax_btn_text = get_option('gt_tax_btn_text') ? get_option('gt_tax_btn_text') : 'incl. tax';
    42             $gt_tax_btn_toggle_text = get_option('gt_tax_btn_toggle_text') ? get_option('gt_tax_btn_toggle_text') : 'excl. tax';
    43        
    44             if(wc_tax_enabled() && $gt_btn_state == 'show'){
    45                 if(is_shop() || is_product_category() || is_product() || is_front_page() || is_cart()) {
    46                     echo '<div class="tax-toggle-prices gt-toggle-button"style = "background-color : '.esc_attr($gt_bg_color).'; color : '.esc_attr($gt_text_color).' ">
    47                             <span class="price-including-tax">'.esc_html($gt_tax_btn_text).'</span>
    48                             <span class="price-excluding-tax">'.esc_html($gt_tax_btn_toggle_text).'</span>
    49                         </div>';
    50                 }   
    51             }
    52             $content = ob_get_contents();
    53             ob_end_clean();
    54             return $content;
     28    }
     29}
     30
     31// Shortcode to render the toggle button
     32function gt_toogle_tax() {
     33    ob_start();
     34    $gt_btn_state = get_option( 'gt_tax_btn_state' ) ? get_option( 'gt_tax_btn_state' ) : 'show';
     35    $gt_bg_color = get_option( 'gt_tax_bg_color' ) ? get_option( 'gt_tax_bg_color' ) : '#333333';
     36    $gt_text_color = get_option( 'gt_tax_text_color' ) ? get_option( 'gt_tax_text_color' ) : '#ffffff';
     37    $gt_tax_btn_text = get_option( 'gt_tax_btn_text' ) ? get_option( 'gt_tax_btn_text' ) : 'incl. tax';
     38    $gt_tax_btn_toggle_text = get_option( 'gt_tax_btn_toggle_text' ) ? get_option( 'gt_tax_btn_toggle_text' ) : 'excl. tax';
     39
     40    if ( wc_tax_enabled() && $gt_btn_state == 'show' ) {
     41        if ( is_shop() || is_product_category() || is_product() || is_front_page() || is_cart() ) {
     42            echo '<div class="tax-toggle-prices gt-toggle-button" style="background-color: ' . esc_attr( $gt_bg_color ) . '; color: ' . esc_attr( $gt_text_color ) . '">
     43                    <span class="price-including-tax">' . esc_html( $gt_tax_btn_text ) . '</span>
     44                    <span class="price-excluding-tax">' . esc_html( $gt_tax_btn_toggle_text ) . '</span>
     45                </div>';
    5546        }
    56 
    57         function gt_add_prices_data_attributes($price_html, $product) {
    58             $gt_tax_text = get_option('gt_tax_text') ? get_option('gt_tax_text') : 'TAX';
    59             // excluding tax price
    60             $excl_reg_price = wc_get_price_excluding_tax( $product, array(
    61                 'price' => $product->get_regular_price()
    62             ));
    63             $excl_sale_price = wc_get_price_excluding_tax($product);
    64             // including tax price
    65             $incl_reg_price = wc_get_price_including_tax( $product, array(
    66                 'price' => $product->get_regular_price()
    67             ));
    68             $incl_sale_price = wc_get_price_including_tax($product);
    69        
    70             if(wc_tax_enabled()){
    71                 if($product->is_on_sale()){ 
    72                     $price_html = '<div class="price-tax-incl">' . wc_format_sale_price(wc_get_price_to_display( $product, array( 'price' => $incl_reg_price ) ),
    73                                                                     wc_get_price_to_display(  $product, array( 'price' => $incl_sale_price ) )) . '<small class="woocommerce-price-suffix"> incl. '.esc_html($gt_tax_text).' </small>' . '</div>
    74                                     <div class="price-tax-excl">' . wc_format_sale_price(wc_get_price_to_display( $product, array( 'price' => $excl_reg_price ) ),
    75                                                                     wc_get_price_to_display(  $product, array( 'price' => $excl_sale_price ) )) . '<small class="woocommerce-price-suffix"> excl. '.esc_html($gt_tax_text).' </small>' . '</div>' ;
    76                 }else{
    77                     $price_html = '<div class="price-tax-incl">' . wc_price( wc_get_price_to_display( $product, array( 'price' => $incl_reg_price ) )). '<small class="woocommerce-price-suffix"> incl. '.esc_html($gt_tax_text).' </small>' . '</div>
    78                                     <div class="price-tax-excl">' . wc_price( wc_get_price_to_display( $product, array( 'price' => $excl_reg_price ) )) . '<small class="woocommerce-price-suffix"> excl. '.esc_html($gt_tax_text).' </small>' . '</div>' ;
    79                 }
    80             }
    81             return $price_html;
    82         }
    83 
    84         function gt_style_head(){
    85             $gt_txt_opt = get_option(" woocommerce_tax_display_shop ");
    86             $gt_btn_state = get_option('gt_tax_btn_state') ? get_option('gt_tax_btn_state') : 'show';
    87             if($gt_btn_state === 'show'){
    88             ?>
    89                 <style>
    90                 .price-tax-excl, .tax-toggle-prices .price-including-tax, .cart_totals  .tax-rate, .cart_totals  .order-total{
    91                     display: <?php if($gt_txt_opt == 'excl'){ echo 'block'; }else{ echo 'none'; } ?>;
    92                 }
    93                 .price-tax-incl, .tax-toggle-prices .price-excluding-tax, .cart_totals  .tax-rate, .cart_totals  .order-total{
    94                     display: <?php if($gt_txt_opt == 'excl'){ echo 'none'; }else{ echo 'block'; } ?>;
    95                 }
    96                 </style>
    97             <?php
    98             }
    99         }
    100 
    10147    }
    10248
    103     $Gt_frontend = new Gt_frontend();       
    104 
     49    return ob_get_clean();
    10550}
    10651
    107 ?>
     52// Add data attributes for prices in WooCommerce
     53function gt_add_prices_data_attributes( $price_html, $product ) {
     54    $gt_tax_text = get_option( 'gt_tax_text' ) ? get_option( 'gt_tax_text' ) : 'TAX';
     55    // Excluding tax price
     56    $excl_reg_price = wc_get_price_excluding_tax( $product, array(
     57        'price' => $product->get_regular_price()
     58    ));
     59    $excl_sale_price = wc_get_price_excluding_tax( $product );
     60    // Including tax price
     61    $incl_reg_price = wc_get_price_including_tax( $product, array(
     62        'price' => $product->get_regular_price()
     63    ));
     64    $incl_sale_price = wc_get_price_including_tax( $product );
     65
     66    if ( wc_tax_enabled() ) {
     67        if ( $product->is_on_sale() ) { 
     68            $price_html = '<div class="price-tax-incl">' . wc_format_sale_price(
     69                wc_get_price_to_display( $product, array( 'price' => $incl_reg_price ) ),
     70                wc_get_price_to_display( $product, array( 'price' => $incl_sale_price ) )
     71            ) . '<small class="woocommerce-price-suffix"> incl. ' . esc_html( $gt_tax_text ) . ' </small>' . '</div>
     72                <div class="price-tax-excl">' . wc_format_sale_price(
     73                wc_get_price_to_display( $product, array( 'price' => $excl_reg_price ) ),
     74                wc_get_price_to_display( $product, array( 'price' => $excl_sale_price ) )
     75            ) . '<small class="woocommerce-price-suffix"> excl. ' . esc_html( $gt_tax_text ) . ' </small>' . '</div>';
     76        } else {
     77            $price_html = '<div class="price-tax-incl">' . wc_price(
     78                wc_get_price_to_display( $product, array( 'price' => $incl_reg_price ) )
     79            ) . '<small class="woocommerce-price-suffix"> incl. ' . esc_html( $gt_tax_text ) . ' </small>' . '</div>
     80                <div class="price-tax-excl">' . wc_price(
     81                wc_get_price_to_display( $product, array( 'price' => $excl_reg_price ) )
     82            ) . '<small class="woocommerce-price-suffix"> excl. ' . esc_html( $gt_tax_text ) . ' </small>' . '</div>';
     83        }
     84    }
     85
     86    return $price_html;
     87}
     88
     89// Add styles dynamically to the head
     90function gt_style_head() {
     91    $gt_txt_opt = get_option( "woocommerce_tax_display_shop" );
     92    $gt_btn_state = get_option( 'gt_tax_btn_state' ) ? get_option( 'gt_tax_btn_state' ) : 'show';
     93
     94    if ( $gt_btn_state === 'show' ) {
     95        ?>
     96        <style>
     97        .price-tax-excl, .tax-toggle-prices .price-including-tax, .cart_totals .tax-rate, .cart_totals .order-total {
     98            display: <?php echo ( $gt_txt_opt == 'excl' ) ? 'block' : 'none'; ?>;
     99        }
     100        .price-tax-incl, .tax-toggle-prices .price-excluding-tax, .cart_totals .tax-rate, .cart_totals .order-total {
     101            display: <?php echo ( $gt_txt_opt == 'excl' ) ? 'none' : 'block'; ?>;
     102        }
     103        </style>
     104        <?php
     105    }
     106}
  • toggle-tax-for-woocommerce/trunk/readme.txt

    r3203723 r3300885  
    11=== Toggle Tax For Woocommerce ===
    22Tags: toggle tax, tax display options, customizable tax display, wooCommerce tax customization
    3 Tested up to: 6.7.1
    4 Stable tag: 1.0.2
     3Tested up to: 6.8
     4Stable tag: 1.0.3
    55Requires PHP: 5.0
    66License: GPLv2 or later
  • toggle-tax-for-woocommerce/trunk/toggle-tax-for-woocommerce.php

    r3203723 r3300885  
    33 * Plugin name: Toggle Tax For Woocommerce
    44 * Description: The Toggle Tax plugin allows store owners to easily toggle tax display for their products in WooCommerce. This plugin allows customers to toggle between including and excluding tax prices of each product.
    5  * Version: 1.0.2
     5 * Version: 1.0.3
    66 * Author: mgplugin
    77 * License: GPLv2 or later
     
    1313}
    1414
    15 if( ! class_exists ('GtTaxToggle') ){
    16 
    17     class GtTaxToggle
    18     {
    19         public function __construct()
    20         {
    21             $this->init();
    22             $this->include();
    23         }
    24 
    25         function init(){
    26             add_action('wp_enqueue_scripts', array($this, 'gt_include_scripts'));
    27         }
    28 
    29         function include(){
    30             include_once('frontend/frontend.php');
    31             include_once('admin/toogle_backend.php');
    32         }
    33 
    34         function gt_include_scripts(){
    35             // Add version to script
    36             wp_enqueue_script(
    37                 'gt-custom-script',
    38                 plugins_url('frontend/js/customscript.js', __FILE__),
    39                 array('jquery'),
    40                 filemtime(plugin_dir_path(__FILE__) . 'frontend/js/customscript.js'),  // Dynamically set version based on file modification time
    41                 true
    42             );
    43 
    44             // Add version to style
    45             wp_enqueue_style(
    46                 'gt-custom-style',
    47                 plugins_url('frontend/css/customstyle.css', __FILE__),
    48                 array(),
    49                 filemtime(plugin_dir_path(__FILE__) . 'frontend/css/customstyle.css'),  // Dynamically set version based on file modification time
    50                 'all'
    51             );
    52 
    53             // Localize script
    54             wp_localize_script('gt-custom-script', 'ajax_url', array(
    55                 'ajaxurl' => admin_url('admin-ajax.php'),
    56                 'taxdisplay' => get_option("woocommerce_tax_display_shop"),
    57             ));
    58 
    59         }
    60        
    61     }
    62 
    63     $GtTaxToggle = new GtTaxToggle(); 
    64    
     15// Check if WooCommerce is active
     16if ( ! in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) ) {
     17    add_action( 'admin_notices', 'gt_woocommerce_error_notice' );
     18    return; // Stop further execution of the plugin if WooCommerce is not active
    6519}
    6620
     21include_once plugin_dir_path( __FILE__ ) . 'backend/backend.php';
     22include_once plugin_dir_path( __FILE__ ) . 'frontend/frontend.php';
     23   
     24add_action( 'wp_enqueue_scripts', 'gt_include_scripts' );
     25// Enqueue scripts and styles
     26function gt_include_scripts() {
     27    // Add version to script
     28    wp_enqueue_script(
     29        'gt-script',
     30        plugins_url( 'frontend/js/script.js', __FILE__ ),
     31        array( 'jquery' ),
     32        filemtime( plugin_dir_path( __FILE__ ) . 'frontend/js/script.js' ), // Dynamically set version based on file modification time
     33        true
     34    );
    6735
     36    // Add version to style
     37    wp_enqueue_style(
     38        'gt-style',
     39        plugins_url( 'frontend/css/style.css', __FILE__ ),
     40        array(),
     41        filemtime( plugin_dir_path( __FILE__ ) . 'frontend/css/style.css' ), // Dynamically set version based on file modification time
     42        'all'
     43    );
    6844
     45    // Localize script
     46    wp_localize_script( 'gt-script', 'ajax_url', array(
     47        'ajaxurl'    => admin_url( 'admin-ajax.php' ),
     48        'taxdisplay' => get_option( 'woocommerce_tax_display_shop' ),
     49    ) );
     50}
    6951
    70 
    71 
    72 
    73 
     52// Error notice for missing WooCommerce
     53function gt_woocommerce_error_notice() {
     54    echo '<div class="error"><p><strong>Toggle Tax For WooCommerce:</strong> This plugin requires WooCommerce to be installed and activated.</p></div>';
     55}
Note: See TracChangeset for help on using the changeset viewer.