Posted by: Vincent on: November 17, 2011
I recently discovered Jigoshop. A very nice, lightweight and well coded e-Commerce plugin for WordPress.
After some experimenting I found that the checkout and it’s fields for billing and shipping information where defined in the code and could not be modified in the settings.
It was a problem since they had set State as a required field, which most countries outside of US don’t have. In their forums there were many threads regarding this subject, and the answer the support staff gave was to modify the plugin files (!!) which you never should do.
So here’s an update safe to do it.
Create a plugin or add this to your theme’s functions.php
function jigo_mod_wp() {
if ( class_exists( 'jigoshop_checkout' ) ) {
$billing_fields = array(
array( 'name'=>'billing-first_name', 'label' => __('First Name', 'jigoshop'), 'placeholder' => __('First Name', 'jigoshop'), 'required' => true, 'class' => array('form-row-first') ),
array( 'name'=>'billing-last_name', 'label' => __('Last Name', 'jigoshop'), 'placeholder' => __('Last Name', 'jigoshop'), 'required' => true, 'class' => array('form-row-last') ),
array( 'name'=>'billing-address', 'label' => __('Address', 'jigoshop'), 'placeholder' => __('Address', 'jigoshop'), 'required' => true ),
array( 'name'=>'billing-city', 'label' => __('City', 'jigoshop'), 'placeholder' => __('City', 'jigoshop'), 'required' => true ),
array( 'validate' => 'postcode', 'format' => 'postcode', 'name'=>'billing-postcode', 'label' => __('Postcode', 'jigoshop'), 'placeholder' => __('Postcode', 'jigoshop'), 'required' => true, 'class' => array('form-row-first') ),
array( 'type'=> 'country', 'name'=>'billing-country', 'label' => __('Country', 'jigoshop'), 'required' => true, 'class' => array('form-row-last') ),
array( 'name'=>'billing-email', 'validate' => 'email', 'label' => __('Email Address', 'jigoshop'), 'placeholder' => __('***@yourdomain.com', 'jigoshop'), 'required' => true )
);
jigoshop_checkout::instance()->billing_fields = $billing_fields;
$shipping_fields = array(
array( 'name'=>'shipping-first_name', 'label' => __('First Name', 'jigoshop'), 'placeholder' => __('First Name', 'jigoshop'), 'required' => true, 'class' => array('form-row-first') ),
array( 'name'=>'shipping-last_name', 'label' => __('Last Name', 'jigoshop'), 'placeholder' => __('Last Name', 'jigoshop'), 'required' => true, 'class' => array('form-row-last') ),
array( 'name'=>'shipping-address', 'label' => __('Address', 'jigoshop'), 'placeholder' => __('Address', 'jigoshop'), 'required' => true ),
array( 'name'=>'shipping-city', 'label' => __('City', 'jigoshop'), 'placeholder' => __('City', 'jigoshop'), 'required' => true ),
array( 'validate' => 'postcode', 'format' => 'postcode', 'name'=>'billing-postcode', 'label' => __('Postcode', 'jigoshop'), 'placeholder' => __('Postcode', 'jigoshop'), 'required' => true, 'class' => array('form-row-first') ),
array( 'type'=> 'country', 'name'=>'shipping-country', 'label' => __('Country', 'jigoshop'), 'required' => true, 'class' => array('form-row-last') ),
array( 'name'=>'shipping-email', 'validate' => 'email', 'label' => __('Email Address', 'jigoshop'), 'placeholder' => __('***@yourdomain.com', 'jigoshop'), 'required' => true )
);
jigoshop_checkout::instance()->shipping_fields = $shipping_fields;
}
} add_action ( 'wp', 'jigo_mod_wp' );
Modify the array and add/remove the fields you want. Some of the items have an array item called required which controls whether a field is required or not.
Always fun to see great plugins that also are pluggable which is a MUST for it to be useful for developers.
Posted by: Vincent on: November 11, 2011
In a collaborative programming environment it is always good to have a set of coding standards that you follow.
Thankfully, WordPress have coding standards which all developers should try to follow.
If you peek at the WordPress source you will notice that (almost) all code follow this standard, which makes it very easy for other developers to read the code.
Take a look at the section discussing shorthand PHP tags, an issue I have written about previously. Space usage is also a very common mistake among developers. The correct space usage can really improve your code’s readability.
Further reading:
Codex: WordPress Coding Standards
Posted by: Vincent on: November 8, 2011
I have used Custom Post Types in almost every WordPress project I have worked on since the feature was introduced in WordPress 3.0.
When collaborating with other developers you also come across some common mistakes, mistakes that I’ve also made in the past. So I would like to share some things to keep in mind when using Custom Post Types.
The $post_type should always be singular
The codex does not explicitly say it anywhere, but all the Codex examples use singular names for $post_type. This is probably the most common mistake I see developers make. If you want the new post type’s URL to have a plural word in it, you can specify it in the slug argument.
Use a namespace for your post types
This is something that even I haven’t done. But the codex makes a good point in their own best practices section. A conflict can occur between theme and plugin post types if you use a common word as the post type name and it is not prefixed with a namespace. So for instance if your post type is a product, do not simply name is product but rather yournamespace_product.
Remember the template hierarchy when creating specific post type templates
WordPress template hierarchy is great, so please use it! I have seen cases where developers have created a new page with an associated template where they query for the posts instead of simply using the default template file to create an archive page for example.
From the codex:
In the same way that posts are shown on their own page with single.php, custom post types will use single-{posttype}.php if it’s available.
Same thing applies to archive-{posttype}.php. This visual overview of the template hierarchy is something I keep referring to.
Adding custom columns to the admin can be easy!
Joost De Valk provides these code snippets that can come in handy when working with custom post types. Often you also have custom taxonomies or other meta data linked to your post types which you might want to present in the admin. Great post!
Posted by: Vincent on: July 15, 2011
This will surely be the event of the year (as far as WordCamp events go).
Posted by: Vincent on: June 30, 2011
The company I work for is currently hiring a front end developer. So if you’re located in Stockholm, Sweden or willing to relocate you should definitely check it out!
We have put together a small site for you turn into HTML as a work sample, which could be fun as a night activity!
More info here:
http://oakwood.se/jobb (English version)
Posted by: Vincent on: April 14, 2011
After upgrading a local installation of WordPress subversion started complaining about missing files, that were deleted during the upgrade.
Since there were a lot of files I searched for an easy way to delete all the missing files at once, and found such a way here.
svn rm $( svn status | sed -e '/^!/!d' -e 's/^!//' )
One of the comments mentions that it doesn’t work with filenames that contains white space, which I haven’t tested.
Posted by: Vincent on: April 2, 2011
The Rich Text Editor (RTE) in WordPress use a JavaScript-library called tinyMCE. It is a widely used library and can be configured in a lot of ways.
WordPress let developers filter the settings to tinyMCE so that it fits your needs.
function mytheme_tiny_mce_before_init($arr){
$arr['theme_advanced_blockformats'] = 'h2,p,blockquote';
$arr['theme_advanced_styles'] = 'Leading=leading';
return $arr;
}
add_filter( 'tiny_mce_before_init', 'mytheme_tiny_mce_before_init' );
function mytheme_mce_buttons($arr){
return array('bold', 'italic', '|', 'bullist', 'numlist', '|', 'formatselect', 'styleselect', '|', 'link', 'unlink' );
}
add_filter( 'mce_buttons', 'mytheme_mce_buttons' );
These few lines of code changes the buttons in the editor, and also adds a format select and a style select.
From the format select you now can select “Heading 2″, “Blockquote” and “Paragraph”. In the style select you can select “Leading” and your element will get the CSS class leading.