Skip to content

Instantly share code, notes, and snippets.

View raphaelchaib's full-sized avatar

Raphael Chaib raphaelchaib

View GitHub Profile
@raphaelchaib
raphaelchaib / functions.php
Created December 12, 2013 16:18
WooCommerce: Changes how price is displayed
<?php
// Changes how price is displayed
add_filter( 'woocommerce_get_price_html', 'wpa83367_price_html', 100, 2 );
function wpa83367_price_html( $price, $product ){
$return = str_replace( '<ins>', 'Por: <ins>', $price );
$return = str_replace( '<del>', '<small class="price-from">De: <del>', $return );
$return = str_replace( '</del>', '</del></small><br/>', $return );
@raphaelchaib
raphaelchaib / functions.php
Created December 11, 2013 06:19
WordPress: Change WordPress dashboard colors If you ever wanted to be able to change WordPress dashboard colors (as well as font or even display) without having to edit WordPress core files, you’ll like this hack for sure. The following example features a basic style change (grey header is replaced by a blue one) but you can easily add as many s…
<?php
// Change wp-admin colors
add_action('admin_head', 'custom_colors');
function custom_colors() {
echo '<style type="text/css">#wphead{background:#069}</style>';
}
@raphaelchaib
raphaelchaib / functions.php
Created December 11, 2013 06:18
WordPress: Remove update nag
<?php
// remove update nag
if ( !current_user_can( 'edit_users' ) ) {
add_action( 'init', create_function( '$a', "remove_action( 'init', 'wp_version_check' );" ), 2 );
add_filter( 'pre_option_update_core', create_function( '$a', "return null;" ) );
}
@raphaelchaib
raphaelchaib / functions.php
Last active December 29, 2015 07:59
[Always display WooCommerce variable product price] If all prices for a product’s variations are the same then variation price will not be displayed. But if it is the only displayed price then you are in trouble. To overcome this situation you can edit your template functions.php file like this:
<?php
// Display variation's price even if min and max prices are the same
add_filter('woocommerce_available_variation', 'variationPriceFix', 10, 3);
function variationPriceFix ($value, $object = null, $variation = null) {
if ($value['price_html'] == '') {
$value['price_html'] = '<span class="price">' . $variation->get_price_html() . '</span>';
}
return $value;
}
@raphaelchaib
raphaelchaib / functions.php
Created September 2, 2013 17:26
PHP: Simple random password generator
<?php
function randomPassword($length = 10) {
$alphabet = 'abcdefghijklmnopqrstuwxyzABCDEFGHIJKLMNOPQRSTUWXYZ0123456789';
$pass = array(); //remember to declare $pass as an array
$alphaLength = strlen($alphabet) - 1; //put the length -1 in cache
for ($i = 0; $i < $length; $i++) {
$n = rand(0, $alphaLength);
$pass = $alphabet[$n];
}
@raphaelchaib
raphaelchaib / schema.sql
Created August 28, 2013 20:17
MySQL: WHILE statement schema (Need to finish it)
DELIMITER $$
CREATE PROCEDURE fillPaisesNome()
BEGIN
DECLARE paisesNoName INT;
DECLARE controle INT;
SET paisesNoName = (SELECT COUNT(*) FROM `io_paises` WHERE `io_paises`.`nome` IS NULL);
SET controle = 0;
WHILE controle < paisesNoName DO
UPDATE `io_paises` AS `pais`
@raphaelchaib
raphaelchaib / app.js
Created August 15, 2013 14:52
Javascript: Select text inside element (can be used with hover, focus, etc)
function SelectText(element) {
var text = document.getElementById(element);
if ($.browser.msie) {
var range = document.body.createTextRange();
range.moveToElementText(text);
range.select();
} else if ($.browser.mozilla || $.browser.opera) {
var selection = window.getSelection();
var range = document.createRange();
range.selectNodeContents(text);
@raphaelchaib
raphaelchaib / app.js
Created August 1, 2013 16:30
Javascript: Make #main's height go to footer and fill up all the page
// Make #main's height go to footer and fill up all the page
jQuery(document).ready(function() {
// Size that main have to be
var mainPredefinedHeight = jQuery(window).height()
- jQuery('#header').outerHeight(true)
- jQuery('#footer').outerHeight(true)
- parseInt(jQuery('#main').css('paddingBottom'))
;
if( jQuery('#main').height() < mainPredefinedHeight) {
@raphaelchaib
raphaelchaib / exclude_files_except
Last active December 20, 2015 04:39
Exclude files and directories via Linux's shell, except some of them.
find . ! -name one ! -name two -maxdepth 1 -type f -delete
@raphaelchaib
raphaelchaib / app.js
Created July 23, 2013 17:26
Disable text selection
function disableselect(e)
{
return false;
}
document.onselectstart=new Function ("return false");
if (window.sidebar){document.onmousedown=disableselect;
document.onclick=reEnable;}