Nội dung: hướng dẫn custom feature image product (ảnh đại diện sản phẩm ) và gallery product (ảnh sản phẩm: nhiều hình ảnh về sản phẩm)
Trước khi anh chi vào bài viết này nên xem qua bài viết Các khái niệm featured image, thumbnail, add image size là gì?
Một số code liên quan đến video:
Remove ảnh đại diện và gallery product mặc định của woocoommerce
add_filter( 'woocommerce_product_tabs', 'add_new_product_tab' );
function add_new_product_tab( $tabs ) {
// Adds the new tab
$tabs['hinh_anh_san_pham'] = array(
'title' => __( 'Hình ảnh sản phẩm', 'woocommerce' ),
'priority' => 50,
'callback' => 'tab_hinh_san_pham'
);
return $tabs;
}
function tab_hinh_san_pham(){
global $post;
$_product_image_gallery = get_post_meta($post->ID,"_product_image_gallery",true);
$_product_image_gallerys = explode("," ,$_product_image_gallery);
if($_product_image_gallerys):
foreach($_product_image_gallerys as $id_image):
//$post_thumbnail_id = get_post_thumbnail_id($id_image);
$src_thumbnail =wp_get_attachment_image_src($id_image ,'full');
?>
<p>
<?php //echo $id_image; ?>
<img src="<?php echo $src_thumbnail[0]; ?>" />
</p>
<?php
endforeach;
endif;
}
|
0 nhận xét: