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
Created April 5, 2017 18:30
WooCommerce - Restore "Free!" for free simple products on WooCommerce 3.0.
<?php
/**
* Restore single product "Free!" on WooCommerce 3.0.
*
* @param string $price Price HTML.
* @param WC_Product $product Product instance.
* @return string.
*/
function my_wc_custom_get_price_html( $price, $product ) {
if ( $product->get_price() == 0 ) {
@claudiosanches
claudiosanches / functions.php
Last active January 8, 2024 19:36
WooCommerce - Adds a custom message about how long will take to delivery.
<?php
/**
* Adds a custom message about how long will take to delivery.
*/
function my_wc_custom_cart_shipping_notice() {
echo '<tr class="shipping-notice"><td colspan="2"><small>';
_e( '<strong>Atenção:</strong> O prazo de entrega começa a contar a partir da aprovação do pagamento.', 'my-text-domain' );
echo '</small></td></tr>';
}
@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]