Skip to content

Instantly share code, notes, and snippets.

@WillBrubaker
WillBrubaker / gist:509ea81f636132e03feb
Created June 12, 2015 12:02
Increase WooCommerce product prices by 20%
add_filter( 'woocommerce_get_price', 'wooninja_price_increase' );
function wooninja_price_increase( $price ) {
return $price + ( $price * .2 );
}
@zstepek
zstepek / change_user_role_after_purchase.php
Created May 5, 2015 17:05
Change user role after purchase is successful. Need to expand this example to include conditional processing based on products purchased.
add_action('woocommerce_thankyou', 'mindsize_change_role_on_successful_purchase');
function mindsize_change_role_on_successful_purchase($order_id ) {
$order = new WC_Order( $order_id );
$user_id = $order->user_id;
$wp_user_object = new WP_User($user_id);
if($wp_user_object->roles[0] != "administrator"){ // Do not change admin role
wp_update_user( array( 'ID' => $wp_user_object->ID, 'role' => "wholesale" ) );
}
}
@reinier
reinier / wp-theme-development.md
Last active March 24, 2017 20:08
How I develop Wordpress themes

How I develop Wordpress themes

This is my process for developing themes for Wordpress at the moment. I've come to this process because I want to deliver a clean theme while using the power of Gulp for Sass parsing and code/image optimization.

Vagrant for running Wordpress

I don't like to flood my computer with all kinds of tools for different kinds of languages all the time. PHP is one of them that I don't want to think about. Vagrant is a great solution to this. Everything you need for your Wordpress (Like PHP, MySQL etc.) you can get in a Vagrant machine.

With the help of PuPHPet I've made this Vagrant setup for my Wordpress development:

WP-dev-box

@mkhairul
mkhairul / replaceImage.php
Created March 5, 2015 11:54
Replace placeholder images with attribute values (woocommerce)
<?php
add_filter('woocommerce_cart_item_thumbnail', 'get_attr_image', 10, 3);
function get_attr_image($image, $item, $item_key)
{
$img_url = array_shift( wc_get_product_terms( $item['product_id'], 'pa_image', array( 'fields' => 'names' ) ) );
if($img_url)
{
$dom = new DOMDocument();
$dom->loadHTML($image);
$node = $dom->getElementsByTagName('img');
@bekarice
bekarice / wc-below-featured-image.php
Last active March 25, 2019 14:06
Add content below WooCommerce Featured image
@illycz
illycz / gist:4bdc53197ff7f54cf6e5
Created July 1, 2014 11:49
Performance Wordpress Checklist
0. RESOURCES
http://www.smashingmagazine.com/2014/06/25/how-to-speed-up-your-wordpress-website/
1. IDENTIFY PLUGINS THAT ARE SLOWING YOU DOWN
https://wordpress.org/plugins/p3-profiler/
2. COMPRESS YOUR WEBSITE
http://checkgzipcompression.com/
https://gist.github.com/illycz/1b896273dfd4cf26d184
@ddbs
ddbs / functions.php
Created March 14, 2014 00:27
woocommerce: add terms & conditions
/**
* Add Terms and Conditions field to the checkout
**/
add_action('woocommerce_after_order_notes', 'my_custom_checkout_field');
function my_custom_checkout_field( $checkout ) {
echo '<div id="terms_conditions"><h3>'.__('Terms and Conditions: ').'<a href="http://sylvanbotanical.org/fiveflavorsherbs/about/terms-and-conditions/">view here</a></h3>';
@DevinWalker
DevinWalker / woocommerce-optimize-scripts.php
Last active June 16, 2025 08:57
Only load WooCommerce scripts on shop pages and checkout + cart
/**
* Optimize WooCommerce Scripts
* Remove WooCommerce Generator tag, styles, and scripts from non WooCommerce pages.
*/
add_action( 'wp_enqueue_scripts', 'child_manage_woocommerce_styles', 99 );
function child_manage_woocommerce_styles() {
//remove generator meta tag
remove_action( 'wp_head', array( $GLOBALS['woocommerce'], 'generator' ) );
@agusmu
agusmu / style.css
Created September 2, 2013 01:20
WooCommerce - Fancy Sale Sticker
/* fancy sale sticker */
.woocommerce ul.products li.product .onsale, .woocommerce-page ul.products li.product .onsale, .woocommerce span.onsale, .woocommerce-page span.onsale {
background: transparent url(images/sale.png) no-repeat !important;
width: 125px;
height: 125px;
text-align: left;
text-indent: -99999px;
padding: 0;
margin: 0;
position: absolute;