Skip to content

Instantly share code, notes, and snippets.

View claudiosanches's full-sized avatar
👨‍💻

Claudio Sanches claudiosanches

👨‍💻
View GitHub Profile
@claudiosanches
claudiosanches / add-to-cart.php
Created January 12, 2013 02:33
WooCommerce - Botão ver detalhes no lugar do botão de adicionar ao carrinho.
<?php
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
global $product;
printf( '<a href="%s" class="button">%s</a>', get_permalink( $product->id ), __( 'Ver detalhes' ) );
@claudiosanches
claudiosanches / functions.php
Last active June 22, 2018 16:57
WooCommerce: Validate cart quantity.
<?php
/**
* Validate product quantity when added to cart.
*/
function cs_add_to_cart_validate_quantity( $valid, $product_id, $quantity ) {
global $woocommerce;
$valid = true;
// Test quantity.
@claudiosanches
claudiosanches / adsense-by-author.php
Created January 19, 2013 20:32
WordPress plugin - Adsense by Author
<?php
/**
* Plugin Name: Adsense by Author
* Plugin URI: http://claudiosmweb.com/
* Description: Adsense by Author.
* Author: claudiosanches
* Author URI: http://claudiosmweb.com/
* Version: 1.0
* License: GPLv2 or later
* Text Domain: adbyauthor
@claudiosanches
claudiosanches / page.php
Last active December 11, 2015 14:39
Listar paginas irmãs.
<?php
if ( $post->post_parent ) {
$args = array(
'hierarchical' => 1,
'exclude' => $post->ID,
'child_of' => $post->post_parent,
'post_type' => 'page',
'post_status' => 'publish'
);
} else {
@claudiosanches
claudiosanches / functions.php
Created January 30, 2013 17:32
WordPress Shortcode Skills
<?php
function cs_skills( $atts ) {
extract( shortcode_atts( array(
'name' => '',
'perc' => '',
), $atts ) );
// Arredonda o valor. de 66 vai para 70.
$perc = round( $perc, -1 );
@claudiosanches
claudiosanches / index.php
Created February 2, 2013 05:53
WP_Query with custom fields
<?php
$sua_query = WP_Query(
array(
'post_type' => array( 'post', 'page'),
'meta_key' => 'destaque_home',
'meta_value' => 1,
'post_status' => 'publish',
'orderby' => 'date', // Não precisava colocar
'order' => 'DESC', // Não precisava colocar
@claudiosanches
claudiosanches / index.php
Created February 15, 2013 21:19
Exemplo de WP_Query com Custom Fields.
<?php
/**
* Exemplo de WP_Query para custom fields.
*/
$custom_query = new WP_Query( array(
'meta_key' => 'custom_field', // Nome do custom field.
'meta_value' => true, // Valor do custom field.
'posts_per_page' => 10, // Quantidade de posts.
'post_status' => 'publish', // Pega apenas os posts publicados
'ignore_sticky_posts' => 1 // Não adiciona os Sticky Post
@claudiosanches
claudiosanches / add-to-cart.php
Created February 25, 2013 00:24
WooCommerce - Template add-to-cart.php with quantity.
<?php
/**
* Custom Loop Add to Cart.
*
* Template with quantity.
*
* @author WooThemes
* @package WooCommerce/Templates
* @version 1.6.4
*/
@claudiosanches
claudiosanches / adsense-by-author.php
Last active December 14, 2015 13:49
Adsense by author with middle content.
<?php
/**
* Plugin Name: Adsense by Author
* Plugin URI: http://claudiosmweb.com/
* Description: Adsense by Author.
* Author: claudiosanches
* Author URI: http://claudiosmweb.com/
* Version: 1.1
* License: GPLv2 or later
* Text Domain: adbyauthor
@claudiosanches
claudiosanches / add-to-cart.php
Last active October 16, 2024 09:38
WooCommerce - Template add-to-cart.php with quantity and Ajax!
<?php
/**
* Custom Loop Add to Cart.
*
* Template with quantity and ajax.
*/
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly.
global $product;