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
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 / GenericBox.php
Last active April 28, 2016 18:48
CMB2 - Generic Box - Group field (image, title, description, link, target, label)
<?php
namespace OOPFunctions\MetaBoxes\GenericBox;
if ( !class_exists('\OOPFunctions\MetaBoxes\GenericBox\GenericBox') ) {
/**
* Description of GenericBox
*
* @author Pablo Pacheco <pablo.pacheco@origgami.com.br>
@pablo-sg-pacheco
pablo-sg-pacheco / functions.php
Last active August 24, 2016 17:07
Converts content in Contact Details fields. Ex: {{email}}
<?php
//Converts content in Contact Details fields. Ex: {{email}}
add_filter( 'the_content', function($content){
$contactDetails = get_option('contact');
foreach ( $contactDetails as $key => $detail ) {
if ( !empty($detail) ) {
if(strpos($detail, '@')!==false){
$content = str_replace('{{'.$key.'}}', '<a href="mailto:' . $detail . '">' . $detail . '</a>', $content);
}else if(strpos($detail, 'http://')!==false){
$content = str_replace('{{'.$key.'}}', '<a target="_blank" href="' . $detail . '">' . $detail . '</a>', $content);
@pablo-sg-pacheco
pablo-sg-pacheco / functions.php
Last active October 5, 2016 17:23
Add default contact details fields
<?php
//Add default contact details fields
add_filter('contact_details', function( $details ) {
unset($details['phone']);
unset($details['fax']);
unset($details['email']);
unset($details['mobile']);
unset($details['address']);
@pablo-sg-pacheco
pablo-sg-pacheco / functions.php
Last active April 12, 2024 12:38
Wordpress - Password protect a custom post type programmatically
<?php
/**
* Password protects a custom post type programmatically.
*
* @param $post
*/
add_action( 'the_post', function( $post ){
if ( $post->post_type != 'post' ) {
return;
}
@pablo-sg-pacheco
pablo-sg-pacheco / functions.php
Last active November 11, 2020 17:26
Frete grátis por região (faixa de cep) - Woocommerce
<?php
//Testa uma faixa de cep
function checkCpfRange($valor, $intervalos) {
$v = (int) preg_replace("/\D+/", "", $valor);
foreach ($intervalos as $range):
list($min, $max) = $range;
if ($v >= $min && $v <= $max)
return true;
endforeach;
return false;
@pablo-sg-pacheco
pablo-sg-pacheco / center-v.css
Last active May 10, 2016 18:01
CSS - Center vertically
.center-v-parent{
-webkit-transform-style: preserve-3d;
-moz-transform-style: preserve-3d;
transform-style: preserve-3d;
}
.center-v {
position: relative;
top: 50%;
transform: translateY(-50%);
}
@pablo-sg-pacheco
pablo-sg-pacheco / Gallery.php
Last active July 4, 2016 19:22
CMB2 - Classe para criar uma galeria padrão, usando CMB2