Skip to content

Instantly share code, notes, and snippets.

View pablo-sg-pacheco's full-sized avatar

Pablo dos Santos Gonçalves Pacheco pablo-sg-pacheco

View GitHub Profile
@pablo-sg-pacheco
pablo-sg-pacheco / functions.php
Created February 20, 2017 17:10
Positions a custom booster field in any order on checkout
<?php
add_filter( 'woocommerce_checkout_fields', function ( $fields ) {
$offset = 2; //Change this by the field position you want to add (remembering it starts from zero)
$custom_field_id = 'billing_wcj_checkout_field_1'; //Your custom field id
$oldArray = $fields['billing'];
$custom_field = array( $custom_field_id => $oldArray[ $custom_field_id ] );
$newArray = array_slice( $oldArray, 0, $offset, true ) + $custom_field + array_slice( $oldArray, $offset, null, true );
$fields['billing'] = $newArray;
return $fields;
}, PHP_INT_MAX );
@pablo-sg-pacheco
pablo-sg-pacheco / convert-string-to-boolean.js
Created January 26, 2017 14:07
Convert a string to Boolean. It handles 'True' and 'False' Strings written as Lowercase or Uppercase. It also detects '0' and '1' Strings
/**
* Convert a string to Boolean.
* It handles 'True' and 'False' Strings written as Lowercase or Uppercase.
* It also detects '0' and '1' Strings
*/
function convertToBoolean(variable){
variable = variable.toLowerCase();
return Boolean(variable == true | variable === 'true');
}
@pablo-sg-pacheco
pablo-sg-pacheco / functions.php
Created November 29, 2016 17:14
Converte o menu para o contact details
<?php
add_filter( 'wp_get_nav_menu_items', function($items, $menu, $args){
if($menu->name!='Rodapé-3'){
return $items;
}
if(is_admin()){
return $items;
}
$contactDetails = get_option('contact');
@pablo-sg-pacheco
pablo-sg-pacheco / addtoany_plugin.js
Created October 19, 2016 18:46
Wordpress plugin - AddToAny Configurar cor
//Colocar na opcao Additional JavaScript, dentro do admin
a2a_config.icon_color = "#B93437";
@pablo-sg-pacheco
pablo-sg-pacheco / functions.php
Last active September 23, 2016 17:02
Order an multidimensional array based on another array
<?php
/*
$terms =
Array
(
[2] => WP_Term Object
(
[term_id] => 6
)
@pablo-sg-pacheco
pablo-sg-pacheco / sql.mysql
Created September 9, 2016 18:20
Teste pra fazer uma query no wordpress puxando os posts e os termos
#TEST1
SELECT wp_posts.post_title, t.name
FROM wp_posts
LEFT JOIN wp_term_relationships tr ON tr.object_id=wp_posts.ID
LEFT JOIN wp_term_taxonomy tt ON tt.term_taxonomy_id=tr.term_taxonomy_id AND tt.taxonomy='shopping_list_tax'
LEFT JOIN wp_terms t ON t.term_id=tt.term_id
WHERE 1=1 AND wp_posts.post_type = 'shopping_list_sg' AND (wp_posts.post_status = 'publish' OR wp_posts.post_status = 'private')
ORDER BY wp_posts.post_date DESC
#TEST 2
@pablo-sg-pacheco
pablo-sg-pacheco / command_line.snippets
Last active August 23, 2016 19:34
GIT - submodules
#COMMIT AND PUSH ALL SUBMODULES
#In Main project
git submodule foreach 'git add .' #recursively add files in submodules
git submodule foreach 'git commit -a -m "Altered submodule" || :'
git add --all :/
git commit -am "Altered submodule"
git push --recurse-submodules=on-demand
@pablo-sg-pacheco
pablo-sg-pacheco / functions.php
Created August 23, 2016 13:50
Woocommerce - Adiciona as informacoes bancarias na pag do pedido
<?php
//Adiciona as informacoes bancarias na pag do pedido
add_action('woocommerce_view_order',function($order_id){
//echo '<hr style="border-top:1px solid #ccc;margin-top:10px;margin-bottom:30px" />';
$order=new WC_Order( $order_id );
if ( $order->payment_method !== 'bacs') return;
$bacs = new WC_Gateway_BACS();
$bacs->thankyou_page( $order_id);
});
@pablo-sg-pacheco
pablo-sg-pacheco / functions.php
Last active May 28, 2020 17:13
Woocommerce - Direct Bank Transfer - Add fields on thank you page and order received email
<?php
/**
* Adds CNPJ and Company Name fields on the Thank You page and Order Received Email when using 'Direct Bank Transfer' payment gateway.
*/
add_filter( 'woocommerce_bacs_account_fields', function ( $fields ) {
$fields['cnpj']['label'] = __( 'CNPJ', 'domain' );
$fields['cnpj']['value'] = '99.999.999/9999-99';
$fields['company_name']['label'] = __( 'Razao Social', 'domain' );
$fields['company_name']['value'] = 'Uma empresa doce e bacana Ltda';
return $fields;
@pablo-sg-pacheco
pablo-sg-pacheco / functions.php
Created August 8, 2016 15:07
Woocommerce - Remove WooCommerce updater message on admin
// Remove WooCommerce Updater
remove_action('admin_notices', 'woothemes_updater_notice');