HEX
Server: LiteSpeed
System: Linux 111n6.sieutocviet.page 3.10.0-1160.el7.x86_64 #1 SMP Mon Oct 19 16:18:59 UTC 2020 x86_64
User: nhathuocat (1048)
PHP: 7.4.30
Disabled: 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
Upload Files
File: /home/nhathuocat/public_html/wp-content/themes/flatsome-child/functions.php
<?php
// Add custom Theme Functions here
add_action('admin_head', 'pvlan_hide_key_active');
function pvlan_hide_key_active() {
	echo '<style>div#flatsome-notice {display: none;}</style>';
}
add_filter('use_block_editor_for_post', '__return_false');

function remove_default_image_sizes( $sizes) {
    unset( $sizes['large']);
    unset( $sizes['thumbnail']);
    unset( $sizes['medium']);
    return $sizes;
}
add_filter('intermediate_image_sizes_advanced', 'remove_default_image_sizes');



// code thêm Brand cho sản phẩm
function brand_pro() {
	$labels = array(
		'name'                       => 'Thương hiệu',
		'singular_name'              => 'Thương hiệu',
		'menu_name'                  => 'Thương hiệu',
		'all_items'                  => 'Tất cả thương hiệu',
		'parent_item'                => 'Thương hiệu cha',
		'parent_item_colon'          => 'Thương hiệu:',
		'new_item_name'              => 'Thêm thương hiệu',
		'add_new_item'               => 'Thêm thương hiệu',
		'edit_item'                  => 'Sửa thương hiệu',
		'update_item'                => 'Cập nhật',
		'separate_items_with_commas' => 'Phân tách thương hiệu bằng dấu phẩy',
		'search_items'               => 'Tìm thương hiệu',
		'add_or_remove_items'        => 'Thêm hoặc xóa thương hiệu',
		'choose_from_most_used'      => 'Chọn từ các Thương hiệu được sử dụng nhiều nhất',
	);
	$args = array(
		'labels'                     => $labels,
		'hierarchical'               => true,
		'public'                     => true,
		'show_ui'                    => true,
		'show_admin_column'          => true,
		'show_in_nav_menus'          => true,
		'show_tagcloud'              => true,
	);
	register_taxonomy( 'thuong-hieu', 'product', $args );
}
add_action( 'init', 'brand_pro', 0 );

if (!function_exists('thuonghieu_abc')) {
	function thuonghieu_abc(){
		$term_arr = array();
		$terms = get_terms( array(
			'taxonomy' => 'thuong-hieu',
			'orderby' => 'name',
			'hide_empty' => false,
		) );
		
		foreach ( $terms as $term ) {
			$brand = $term->name;
			$slug = $term->slug;

			$letter = substr($brand, 0, 1);
			if(!array_key_exists($letter, $term_arr))
				$term_arr[$letter] = array($slug => $brand);
			else
				$term_arr[$letter][$slug] = $brand;
		}

		$output = '<div class="brandlist-container">';
		
		echo '<h1 class="title-thuonghieu">Có <span>'.count($terms).' </span>thương hiệu</h1>';
		echo '<div class="div-thuognhieu">
					<ul>
						<li><a href="#thuong-hieu-A">A</a></li>
						<li><a href="#thuong-hieu-Â">Â</a></li>
						<li><a href="#thuong-hieu-B">B</a></li>
						<li><a href="#thuong-hieu-C">C</a></li>
						<li><a href="#thuong-hieu-D">D</a></li>
						<li><a href="#thuong-hieu-Đ">Đ</a></li>
						<li><a href="#thuong-hieu-E">E</a></li>
						<li><a href="#thuong-hieu-F">F</a></li>
						<li><a href="#thuong-hieu-G">G</a></li>
						<li><a href="#thuong-hieu-H">H</a></li>
						<li><a href="#thuong-hieu-I">I</a></li>
						<li><a href="#thuong-hieu-Í">Í</a></li>
						<li><a href="#thuong-hieu-J">J</a></li>
						<li><a href="#thuong-hieu-K">K</a></li>
						<li><a href="#thuong-hieu-L">L</a></li>
						<li><a href="#thuong-hieu-M">M</a></li>
						<li><a href="#thuong-hieu-N">N</a></li>
						<li><a href="#thuong-hieu-O">O</a></li>
						<li><a href="#thuong-hieu-ô">ô</a></li>
						<li><a href="#thuong-hieu-P">P</a></li>
						<li><a href="#thuong-hieu-R">R</a></li>
						<li><a href="#thuong-hieu-S">S</a></li>
						<li><a href="#thuong-hieu-T">T</a></li>
						<li><a href="#thuong-hieu-U">U</a></li>
						<li><a href="#thuong-hieu-V">V</a></li>
						<li><a href="#thuong-hieu-W">W</a></li>
						<li><a href="#thuong-hieu-X">X</a></li>
						<li><a href="#thuong-hieu-Y">Y</a></li>
						<li><a href="#thuong-hieu-Z">Z</a></li>                    
					</ul>
				</div>';
		
		foreach( $term_arr as $key_letter => $terms_in_letter ){
			$output .= '<div id="thuong-hieu-'.  $key_letter  .'" class="ct-th">'. $key_letter .'</div>
		                  <ul class="brandlist">';
			foreach( $terms_in_letter as $key => $value ){
				$output .= '<li><a href="/thuong-hieu/'.$key.'/">'.$value.'</a></li>';
			}
			$output .= '</ul>';
		}
		$output .= '</div>';

		return $output;
	}
	add_shortcode( 'thuonghieu_abc', 'thuonghieu_abc' );

}

// Khoảng giá
function taxonomy_khoanggia() {
    $labels = array(
        'name'                       => 'Khoảng giá',
        'singular_name'              => 'khoang-gia',
        'menu_name'                  => 'Khoảng giá',
        'all_items'                  => 'Tất cả Khoảng giá',
        'parent_item'                => 'Khoảng giá',
        'new_item_name'              => 'Thêm Khoảng giá',
        'add_new_item'               => 'Thêm Khoảng giá',
        'edit_item'                  => 'Sửa Khoảng giá',
        'update_item'                => 'Cập nhật',
        'search_items'               => 'Tìm Khoảng giá',
		'not_found'           		 => 'Không tìm thấy Khoảng giá',
		'not_found_in_trash'   		 => 'Không tìm thấy Khoảng giá ở thùng rác',
        'add_or_remove_items'        => 'Thêm hoặc xóa Khoảng giá',
        'choose_from_most_used'      => 'Chọn Khoảng giá được sử dụng nhiều',
    );
    $args = array(
        'labels'                     => $labels,
        'hierarchical'               => true,
        'public'                     => true,
        'show_ui'                    => true,
        'show_admin_column'          => true,
        'show_in_nav_menus'          => true,
        'show_tagcloud'              => true,
    );
    register_taxonomy( 'khoang-gia', 'product', $args );
}
add_action( 'init', 'taxonomy_khoanggia', 0 );


// Xuất xứ
function taxonomy_xuatxu() {
    $labels = array(
        'name'                       => 'Xuất xứ',
        'singular_name'              => 'xuat-xu',
        'menu_name'                  => 'Xuất xứ',
        'all_items'                  => 'Tất cả Xuất xứ',
        'parent_item'                => 'Xuất xứ',
        'new_item_name'              => 'Thêm Xuất xứ',
        'add_new_item'               => 'Thêm Xuất xứ',
        'edit_item'                  => 'Sửa Xuất xứ',
        'update_item'                => 'Cập nhật',
        'search_items'               => 'Tìm Xuất xứ',
		'not_found'           		 => 'Không tìm thấy Xuất xứ',
		'not_found_in_trash'   		 => 'Không tìm thấy Xuất xứ ở thùng rác',
        'add_or_remove_items'        => 'Thêm hoặc xóa Xuất xứ',
        'choose_from_most_used'      => 'Chọn Xuất xứ được sử dụng nhiều',
    );
    $args = array(
        'labels'                     => $labels,
        'hierarchical'               => true,
        'public'                     => true,
        'show_ui'                    => true,
        'show_admin_column'          => true,
        'show_in_nav_menus'          => true,
        'show_tagcloud'              => true,
    );
    register_taxonomy( 'xuat-xu', 'product', $args );
}
add_action( 'init', 'taxonomy_xuatxu', 0 );

// Đối tượng
function taxonomy_doituong() {
    $labels = array(
        'name'                       => 'Đối tượng',
        'singular_name'              => 'doi-tuong',
        'menu_name'                  => 'Đối tượng',
        'all_items'                  => 'Tất cả Đối tượng',
        'parent_item'                => 'Đối tượng',
        'new_item_name'              => 'Thêm Đối tượng',
        'add_new_item'               => 'Thêm Đối tượng',
        'edit_item'                  => 'Sửa Đối tượng',
        'update_item'                => 'Cập nhật',
        'search_items'               => 'Tìm Đối tượng',
		'not_found'           		 => 'Không tìm thấy Đối tượng',
		'not_found_in_trash'   		 => 'Không tìm thấy Đối tượng ở thùng rác',
        'add_or_remove_items'        => 'Thêm hoặc xóa Đối tượng',
        'choose_from_most_used'      => 'Chọn Đối tượng được sử dụng nhiều',
    );
    $args = array(
        'labels'                     => $labels,
        'hierarchical'               => true,
        'public'                     => true,
        'show_ui'                    => true,
        'show_admin_column'          => true,
        'show_in_nav_menus'          => true,
        'show_tagcloud'              => true,
    );
    register_taxonomy( 'doi-tuong', 'product', $args );
}
add_action( 'init', 'taxonomy_doituong', 0 );




function pvlan_custom_fields() {
    global $woocommerce, $post;
    echo '<div class="options_group">';
	woocommerce_wp_text_input(
        array(
            'id'          => '_text_quycach',
            'label'       => __( 'Quy cách', 'woocommerce' ),
            'placeholder' => 'Hộp/chai bao nhiêu viên',
        )
    );
    echo '</div>';
}
add_action( 'woocommerce_product_options_reviews', 'pvlan_custom_fields' );

// lưu dữ liệu bảo hành
function pvlan_custom_field_save( $post_id ){
	$woocommerce_text_field = $_POST['_text_quycach'];
    update_post_meta( $post_id, '_text_quycach', esc_attr( $woocommerce_text_field ) );
}
add_action( 'woocommerce_process_product_meta', 'pvlan_custom_field_save' );

function pvlan_show_text_quycach(){
    global $product;
    $data = $product->get_meta( '_text_quycach' );
    if(!empty($data)){
        echo $data;
    }
}
add_shortcode('pvlan_show_text_quycach','pvlan_show_text_quycach');


function show_xuatxu_and_quycach () {
	global $product;
	?>
	
	<div class="ct-xuatxu-qc">
		<table class="table-detail">
			<tbody>
				<tr>
					<td>Xuất xứ</td>
					<td><?php the_terms( $product->get_id(), 'xuat-xu', '', ',' ); ?></td>
				</tr>
				<tr>
					<td>Thương hiệu</td>
					<td><?php the_terms( $product->get_id(), 'thuong-hieu', '', ',' ); ?></td>
				</tr>
				<tr>
					<td>Quy cách</td>
					<td><?php echo do_shortcode('[pvlan_show_text_quycach]'); ?></td>
				</tr>
			</tbody>
		</table>
	</div>

<?php
}
add_shortcode('show_xuatxu_and_quycach', 'show_xuatxu_and_quycach');




// Tách Product Tabs thành các section riêng biệt
if ( ! function_exists( 'woocommerce_output_product_data_tabs' ) ) {
   function woocommerce_output_product_data_tabs() {
      wc_get_template( 'single-product/tabs/tabs.php' );
   }
}

function woocommerce_output_product_data_tabs() {
   $product_tabs = apply_filters( 'woocommerce_product_tabs', array() );
   if ( empty( $product_tabs ) ) return;
  
   foreach ( $product_tabs as $key => $product_tab ) {
      ?>
		<div class="count-cmt"><?php echo do_shortcode('[count_cmt_page_product]'); ?></div>
         <div id="tab-<?php echo esc_attr( $key ); ?>">
            <?php
            if ( isset( $product_tab['callback'] ) ) {
               call_user_func( $product_tab['callback'], $key, $product_tab );
            }
            ?>
         </div>
      <?php         
   }
   echo '</div>';
}

// Xóa Tab Review
add_filter( 'woocommerce_product_tabs', 'woo_remove_product_tabs', 98 );
function woo_remove_product_tabs( $tabs ) {
	unset( $tabs['reviews'] ); // Bỏ tab đánh giá
	unset( $tabs['additional_information'] ); // Bỏ Tab Thông tin bổ sung
	return $tabs;
}
// Di chuyển Tab Review xuống bên dưới nội dung mô tả sản phẩm
function woocommerce_template_product_reviews() {
	woocommerce_get_template( 'single-product-reviews.php' );
}
add_action( 'woocommerce_after_single_product', 'comments_template', 50 );

function itcodewp_widgets_init(){
    register_sidebar( array(
        'name'          => __( 'Sidebar Fixed Toc', 'text_domain' ),
        'id'            => 'sidebar-fix-toc',
        'description'   => __( 'Kéo Widget vào đây', 'text_domain' ),
        'before_widget' => '<section id="%1$s" class="widget sb-right %2$s">',
        'after_widget'  => '</section>',
        'before_title'  => '<h2 class="widget-title">',
        'after_title'   => '</h2>',
    ) );
}
add_action( 'widgets_init', 'itcodewp_widgets_init' );


function addstar_itcodewp(){
	if ( is_singular( 'product' ) ) {
	  global $product;
	  $rating_arr = $product->get_rating_counts();
	  $review_count = $product->get_rating_count();
	  $countstar = $product->get_average_rating();
	  if($countstar=='0'){$countstar = '<span class="no-cmt">Chưa có đánh giá</span>';}?>
	  <div class="ct-rating row row-small align-middle" id="danhgia">
		  <div class="ct-rating__total col large-3 small-5">
			<div class="title-rating hide-for-small">Điểm đánh giá trung bình</div>
			<div class="rating_total"><?php echo $countstar;?> </div>
			<div class="star-rating-custom"><?php echo wc_get_rating_html( $countstar, $review_count );?></div>
			  <div class="tong-cmt">
				  ( <?php echo $review_count ?> nhận xét )
			  </div>
		  </div>
		  <div class="ct-rating__bar col large-5 small-7 ">
			<div class="bar-star">
				<?php for ($i=5; $i >0 ; $i--) { 
					$rating_count = 0;
					$rating_per = 0;
					if(isset($rating_arr[$i])){
					  $rating_count = $rating_arr[$i];
					  $rating_per = round(($rating_count/$review_count)*100,0);
					  }
					  echo '<div class="itcode-row star-rating-'.$i.'">';
					  echo '<div class="itcode-icon-star">'.$i.'</div>';
					  echo '<div class="itcode-col-2"><div class="itcode-meter-bar"><div class="itcode-bar-temperature" style="width:'.$rating_per.'%"></div></div></div>';
					  echo '<div class="itcode-col-3">'.$rating_count.'</div>';
					  echo '</div>';
				};?>
			</div>
		  </div>
		  <div class="col large-1 hide-for-small">
			  
		  </div>
		  <div class="ct-rating_cmt col large-3 small-12 ">
			  <span class="cs-textcsnxvb">Chia sẻ nhận xét</span>
			  <div class="btn-cmt-ct">Đánh giá và nhận xét</div>
		  </div>
	  </div>
		<style>
			.ct-rating_cmt button{
				border: 1px solid transparent;
				border-radius: 4px;
				padding: 12px 16px;
				font-size: 14px;
				line-height: 14px;
				color: #fff;
				background: #60842a;
			}
			.rating_total {
				font-size: 30px;
				line-height: 60px;
				color: #ff9400;
				font-weight: 600;
			}
			.tong-cmt {
				margin-top: 10px;
			}
			.title-rating{
				font-size:18px;
				line-height: 20px;
			}
			.itcode-bar-temperature{
				height: 100%;
				background:#ff9400;
				border-radius: 5px;
			}
			.fa-star {
				font-size: 13px;
				color: #ea9d02;
				margin-left: 3px;
			}
			.itcode-icon-star{
				width: 35px;
				display: flex;
				justify-content: space-around;
				align-items: center;
				text-align: left;
			}
			.itcode-icon-star:after {
				content: "";
				color: #ff9400;
				font-family: 'fl-icons';
			}
			.ct-rating__total,.ct-rating_cmt{
				text-align:center
			}
			.star-rating-custom .star-rating{
				margin:auto;
			}
			.itcode-col-2{
				width:100%;
				margin:auto 10px;
			}
			.itcode-meter-bar{
				border-radius: 5px;
				height: 10px;
				width: 100%;
				background: #d2d2d2;
			}
			.itcode-row{
				display: flex;
				align-items: center;
				justify-content: space-between;
			}
			.star-cust {
				height: 15px;
				margin: auto;
			}
			.btn-cmt-ct {
				background: #f67167;
				color: #fff;
				text-align: center;
				border: none !important;
				padding: 8px;
				cursor: pointer;
				border-radius: 4px;
				line-height: 22px;
				margin-top: 5px;
			}
			span.cs-textcsnxvb {
				font-size: 14px;
			}
			@media (max-width: 549px) {
				.rating_total {
					font-size: 18px;
					line-height: 24px;
				}
			}
		</style>
	<?php 
	}
}
add_filter( 'comments_template', 'addstar_itcodewp', 10 );

// ước tính thời gian đọc
function itcodewp_estimated_reading_time( $content = '') {
    $wpm = 150;         
    $text_content = strip_shortcodes( $content );     
    $str_content = strip_tags( $text_content );      
    $word_count = str_word_count( $str_content );
    $readtime = ceil( $word_count / $wpm );
    if ($readtime == 1) {
        $postfix = " Phút";
    } else {
        $postfix = " Phút";
    }
    $readingtime = $readtime . $postfix;
    return $readingtime;
}

// code tính số lượt bình luận cho mỗi sản phẩm cụ thể
function pvlan_post_comment_count() { 
	function comment_count( $count ) {
		if (is_admin() ) {
			global $product; 
			$comments_by_type = &separate_comments(get_comments('status=approve&product_id='. $product->get_id() ));
			return count($comments_by_type['comment']);
		} else {
			return $count;
		}
	}
	add_filter('get_comments_number', 'comment_count', 0);
	
	$actual_comment_count = get_comments_number(); 
	return $actual_comment_count;
}
add_shortcode('post_comment_count', 'pvlan_post_comment_count');

add_shortcode('count_cmt_page_product', 'count_cmt_page_product');
function count_cmt_page_product() {
    global $product;
	
	?>
	<div class="ct-scroll">
		<ul class="">
			<li><span><b>Nội dung</b></span></li>
			<li><a href="#hoidap">Hỏi & Đáp <i id="bg-count"><?php echo do_shortcode('[post_comment_count]'); ?></i></a></li>
			<li><a href="#danhgia">Đánh giá <i id="bg-count"><?php echo $product->get_review_count(); ?></i></a></li>
			
		</ul>
	</div>
<?php
}

// thay đổi text button add to cart
add_filter( 'woocommerce_product_single_add_to_cart_text', 'pv_custom_cart_button_text' );
function pv_custom_cart_button_text() {
  return __( 'Thêm vào giỏ', 'woocommerce' );
}


add_filter( 'woocommerce_product_add_to_cart_text', 'pv_archive_custom_cart_button_text' );
function pv_archive_custom_cart_button_text() {
    return __( 'Thêm vào giỏ', 'woocommerce' );
}

//add_action('woocommerce_after_add_to_cart_button', 'yeu_cau_goi_lai');
function yeu_cau_goi_lai () {
	echo do_shortcode('[contact-form-7 id="119" title="Form yêu cầu gọi lại"]');
}

add_action('wp_footer', 'popup_form_tai_len_don_thuoc');
function popup_form_tai_len_don_thuoc () {
	echo do_shortcode('[lightbox id="don-thuoc" width="400px" padding="20px"][contact-form-7 id="129" title="Tải lên đơn thuốc"][/lightbox]');
}


add_action('wp_footer', 'add_code_js_click_show_comment_product');
function add_code_js_click_show_comment_product () {
	?>
		<script type="text/javascript">
			jQuery(document).ready(function($){
    			$(function () {
					$('.review-form-inner.has-border').hide();
					$('.btn-cmt-ct').click(function(){
						$('.review-form-inner.has-border').show();
					})
				});
			});
		</script>
<?php
}

//  Thêm nút mua ngay vào woocommerce
add_action('woocommerce_after_add_to_cart_button','kids_quickbuy_after_addtocart_button');
function kids_quickbuy_after_addtocart_button(){
    global $product;
    ?>
    <button type="submit" name="add-to-cart" value="<?php echo esc_attr($product->get_id()); ?>" class="single_add_to_cart_button button alt btn-muangay" id="buy_now_button">
        <?php _e('Mua ngay', 'kids'); ?>
    </button>
    <input type="hidden" name="is_buy_now" id="is_buy_now" value="0" />
    <script>
        jQuery(document).ready(function(){
            jQuery('body').on('click', '#buy_now_button', function(){
                if(jQuery(this).hasClass('disabled')) return;
                var thisParent = jQuery(this).closest('form.cart');
                jQuery('#is_buy_now', thisParent).val('1');
                thisParent.submit();
            });
        });
    </script>
    <?php
	echo do_shortcode('[contact-form-7 id="119" title="Form yêu cầu gọi lại"]');
}
add_filter('woocommerce_add_to_cart_redirect', 'redirect_to_checkout');
function redirect_to_checkout($redirect_url) {
    if (isset($_REQUEST['is_buy_now']) && $_REQUEST['is_buy_now']) {
        $redirect_url = wc_get_checkout_url();
    }
    return $redirect_url;
}


// thêm mailer
add_action( 'phpmailer_init', function( $phpmailer ) {
    if ( !is_object( $phpmailer ) )
    $phpmailer = (object) $phpmailer;
    $phpmailer->Mailer     = 'smtp';
    $phpmailer->Host       = 'smtp.gmail.com';
    $phpmailer->SMTPAuth   = 1;
    $phpmailer->Port       = 587;
    $phpmailer->Username   = 'phamvanlan1601@gmail.com';
    $phpmailer->Password   = 'jttqzlrrfqypwtns';
    $phpmailer->SMTPSecure = 'TLS';
    $phpmailer->From       = 'phamvanlan1601@gmail.com';
    $phpmailer->FromName   = 'Mẫu Website bán thuốc - Mẫu website được phẩm';
});
// end mailer
/* code trang checkout */
add_filter( 'woocommerce_checkout_fields' , 'custom_checkout_form' );
function custom_checkout_form( $fields ) {
    unset($fields['billing']['billing_postcode']); //Ẩn postCode
    unset($fields['billing']['billing_state']); //Ẩn bang hạt
    unset($fields['billing']['billing_country']);// Ẩn quốc gia
    unset($fields['billing']['billing_address_2']); //billing_company
    unset($fields['billing']['billing_company']);
    unset($fields['billing']['billing_last_name']);
    unset($fields['billing']['order_comments']);// Ẩn quốc gia
    unset($fields['billing']['billing_city']); //Ẩn select box chọn thành phố
    //unset($fields['billing']['billing_email']); //Ẩn select box chọn thành phố
     $fields['billing']['billing_first_name']['placeholder'] = "Họ và tên";
     $fields['billing']['billing_phone']['placeholder'] = "Số điện thoại";
     $fields['billing']['billing_email']['placeholder'] = "Email nhận hóa đơn";
    return $fields;
}
function custom_checkout_field_label( $fields ) {
    $fields['address_1']['label'] = 'Địa chỉ giao sản phẩm';
    $fields['first_name']['label'] = 'Tên';
    return $fields;
}
add_filter( 'woocommerce_default_address_fields', 'custom_checkout_field_label' );