Skip to content

Instantly share code, notes, and snippets.

@simonlk
simonlk / WooCommerce - change "Choose an option" to be the name of the attribute
Last active December 16, 2015 18:39
WooCommerce - change "Choose an option" to be the name of the attribute
// Looks up the slug of the attribute and manually replaces it with the text
// Within single-product/add-to-cart/variable.php replace the line:
// <option value=""><?php echo __( 'Choose an option', 'woocommerce' ) ?>&hellip;</option>
<option value="">
<?php
if ($name == 'pa_colour') {
$attr_name = 'Colour';
} elseif ($name == 'pa_size') {
$attr_name = 'Size';
}
@simonlk
simonlk / Woocommerce - change paypal icon
Created November 28, 2012 00:41 — forked from mikejolley/gist:1425282
This snippet lets you edit the icon for the PayPal gateway in WooCommerce.
// Change the paypal icon
add_filter('woocommerce_paypal_icon', 'custom_woocommerce_paypal_icon');
function custom_woocommerce_paypal_icon( $url ) {
$url = get_bloginfo('template_url')."/assets/img/payment-icons.png";
return $url;
}
@simonlk
simonlk / Woocommerce - hide other shipping methods when free shipping is available
Created November 27, 2012 04:41
Woocommerce - hide other shipping methods when free shipping is available
// Based on http://wcdocs.woothemes.com/snippets/hide-other-shipping-methods-when-free-shipping-is-available/
// Goes beyond by hiding the default internation shipping too
// Hide shipping options when free shipping is available
add_filter( 'woocommerce_available_shipping_methods', 'hide_standard_shipping_when_free_is_available' , 10, 1 );
/**
* Hide Standard Shipping option when free shipping is available
*
* @param array $available_methods
*/
@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
@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>';
// 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 / 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;
}
@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 - 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 / 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