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 / query.sql
Created December 14, 2017 13:11
Get WooCommerce product type
SELECT p.ID, p.post_title, t.name AS product_type
FROM wp_posts AS p
JOIN wp_term_relationships AS tr ON tr.object_id = p.id
JOIN wp_term_taxonomy AS tt ON tr.term_taxonomy_id=tt.term_taxonomy_id
JOIN wp_terms AS t ON t.term_id = tt.term_id
WHERE p.id = 111 AND tt.taxonomy = 'product_type'
@pablo-sg-pacheco
pablo-sg-pacheco / wishlist-update.js
Last active November 24, 2017 18:06
Update the whole wishlist every time an item is added or removed, considering the wishlist is always present in all pages
/**
* Update the whole wishlist every time an item is added or removed, considering the wishlist is always present in all pages
* Plugin: Wish list for WooCommerce
*/
jQuery(document).ready(function($){
//Get your wish list element first (Replace it by your wish list css class)
var wish_list_div = '.wish-list';
@pablo-sg-pacheco
pablo-sg-pacheco / function.php
Last active April 19, 2017 17:40 — forked from hlashbrooke/function.php
WooCommerce - Check if you are running a specified WooCommerce version (or higher)
<?php
function woocommerce_version_check( $version = '3.0' ) {
if ( class_exists( 'WooCommerce' ) ) {
global $woocommerce;
if( version_compare( $woocommerce->version, $version, ">=" ) ) {
return true;
}
}
return false;
}
@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 / functions.php
Last active November 24, 2016 01:29
Shows out of stock message when a variable product has all variations out of stock
<?php
//Shows out of stock message when a variable product has all variations out of stock
add_filter('wp_footer', function(){
if(is_product()){
global $product;
if($product->is_type('variable')){
if(!$product->is_in_stock()){
?>
<script>
jQuery(window).load(function(){
@pablo-sg-pacheco
pablo-sg-pacheco / functions.php
Last active November 24, 2016 01:29
Replaces product price by out of stock message in case a variable product is out of stock (Woocommerce)
<?php
//Replaces product price by out of stock message in case a variable product is out of stock (optional)
add_action('woocommerce_before_single_product_summary',function(){
if(is_product()){
global $product;
if(!$product->is_in_stock()){
remove_action('woocommerce_single_variation','woocommerce_single_variation');
remove_action('woocommerce_single_product_summary','woocommerce_template_single_price');
add_action('woocommerce_single_product_summary',function(){
?>
@pablo-sg-pacheco
pablo-sg-pacheco / auth.json
Last active November 22, 2016 13:23
Origgami Wordpress Install (using Odin and Oggone Themes)
{
"http-basic": {
"bitbucket.org": {
"username": "email@origgami.com.br",
"password": "senhanobitbucket"
}
}
}
@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";