Một số đoạn code thêm vào Function.php

// Hiển thị Liên hệ khi giá 0 đồng

function chowordpress_wc_custom_get_price_html( $price, $product ) {
if ( $product->get_price() == 0 ) {
if ( $product->is_on_sale() && $product->get_regular_price() ) {
$regular_price = wc_get_price_to_display( $product, array( ‘qty’ => 1, ‘price’ => $product->get_regular_price() ) );

$price = wc_format_price_range( $regular_price, __( ‘Liên hệ’, ‘woocommerce’ ) );
} else {
$price = ‘<span class=”amount”>’ . __( do_shortcode(‘<span class=”amount”><a href=”#bao-gia” target=”_self” class=”button primary”>#<span>LIÊN HỆ</span></a></span>’), ‘woocommerce’ ) . ‘</span>’;
}
}
return $price;
}
add_filter( ‘woocommerce_get_price_html’, ‘chowordpress_wc_custom_get_price_html’, 10, 2 );

// Số lượng =1 hiển thị Liên hệ. Số lượng khác 1 hiển Thị download Cataloge

function chowordpress_wc_custom_get_price_html( $price, $product ) {
if ( $product->get_price() == 0 ) {
if ( $product->is_on_sale() && $product->get_regular_price() ) {
$regular_price = wc_get_price_to_display( $product, array( ‘qty’ => 1, ‘price’ => $product->get_regular_price() ) );

$price = wc_format_price_range( $regular_price, __( ‘Liên hệ’, ‘woocommerce’ ) );
} else {
$price = ‘<span class=”amount”>’ . __( do_shortcode(‘<span class=”amount”><a href=”#bao-gia” target=”_self” class=”button primary”><i class=”fas fa-download”></i><span>Catalogue</span></a></span>

‘), ‘woocommerce’ ) . ‘</span>’;
}
}
return $price;
}
add_filter( ‘woocommerce_get_price_html’, ‘chowordpress_wc_custom_get_price_html’, 10, 2 );

//Tiết kiệm tiền mua sản phẩm

function ts_you_save() {

global $product;

if( $product->is_type(‘simple’) || $product->is_type(‘external’) || $product->is_type(‘grouped’) ) {

$regular_price = get_post_meta( $product->get_id(), ‘_regular_price’, true );
$sale_price = get_post_meta( $product->get_id(), ‘_sale_price’, true );

if( !empty($sale_price) ) {

$amount_saved = $regular_price – $sale_price;
$currency_symbol = get_woocommerce_currency_symbol();
$percentage = round( ( ( $regular_price – $sale_price ) / $regular_price ) * 100 );
?>
<p >Tiết kiệm: <b><span style=”font-size:20px;color:red;”> <?php echo number_format($percentage,0, ”, ”).’%’; ?> </span></b></p>
<?php
}
}
}
add_action( ‘woocommerce_single_product_summary’, ‘ts_you_save’, 11 );

//CHEN QUANG CAO VAO GIUA BAI VIET – P1

add_filter( ‘the_content’, ‘prefix_insert_post_ads’ );

function prefix_insert_post_ads( $content ) {

$ad_code = ‘<div> <p><a href=”https://zlove.com.vn/?utm_source=SEO&amp;utm_campaign=BANNER-LASEN&amp;utm_content=DUC&amp;utm_medium=WEBLASEN” rel=”nofollow” target=”blank” title=”trang chủ website zlove chính hãng”><img src=”https://zlove.com.vn/wp-content/uploads/banner-giua-bai-viet-zlove-com-vn.gif” alt=”banner quảng cáo viên uống zlove”/></a> </p></div>’;

if ( is_single() && !is_admin() ) {
return prefix_insert_after_paragraph( $ad_code, 6, $content );
}

return $content;
}

//CHEN QUANG CAO VAO GIUA BAI VIET – P2

function prefix_insert_after_paragraph( $insertion, $paragraph_id, $content ) {
$closing_p = ‘</p>’;
$paragraphs = explode( $closing_p, $content );
foreach ($paragraphs as $index => $paragraph) {

if ( trim( $paragraph ) ) {
$paragraphs[$index] .= $closing_p;
}

if ( $paragraph_id == $index + 1 ) {
$paragraphs[$index] .= $insertion;
}
}

return implode( ”, $paragraphs );
}

// Việt hóa một vài cụm từ tiếng Anh
function my_custom_translations( $translated_text, $text, $domain ) {
$translations = array(
‘CATEGORY ARCHIVES’ => ‘Danh mục’,
‘Quick View’ => ‘Xem nhanh’,
‘SHOPPING CART’ => ‘Giỏ hàng’,
‘CHECKOUT DETAILS’ => ‘Thanh toán’,
‘TAG ARCHIVES’ => ‘Thẻ bài viết’,
‘ORDER COMPLETE’ => ‘Hoàn thành’
);

// So khớp không phân biệt hoa thường
foreach ( $translations as $original => $translated ) {
if ( stripos( $translated_text, $original ) !== false ) {
return str_ireplace( $original, $translated, $translated_text );
}
}

return $translated_text;
}
add_filter( ‘gettext’, ‘my_custom_translations’, 20, 3 );

// Một số lệnh truy vấn xóa dữ liệu
SELECT * FROM `wp_users` WHERE `user_login` LIKE ‘%blog%’;
DELETE FROM `wp_users` WHERE `user_login` LIKE ‘%blog%’;
 
 
//Xóa database
DROP DATABASE ten_co_so_du_lieu;
 
// Đổi tên bảng
ALTER TABLE tên_bảng_hiện_tại
RENAME TO tên_mới;
 
// Thêm khóa chính vào bảng đã tạo
ALTER TABLE nhanvien
ADD CONSTRAINT nhanvien_pk PRIMARY KEY (nhanvien_id);