Skip to content

Instantly share code, notes, and snippets.

@asadaly111
Last active October 11, 2018 15:25
Show Gist options
  • Save asadaly111/2f260958a3281f98ae1cbe8fa8d83e8e to your computer and use it in GitHub Desktop.
Save asadaly111/2f260958a3281f98ae1cbe8fa8d83e8e to your computer and use it in GitHub Desktop.
WooCommerce Product Loop
//get product url with its id
$url = get_permalink( $product_id );
<?php
$args = array(
'post_type' => 'product',
'product_cat' => 'feature',
'posts_per_page' => 3
);
$loop = new WP_Query( $args );
if ( $loop->have_posts() ) {
while ( $loop->have_posts() ) : $loop->the_post();
?>
<div class="col-md-4">
<li id="my_calss" class="post-24 product type-product status-publish has-post-thumbnail first instock shipping-taxable purchasable product-type-simple">
<a href="<?php the_permalink(); ?>" class="woocommerce-LoopProduct-link">
<?php
global $woocommerce;
$currency = get_woocommerce_currency_symbol();
$price = get_post_meta( get_the_ID(), '_regular_price', true);
$sale = get_post_meta( get_the_ID(), '_sale_price', true);
?>
<?php if($sale) : ?>
<p class="product-price-tickr"><del><?php echo $currency; echo $price; ?></del> <?php echo $currency; echo $sale; ?></p>
<?php elseif($price) : ?>
<p class="product-price-tickr"><?php echo $currency; echo $price; ?></p>
<?php endif; ?>
<?php
if ( has_post_thumbnail() ) {
$image_title = esc_attr( get_the_title( get_post_thumbnail_id() ) );
$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' => $image_title,
'alt' => $image_title
) );
$attachment_count = count( $product->get_gallery_attachment_ids() );
if ( $attachment_count > 0 ) {
$gallery = '[product-gallery]';
} else {
$gallery = '';
}
apply_filters( 'woocommerce_single_product_image_html', sprintf($image_link, $image_caption, $image ), $post->ID );
echo "<img width='300' height='300' src=".$image_link." class='img img-responsive'>";
} else {
echo apply_filters( 'woocommerce_single_product_image_html', sprintf( '<img src="%s" alt="%s" class="img img-responsive"/>', wc_placeholder_img_src(), __( 'Placeholder', 'woocommerce' ) ), $post->ID );
}
?>
<?php do_action( 'woocommerce_product_thumbnails' ); ?>
<div class="pro-info">
<h3><?php the_title(); ?></h3>
<p style="color:black;">$<?php echo $price = get_post_meta( get_the_ID(), '_sale_price', true); ?></p>
</div>
</a>
</li>
</div>
<?php
// end loop here
endwhile;
} else {
echo __( 'No products found' );
}
wp_reset_postdata();
?>
<!-- SHOW WOOCOOMMERCE POST META -->
<?php echo $price = get_post_meta( get_the_ID(), '_price', true); ?>
_price =
_stock_status = outofstock
_downloadable = yes
_wpuf_form_id = 43
_edit_lock = 1370858513:1
_edit_last = 1
_visibility = visible
total_sales = 0
_virtual = no
_product_image_gallery =
_regular_price =
_sale_price =
_tax_status =
_tax_class =
_purchase_note =
_featured = no
_weight =
_length =
_width =
_height =
_sku =
_product_attributes = a:1:{s:7:"pa_test";a:6:{s:4:"name";s:7:"pa_test";s:5:"value";s:0:"";s:8:"position";s:1:"0";s:10:"is_visible";i:1;s:12:"is_variation";i:0;s:11:"is_taxonomy";i:1;}}
_sale_price_dates_from =
_sale_price_dates_to =
_sold_individually =
_stock =
_backorders = no
_manage_stock = no
_file_paths = a:0:{}
_download_limit =
_download_expiry =
linked_item = 0
Double click for select all.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment