Skip to content

Instantly share code, notes, and snippets.

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

Block or report user

Report or block pablo-sg-pacheco

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@pablo-sg-pacheco
pablo-sg-pacheco / functions.php
Last active Jan 31, 2018 — forked from jayarnielsen/functions.php
WP Query Orderby Taxonomy Term Name
View functions.php
<?php
add_filter('posts_clauses', 'posts_clauses_with_tax', 10, 2);
function posts_clauses_with_tax( $clauses, $wp_query ) {
global $wpdb;
//array of sortable taxonomies
$taxonomies = array('example-taxonomy', 'other-taxonomy');
if (isset($wp_query->query['orderby']) && in_array($wp_query->query['orderby'], $taxonomies)) {
$clauses['join'] .= "
LEFT OUTER JOIN {$wpdb->term_relationships} AS rel2 ON {$wpdb->posts}.ID = rel2.object_id
LEFT OUTER JOIN {$wpdb->term_taxonomy} AS tax2 ON rel2.term_taxonomy_id = tax2.term_taxonomy_id
@pablo-sg-pacheco
pablo-sg-pacheco / query.sql
Created Dec 14, 2017
Get WooCommerce product type
View query.sql
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 / functions.php
Last active Apr 10, 2018
Make the plugin Wish list for WooCommerce compatible with Yith Infinite scrolling
View functions.php
/**
* Makes the plugin Wish list for WooCommerce compatible with Yith Infinite scrolling
*/
add_action('wp_footer',function(){
?>
<script>
jQuery(document).on('yith_infs_added_elem',function(){
jQuery('.alg-wc-wl-btn').addClass('ajax-loading');
var alg_wc_wl_show = function(){
jQuery('.alg-wc-wl-btn.ajax-loading').removeClass('ajax-loading');
@pablo-sg-pacheco
pablo-sg-pacheco / wishlist-update.js
Last active Nov 24, 2017
Update the whole wishlist every time an item is added or removed, considering the wishlist is always present in all pages
View wishlist-update.js
/**
* 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 Apr 19, 2017 — forked from hlashbrooke/function.php
WooCommerce - Check if you are running a specified WooCommerce version (or higher)
View function.php
<?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 Feb 20, 2017
Positions a custom booster field in any order on checkout
View functions.php
<?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 Jan 26, 2017
Convert a string to Boolean. It handles 'True' and 'False' Strings written as Lowercase or Uppercase. It also detects '0' and '1' Strings
View convert-string-to-boolean.js
/**
* 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 Nov 29, 2016
Converte o menu para o contact details
View functions.php
<?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 Oct 19, 2016
Wordpress plugin - AddToAny Configurar cor
View addtoany_plugin.js
//Colocar na opcao Additional JavaScript, dentro do admin
a2a_config.icon_color = "#B93437";
@pablo-sg-pacheco
pablo-sg-pacheco / functions.php
Last active Sep 23, 2016
Order an multidimensional array based on another array
View functions.php
<?php
/*
$terms =
Array
(
[2] => WP_Term Object
(
[term_id] => 6
)
You can’t perform that action at this time.