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 / functions.php
Last active August 4, 2022 17:16
Adicionar opções do produto aos produtos do loop
<?php
/*
* @version 1.1.0
*/
add_action( 'woocommerce_after_shop_loop_item_title', 'lpb_wc_add_product_options', 9 );
function lpb_wc_add_product_options () {
global $post;
$product = wc_get_product( $post->ID );
if ( ! $product->is_type( 'variable' ) ) return;
@luizbills
luizbills / remove-price-col.css
Last active August 29, 2022 15:03
Remover coluna de preço no carrinho do Woocommerce
.shop_table .product-subtotal,
.shop_table .product-price {
display: none;
}
@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 / 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 / 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 / example.php
Created May 18, 2017 13:07
Google Tag Manager in Elementor Canvas
// please, replace the GTM-XXXX
add_action( 'wp_head', 'custom_add_google_tag_manager_head', 0 );
function custom_add_google_tag_manager_head () {
?>
<!-- Google Tag Manager -->
<script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
})(window,document,'script','dataLayer','GTM-XXXX');</script>
@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
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")
@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;
}