Skip to content

Instantly share code, notes, and snippets.

View gfcarvalho's full-sized avatar

Gustavo Carvalho gfcarvalho

View GitHub Profile
@gfcarvalho
gfcarvalho / functions.php
Last active September 16, 2021 23:46
Woocommerce - change variable price range to display the starting price ("A partir de")
<?php
/**
* Change variable price range to display the starting price (A partir de...
* https://wedevs.com/105501/disable-woocommerce-variable-product-price/
*/
function wc_varb_price_range( $wcv_price, $product ) {
$prefix = sprintf('%s: ', __('A partir de', 'wcvp_range'));

Zip excluding specific directories

Exclude .git file and node_modules directory

$ zip -r9 [target_file] [source_file] -x *.git* node_modules/\*

Exclude .git file and files in node_modules directory, but keep node_modules directory

$ zip -r9 [target_file] [source_file] -x *.git* node_modules/**\*
@gfcarvalho
gfcarvalho / WC_Variable_Product_Price_Range
Created April 18, 2019 01:51 — forked from maion11/WC_Variable_Product_Price_Range
Changing WooCommerce Variable Products Price Range
function wc_varb_price_range( $wcv_price, $product ) {
$prefix = sprintf('%s: ', __('From', 'wcvp_range'));
$wcv_reg_min_price = $product->get_variation_regular_price( 'min', true );
$wcv_min_sale_price = $product->get_variation_sale_price( 'min', true );
$wcv_max_price = $product->get_variation_price( 'max', true );
$wcv_min_price = $product->get_variation_price( 'min', true );
$wcv_price = ( $wcv_min_sale_price == $wcv_reg_min_price ) ?
@gfcarvalho
gfcarvalho / external_database.php
Created February 26, 2019 13:36 — forked from MrSaints/external_database.php
A custom database class to demonstrate how WordPress' wpdb class can be instantiated and extended to allow you to connect to another / an external or secondary database. The global $wpdb object is only capable of communicating with the WordPress database. Refer to http://codex.wordpress.org/Class_Reference/wpdb for more information.
<?php
/*
The MIT License (MIT)
Copyright © 2014 Ian Lai
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the “Software”), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
@gfcarvalho
gfcarvalho / anchor-offset.css
Last active March 4, 2016 18:31
Scroll to offset anchor links. Change the numbers to fit the height of your heading. Include <a class="anchor-offset" id="your-anchor-name"></a> in your HTML file where you want to place the anchor.
.anchor-offset {
display: block;
margin-top: -100px;
padding-top: 100px;
width: 1px;
}
@gfcarvalho
gfcarvalho / avoidfouc.html
Created April 28, 2014 03:53
Avoiding FOUC
<html class="no-js">
<head>
<script>(function(H){H.className=H.className.replace(/\bno-js\b/,'js')})(document.documentElement)</script>
# Compiled source #
###################
*.com
*.class
*.dll
*.exe
*.o
*.so
# Packages #

Deploy your site with git

This gist assumes:

  • you have a local git repo
  • with an online remote repository (github / bitbucket etc)
  • and a cloud server (Rackspace cloud / Amazon EC2 etc)
    • your (PHP) scripts are served from /var/www/html/
    • your webpages are executed by apache
  • apache's home directory is /var/www/
@gfcarvalho
gfcarvalho / removeChildren.js
Created April 1, 2014 03:34
Remove all children from a given element
function removeChildren(elem) {
var last;
while (last = elem.lastChild) {
elem.removeChild(last);
}
}
@gfcarvalho
gfcarvalho / shuffle.js
Created April 1, 2014 03:26
Shuffles a given array using an implemented version of Fisher–Yates algorithm
function shuffle(array) {
var counter = array.length, temp, index;
// While there are elements in the array
while (counter--) {
// Pick a random index
index = (Math.random() * (counter+1)) | 0;
// And swap the last element with it
temp = array[counter];