Skip to content

Instantly share code, notes, and snippets.

@michaelwilhelmsen
michaelwilhelmsen / vertical-align.css
Created March 14, 2014 13:13
Vertically align anything with just three lines of CSS
.element {
position: relative;
top: 50%;
transform: translateY(-50%);
}
@michaelwilhelmsen
michaelwilhelmsen / link-twitter-usernames.php
Created May 2, 2014 09:16
Automatically link Twitter usernames in WordPressEx: @username - links to the users profile-page
remove_action( 'wp_head', 'rsd_link' );
remove_action( 'wp_head', 'wlwmanifest_link' );
remove_action( 'wp_head', 'wp_generator' );
remove_action( 'wp_head', 'start_post_rel_link' );
remove_action( 'wp_head', 'index_rel_link' );
remove_action( 'wp_head', 'adjacent_posts_rel_link' );
remove_action( 'wp_head', 'wp_shortlink_wp_head' );
@michaelwilhelmsen
michaelwilhelmsen / remove-product-tabs.php
Created May 2, 2014 09:24
Remove specific (or all) of the product tabs.
add_filter( 'woocommerce_product_tabs', 'woo_remove_product_tabs', 98 );
function woo_remove_product_tabs( $tabs ) {
unset( $tabs['description'] ); // Remove the description tab
unset( $tabs['reviews'] ); // Remove the reviews tab
unset( $tabs['additional_information'] ); // Remove the additional information tab
return $tabs;
@michaelwilhelmsen
michaelwilhelmsen / change-number-related-products.php
Created May 2, 2014 09:28
Change the number of related products displayed in your shop. Note: - 4 is for the number of products in each row. - 2 is for the number of rows.
@michaelwilhelmsen
michaelwilhelmsen / custom-add-to-cart-text.php
Created May 2, 2014 09:31
Customise 'add to cart' text on single product pages. Replace 'my button text' with whatever you want it to say.
add_filter( 'add_to_cart_text', 'woo_custom_cart_button_text' ); // < 2.1
add_filter( 'woocommerce_product_single_add_to_cart_text', 'woo_custom_cart_button_text' ); // 2.1 +
function woo_custom_cart_button_text() {
return __( 'My Button Text', 'woocommerce' );
}
@michaelwilhelmsen
michaelwilhelmsen / full-cart-content.php
Created May 2, 2014 09:33
Show cart contents/total.
<?php global $woocommerce; ?>
<a class="cart-contents" href="<?php echo $woocommerce->cart->get_cart_url(); ?>" title="<?php _e('View your shopping cart', 'woothemes'); ?>"><?php echo sprintf(_n('%d item', '%d items', $woocommerce->cart->cart_contents_count, 'woothemes'), $woocommerce->cart->cart_contents_count);?> - <?php echo $woocommerce->cart->get_cart_total(); ?></a>
@michaelwilhelmsen
michaelwilhelmsen / ajaxify-cart.php
Created May 2, 2014 09:35
Ajaxify your cart viewer so it updates when an item is added (via ajax)
// Ensure cart contents update when products are added to the cart via AJAX (place the following in functions.php)
add_filter('add_to_cart_fragments', 'woocommerce_header_add_to_cart_fragment');
function woocommerce_header_add_to_cart_fragment( $fragments ) {
global $woocommerce;
ob_start();
?>
<a class="cart-contents" href="<?php echo $woocommerce->cart->get_cart_url(); ?>" title="<?php _e('View your shopping cart', 'woothemes'); ?>"><?php echo sprintf(_n('%d item', '%d items', $woocommerce->cart->cart_contents_count, 'woothemes'), $woocommerce->cart->cart_contents_count);?> - <?php echo $woocommerce->cart->get_cart_total(); ?></a>
@michaelwilhelmsen
michaelwilhelmsen / encourage-register-field.php
Created May 2, 2014 09:36
Encourage people to register on your site by adding a message above the login/registration form.
add_action( 'woocommerce_before_customer_login_form', 'jk_login_message' );
function jk_login_message() {
if ( get_option( 'woocommerce_enable_myaccount_registration' ) == 'yes' ) {
?>
<div class="woocommerce-info">
<p><?php _e( 'Returning customers login. New users register for next time so you can:' ); ?></p>
<ul>
<li><?php _e( 'View your order history' ); ?></li>
<li><?php _e( 'Check on your orders' ); ?></li>
<li><?php _e( 'Edit your addresses' ); ?></li>
@michaelwilhelmsen
michaelwilhelmsen / remove-sidebar.css
Created May 2, 2014 09:38
Remove the sidebar and make all your pages full width
.woocommerce #sidebar{display:none}