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
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 / 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
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 / 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 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 / 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 / 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 / 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 / functions.php
Last active January 31, 2018 19:11 — forked from jnlsn/functions.php
WP Query Orderby Taxonomy Term Name
<?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 / functions.php
Last active February 23, 2018 20:12
Add Pinterest meta on HB Charity theme
<?php
add_action('wp_head',function(){
?>
<?php //Add your meta here ?>
<meta />
<?php
});
?>