Skip to content

Instantly share code, notes, and snippets.

View luizbills's full-sized avatar
I may be slow to respond.

Luiz Bills luizbills

I may be slow to respond.
View GitHub Profile
@luizbills
luizbills / estados.php
Last active November 29, 2019 11:40
Estados brasileiros em array (Brazilian states in array)
<?php
$states = [
'AC' => 'Acre',
'AL' => 'Alagoas',
'AP' => 'Amapá',
'AM' => 'Amazonas',
'BA' => 'Bahia',
'CE' => 'Ceará',
'DF' => 'Distrito Federal',
@luizbills
luizbills / code.php
Created February 7, 2018 17:12
Mudar resposta do correios de "Entrega em" para "Entrega em até"
add_filter( 'woocommerce_package_rates', 'lpb_change_correios_shipping_response_label', 10, 2 );
function lpb_change_correios_shipping_response_label ( $rates, $package ) {
foreach ( $rates as $rate) {
if ( false !== strpos($rate->id, 'correios') ) {
$rate->label = str_replace( 'Entrega em', 'Entrega em até', $rate->label );
}
}
return $rates;
}
@luizbills
luizbills / code.php
Created February 7, 2018 23:37
remove campo de cidade da calculadora de CEP
add_filter( 'woocommerce_shipping_calculator_enable_city', '__return_false' );
@luizbills
luizbills / render-template.js
Last active February 16, 2018 16:44
very simple template renderer
function renderTemplate(template, data) {
var result = template;
for (var key in data) {
if (data.hasOwnProperty(key)) {
var regex = new RegExp('{{\\s*' + key + '\\s*}}', 'g');
result = result.replace(regex, data[key]);
}
}
return result;
}
@luizbills
luizbills / code.php
Created February 15, 2018 18:38
remover filtros de preço
<?php
add_filter( 'woocommerce_catalog_orderby', function ( $filters ) {
unset( $filters['price'] );
unset( $filters['price-desc'] );
return $filters;
} );
@luizbills
luizbills / code.php
Created February 19, 2018 04:02
Remover admin bar para todos exceto os administradores
add_action( 'after_setup_theme', 'lpb_remove_admin_bar' );
function lpb_remove_admin_bar () {
if ( !current_user_can( 'administrator' ) && ! is_admin () ) {
show_admin_bar(false);
}
}
<?php
add_filter( 'woocommerce_package_rates', 'custom_correios_free_shipping', 10, 2 );
function custom_correios_free_shipping ( $rates, $package ) {
$free_shipping_amount = 350;
$cart_total = WC()->cart->subtotal;
if ( $cart_total >= $free_shipping_amount ) {
foreach ( $rates as $rate) {
if ( 'correios-pac' === $rate->method_id && $rate->cost > 0 ) {
@luizbills
luizbills / code.php
Created April 7, 2018 04:46
custom checkout fields
<?php
add_filter( 'woocommerce_checkout_fields' , 'lpb_override_checkout_fields', 20 );
function lpb_override_checkout_fields ( $fields ) {
// remove o campo "sexo"
unset( $fields['billing']['billing_sex'] );
// remove obrigatoriedade do campo "data de nascimento"
if ( isset( $fields['billing']['billing_birthdate'] ) ) {
$fields['billing']['billing_birthdate']['required'] = false;
@luizbills
luizbills / code.php
Last active September 9, 2024 16:21
Send emails using the WooCommerce template
<?php
$email_subject = 'Subject';
$email_to = '[email protected], [email protected]';
$title = 'Custom email';
$message = 'Hello world!';
WC()->mailer()->send(
$email_to,
@luizbills
luizbills / code.php
Last active March 26, 2024 15:40
Change message of "WooCommerce Force Authentification Before Checkout" plugin
<?php
/*
english: put the below code in your functions.php
português: coloque o código abaixo no seu functions.php ou siga este guia: https://bit.ly/2Nn0SvD
*/
add_filter( 'wc_force_auth_message', function ( $message ) {
return 'your new message/sua nova mensagem';
} );