Skip to content

Instantly share code, notes, and snippets.

@simonlk
simonlk / Woocommerce - show empty categories
Created October 21, 2012 06:33
Show empty categories within Woocommerce. Paste this in to your theme's functions file. It's just a copy and paste of a function within woocommerce-template.php and changing value of hide_empty to 0
// Paste this in to your theme's functions file
// Redefine sub category display to output empty categories
function woocommerce_product_subcategories( $args = array() ) {
global $woocommerce, $wp_query, $_chosen_attributes;
$defaults = array(
'before' => '',
'after' => '',
'force_display' => false
);
@simonlk
simonlk / get current taxonomy id
Created October 22, 2012 12:01
Get the details of the current taxonomy. This is for Woocommerce categories but would work for any custom taxonomies
<?php
$current_tax = get_query_var( 'product_cat' );
$term =get_term_by( 'slug', $current_tax, 'product_cat');
$term_name = $term->name;
$term_id = $term->term_id;
?>
@simonlk
simonlk / Woocommerce - list of available product variations
Created October 28, 2012 04:53
Output Woocommerce product variations as a table so they look like a single product
<?php
// Output variations as a list so they look like a single product
// Works in theme/woocommerce/single-product/add-to-car/variable.php
?>
<table class="table table-striped table-hover">
<thead>
<tr>
<th>Ref #</th>
<?php foreach ( $attributes as $name => $options) :?>
<th><?php echo $woocommerce->attribute_label($name); ?></th>
@simonlk
simonlk / Woocommerce - output product variations in tab
Last active February 21, 2022 20:27
Output Woocommerce product variations as a table within a tab on the single product page
// Add to functions.php
/*===================================================
Created by sk from Renegade Empire with help
from these sources:
http://docs.woothemes.com/document/editing-product-data-tabs/
http://www.sean-barton.co.uk/2013/03/remove-woocommerce-20-reviews-tab/#.UYnWe7XfB6N
http://www.sean-barton.co.uk/2013/03/sb-add-woocommerce-tabs-wordpress-plugin/#.UYrYL7XfB6M
@simonlk
simonlk / Wordpress - login with email
Created October 28, 2012 07:35
Allow user to login to Wordpress with their email address
// Allow users to login with their e-mail address
// source: http://www.benblanco.com
function login_with_email_address($username) {
$user = get_user_by('email',$username);
if(!empty($user->user_login))
$username = $user->user_login;
return $username;
}
add_action('wp_authenticate','login_with_email_address');
function change_username_wps_text($text){
@simonlk
simonlk / Shortcode for adding menu items with custom arguments and
Created October 31, 2012 02:46
Create short code for menu items with arguments like wp_nav_menu and allow short codes to be added to widgets
// Function that will return our Wordpress menu
// from http://www.cozmoslabs.com/1170-wp_nav_menu-shortcode/
function list_menu($atts, $content = null) {
extract(shortcode_atts(array(
'menu' => '',
'container' => 'div',
'container_class' => '',
'container_id' => '',
'menu_class' => 'menu',
'menu_id' => '',
@simonlk
simonlk / Wordpress - change login image login url and url title
Created November 2, 2012 05:44
Wordpress - change login image, login url and url title
// add this to your themes functions.php file
// change login image
add_action("login_head", "my_login_head");
function my_login_head() {
echo "
<style>
body.login #login h1 a {
background: url('".get_bloginfo('template_url')."/assets/img/image-name.png') no-repeat scroll center top transparent;
height: 59px;
}
// First remove default wrapper
remove_action( 'woocommerce_before_main_content', 'woocommerce_output_content_wrapper', 10);
remove_action( 'woocommerce_after_main_content', 'woocommerce_output_content_wrapper_end', 10);
// Then add new wrappers
add_action('woocommerce_before_main_content', 'my_theme_wrapper_start', 10);
add_action('woocommerce_after_main_content', 'my_theme_wrapper_end', 10);
function my_theme_wrapper_start() {
echo '<section id="main">';
@simonlk
simonlk / Roots - add description to menu item output
Created November 5, 2012 04:51
Output menu item description within Roots theme menu item
// goes within nav.php before $output .= $item_html;
// output menu description
$item_html .= ' <span class="menu-desc">' . $item->description . '</span>';
@simonlk
simonlk / Wooocommerce - add description field to product variations
Created November 6, 2012 14:13
Add a description input field for each product variation that saves to post_content
<?php
/**
* Variable Product Type
*
* Functions specific to variable products (for the write panels).
*
* @author WooThemes
* @category Admin
* @package WooCommerce/Admin/WritePanels
* @version 1.6.4