Skip to content

Instantly share code, notes, and snippets.

View chrdesigner's full-sized avatar

César Ribeiro chrdesigner

View GitHub Profile
@chrdesigner
chrdesigner / functions.php
Created August 21, 2015 13:19
WordPress - Search in Specific Post Type
<?php
/*
* Search in Specific Post Type
*/
function search_specific_post_type($query) {
if ($query->is_search) {
$query->set('post_type', array('post'));
};
return $query;
};
<?php
/*
* Add Stock Quantity in Catalog Loop
*/
function odin_stock_catalog() {
global $product;
if ( $product->is_in_stock() ) {
echo '<div class="stock" >' . $product->get_stock_quantity() . __( 'EM ESTOQUE', 'odin' ) . '</div>';
} else {
echo '<div class="out-of-stock" >' . __('SEM ESTOQUE', 'odin' ) . '</div>';
@chrdesigner
chrdesigner / functions.php
Created August 11, 2015 16:02
Add wysija shortcode after the_content
<?php
/*
* Add wysija shortcode after the_content
*/
add_filter( 'the_content', 'chr_add_after_content' );
function chr_add_after_content( $content ) {
if( is_single() ) :
$custom_content .= $content;
$custom_content .= '<h2 class="widgettitle">Newsletter</h2>';
<?php
/**
* Remove Widget Product Gallery - WooCommerce
*/
add_action( 'add_meta_boxes' , 'chr_remove_meta_boxe', 40 );
function chr_remove_meta_boxe(){
remove_meta_box( 'woocommerce-product-images', 'product', 'side');
}
@chrdesigner
chrdesigner / functions.php
Last active August 29, 2015 14:25
Function Remove Special Characters and Convert Text in Lowercase
<?php
/*
* Function Remove Special Characters and Convert Text in Lowercase
*/
function chrConvertText($text) {
$transliterationTable = array('á' => 'a', 'Á' => 'A', 'à' => 'a', 'À' => 'A', 'ă' => 'a', 'Ă' => 'A', 'â' => 'a', 'Â' => 'A', 'å' => 'a', 'Å' => 'A', 'ã' => 'a', 'Ã' => 'A', 'ą' => 'a', 'Ą' => 'A', 'ā' => 'a', 'Ā' => 'A', 'ä' => 'ae', 'Ä' => 'AE', 'æ' => 'ae', 'Æ' => 'AE', 'ḃ' => 'b', 'Ḃ' => 'B', 'ć' => 'c', 'Ć' => 'C', 'ĉ' => 'c', 'Ĉ' => 'C', 'č' => 'c', 'Č' => 'C', 'ċ' => 'c', 'Ċ' => 'C', 'ç' => 'c', 'Ç' => 'C', 'ď' => 'd', 'Ď' => 'D', 'ḋ' => 'd', 'Ḋ' => 'D', 'đ' => 'd', 'Đ' => 'D', 'ð' => 'dh', 'Ð' => 'Dh', 'é' => 'e', 'É' => 'E', 'è' => 'e', 'È' => 'E', 'ĕ' => 'e', 'Ĕ' => 'E', 'ê' => 'e', 'Ê' => 'E', 'ě' => 'e', 'Ě' => 'E', 'ë' => 'e', 'Ë' => 'E', 'ė' => 'e', 'Ė' => 'E', 'ę' => 'e', 'Ę' => 'E', 'ē' => 'e', 'Ē' => 'E', 'ḟ' => 'f', 'Ḟ' => 'F', 'ƒ' => 'f', 'Ƒ' => 'F', 'ğ' => 'g', 'Ğ' => 'G', 'ĝ' => 'g', 'Ĝ' => 'G', 'ġ' => 'g', 'Ġ' => 'G', 'ģ' => 'g', 'Ģ' => 'G', 'ĥ' => 'h', 'Ĥ' => 'H', 'ħ' =
@chrdesigner
chrdesigner / main.js
Created July 20, 2015 12:26
Vertical Align with jQuery
$(function() {
$('.classVerticalAlign').css({
'position' : 'absolute',
'left' : '50%',
'top' : '50%',
'margin-left' : -$('.classVerticalAlign').outerWidth()/2,
'margin-top' : -$('.classVerticalAlign').outerHeight()/2
});
});
@chrdesigner
chrdesigner / functions.php
Created June 17, 2015 14:14
Custom single post format template
<?php
/**
* Custom single post format template
* Reference: https://codex.wordpress.org/Function_Reference/get_post_format
*/
function chr_custom_single_post_format( $template ) {
if ( is_single() && has_post_format() ) {
$post_format_template = locate_template( 'single-' . get_post_format() . '.php' );
if ( $post_format_template ) {
$template = $post_format_template;
@chrdesigner
chrdesigner / functions.php
Last active August 29, 2015 14:22
allow AED for WooCommerce
<?php
// allow AED for WooCommerce
add_filter( 'woocommerce_paypal_supported_currencies', 'paypal_aed_current' );
function paypal_aed_current($currency_array) {
$currency_array[] = 'AED';
return $currency_array;
}
@chrdesigner
chrdesigner / functions.php
Last active August 29, 2015 14:22
Add symbol United Arab Emirates Dirham
<?php
// Add symbol United Arab Emirates Dirham
add_filter( 'woocommerce_currencies', 'add_custom_currency' );
function add_custom_currency( $currencies ) {
$currencies['AED'] = __( 'United Arab Emirates Dirham', 'woocommerce' );
return $currencies;
}
add_filter('woocommerce_currency_symbol', 'add_custom_currency_symbol', 10, 2);
function add_custom_currency_symbol( $currency_symbol, $currency ) {
@chrdesigner
chrdesigner / functions.php
Created May 23, 2015 15:36
Adicionar Um Unico Item por Carrinho - WooCommerce
<?php
/*
* Função para adicionar um único item por carrinho
*/
function woo_unico_produto( $cart_item_data ) {
global $woocommerce;
$woocommerce->cart->empty_cart();
return $cart_item_data;
}