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
Last active August 25, 2015 23:35
Function - Remove Loop/Single Button Add to Cart
<?php
/*
* Function - Remove Loop/Single Button Add to Cart
*/
add_action('init','remove_add_to_cart');
function remove_add_to_cart(){
if(is_user_logged_in()){}else{
remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart', 10 );
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_add_to_cart', 30 );
<?php
/*
* WP_Query - Show in your result search page, How many, products were found.
*/
$mySearch =& new WP_Query("s=$s & showposts=-1"); $num = $mySearch->post_count; ?>
<h1 class="page-title search-products-alert">
Foram encontrados <strong><?php echo $num;?></strong> resultados para a busca: <strong><?php echo get_search_query(); ?></strong>
</h1>
@chrdesigner
chrdesigner / functions.php
Last active August 25, 2015 23:35
Function - Show the price only after logging
<?php
/*
* Function - Show the price only after logging
*/
add_filter('woocommerce_get_price_html','show_price_logged');
function show_price_logged($price){
if( is_user_logged_in() ){
return $price;
} else {
return '<a href="' .get_permalink(woocommerce_get_page_id('myaccount')). '" title="Já tenho Conta" class="btn-myaccount">Já tenho Conta</a> ou <a href="' .get_permalink(woocommerce_get_page_id('myaccount')). '" title="Registrar para visualizar o preço!" class="btn-registrar">Registrar para visualizar o preço!</a>';
@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;