facebook-icon

Hướng dẫn tạo bảng giá sản phẩm kim cương đẹp

34482966 2043001085951205 8004582827897126912 n

 

CHÈN BẢNG MÃ : [table_kim_cuong id_cat=”71″]

<?php
add_action(‘woocommerce_template_loop_price’, ‘woocommerce_template_loop_price’, 10);

/**
* Theme options
*/
function table_kim_cuong($id, $content) {
$args = array(
‘post_type’ => ‘product’,
‘posts_per_page’ => -1,
‘no_found_rows’ => true,
‘post_status’ => ‘publish’,
‘cache_results’ => false,
‘update_post_meta_cache’ => false,
‘update_post_term_cache’ => false,
‘meta_query’ => WC()->query->get_meta_query(),
‘tax_query’ => WC()->query->get_tax_query()
);
$args[‘tax_query’] = array(
array(
‘taxonomy’ => ‘product_cat’,
‘field’ => ‘id’,
‘terms’ => $id[‘id_cat’],
),
);

$products = new WP_Query($args);
echo ‘<div class=”table-kimcuong-wrap”>’;
if ($products->have_posts()) :
$count = $products->post_count;
echo ‘<h3 class=”title”>’.$count . ‘ VIÊN KIM CƯƠNG</h3>’;
?>
<table>
<thead>
<tr>
<th class=”product-thumbnail”><?php esc_html_e(‘Hình dáng’, ‘flatsome’); ?></th>
<th class=”product-title”><?php esc_html_e(‘Tên sản phẩm’, ‘flatsome’); ?></th>
<th class=”product-kichthuoc”><?php esc_html_e(‘Kích thước’, ‘flatsome’); ?></th>
<th class=”product-mausac”><?php esc_html_e(‘Màu sắc’, ‘flatsome’); ?></th>
<th class=”product-dotinhkhiet”><?php esc_html_e(‘Độ tinh khiết’, ‘flatsome’); ?></th>
<th class=”product-netcat”><?php esc_html_e(‘Nét cắt’, ‘flatsome’); ?></th>
<th class=”product-gia”><?php esc_html_e(‘Giá’, ‘flatsome’); ?></th>
<th class=”product-chitiet”><?php esc_html_e(‘Chi tiết’, ‘flatsome’); ?></th>
</tr>
</thead>
<tbody>
<?php
while ($products->have_posts()) : $products->the_post();
$post_id = get_the_ID();
$thumb = get_the_post_thumbnail($post_id, array(80, 80));
$res = get_post_meta($post_id, ‘_product_attributes’, true);
$kichthuoc = get_post_meta($post_id, ‘_kc_kichthuoc’, true);
$mausac = get_post_meta($post_id, ‘_kc_mausac’, true);
$dotinhkhiet = get_post_meta($post_id, ‘_kc_dotinhkhiet’, true);
$netcat = get_post_meta($post_id, ‘_kc_netcat’, true);
//print_r($res);
?>
<tr>
<td><?php echo $thumb; ?></td>
<td><?php the_title(); ?></td>
<td><?php echo $kichthuoc; ?></td>
<td><?php echo $mausac; ?></td>
<td><?php echo $dotinhkhiet; ?></td>
<td><?php echo $netcat; ?></td>
<td><?php do_action(‘woocommerce_template_loop_price’); ?></td>
<td><a class=”btn-xem” href=”<?php echo esc_url(the_permalink()); ?>”><?php echo esc_html__(‘Xem’, ‘flatsome’) ?></a></td>
</tr>
<?php
endwhile; // end of the loop.
?>
</tbody>
</table>
<?php
endif;
echo ‘</div>’;
}

add_shortcode(‘table_kim_cuong’, ‘table_kim_cuong’);

add_action(‘woocommerce_product_options_pricing’, ‘nhogem_woocommerce_product_options_kichthuoc’);

function nhogem_woocommerce_product_options_kichthuoc() {
woocommerce_wp_text_input(
array(
‘id’ => ‘_kc_kichthuoc’,
‘class’ => ‘wc_input_kc_kichthuoc short’,
‘label’ => __(‘Kích thước’, ‘flatsome’),
‘type’ => ‘text’
)
);
}

add_action(‘woocommerce_product_options_pricing’, ‘nhogem_woocommerce_product_options_mausac’);

function nhogem_woocommerce_product_options_mausac() {
woocommerce_wp_text_input(
array(
‘id’ => ‘_kc_mausac’,
‘class’ => ‘wc_input_kc_mausac short’,
‘label’ => __(‘Màu sắc’, ‘flatsome’),
‘type’ => ‘text’
)
);
}

add_action(‘woocommerce_product_options_pricing’, ‘nhogem_woocommerce_product_options_dotinhkhiet’);

function nhogem_woocommerce_product_options_dotinhkhiet() {
woocommerce_wp_text_input(
array(
‘id’ => ‘_kc_dotinhkhiet’,
‘class’ => ‘wc_input_kc_dotinhkhiet short’,
‘label’ => __(‘Độ tinh khiết’, ‘flatsome’),
‘type’ => ‘text’
)
);
}

add_action(‘woocommerce_product_options_pricing’, ‘nhogem_woocommerce_product_options_netcat’);

function nhogem_woocommerce_product_options_netcat() {
woocommerce_wp_text_input(
array(
‘id’ => ‘_kc_netcat’,
‘class’ => ‘wc_input_kc_netcat short’,
‘label’ => __(‘Nét cắt’, ‘flatsome’),
‘type’ => ‘text’
)
);
}

add_action(‘woocommerce_process_product_meta_simple’, ‘nhogem_woocommerce_process_product_meta_simple’, 10, 1);

function nhogem_woocommerce_process_product_meta_simple($product_id) {
if (isset($_POST[‘_kc_kichthuoc’]) && $_POST[‘_kc_kichthuoc’] != ”) {
update_post_meta($product_id, ‘_kc_kichthuoc’, $_POST[‘_kc_kichthuoc’]);
}
if (isset($_POST[‘_kc_mausac’]) && $_POST[‘_kc_mausac’] != ”) {
update_post_meta($product_id, ‘_kc_mausac’, $_POST[‘_kc_mausac’]);
}
if (isset($_POST[‘_kc_dotinhkhiet’]) && $_POST[‘_kc_dotinhkhiet’] != ”) {
update_post_meta($product_id, ‘_kc_dotinhkhiet’, $_POST[‘_kc_dotinhkhiet’]);
}
if (isset($_POST[‘_kc_netcat’]) && $_POST[‘_kc_netcat’] != ”) {
update_post_meta($product_id, ‘_kc_netcat’, $_POST[‘_kc_netcat’]);
}
}

/* custom admin user */
function custom_user_table($column) {
$column[‘phone’] = ‘Điện thoại’;
return $column;
}

add_filter(‘manage_users_columns’, ‘custom_user_table’);

function custom_user_table_row($val, $column_name, $user_id) {
switch ($column_name) {
case ‘phone’ :
return get_the_author_meta(‘phone’, $user_id);
break;
default:
}
return $val;
}

add_filter(‘manage_users_custom_column’, ‘custom_user_table_row’, 10, 3);

function custom_user_profile_fields($user) {
?>
<h3>Thông tin hồ sơ bổ sung</h3>
<table class=”form-table”>
<tr>
<th><label for=”phone”>Số điện thoại</label></th>
<td>
<input type=”text” class=”regular-text” name=”phone” value=”<?php echo esc_attr(get_the_author_meta(‘phone’, $user->ID)); ?>” id=”phone” /><br />
<span class=”description”>Thêm số điện thoại</span>
</td>
</tr>
</table>
<?php
}

add_action(‘show_user_profile’, ‘custom_user_profile_fields’);
add_action(‘edit_user_profile’, ‘custom_user_profile_fields’);
add_action(“user_new_form”, “custom_user_profile_fields”);

function save_custom_user_profile_fields($user_id) {
# again do this only if you can
if (!current_user_can(‘manage_options’))
return false;

# save my custom field
update_usermeta($user_id, ‘phone’, $_POST[‘phone’]);
}

add_action(‘user_register’, ‘save_custom_user_profile_fields’);
add_action(‘profile_update’, ‘save_custom_user_profile_fields’);

 

 

MÃ STYLE :

.table-kimcuong-wrap{
font-family: ‘Open Sans’, sans-serif;
overflow: auto;
}
.table-kimcuong-wrap .title {
font-family: ‘Jura’, sans-serif;
font-size: 32px;
line-height: 40px;
text-transform: uppercase;
text-align: center;
margin-bottom: 25px;
}
.table-kimcuong-wrap a.btn-xem {
display: inline-block;
font-size: 13px;
line-height: 21px;
font-weight: bold;
background: #565656;
color: #ffffff;
padding: 4px 12px;
border-radius: 5px;
}
.table-kimcuong-wrap a.btn-xem:hover {
background: #444444;
color: #ffffff;
}
.table-kimcuong-wrap tr th {
padding: 10px;
font-size: 13px;
line-height: 21px;
border: solid 1px #565656;
border-right: none;
text-align: center;
}
.table-kimcuong-wrap tr th:last-child {
border-right: solid 1px #565656;
}
.table-kimcuong-wrap tr td {
padding: 25px 10px;
border-bottom: solid 1px #565656;
text-align: center;
}
.table-kimcuong-wrap tr td:first-child {
border-left: solid 1px #565656;
}
.table-kimcuong-wrap tr td:last-child {
border-right: solid 1px #565656;
}

 

5/5 - (100 bình chọn)