Skip to content

Instantly share code, notes, and snippets.

View NiBow's full-sized avatar

Nick Bowman NiBow

View GitHub Profile
@NiBow
NiBow / gist:e55d3100bb23a3bf0a859b1310500b17
Created August 2, 2017 21:02 — forked from basepack/gist:09fdbdd569020e2a0ff1
WooCommerce : add custom fields to product variations v2.0
<?php
//Display Fields
add_action( 'woocommerce_product_after_variable_attributes', 'variable_fields', 10, 3 );
//JS to add fields for new variations
add_action( 'woocommerce_product_after_variable_attributes_js', 'variable_fields_js' );
//Save variation fields
add_action( 'woocommerce_save_product_variation', 'save_variable_fields', 10, 1 );
/**
margin-top: -0px;
background-color: rgb(255, 255, 255);
box-shadow: 0px 0px 38px 0px rgba(0, 0, 0, 0.1);
-webkit-box-shadow: 0px 0px 38px 0px rgba(0, 0, 0, 0.1);
-moz-box-shadow: 0px 0px 38px 0px rgba(0, 0, 0, 0.1);
-ms-box-shadow: 0px 0px 38px 0px rgba(0, 0, 0, 0.1);
padding: 30px; */
z-index: 10;
position: relative;
display: inline-block; */
// Login log out functionality in menu, add stuff to menu
add_filter( 'wp_nav_menu_items', 'add_loginout_link', 10, 2 );
function add_loginout_link( $items, $args ) {
if (is_user_logged_in() && $args->theme_location == 'top_nav') {
$items .= '<li><a href="'. wp_logout_url() .'">Log Out</a></li>';
}
elseif (!is_user_logged_in() && $args->theme_location == 'top_nav') {
$items .= '<li><a href="'. site_url('wp-login.php') .'">Log In</a></li>';
}
return $items;
@NiBow
NiBow / functions.php
Created December 12, 2014 10:34
Woocommerce - simple menu cart
<?php
//* Do NOT include the opening php tag
//* Make Font Awesome available
add_action( 'wp_enqueue_scripts', 'enqueue_font_awesome' );
function enqueue_font_awesome() {
wp_enqueue_style( 'font-awesome', '//netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.css' );
}
@NiBow
NiBow / functions.php
Created December 1, 2014 14:56
Woocommerce - choose free and hide paid shipping if available
/**
* Hide free shipping option when Standard Shipping is available
*
* @param array $available_methods
*/
function mwe_hide_free_shipping_when_standard_shipping_is_available($available_methods) {
// remove standard shipping option
if (isset($available_methods['free_shipping']) AND isset( $available_methods['flat_rate'])) {
unset($available_methods['free_shipping']);
@NiBow
NiBow / price.php
Created December 1, 2014 11:57
Woocommerce - Hide price if variable products have same price
$hide_main_offer = false;
if($product->is_type('variable'))
{
ob_start();
echo $product->get_price_html();
$price_html = ob_get_clean();
@NiBow
NiBow / function.php
Created November 19, 2014 09:12
Woocommerce - change price $x-$y to from $x
// Use WC 2.0 variable price format, now include sale price strikeout
add_filter( 'woocommerce_variable_sale_price_html', 'wc_wc20_variation_price_format', 10, 2 );
add_filter( 'woocommerce_variable_price_html', 'wc_wc20_variation_price_format', 10, 2 );
function wc_wc20_variation_price_format( $price, $product ) {
// Main Price
$prices = array( $product->get_variation_price( 'min', true ), $product->get_variation_price( 'max', true ) );
$price = $prices[0] !== $prices[1] ? sprintf( __( 'From: %1$s', 'woocommerce' ), wc_price( $prices[0] ) ) : wc_price( $prices[0] );
// Sale Price
$prices = array( $product->get_variation_regular_price( 'min', true ), $product->get_variation_regular_price( 'max', true ) );
sort( $prices );
@NiBow
NiBow / functions.php
Created November 18, 2014 16:19
Woocommerce - Change danish currency symbol "kr." to "DKK"
add_filter('woocommerce_currency_symbol', 'change_denmark_existing_currency_symbol', 10, 2);
function change_denmark_existing_currency_symbol( $currency_symbol, $currency ) {
switch( $currency ) {
case 'DKK' : $currency_symbol = 'DKK'; break;
}
return $currency_symbol;
}
@NiBow
NiBow / gist:4169441
Created November 29, 2012 14:29 — forked from lucasfais/gist:1207002
Sublime Text 2 - Useful Shortcuts

Sublime Text 2 – Useful Shortcuts (Mac OS X)

General

⌘T go to file
⌘⌃P go to project
⌘R go to methods
⌃G go to line
⌘KB toggle side bar
⌘⇧P command prompt