Category Archives: WooCommerce

How To Display WooCommerce Featured Products

This is done by using the meta_key as bellow:

[php]
$args = array(
‘post_type’ => ‘product’,
‘meta_key’ => ‘_featured’,
‘meta_value’ => ‘yes’,
‘posts_per_page’ => 1
);

$featured_query = new WP_Query( $args );

if ($featured_query->have_posts()) :

while ($featured_query->have_posts()) :

$featured_query->the_post();

$product = get_product( $featured_query->post->ID );

// Output product information here

endwhile;

endif;

wp_reset_query(); // Remember to reset
[/php]

Enjoy!

Show posts on front end, even if they are already visible in admin

When importing products, they need to have the meta_key “total_sales” set to 0. Otherwise, use this code:

[php]

include_once ‘../wp-config.php’;

$query = "SELECT * FROM wp_posts WHERE post_type=’product’";
$products = $wpdb->get_results($query);

foreach ($products as $product){

$q = "SELECT meta_value FROM wp_postmeta WHERE meta_key = ‘total_sales’ AND post_id = " . $product->ID;
$x = $wpdb->get_results($q);
if (!$x){
$query = "INSERT INTO wp_postmeta (`post_id`, `meta_key`, `meta_value`)
VALUES ($product->ID, ‘total_sales’, ‘0’);";

$x = $wpdb->query($query);
}

}

[/php]

Make price widget draggable on touch devices

Grab this script and save it to the js folder in your theme directory.

Add the following code to your themes functions.php file (remember to make sure the path matches your theme structure) to enqueue it:

[php]
add_action( ‘wp_enqueue_scripts’, ‘load_touch_punch_js’ , 35 );
function load_touch_punch_js() {
global $version;

wp_enqueue_script( ‘jquery-ui-widget’ );
wp_enqueue_script( ‘jquery-ui-mouse’ );
wp_enqueue_script( ‘jquery-ui-slider’ );
wp_register_script( ‘woo-jquery-touch-punch’, get_stylesheet_directory_uri() . "/js/jquery.ui.touch-punch.min.js", array(‘jquery’), $version, true );
wp_enqueue_script( ‘woo-jquery-touch-punch’ );
}
[/php]

Problem solved!