Display featured products through custom loop in woocommerce on template page

Change your args to be like this: $meta_query = WC()->query->get_meta_query(); $meta_query[] = array( ‘key’ => ‘_featured’, ‘value’ => ‘yes’ ); $args = array( ‘post_type’ => ‘product’, ‘stock’ => 1, ‘showposts’ => 6, ‘orderby’ => ‘date’, ‘order’ => ‘DESC’, ‘meta_query’ => $meta_query ); If you go to wp-content/plugins/woocommerce/includes/class-wc-shortcodes.php (@595) you can find how it’s done for … Read more

Get the product list of a given Category ID

I suspect the main problem is that you should be using the WP_Query object rather than get_posts(). The later by default only returns items with a post_type of post not products, So given a category with ID 26, the following code would return it’s products (WooCommerce 3+): $args = array( ‘post_type’ => ‘product’, ‘post_status’ => … Read more

Woocommerce – Add a product to cart programmatically via JS or PHP [closed]

OK so here’s how I solved it in the end. A quick and dirty example, uses JQuery. <a id=”buy” href=”#”>Buy this!</a> <script> $(‘#buy’).click(function(e) { e.preventDefault(); addToCart(19); return false; }); function addToCart(p_id) { $.get(‘/wp/?post_type=product&add-to-cart=” + p_id, function() { // call back }); } </script> This just makes an AJAX GET request to the cart url /wp/?post_type=product&add-to-cart=[PRODUCT_ID]

How to add product in woocommerce with php code [closed]

The method below is now out of date as WooCommerce have added the wc_product_meta_lookup table which also needs to be updated with some of the meta values. Woo have now provided a CRUD interface so use that instead. $post_id = wp_insert_post( array( ‘post_title’ => $title, ‘post_type’ => ‘product’, ‘post_status’ => ‘publish’, ‘post_content’ => $body, )); … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)