Skip to content

Instantly share code, notes, and snippets.

View chrdesigner's full-sized avatar

César Ribeiro chrdesigner

View GitHub Profile
@chrdesigner
chrdesigner / function.php
Last active August 29, 2015 14:19
Adding a hook callback - alphabet order - WooCommerce
<?php
// Adding a hook callback.
add_filter( 'woocommerce_default_catalog_orderby_options', 'custom_woocommerce_catalog_orderby' );
add_filter( 'woocommerce_catalog_orderby', 'custom_woocommerce_catalog_orderby' );
function custom_woocommerce_catalog_orderby( $sortby ) {
$sortby['title_asc'] = __('Alphabetical - (A - Z)', 'your-theme');
$sortby['title_desc'] = __('Alphabetical - (Z - A)', 'your-theme');
return $sortby;
}
@chrdesigner
chrdesigner / function.php
Last active August 29, 2015 14:19
Custom sorting options - alphabet order - WooCommerce
<?php
// Custom sorting options
add_filter( 'woocommerce_get_catalog_ordering_args', 'custom_woocommerce_get_catalog_ordering_args' );
function custom_woocommerce_get_catalog_ordering_args( $args ) {
$orderby_value = isset( $_GET['orderby'] ) ? woocommerce_clean( $_GET['orderby'] ) : apply_filters( 'woocommerce_default_catalog_orderby', get_option( 'woocommerce_default_catalog_orderby' ) );
if ('title_asc' == $orderby_value) {
$args['orderby'] = 'title';
$args['order'] = 'ASC';
$args['meta_key'] = '';
@chrdesigner
chrdesigner / function.php
Last active August 29, 2015 14:06
WooCommerce - Additional Information tab
<?php
//Hide dimensions in Additional Information tab
add_filter( 'wc_product_enable_dimensions_display', '__return_false' );
//Hide Additional Information tab
function custom_woocommerce_product_tabs( $tabs ) {
if ( isset( $tabs['additional_information'] ) ) {
unset( $tabs['additional_information'] );
@chrdesigner
chrdesigner / function.php
Last active August 29, 2015 14:02
add rel prettyphoto to all images
<?php
/* add rel prettyphoto to all images */
function autoadd_rel_prettyPhoto($content) {
global $post;
$pattern = "/(<a(?![^>]*?data-rel=['\"]prettyPhoto.*)[^>]*?href=['\"][^'\"]+?\.(?:bmp|gif|jpg|jpeg|png)['\"][^\>]*)>/i";
$replacement = '$1 data-rel="prettyPhoto['.$post->ID.']">';
$content = preg_replace($pattern, $replacement, $content);
return $content;
}
add_filter("the_content","autoadd_rel_prettyPhoto");
<?php
// Remove o Field de Informação adicional
add_filter( 'woocommerce_checkout_fields' , 'alter_woocommerce_checkout_fields' );
function alter_woocommerce_checkout_fields( $fields ) {
unset($fields['order']['order_comments']);
return $fields;
}
// Remove o título de Informação adicional
add_filter( 'woocommerce_enable_order_notes_field', '__return_false' );
@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
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>