admin_url( ‘admin-ajax.php’ ),
));
}
}

add_action(‘wp_enqueue_scripts’,’add_script_to_site’);

add_action( ‘wp_ajax_filter_project’, ‘filter_project’ );
add_action( ‘wp_ajax_nopriv_filter_project’, ‘filter_project’ );
function filter_project() {
global $post;
$loaiHinh = $_POST[‘loaiHinh’] && $_POST[‘loaiHinh’] != “all” ? $_POST[‘loaiHinh’] : “”;
$dienTich = $_POST[‘dienTich’] && $_POST[‘dienTich’] != “all” ? $_POST[‘dienTich’] : “”;
$chuDe = $_POST[‘chuDe’] && $_POST[‘chuDe’] != “all” ? $_POST[‘chuDe’] : “”;
$nganSach = $_POST[‘nganSach’] && $_POST[‘nganSach’] != “all” ? $_POST[‘nganSach’] : “”;

$arrayTax = [
‘loai_hinh’ => $loaiHinh,
‘dien_tich’ => $dienTich,
‘chu_de’ => $chuDe,
‘ngan_sach’ => $nganSach,
];

// Build param để hiển thị
$parmQuery = [
‘relation’ => ‘AND’,
];

foreach ($arrayTax as $key => $termId) {
if($termId) {
array_push($parmQuery, [
‘taxonomy’ => $key,
‘field’ => ‘id’,
‘terms’ => array( $termId ),
‘operator’ => ‘IN’
]);
}
}

$args = [
“post_type” => “du-an”,
“posts_per_page” => 100 ,
“tax_query” => $parmQuery
];

$queryFilter = new WP_Query( $args );

$html = “”;
if( $queryFilter->have_posts() ){
while( $queryFilter->have_posts() ){
$queryFilter->the_post();
$acreage = get_field(‘dien_tich’);
$price = get_field(‘chi_phi_dau_tu’);
$location = get_field(‘dia_diem’);
?>

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, __( ‘Free!’, ‘woocommerce’ ) );
} else {
$price = ‘‘ . __( ‘Liên Hệ’, ‘woocommerce’ ) . ‘‘;
}
}
return $price;
}
add_filter( ‘woocommerce_get_price_html’, ‘devvn_wc_custom_get_price_html’, 10, 2 );

function thangdangblog_show_price() {

}

function thangdangblog_custom_product() {
global $product;
global $post;
global $wpdb;
$regular_price = (int)$product->get_regular_price();
$sale_price = (int)$product->get_sale_price();

$results = $wpdb->get_results( “SELECT filters,bulk_adjustments FROM {$wpdb->prefix}wdr_rules WHERE discount_type = ‘wdr_bulk_discount’ AND enabled = 1”, OBJECT );
if($results && count($results) > 0) {
foreach ($results as $key => $data_filter) {
// Mỗi vòng lặp sẽ là một data_filter chứa dữ liệu cài đặt
// Lọc lấy mảng chứa danh sách sản phẩm
$filters = json_decode($data_filter->filters);
$bulk_adjustments = json_decode($data_filter->bulk_adjustments);
$array_product = [];
// Lọc lấy toàn bộ danh sách sản phẩm
foreach ($filters as $key => $value) {
if($value->method == ‘in_list’){
$array_product = array_merge($array_product, $value->value);
}

}

// Kiểm tra xem có sản phẩm đang loop trong đây hay không
// Nếu tồn tại rồi thì thực hiện tính toán để hiển thị
if(in_array($post->ID,$array_product)) {

// Có nhiều mảng trong range để hiển thị
// Do có thể giảm giá dựa vào số lượng mua
if($bulk_adjustments->ranges && count($bulk_adjustments->ranges) > 0){
$arr_price = [];
foreach ($bulk_adjustments->ranges as $key => $value) {
$type_product = $value->type;
if($type_product == ‘percentage’){
$regular_price_a = $product->get_regular_price();
$percent = $value->value;
$price = ($regular_price_a / 100) * $percent;
array_push($arr_price, $price);
}else{
array_push($arr_price, $value->value);
}

}
$price_setting = max($arr_price);

$sale_price = $regular_price – (int)$price_setting;
$product->set_price($sale_price);
$product->set_sale_price($sale_price);
}

break;
}

}

}

$percent = 0;
if($sale_price > 0) {
$percent = 100 – ceil(($sale_price/$regular_price) * 100) ;
}

if($percent > 0){
echo “

“.$percent.”%

“;
}

}
add_action(‘woocommerce_before_shop_loop_item’,’thangdangblog_custom_product’);

add_filter(‘woocommerce_empty_price_html’, ‘thangdangblog_custom_for_price’);

function thangdangblog_custom_for_price() {
global $product;
global $post;

$productName = $product->get_name();
$productLink = $product->get_permalink();
$productImage = $product->get_image();
$productSKU = $product->get_sku();
return “

Mã sản phẩm: