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
Created May 23, 2015 10:06
WordPress - Auto Set Featured Image
<?php
function autoset_featured() {
global $post;
$already_has_thumb = has_post_thumbnail($post->ID);
if (!$already_has_thumb) {
$attached_image = get_children( "post_parent=$post->ID&post_type=attachment&post_mime_type=image&numberposts=1" );
if ($attached_image) {
foreach ($attached_image as $attachment_id => $attachment) {
set_post_thumbnail($post->ID, $attachment_id);
}
@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 / style.css
Created May 23, 2015 10:17
WooCommerce - Responsive Chechout for Mobile
/* START Make the cart table responsive */
/* http://css-tricks.com/responsive-data-tables/ */
/* http://www.jeremycarter.com.au/optimising-woocommerce-checkout-for-mobile/ */
@media screen and (max-width: 600px) {
/* Force table to not be like tables anymore */
.woocommerce table.shop_table,
.woocommerce table.shop_table thead,
.woocommerce table.shop_table tbody,
.woocommerce table.shop_table th,
@ofernandolopes
ofernandolopes / functions.php
Last active August 29, 2015 14:21
WooCommerce - Remove Menu Customers Option
//Remove Menu Customers Option of WooCommerce
add_action( 'admin_menu', 'remove_menu_pages', 999 );
function remove_menu_pages() {
remove_menu_page( 'wc-customers-list' );
};
@ofernandolopes
ofernandolopes / functions.php
Created May 23, 2015 10:36
WooCommerce - Remove the product description tabs
//Remove the product description tabs of WooCommerce
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;
@ofernandolopes
ofernandolopes / functions.php
Last active August 29, 2015 14:21
WordPress - Remove menus and sub-menus
//Remove menus and sub-menus
function remove_menus(){
remove_menu_page( 'edit.php' ); // Posts
remove_menu_page( 'upload.php' ); // Media
remove_menu_page( 'link-manager.php' ); // Links
remove_menu_page( 'edit-comments.php' ); // Comments
remove_menu_page( 'edit.php?post_type=page' ); // Pages
remove_menu_page( 'plugins.php' ); // Plugins
remove_menu_page( 'themes.php' ); // Appearance
@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
Created May 23, 2015 10:56
WordPress - Remove contact form 7 menu for non-administrator users
//Remove contact form 7 menu for non-administrator users
if (!(current_user_can('administrator'))) {
function remove_wpcf7() {
remove_menu_page( 'wpcf7' );
}
add_action('admin_menu', 'remove_wpcf7');
}