Skip to content

Instantly share code, notes, and snippets.

View claudiosanches's full-sized avatar
👨‍💻

Claudio Sanches claudiosanches

👨‍💻
View GitHub Profile
@claudiosanches
claudiosanches / functions.php
Last active June 4, 2022 07:52
WooCommerce - Add Order Again button to My Orders actions
<?php
/**
* Add order again button in my orders actions.
*
* @param array $actions
* @param WC_Order $order
* @return array
*/
function cs_add_order_again_to_my_orders_actions( $actions, $order ) {
if ( $order->has_status( 'completed' ) ) {
@claudiosanches
claudiosanches / functions.php
Last active June 1, 2022 17:20
WooCommerce - Hide the "In stock" message on product page.
<?php
/**
* Hide the "In stock" message on product page.
*
* @param string $html
* @param string $text
* @param WC_Product $product
* @return string
*/
function my_wc_hide_in_stock_message( $html, $text, $product ) {
@claudiosanches
claudiosanches / functions.php
Last active April 16, 2022 09:14
WooCommerce - Hide shipping rates when free shipping is available.
<?php
/**
* Hide shipping rates when free shipping is available.
* Updated to support WooCommerce 2.6 Shipping Zones.
*
* @param array $rates Array of rates found for the package.
* @return array
*/
function my_hide_shipping_when_free_is_available( $rates ) {
$free = array();
@claudiosanches
claudiosanches / functions.php
Created November 23, 2012 15:01
WooCommerce - Customizar o summary do content-single-product.php
<?php
// Colar no functions.php
// Para remover os hooks
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_title' );
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_price' );
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_excerpt' );
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_add_to_cart' );
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_meta' );
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_sharing' );
@claudiosanches
claudiosanches / price.php
Created December 18, 2012 23:19
WooCommerce - Ocultar o preço para produtos com variáveis.
<?php
/**
* Single Product Price, including microdata for SEO
*
* @author WooThemes
* @package WooCommerce/Templates
* @version 1.6.4
*/
global $post, $product;
@claudiosanches
claudiosanches / functions.php
Created July 24, 2012 03:22
Wordpress Related Posts function
<?php
/**
* Related Posts.
*
* Usage:
* To show related by categories:
* Add in single.php <?php dfw_related_posts(); ?>.
* To show related by tags:
* Add in single.php <?php dfw_related_posts('tag'); ?>.
@claudiosanches
claudiosanches / functions.php
Created January 9, 2014 16:32
WooCommerce 2.1 - Extra fields in WooCommerce registration.
<?php
/**
* Add new register fields for WooCommerce registration.
*
* @return string Register fields HTML.
*/
function cs_wc_extra_register_fields() {
?>
<p class="form-row form-row-first">
<label for="reg_billing_first_name"><?php _e( 'Nome', 'textdomain' ); ?> <span class="required">*</span></label>
@claudiosanches
claudiosanches / woocommerce-pay-button-sample.php
Created November 7, 2019 20:40
WooCommerce - Pay Button sample
<?php
/**
* Plugin Name: Test "pay button" support
*/
add_action( 'plugins_loaded', function() {
class My_Custom_Gateway extends WC_Payment_Gateway {
public function __construct() {
$this->id = 'custom_gateway';
$this->has_fields = false;
@claudiosanches
claudiosanches / functions.php
Created June 8, 2014 22:23
WooCommerce - Change product loop add to cart button
<?php
function custom_woocommerce_loop_add_to_cart_link( $html, $product ) {
return '<a href="' . get_permalink( $product->id ) . '" class="button">' . __( 'Texto do botão' ) . '</a>';
}
add_filter( 'woocommerce_loop_add_to_cart_link', 'custom_woocommerce_loop_add_to_cart_link', 10, 2 );
@claudiosanches
claudiosanches / functions.php
Created November 8, 2016 14:13
WooCommerce - Validating new "My account" registration fields
<?php
/**
* Validate the extra register fields.
*
* @param WP_Error $validation_errors Errors.
* @param string $username Current username.
* @param string $email Current email.
*
* @return WP_Error
*/