hacks Archives | Lee Willis https://www.leewillis.co.uk/tag/hacks/ Mon, 02 Jan 2012 11:21:57 +0000 en-US hourly 1 https://wordpress.org/?v=6.7.2 Sorting the list of downloadable files in WP e-Commerce https://www.leewillis.co.uk/sorting-the-list-of-downloadable-files-in-wp-e-commerce/ https://www.leewillis.co.uk/sorting-the-list-of-downloadable-files-in-wp-e-commerce/#comments Mon, 02 Jan 2012 11:19:39 +0000 http://www.leewillis.co.uk/?p=417 Those of you who run stores with downloadable products may well have struggled with the following problem. If you try an attach an existing file to a product (Either because the same file is supplied with different products, or you … Continue reading

The post Sorting the list of downloadable files in WP e-Commerce appeared first on Lee Willis.

]]>
Those of you who run stores with downloadable products may well have struggled with the following problem. If you try an attach an existing file to a product (Either because the same file is supplied with different products, or you have product variants that you need to set downloads against), then you may well have run into the following:

This list is a bit of a nightmare to find the file you want. It’s not sorted by anything obvious – not name, and not date-modified as far as I can tell. Finding a file is a bit of a scroll-and-hope affair. Much better to have a nice, ordered list like this:

This is an itch I’ve been wanting to scratch for a while now, and it turns out the code is pretty simple. Just drop the following in your theme’s functions.php file and revel in the glory of a nice, ordered file list.

function site_plugin_custom_sort_function ( $a, $b ) {
  return strtolower($a['display_filename']) > strtolower($b['display_filename']);
}

function site_plugin_sort_download_list ( $download_list ) {
  // Sort the multidimensional array
  usort($download_list, "site_plugin_custom_sort_function");
  return $download_list;
}
add_filter ( 'wpsc_downloadable_file_list', 'site_plugin_sort_download_list' );

The post Sorting the list of downloadable files in WP e-Commerce appeared first on Lee Willis.

]]>
https://www.leewillis.co.uk/sorting-the-list-of-downloadable-files-in-wp-e-commerce/feed/ 3
Adding custom post type archives to your sitemap https://www.leewillis.co.uk/adding-custom-post-type-archives-to-your-sitemap/ https://www.leewillis.co.uk/adding-custom-post-type-archives-to-your-sitemap/#respond Tue, 01 Mar 2011 22:54:20 +0000 http://www.leewillis.co.uk/?p=362 The snippet below is a modification to Yoast’s excellent WordPress SEO plugin to include custom post type archives to the XML sitemaps it produces. Hope you find it useful. $post_type_archive_link = get_post_type_archive_link($post_type); if ($post_type_archive_link) { $url = array(); $url['loc'] = … Continue reading

The post Adding custom post type archives to your sitemap appeared first on Lee Willis.

]]>
The snippet below is a modification to Yoast’s excellent WordPress SEO plugin to include custom post type archives to the XML sitemaps it produces. Hope you find it useful.

            $post_type_archive_link = get_post_type_archive_link($post_type);
            if ($post_type_archive_link) {
                $url = array();
                $url['loc'] = $post_type_archive_link;
                $url['pri'] = 0.8;
                $url['chf'] = 'weekly';
                $this->write_sitemap_loc( $f, $url, $echo );
            }

Just add this snippet inside wp-content/plugins/wordpress-seo/sitemaps/xml-sitemap-class.php inside the function generate_sitemap. The code should go just inside the loop through the custom post types, e.g. after this chunk:

           if ( isset($options['post_types-'.$post_type.'-not_in_sitemap']) && $options['post_types-'.$post_type.'-not_in_sitemap'] )
                continue;
            if ( in_array( $post_type, array('revision','nav_menu_item','attachment') ) )
                continue;

Once you’ve added the code – just rebuild your Sitemap by visiting Seo » Dashboard » (Re)build XML Sitemap.

The post Adding custom post type archives to your sitemap appeared first on Lee Willis.

]]>
https://www.leewillis.co.uk/adding-custom-post-type-archives-to-your-sitemap/feed/ 0
Extending Virtuemart the smart way https://www.leewillis.co.uk/extending-virtuemart-the-smart-way/ https://www.leewillis.co.uk/extending-virtuemart-the-smart-way/#respond Thu, 10 Jun 2010 18:00:44 +0000 http://www.leewillis.co.uk/?p=276 Someone left a comment on my article about Virtuemart Category Discounts the other day – that I though was worthy of a post of its own. What James pointed out was that instead of amending core files, you can create … Continue reading

The post Extending Virtuemart the smart way appeared first on Lee Willis.

]]>
Someone left a comment on my article about Virtuemart Category Discounts the other day – that I though was worthy of a post of its own.

What James pointed out was that instead of amending core files, you can create “class overrides” to amend functionality you want to.

You can read James’ original comment, or skip straight to the article that explains everything!

My future Virtuemart customisations will definitely make use of this – thanks James!

The post Extending Virtuemart the smart way appeared first on Lee Willis.

]]>
https://www.leewillis.co.uk/extending-virtuemart-the-smart-way/feed/ 0
Getting URL of Post Thumbnails in WordPress 2.9 https://www.leewillis.co.uk/getting-url-post-thumbnails-wordpress/ https://www.leewillis.co.uk/getting-url-post-thumbnails-wordpress/#comments Fri, 29 Jan 2010 22:25:59 +0000 http://www.leewillis.co.uk/?p=197 One of the improvements in WordPress 2.9 is native support for thumbnail images on posts. The API is pretty good – although it assumes that you want to return the whole IMG tag. In my case I wanted to return … Continue reading

The post Getting URL of Post Thumbnails in WordPress 2.9 appeared first on Lee Willis.

]]>
One of the improvements in WordPress 2.9 is native support for thumbnail images on posts. The API is pretty good – although it assumes that you want to return the whole IMG tag. In my case I wanted to return the URL of the image (So I could wrap the actual thumbnail in a lightbox-style link to the larger versions).

So – if you want to get the URL of your posts thumbnail – here’s the code you need:

$image_id = get_post_thumbnail_id();
$image_url = wp_get_attachment_image_src($image_id,'large');
$image_url = $image_url[0];

I hope this helps you with your theme development.

The post Getting URL of Post Thumbnails in WordPress 2.9 appeared first on Lee Willis.

]]>
https://www.leewillis.co.uk/getting-url-post-thumbnails-wordpress/feed/ 40
Featured Products With Virtuemart https://www.leewillis.co.uk/featured-products-virtuemart/ https://www.leewillis.co.uk/featured-products-virtuemart/#comments Wed, 06 May 2009 21:09:35 +0000 http://www.leewillis.co.uk/?p=61 Featured Products e-Commerce stores often want to highlight a particular product or products. This can because they have new products to promote, special offers, stock to clear – or just because they believe it will help conversion. While the popular … Continue reading

The post Featured Products With Virtuemart appeared first on Lee Willis.

]]>
Featured Products

e-Commerce stores often want to highlight a particular product or products. This can because they have new products to promote, special offers, stock to clear – or just because they believe it will help conversion.

While the popular Virtuemart e-commerce system will let you mark products as “On Special”, it doesn’t offer an out-of-the box way to highlight these special products on the main shop pages.

This article will show you how you can use this “On Special” functionality to implement “featured products” in your product listing pages on your Virtuemart Site – take a look at the example below:

Featured Baby Carriers

Standard Functionality

The standard Virtuemart functionality allows you to set a product as “On Special” – as the image below shows.
Setting the On Special Flag
Unfortunately, this information about your products isn’t available to your theme, so you can’t style your products differently, nor can you sort them to the top of your list (As most designs would require).

Getting the information

The first thing we need to do is make sure that the details about whether the flag is set or not is pulled back from the database. The file we’re interested in is shop_browse_queries.php which is in administrator/components/com_virtuemart/html/.

Line 39 specifies a variable called $field_names, so we need to add the database field product_special to this list, e.g.

shop_browse_queries.php – Line 39:
$fieldnames = "`product_name`, `products_per_row` , `category_browsepage` ,
`category_flypage` , `#__{vm}_category`.`category_id` ,
`#__{vm}_product`.`product_id` , `product_full_image` , `product_thumb_image` ,
`product_s_desc` , `product_parent_id` , `product_publish` ,
`product_in_stock` , `product_sku` , `product_url` ,
`product_weight` , `product_weight_uom` , `product_length` ,
`product_width` , `product_height` , `product_lwh_uom` ,
`product_in_stock` , `product_available_date` ,
`product_availability` , `product_special`,
`#__{vm}_product`.`mdate` ,  `#__{vm}_product`.`cdate`";

We then need to make sure that this information is added to the product array available to the layout code.

shop.browse.php – Line 450:
$products[$i]['product_special'] = $db_browse->f("product_special");

Now, in your browse page template, you can simply check the value of $product_special, and change your HTML output accordingly. For example, on SnugBaby, we wrap featured products in a styled div:

<?php if ($product_special == 'Y') : ?> <div class="featuredheading"> <h3>Featured Product</h3> </div> <div class="featured"> <?php endif; ?>

Bubbling up…

So far we’ve managed to highlight featured products, and the next change is a bit take it or leave it. However, when we were doing our implementation of this on SnugBaby we decided that it looked considerably better if the featured products were first in the list. So, the following change makes special products jump up to the top of your list, with the rest of the product according to your standard ordering rules:

shop.browse.php – Line 450:
$q .= "\n ORDER BY product_special desc, $orderbyField $DescOrderBy";

If you want to see the final result, check out the SnugBaby Baby Carrier pages.

The post Featured Products With Virtuemart appeared first on Lee Willis.

]]>
https://www.leewillis.co.uk/featured-products-virtuemart/feed/ 7
Virtuemart Category Discounts https://www.leewillis.co.uk/virtuemart-category-discounts/ https://www.leewillis.co.uk/virtuemart-category-discounts/#comments Thu, 30 Apr 2009 08:30:23 +0000 http://www.leewillis.co.uk/?p=38 Background Virtuemart is an excellent Open Source e-Commerce system that integrates with the Joomla content management system. I use it on a number of sites – some with more challenging eCommerce requirements than others. While Virtuemart offers bulk purchase discounts … Continue reading

The post Virtuemart Category Discounts appeared first on Lee Willis.

]]>
Background

Virtuemart is an excellent Open Source e-Commerce system that integrates with the Joomla content management system. I use it on a number of sites – some with more challenging eCommerce requirements than others.

While Virtuemart offers bulk purchase discounts (£10 each, or 3 or £27 style offers) – it unfortunately only implements these on a per-product basis. This is great if you want to order 3 of the exact same pair of baby shoes.

However, a common request is to implement category-based discounts, so  for example you would be able to offer a discount where people buy multiple products from a particular category.

We do just this on SnugBaby, where we periodically run category based discounts on our baby shoes, where the requirement is that you get a discount if you choose to buy multiple products from a particular category.

Caveats

There are some caveats to the approach we’re going to describe below:

  1. It involves patching the Virtuemart source files  – this is not a Plugin, Component, or module. You should attempt this only if you’re comfortable editing PHP code
  2. Further to the above – if you upgrade Virtuemart this will need re-applying, possibly with some tweaks and tickles
  3. This assumes you’re running Virtuemart 1.1.3 (Although the theory of the approach works with VM 1.0.x as well)

Summary

This approach uses the Virtuemart bulk pricing model to store the bulk prices. This means you need to go through the products that are on special offer and add in the bulk prices. In the example I’m going to use here we are selling baby shoes. The standard price is £16.50 per pair, but if you buy more than 1 pair (Of any design), then you get them for £15.00 per pair.

We market this as “2 for £30” – however the reality (Probably should be caveat number 4!) is that it becomes £15 per pair for any number of shoes 2 and over (E.g. you could get 3 pairs for £45, 4 pairs for £60 and so on …).

So. First things first. Add the pricing to Virtuemart. If you’ve never done bulk pricing in Virtuemart here’s a quick guide. For each of your products in turn, edit the product, and choose “List Prices”:

listprices

Then you’ll need to specify your pricing:

productprices

Once this is done then your customers can get the special price, but only if they buy 2 or more of the same product.

The fun part

We can make all the changes we need to in just one file, administrator/components/com_virtuemart/classes/ps_product.php. This file is responsible for calculating product pricing, taking into account quantity discounts. The function in question is get_price().

This function out-of-the-box is given a product ID and is asked to calculate the price. It has a section relating to quantity pricing which roughly follows the following logic:

– Cycle through all cart contents

– If the product_id of the cart item matches the product_id we’re trying to cost then sum up the quantity of this item

– Retrieve the product price based on total volume of a product in the cart

We’re going to amend the second step such that it sums up the quantities of all products in the same category as the product we’re trying to cost.

The full patch (For the impatient) is here.

The patch is split into 2 main sections. The first gets the category that the product we’re costing belongs to (Caveat #5 – I have no idea what happens if your bulk purchase products are in multiple categories!). It also checks if that category is eligible for bulk discounts. You’ll need to change the 28 below to match your category ID.

Line 1608:
// Get the product_parent_id for this product/item
$product_parent_id = $this->get_field($product_id, “product_parent_id”);
// LW PATCH – Get the category of this product – used later to drive category-based multiple purchases
$sesq = “SELECT category_id FROM #__{vm}_product_category_xref WHERE product_id=’$product_id'”;
$db->setQuery($sesq); $db->query();
$db->next_record();
$sesprodcat = $db->f(“category_id”);
if ($sesprodcat == 28) {
$ses_cat_discount = TRUE;
} else {
$ses_cat_discount = FALSE;
}
// END LW PATCH

The next section changes the calculation so that instead of comparing the product IDs, we comapre category IDs:

Line 1622:
// LW PATCH – If any product in the cart is in the same category then treat as volume purchase
if ($ses_cat_discount) {
  $sesq = “SELECT category_id FROM #__{vm}_product_category_xref WHERE product_id='”.$cart[$i][“product_id”].”‘”;
  $db->setQuery($sesq); $db->query();
  $db->next_record();
  $sesprodchildcat = $db->f(“category_id”);
  if ($sesprodchildcat == $sesprodcat) {
    $quantity += $cart[$i][“quantity”];
  }
} else {

  if ($cart[$i][“product_id”] == $product_id) {
    if ($parent) {
      $parent_id = $cart[$i][“parent_id”];
Line 1631:
       }
     }
   }
}
// END LW PATCH

And that’s that. Give it a try, let me know what you think!

The post Virtuemart Category Discounts appeared first on Lee Willis.

]]>
https://www.leewillis.co.uk/virtuemart-category-discounts/feed/ 61