Skip to content

Instantly share code, notes, and snippets.

Avatar
👨‍💻

Claudio Sanches claudiosanches

👨‍💻
View GitHub Profile
@claudiosanches
claudiosanches / functions.php
Last active Mar 26, 2018
WooCommerce Correios - Free PAC for Shipping Zone
View functions.php
<?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 Sep 5, 2017
WooCommerce Correios - Free PAC when cart costs more than 100
View functions.php
<?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 Dec 29, 2016
WooCommerce Correios - PAC Free
View functions.php
<?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 Dec 2, 2016
WooCommerce - Restore the "(Free)" message when shipping method does not charge any cost.
View file.php
<?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 Nov 8, 2016
WooCommerce - Saving new "My account" registration fields
View functions.php
<?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 Nov 8, 2016
WooCommerce - Validating new "My account" registration fields
View functions.php
<?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 Sep 29, 2016
Fix &amp; in URLs
View .htaccess
RewriteCond %{THE_REQUEST} \s(.*?)\&amp\;([^\s]*) [NC]
RewriteRule ^ /%1&%2 [L,NE,R]
@claudiosanches
claudiosanches / functions.php
Created Jul 20, 2016
WooCommerce - Redirect to checkout after add product to the cart
View functions.php
<?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 Jul 6, 2016
WooCommerce - Custom tag cloud shortcode
View functions.php
<?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 ) );
}
@claudiosanches
claudiosanches / functions.php
Last active Jan 26, 2019
WooCommerce - Hide the "In stock" message on product page.
View functions.php
<?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 ) {
You can’t perform that action at this time.