Disable Free Shipping on a per Product Basis in WooCommerce

Lego Fork Lift

Shipping is one of the most complex aspects of e-commerce. You have to worry about shipping provider regulations, large products that have awkward dimensions & box sizes, small products that the shipping calculators incorrectly estimate and you over charge, or you could have a mix match of product sizes and it's hard to come up with a fair flat rate shipping fee.

One of the approaches many store owners take is to mark up their products a little more and then offer free shipping. I think this is brilliant idea, but what happens if you have many small items and one large item that throws off the flat rate fee? If you're using WooCommerce there's a filter you can use to disable free shipping when a specific product is in the cart.

Continue Reading…

gettext – The Most Useful Filter in WordPress

camera filter

So you've found the perfect plugin: it has all of the functionality you need, it's within your budget, and there's surprisingly awesome support. Great – but what if you need to change just one little line of text? What if you want to do something simple like change “Add to Cart” to “Add to Basket”? Or change “Related Products” to “See these related products”?

If you're lucky there's a filter for that particular string but sometimes there isn't. Then what do you do?

Continue Reading…

Add oEmbed to Post Meta Data in WordPress

WordPress has an awesome oEmbed feature where a user just has to enter the url of the media you want embedded and WordPress takes care of the rest. Sadly, this only works when you put the link in the content. If you're creating custom post types, a plugin, or using custom meta data you may run into a situation where you want to embed some media that isn't in the content in which case you need to do a little coding.

Apply Filters to the Media

The first thing we have to do is add a filter right before you print your content. You can think of the apply_filters() function as a placeholder for more code.


<?php
// get media; could be a url to a tweet, or youtube video, or something else;
$media;
$media = apply_filters( "my_media_filter", $media );
// add filter for oEmbed
$media = apply_filters( "my_media_filter", $media );
// print embedded media
echo $media;

view raw

functions.php

hosted with ❤ by GitHub

Add WordPress Embed Functionality to Filter

The last thing we have to do is tell WordPress to add the default oEmbed functionality to anything in our filter.


<?php
// add filters for oEmbed
global $wp_embed;
add_filter( 'my_media_filter', array( $wp_embed, 'autoembed' ), 8 );

view raw

functions.php

hosted with ❤ by GitHub

Conclusion

You're custom post data has the awesome oEmbed functionality. Time to celebrate. 🙂

Removing the Tagline from the Theme Customizer in WordPress

I've finally started setting up the Theme Customizer in WordPress for my clients. I ran into an issue where the Theme Customizer has certain defaults that not all themes use. It is pretty rare for my sites to include a tagline; for us at BR the brand's tagline is usually included in the logo so we don't need to restate it. It would be very confusing if your theme customizer has an editable tagline that doesn't appear anywhere on the site.

Since this feature only came out this year there is still a lot of bad information running around; yes there is even some misinformation on WordPress Answers. Continue Reading…

A WordPress Plugin Deployment Shell Script

Writing plugins for yourself or others is a natural step for a developer that uses WordPress. Unfortunately if you want to share your plugins with the WordPress community that means submitting them to the WordPress plugin repository and there is one really sucky part about that – learning Subversion.

Subversion, or SVN, was great years ago when Git didn't exist. But since the emergence of GitHub, Git has become hugely popular and produces far fewer headaches than SVN. As a result new developers don't even bother learning SVN. Why learn to drive a stick shift when you can drive an automatic that has better gas mileage and more control?

With a lot of googling and several hacking sessions I took an existing shell script and modified it so that is does all of the cumbersome SVN for you. It will pull down the latest version of your Git repo, reproduce it in SVN, and push the changes to the WordPress plugin repository. It will even move your plugin assets (including the header image and screenshots) to the appropriate spot in the SVN repo.

Continue Reading…

Disable A Plugin’s CSS File

WordPress plugins have the ability to include their own CSS files and most of the time this is great. Good plugins will write selectors that only affect the plugins content but some of the plugins don't write specific enough CSS or their CSS uses techniques that make it more challenging to override with your own CSS. Regardless of the reason I knew there had to be a better way to allow your own styles to be applied to the content.

Continue Reading…