One of the requests I hear all the time is how to remove the WooCommerce “From: $$” price on the variable product page. Some people feel that it adds unnecessary clutter to the page. The good news here is that WooCommerce is incredibly flexible. With a simple filter you can modify that price however you want or remove it entirely.
Category Archives: Code Snippets
Disable Free Shipping on a per Product Basis in WooCommerce
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.
gettext – The Most Useful Filter in WordPress
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?
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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; |
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// add filters for oEmbed | |
global $wp_embed; | |
add_filter( 'my_media_filter', array( $wp_embed, 'autoembed' ), 8 ); |
Conclusion
You're custom post data has the awesome oEmbed functionality. Time to celebrate. 🙂
Delete Orphaned Post Meta Data in WordPress
Sometimes while developing a new plugin you have to do lots of database work including creating posts, editing posts, and deleting posts. All of these actions affect the post meta data table and if you aren't careful with how to manage the post meta data you'll have thousands and thousands of rows of data. By deleting orphaned post meta data (meta data belonging to posts which no longer exist) you immediately remove thousands of records that weren't doing anything.
Common MAMP Problems
Developing on your local machine instead of a webserver saves a developer a lot of time and allows you to test functionality without the need for a test site. There are a couple of tools to allow someone to set up a server on their local machine; one of the most common tools is MAMP. Continue Reading…
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…
Making Images Responsive in WordPress
I've been creating responsive WordPress themes pretty much since Ethan Marcotte wrote his Responsive Web Design article on A List Apart and I've been tinkering around with various ways to make images responsive in WordPress. I want to share my current method to accomplish it.
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.
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.