Skip to content

Instantly share code, notes, and snippets.

View luizbills's full-sized avatar

Luiz Bills luizbills

View GitHub Profile
@luizbills
luizbills / functional-utils.js
Created January 13, 2016 01:05 — forked from bendc/functional-utils.js
A set of pure and immutable ES2015 functions aimed to make functional JavaScript more idiomatic.
// array utils
// =================================================================================================
const combine = (...arrays) => [].concat(...arrays);
const compact = arr => arr.filter(Boolean);
const contains = (() => Array.prototype.includes
? (arr, value) => arr.includes(value)
: (arr, value) => arr.some(el => el === value)
@luizbills
luizbills / remove_some_checkout_fields.php
Created September 27, 2016 00:06
Remover campos de CPF e CNPJ quando estiver no checkout em inglês
add_filter( 'woocommerce_checkout_fields' , 'prefix_remove_some_checkout_fields' );
function prefix_remove_some_checkout_fields( $fields ) {
if ( $_GET['lang'] === 'en' ) {
unset( $fields['billing']['billing_persontype'] );
unset( $fields['billing']['billing_cpf'] );
unset( $fields['billing']['billing_cnpj'] );
}
return $fields;
}
@luizbills
luizbills / functions.php
Created January 26, 2017 16:59
Show different menu in wordpress
<?php
add_filter( 'wp_nav_menu_args', 'custom_change_primary_menu' );
function custom_change_primary_menu ( $args ) {
if ( $args['theme_location'] === 'primary' ) {
$args['menu'] = 'Menu 2';
}
return $args;
}
@luizbills
luizbills / custom_variable_price_html.php
Last active January 26, 2017 17:02
custom_variable_price_html.php
<?php
/**
* @version 1.0.1
*/
add_filter( 'woocommerce_get_price_html', 'custom_variable_price_html', 10, 2 );
function custom_variable_price_html( $price, $product ) {
if ( ! $product->is_type( 'variable' ) || $product->get_price() === '') return $price;
$result = '';
$prices = $product->get_variation_prices( true );
@luizbills
luizbills / example.php
Created May 22, 2017 21:10
Remove WooCommerce Reviews Tab
<?php
add_filter( 'woocommerce_product_tabs', 'lpb_wc_remove_reviews_tab', 98 );
function lpb_wc_remove_reviews_tab ( $tabs ) {
unset($tabs['reviews']);
return $tabs;
}
@luizbills
luizbills / example.php
Created June 2, 2017 01:48
Fazer o campo de número do endereço aceitar apenas números
<?php
add_filter( 'woocommerce_checkout_fields' , 'lpb_change_address_number_field_input_type', 999 );
function lpb_change_address_number_field_input_type ( $fields ) {
$fields['billing']['billing_number']['type'] = 'number';
$fields['shipping']['shipping_number']['type'] = 'number';
return $fields;
}
@luizbills
luizbills / example.php
Created June 6, 2017 20:45
WordPress Front-end Optimizations
<?php
add_filter( 'style_loader_src', 'generate_remove_cssjs_ver', 10, 2 );
add_filter( 'script_loader_src', 'generate_remove_cssjs_ver', 10, 2 );
function generate_remove_cssjs_ver( $src ) {
if( strpos( $src, '?ver=' ) ) $src = remove_query_arg( 'ver', $src );
return $src;
}
add_action( 'init', 'generate_disable_wp_emojicons' );
@luizbills
luizbills / code.php
Created July 6, 2017 17:58
[WooCommerce] Mostrar "valor economizado" dos produtos em promoção
add_filter( 'woocommerce_get_price_html', 'lpb_wc_add_sale_discount', 99, 2 );
function lpb_wc_add_sale_discount ( $price, $product ) {
if ( ( ! $product->is_type( 'variable' ) && is_single( $product->get_id() ) )
|| ( $product->is_type( 'variation' ) && is_single( $product->get_parent_id() ) ) )
{
if ( $product->is_on_sale() ) {
$message = __( 'economize %s', 'lpb-sale-discount' );
$amount = wc_price( $product->get_regular_price() - $product->get_sale_price() );
$price .= '&nbsp;<small class="sale-discount">' . sprintf( $message, $amount ) . '</small>';
@luizbills
luizbills / code.php
Last active July 11, 2017 15:06
Produces cleaner filenames for uploads
<?php
/**
* Produces cleaner filenames for uploads
*
* @author WP Artisan https://wpartisan.me/
*
* @param string $filename
* @return string
*/
@luizbills
luizbills / example.php
Last active July 14, 2017 14:24
Mostra uma notificação informando quanto precisa comprar a mais para ter frete grátis
<?php
add_action( 'woocommerce_check_cart_items', 'lpb_free_shipping_cart_notice' );
function lpb_free_shipping_cart_notice () {
if ( ! is_cart() ) return;
// mude o valor 150 para o valor mínimo do frete grátis
$free_shipping_amount = 150;
// modelo da mensagem (não remova o "%s")