Skip to content

Instantly share code, notes, and snippets.

View claudiosanches's full-sized avatar
👨‍💻

Claudio Sanches claudiosanches

👨‍💻
View GitHub Profile
@claudiosanches
claudiosanches / .htaccess
Created March 8, 2017 22:32
Redirect all pages to a new domain
RewriteEngine On
RewriteRule ^(.*)$ https://newdomain.com/$1 [R=301,L]
@claudiosanches
claudiosanches / functions.php
Last active March 26, 2018 13:58
WooCommerce Correios - Free PAC for Shipping Zone
<?php
function custom_woocommerce_correios_shipping_methods( $rate, $instance_id ) {
// Verifica se esta utilizando a instancia correta, se não estiver para o código.
if ( 99 !== $instance_id ) {
return $rate;
}
$rate['cost'] = 0;
return $rate;
@claudiosanches
claudiosanches / functions.php
Last active September 5, 2017 16:08
WooCommerce Correios - Free PAC when cart costs more than 100
<?php
function custom_woocommerce_correios_shipping_methods( $rate ) {
if ( isset( WC()->cart->subtotal ) && 100 <= WC()->cart->subtotal ) {
$rate['cost'] = 0;
}
return $rate;
}
add_filter( 'woocommerce_correios_correios-pac_rate', 'custom_woocommerce_correios_shipping_methods' );
@claudiosanches
claudiosanches / functions.php
Last active October 31, 2022 16:02
WooCommerce Correios - PAC Free
<?php
function custom_woocommerce_correios_shipping_methods( $rate ) {
$rate['cost'] = 0;
return $rate;
}
add_filter( 'woocommerce_correios_correios-pac_rate', 'custom_woocommerce_correios_shipping_methods' );
@claudiosanches
claudiosanches / file.php
Created December 2, 2016 22:53
WooCommerce - Restore the "(Free)" message when shipping method does not charge any cost.
<?php
/**
* Display (Free) when shipping method does not charge any cost.
*
* @param String $label Shipping method label.
* @param WC_Shipping_Rate $method Shipping method data.
* @return string
*/
function my_wc_custom_free_shipping_label( $label, $method ) {
// Only apply when is free and not using the free shipping method.
@claudiosanches
claudiosanches / functions.php
Created November 8, 2016 14:14
WooCommerce - Saving new "My account" registration fields
<?php
/**
* Save the extra register fields.
*
* @param int $customer_id Current customer ID.
*/
function wooc_save_extra_register_fields( $customer_id ) {
if ( isset( $_POST['billing_first_name'] ) ) {
// WordPress default first name field.
update_user_meta( $customer_id, 'first_name', sanitize_text_field( $_POST['billing_first_name'] ) );
@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
*/
@claudiosanches
claudiosanches / .htaccess
Last active September 29, 2016 14:28
Fix &amp; in URLs
RewriteCond %{THE_REQUEST} \s(.*?)\&amp\;([^\s]*) [NC]
RewriteRule ^ /%1&%2 [L,NE,R]
@claudiosanches
claudiosanches / functions.php
Created July 20, 2016 11:30
WooCommerce - Redirect to checkout after add product to the cart
<?php
/**
* Add to cart redirect to checkout.
*
* @param string $url
* @return string
*/
function my_wc_add_to_cart_redirect_to_checkout( $url ) {
return wc_get_checkout_url();
@claudiosanches
claudiosanches / functions.php
Created July 6, 2016 03:34
WooCommerce - Custom tag cloud shortcode
<?php
/**
* Custom WooCommerce tag cloud shortcode.
*
* Use the follow shortcode in your pages: [my_wc_tag_cloud]
*/
function my_custom_wc_tag_cloud_shortcode() {
return wp_tag_cloud( array( 'taxonomy' => 'product_tag', 'echo' => false ) );
}