guys
trying so long add quantity category page and home page but not success yet.
add bellow code in function. it working category page. no problem. but it not added in homage recent product.. hompage recent short code was
[recent_products per_page="16" columns="4"]
/**
* start the customisation
*/
function custom_woo_before_shop_link()
{
add_filter('woocommerce_loop_add_to_cart_link', 'custom_woo_loop_add_to_cart_link', 10, 2);
add_action('woocommerce_after_shop_loop', 'custom_woo_after_shop_loop');
}
add_action('woocommerce_before_shop_loop', 'custom_woo_before_shop_link');
/**
* customise Add to Cart link/button for product loop
* @param string $button
* @param object $product
* @return string
*/
function custom_woo_loop_add_to_cart_link($button, $product)
{
// not for variable, grouped or external products
if (!in_array($product->product_type, array(
'variable',
'grouped',
'external'
))) {
// only if can be purchased
if ($product->is_purchasable()) {
// show qty +/- with button
ob_start();
woocommerce_simple_add_to_cart();
$button = ob_get_clean();
// modify button so that AJAX add-to-cart script finds it
$replacement = sprintf('data-product_id="%d" data-quantity="1" $1 add_to_cart_button product_type_simple ', $product->id);
$button = preg_replace('/(class="single_add_to_cart_button)/', $replacement, $button);
}
}
return $button;
}
/**
* add the required JavaScript
*/
function custom_woo_after_shop_loop()
{
?>
<script>
jQuery(function($) {
<?php
/* when product quantity changes, update quantity attribute on add-to-cart button */
?>
$("form.cart").on("change", "input.qty", function() {
$(this.form).find("button[data-quantity]").attr("data-quantity", this.value);
});
<?php
/* remove old "view cart" text, only need latest one thanks! */
?>
$(document.body).on("adding_to_cart", function() {
$("a.added_to_cart").remove();
});
});
</script>
<?php
}
Another way tried.
bellow code added in index.php but can not add quantity field manually . any idea how
<?php
$args = array(
'post_type' => 'product',
'stock' => 1,
'posts_per_page' => 16,
'orderby' =>'date',
'order' => 'DESC' );
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post(); global $product; ?>
<div class="span3">
<a id="id-<?php the_id(); ?>" href="<?php the_permalink(); ?>" title="<?php the_title(); ?>">
<?php if (has_post_thumbnail( $loop->post->ID )) echo get_the_post_thumbnail($loop->post->ID, 'shop_catalog'); else echo '<img src="'.woocommerce_placeholder_img_src().'" alt="My Image Placeholder" width="65px" height="115px" />'; ?>
<h3><?php the_title(); ?></h3>
<span class="price"><?php echo $product->get_price_html(); ?></span>
</a>
<?php woocommerce_template_loop_add_to_cart( $loop->post, $product ); ?>
</div><!-- /span3 -->
<?php endwhile; ?>
<?php wp_reset_query(); ?>
Tried also WooCommerce Thumbnail Input Quantities plugins too. it added quantity field everywhere but not work.
Guys any idea how can solve my thing.
Thanks
Aucun commentaire:
Enregistrer un commentaire