Các hàm hiển thị dữ liệu trong Woocommerce – WordPress Nâng cao

Tăng giảm số lượng sản phẩm và nút mua hàng

<form class=”cart” action=”<?php the_permalink() ?>” method=”post” enctype=”multipart/form-data”>
<div class=”quantity”>
<input type=”number” step=”1″ min=”1″ max=”9″ name=”quantity” value=”1″ title=”<?php _e(‘Szt.’, ‘my-theme’); ?>” class=”input-text qty text” size=”4″>
</div>
<input type=”hidden” name=”add-to-cart” value=”<?php echo esc_attr($product->id); ?>”>
<button type=”submit”><?php echo $product->single_add_to_cart_text(); ?></button>
</form>

Hiển thị ảnh chi tiết và thumbnails

<div class=”images”>
<?php
if ( has_post_thumbnail() ) {
$image_caption = get_post( get_post_thumbnail_id() )->post_excerpt;
$image_link    = wp_get_attachment_url( get_post_thumbnail_id() );
$image         = get_the_post_thumbnail( $post->ID, apply_filters( ‘single_product_large_thumbnail_size’, ‘shop_single’ ), array(
‘title’ => get_the_title( get_post_thumbnail_id() )
) );

$attachment_count = count( $product->get_gallery_attachment_ids() );

if ( $attachment_count > 0 ) {
$gallery = ‘[product-gallery]’;
} else {
$gallery = ”;
}

echo apply_filters( ‘woocommerce_single_product_image_html’, sprintf( ‘<a href=”%s” itemprop=”image” class=”woocommerce-main-image zoom” title=”%s” data-rel=”prettyPhoto’ . $gallery . ‘”>%s</a>’, $image_link, $image_caption, $image ), $post->ID );

} else {

echo apply_filters( ‘woocommerce_single_product_image_html’, sprintf( ‘<img src=”%s” alt=”%s” />’, wc_placeholder_img_src(), __( ‘Placeholder’, ‘woocommerce’ ) ), $post->ID );

}
?>

<?php do_action( ‘woocommerce_product_thumbnails’ ); ?>
</div>

Vòng lặp hiển thị sản phẩm căn bản

<?php
$params = array(‘posts_per_page’ => 5, ‘post_type’ => ‘product’);
$wc_query = new WP_Query($params);
?>
<?php if ($wc_query->have_posts()) : ?>
<?php while ($wc_query->have_posts()) :
$wc_query->the_post(); ?>
<?php the_title(); ?>
<?php endwhile; ?>
<?php wp_reset_postdata(); ?>
<?php else:  ?>
<p>
<?php _e( ‘No Products’); ?>
</p>
<?php endif; ?>

1 số hàm cơ bản

the_title () – Hiển thị tên của sản phẩm.
the_excerpt () – Hiển thị một mô tả ngắn gọn của sản phẩm.
the_content () – Hiển thị mô tả đầy đủ của sản phẩm.
the_permalink () – Hiển thị các URL của sản phẩm.
the_ID () – Hiển thị ID của sản phẩm.
the_post_thumbnail () – Hiển thị các hình ảnh sản phẩm.

Hiển thị giá sản phẩm

<?php echo $product->get_price_html(); ?>

Trả lời

Email của bạn sẽ không được hiển thị công khai. Các trường bắt buộc được đánh dấu *