Skip to content

Instantly share code, notes, and snippets.

@ofernandolopes
ofernandolopes / functions.php
Created April 13, 2014 07:44 — forked from ChromeOrange/functions.php
WooCommerce - Purchase Minimum Amount
add_action( 'woocommerce_checkout_process', 'wc_minimum_order_amount' );
add_action( 'woocommerce_before_cart' , 'wc_minimum_order_amount' );
function wc_minimum_order_amount() {
// Set this variable to specify a minimum order value
$minimum = 50;
if ( WC()->cart->total < $minimum ) {
if( is_cart() ) {
@ofernandolopes
ofernandolopes / functions.php
Last active February 15, 2017 02:38 — forked from woogist/functions.php
WooCommerce - Sell in specific States/Provinces/Regions
<?php
/**
* Sell only in Minas Gerais. Brazil
*/
function wc_sell_only_states( $states ) {
$states['BR'] = array(
'MG' => __( 'Minas Gerais', 'woocommerce' ),
);
return $states;
@ofernandolopes
ofernandolopes / functions.php
Last active August 29, 2015 14:21 — forked from woogist/functions.php
WooCommerce - Redirect to the shop page after add to cart
add_filter( 'woocommerce_add_to_cart_redirect', 'wc_custom_cart_redirect' );
function wc_custom_cart_redirect() {
return get_permalink( wc_get_page_id( 'shop' ) );
}
@ofernandolopes
ofernandolopes / functions.php
Last active August 29, 2015 14:21 — forked from claudiosanches/functions.php
WooCommerce - Custom CSS
<?php
function my_theme_woocommerce_enqueue_styles( $styles ) {
$base_url = str_replace( array( 'http:', 'https:' ), '', get_stylesheet_directory_uri() ) . '/inc/woocommerce/css/';
$styles['woocommerce-layout']['src'] = $base_url . 'woocommerce-layout.css';
$styles['woocommerce-smallscreen']['src'] = $base_url . 'woocommerce-smallscreen.css';
$styles['woocommerce-general']['src'] = $base_url . 'woocommerce.css';
return $styles;
@ofernandolopes
ofernandolopes / functions.php
Last active August 29, 2015 14:21 — forked from ChromeOrange/gist:9832001
WooCommerce - Set the store base city and postcode / zipcode
/**
* Set the store base city and postcode / zipcode
*/
add_filter( 'woocommerce_countries_base_city' , 'set_woocommerce_countries_base_city' );
function set_woocommerce_countries_base_city() {
// Replace with your store town/city
return 'Townland';
}
add_filter( 'woocommerce_countries_base_postcode' , 'set_woocommerce_countries_base_postcode' );
@ofernandolopes
ofernandolopes / functions.php
Last active August 29, 2015 14:21 — forked from ChromeOrange/gist:8287925
WordPress - Delete ALL tax rates
/**
* Delete ALL WooCommerce tax rates
*
* Add to your theme functions.php then go to woocommerce -> system status -> tools and there will be a delete all tax rates button http://cld.wthms.co/tXvp
*/
add_filter( 'woocommerce_debug_tools', 'custom_woocommerce_debug_tools' );
function custom_woocommerce_debug_tools( $tools ) {
$tools['woocommerce_delete_tax_rates'] = array(
@ofernandolopes
ofernandolopes / functions.php
Last active August 29, 2015 14:21 — forked from ChromeOrange/gist:5350273
WooCommerce - Create a cost price field for simple products
add_action('woocommerce_product_options_pricing','custom_cost_price');
function custom_cost_price() {
woocommerce_wp_text_input( array( 'id' => '_cost_price', 'class' => 'wc_input_price short', 'label' => __( 'Cost Price', 'woocommerce' ) . ' ('.get_woocommerce_currency_symbol().')', 'type' => 'number', 'custom_attributes' => array(
'step' => 'any',
'min' => '0'
) ) );
}
add_action('woocommerce_process_product_meta_simple', 'save_custom_cost_price');
function save_custom_cost_price($post_id) {
@ofernandolopes
ofernandolopes / functions.php
Created May 23, 2015 13:57 — forked from AmelieBassart/gist:631c6cf6c2556d447858
WooCommerce - Don't Ship to PO Boxes
add_action('woocommerce_after_checkout_validation', 'deny_pobox_postcode');
function deny_pobox_postcode( $posted ) {
global $woocommerce;
$address = ( isset( $posted['shipping_address_1'] ) ) ? $posted['shipping_address_1'] : $posted['billing_address_1'];
$postcode = ( isset( $posted['shipping_postcode'] ) ) ? $posted['shipping_postcode'] : $posted['billing_postcode'];
$replace = array(" ", ".", ",");
$address = strtolower( str_replace( $replace, '', $address ) );
@ofernandolopes
ofernandolopes / functions.php
Last active August 29, 2015 14:21 — forked from ChromeOrange/functions.php
WordPress - Add login / logout links to any menu and position it
<?php
/**
* Add login / logout links to any menu and position it
* Based On : http://www.viper007bond.com/2011/09/20/code-snippet-add-a-link-to-latest-post-to-wordpress-nav-menu/
*
* Instructions :
* 1 - Add this code to your theme functions file
* 2 - create a new custom menu item : http://cl.ly/image/092k303O3C2z DO NOT change this #loginlogout
* 3 - Position the menu item where ever you would like it to appear : http://cl.ly/image/0p00131v1L09
**/
@ofernandolopes
ofernandolopes / functions.php
Last active August 29, 2015 14:21 — forked from ChromeOrange/functions.php
WooCommerce - Add login menu item to menus with 'My Account'
<?php
/**
* Add login link to my account menu.
*
* Add this to your theme functions file
*/
add_filter( 'wp_nav_menu_items', 'woocommerce_nav_menu_items_login', 10, 2 );
function woocommerce_nav_menu_items_login( $items, $args ) {
if ( get_option('woocommerce_menu_logout_link')=='yes' && strstr($items, get_permalink(woocommerce_get_page_id('myaccount'))) && !is_user_logged_in() )