https://t.me/AnonymousX5
Server : Apache/2
System : Linux vps.sdns.vn 3.10.0-1160.15.2.el7.x86_64 #1 SMP Wed Feb 3 15:06:38 UTC 2021 x86_64
User : phatdatpq ( 1022)
PHP Version : 7.2.34
Disable Function : exec,system,passthru,shell_exec,proc_close,proc_open,dl,popen,show_source,posix_kill,posix_mkfifo,posix_getpwuid,posix_setpgid,posix_setsid,posix_setuid,posix_setgid,posix_seteuid,posix_setegid,posix_uname
Directory :  /home/phatdatpq/public_html/wp-content/themes/dien-may-xanh/myattr/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /home/phatdatpq/public_html/wp-content/themes/dien-may-xanh/myattr/variation-isures.php
<?php
if (!defined('ABSPATH')) {
    exit;
}

class isures_variation_product
{
    function __construct()
    {
        
        add_filter('woocommerce_dropdown_variation_attribute_options_html', array( $this , 'variation_radio_buttons'), 20, 2);
        add_filter('woocommerce_variation_is_active', array( $this ,'variation_check'), 10, 2);
        add_action('wp_enqueue_scripts', array( $this ,'isures_reg_script'));
		add_filter('woocommerce_product_data_tabs', array($this, 'isures_create_tab_settings'));
         add_action('woocommerce_product_data_panels', array($this, 'isures_field_in_tab_settings'));
        add_action('woocommerce_process_product_meta', array($this, 'isures_variation_save_fields_in_tab'), 10, 2);
		 add_action('admin_head', array($this, 'isures_tab_style'));
    }
	public function isures_tab_style()
    { ?>
        <style>
            #woocommerce-product-data ul.wc-tabs li.isures-variation_tab a {
                
                color: #0073aa;
            }

            #woocommerce-product-data ul.wc-tabs li.isures-variation_tab a:before {
                   font-family: Dashicons;
    content: "\f111";
				  color: #0073aa;
            }

            fieldset.form-field.radio-isures {
                padding: 20px !important;
                margin: 15px 0;
            }

            .radio-isures legend {
                display: block;
                width: 100%;
                float: none;
                margin: 0 !important;
                font-size: 18px;
                color: #222;
            }

            .radio-isures ul.wc-radios {
                display: flex;
                float: none !important;
            }

            .radio-isures ul.wc-radios label {
                float: none;
                display: block;
                margin: 0 !important;
            }
        </style>
    <?php
    }
	public function isures_create_tab_settings($tabs)
    {
        $tabs['isures-variation'] = array(
            'label'    => 'Cấu hình biến thể nâng cao',
            'target'   => 'isures_variation_settings',
            'class'    => array('show_if_variable'),
            // 'priority' => 1,
        );
        return $tabs;
    }
	 public function isures_field_in_tab_settings()
    {
        global $post;

        $post_id = $post->ID;
		 $scroll = '';
		
		 $scroll = (get_post_meta( $post_id, '_scroll_on_off', true )==''?'off':get_post_meta( $post_id, '_scroll_on_off', true ));
		
		 $type_button = (get_post_meta( $post_id, '_type_active_button', true )==''?'on':get_post_meta( $post_id, '_type_active_button', true ));
		 $url_button = (get_post_meta( $post_id, '_type_link_button', true )==''?'off':get_post_meta( $post_id, '_type_link_button', true ));
    ?>

        <div id="isures_variation_settings" class="panel woocommerce_options_panel">
            <?php

            woocommerce_wp_radio(array(
                'id'            => '_scroll_on_off',
                'label'         => __('Thanh cuộn biến thể', 'isures_com'),
                'wrapper_class' => 'radio-isures',
                'description'   => __('* Bật thanh trượt khi có nhiều biến thể'),
                'options'       => array(
                    'on'       => __('On'),
                    'off'       => __('Off'),
                ),
				'value' => $scroll
            ));
woocommerce_wp_radio(array(
                'id'            => '_type_active_button',
                'label'         => __('Kiểu hiển thị', 'isures_com'),
                'wrapper_class' => 'radio-isures',
                'description'   => __('* Kiểu hiển thị biến thể được chọn'),
                'options'       => array(
                    'on'       => __('Kiểu 1'),
                    'off'       => __('Kiểu 2'),
                ),
				'value' => $type_button
            ));
		 woocommerce_wp_radio(array(
                'id'            => '_type_link_button',
                'label'         => __('Biến thể dạng link', 'isures_com'),
                'wrapper_class' => 'radio-isures',
                'description'   => __('* Chuyển hướng khi biến thể được chọn'),
                'options'       => array(
                    'on'       => __('Yes'),
                    'off'       => __('No'),
                ),
				'value' => $url_button
            ));
            ?>
        </div>
<?php
    }

    public function isures_variation_save_fields_in_tab($post_id)
    {
        if (isset($_POST['_scroll_on_off'])){
            update_post_meta($post_id, '_scroll_on_off', esc_attr($_POST['_scroll_on_off']));
		}
		 if (isset($_POST['_type_active_button'])){
            update_post_meta($post_id, '_type_active_button', esc_attr($_POST['_type_active_button']));
		}
		 if (isset($_POST['_type_link_button'])){
            update_post_meta($post_id, '_type_link_button', esc_attr($_POST['_type_link_button']));
		}
    }
    public function get_product_variation_price($variation_id)
        {

            global $woocommerce;
            $product = new WC_Product_Variation($variation_id);
            return $product->get_price_html(); // Works. Use this if you want the formatted price

        }

        public function variation_radio_buttons($html, $args)
        {
			 global $woocommerce;
         
            $args = wp_parse_args(apply_filters('woocommerce_dropdown_variation_attribute_options_args', $args), array(
                'options'          => false,
                'attribute'        => false,
                'product'          => false,
                'selected'         => false,
                'name'             => '',
                'id'               => '',
                'class'            => '',
                'show_option_none' => __('Choose an option', 'woocommerce'),
            ));
            
                if (false === $args['selected'] && $args['attribute'] && $args['product']) {
                    $selected_key     = 'attribute_' . sanitize_title($args['attribute']);
                    $args['selected'] = isset($_REQUEST[$selected_key]) ? wc_clean(wp_unslash($_REQUEST[$selected_key])) : $args['product']->get_variation_default_attribute($args['attribute']);
                }
            
                $options               = $args['options'];
                $product               = $args['product'];
                $attribute             = $args['attribute'];
                $name                  = $args['name'] ? $args['name'] : 'attribute_' . sanitize_title($attribute);
                $id                    = $args['id'] ? $args['id'] : sanitize_title($attribute);
                $class                 = $args['class'];
                $show_option_none      = (bool) $args['show_option_none'];
                $show_option_none_text = $args['show_option_none'] ? $args['show_option_none'] : __('Choose an option', 'woocommerce');
            
                if (empty($options) && !empty($product) && !empty($attribute)) {
                    $attributes = $product->get_variation_attributes();
                    $options    = $attributes[$attribute];
                }
                //echo $name  ;
                global $post;
        $post_id = $post->ID;
       $scroll = (get_post_meta( $post_id, '_scroll_on_off', true )==''?'off':get_post_meta( $post_id, '_scroll_on_off', true ));
		
		$type_button = (get_post_meta( $post_id, '_type_active_button', true )==''?'on':get_post_meta( $post_id, '_type_active_button', true ));
			 $url_button = (get_post_meta( $post_id, '_type_link_button', true )==''?'off':get_post_meta( $post_id, '_type_link_button', true ));
			$scroll_class = '';
			$type_button_class= '';
        if($scroll == 'on'){
            $scroll_class =  'scroll-on slider slider-nav-simple slider-nav-normal slider-style-normal';
        }else{
            $scroll =  '';
        }
			if($type_button == 'off'){
            $type_button_class =  'type_button_2';
        }
			 wp_enqueue_script('isures-script-variation', ISURES_ELM . '/assets/js/variation.js', array('jquery') , '1.0' ,true);
            wp_enqueue_style('isures-style-variation', ISURES_ELM . '/assets/css/variation.css');
			
									$radios = '<script> var url_button_var = "'. $url_button .'";</script>';
								
                $radios .= '<div class="isures-radio-variable '. $scroll_class .' ' .$type_button_class .'" ' . ($scroll=='on'? 'data-flickity-options=\'{
            "cellAlign": "left",
            "imagesLoaded": true,
            "lazyLoad": 1,
            "freeScroll": false,
           "wrapAround": true,
            "autoPlay": 3000,
            "pauseAutoPlayOnHover" : true,
            "prevNextButtons": true,
            "contain" : true,
            "adaptiveHeight" : true,
            "dragThreshold" : 10,
           
            "pageDots": false,
            "rightToLeft": false,
            "draggable": true
                }\'':'').'>';
            
                 
                // dump_data($attributes);
            
                if (!empty($options)) {
            
            
            
                    $attributes = $product->get_available_variations();
                    foreach ($attributes as $check) {
                        $count_variation = count($check['attributes']);
                    }
                    if ($count_variation < 2) {
                        foreach ($product->get_available_variations() as $test) {
                            
            
                            foreach ($test['attributes'] as $oke) {
							//	var_dump($test);
							  $product_v = new WC_Product_Variation($test['variation_id']);
								//echo $url_button;
								if($url_button == 'on'){
									$radios .= '<a class="isures-option_link" href="'. $product_v->get_permalink()  .'">';
								}
                                $checked    = sanitize_title($args['selected']) === $args['selected'] ? checked($args['selected'], $oke, false) : checked($args['selected'], $oke, false);
                                $radios .= '<label class="isures-option myoption">';
                                $radios    .= '<input data-id="'. $test['variation_id'] .'" type="radio" name="' . esc_attr($name) . '" value="' . $oke . '" ' . $checked . '>';
                                $radios .= '<span class="option-child">' . $oke . '</span>';
								 
                                // Works. Use this if you want the formatted price
                                $radios .= $product_v->get_price_html();
            
                                $radios .= '</label>';
								if($url_button== 'on'){
									$radios .= '</a>';
								}
                            }
                        }
                    } else {
                        foreach ($options as $key => $option) {
                            // dump_data(count($options));
                            $checked    = sanitize_title($args['selected']) === $args['selected'] ? checked($args['selected'], sanitize_title($option), false) : checked($args['selected'], $option, false);
                            $radios .= '<label class="isures-option" for="' . sanitize_title($option) . '">';
                            $radios    .= '<input data-id="'. $test['variation_id'] .'" type="radio" name="' . esc_attr($name) . '" value="' . esc_attr($option) . '" id="' . sanitize_title($option) . '" ' . $checked . '>';
                            $radios .= '<span class="option-child">' . esc_html(apply_filters('woocommerce_variation_option_name', $option)) . '</span>';
							//$radios .= $option['price_html'];
                            $radios .= '</label>';
                        }
                    }
            
                }
            
                $radios .= '</div>';
            
                if(substr($name,0,12) !='attribute_pa'){return $radios . $html; }
			else{
				return $html;
			}
        }

        public function variation_check($active, $variation)
        {
            if (!$variation->is_in_stock() && !$variation->backorders_allowed()) {
                return false;
            }
            return $active;
        }


        public function isures_reg_script()
        {

           // wp_enqueue_script('isures-script-variation', ISURES_ELM . '/assets/js/variation.js', array('jquery') , '1.0' ,true);
           // wp_enqueue_style('isures-style-variation', ISURES_ELM . '/assets/css/variation.css');
           // wp_enqueue_style('isures-fontawe', ISURES_ELM . '/assets/css/all.min.css');
        }

}

new isures_variation_product();

https://t.me/AnonymousX5 - 2025