Skip to content

Instantly share code, notes, and snippets.

View luizbills's full-sized avatar
I may be slow to respond.

Luiz Bills luizbills

I may be slow to respond.
View GitHub Profile
@luizbills
luizbills / example.php
Last active April 28, 2021 13:18
Mostrar preço dos produtos variáveis com "apartir de"
<?php
/**
* @version 2.0.0
* @author Luiz Paulo Bills <[email protected]>
*/
add_filter( 'woocommerce_variable_sale_price_html', 'lpb_wc_variable_product_price_html', 10, 2 );
add_filter( 'woocommerce_variable_price_html','lpb_wc_variable_product_price_html', 10, 2 );
function lpb_wc_variable_product_price_html ( $html, $product ) {
$min_price = $product->get_variation_regular_price( 'min', true );
@luizbills
luizbills / example.php
Created June 6, 2017 20:45
WordPress Front-end Optimizations
<?php
add_filter( 'style_loader_src', 'generate_remove_cssjs_ver', 10, 2 );
add_filter( 'script_loader_src', 'generate_remove_cssjs_ver', 10, 2 );
function generate_remove_cssjs_ver( $src ) {
if( strpos( $src, '?ver=' ) ) $src = remove_query_arg( 'ver', $src );
return $src;
}
add_action( 'init', 'generate_disable_wp_emojicons' );
@luizbills
luizbills / code.php
Last active August 4, 2022 17:30
Desativar pagamento quando a opção de frete "Retirar no local" for escolhida
<?php
add_filter( 'woocommerce_available_payment_gateways', 'lpb_remove_other_payment_options_for_local_pickup' );
function lpb_remove_other_payment_options_for_local_pickup ( $gateways ) {
$chosen_shipping_rates = WC()->session->get( 'chosen_shipping_methods' );
if ( ! empty( $chosen_shipping_rates ) && strpos( $chosen_shipping_rates[0], 'local_pickup' ) !== false ) {
// disable payment
add_filter( 'woocommerce_cart_needs_payment', '__return_false' );
@luizbills
luizbills / code.php
Created July 6, 2017 17:58
[WooCommerce] Mostrar "valor economizado" dos produtos em promoção
add_filter( 'woocommerce_get_price_html', 'lpb_wc_add_sale_discount', 99, 2 );
function lpb_wc_add_sale_discount ( $price, $product ) {
if ( ( ! $product->is_type( 'variable' ) && is_single( $product->get_id() ) )
|| ( $product->is_type( 'variation' ) && is_single( $product->get_parent_id() ) ) )
{
if ( $product->is_on_sale() ) {
$message = __( 'economize %s', 'lpb-sale-discount' );
$amount = wc_price( $product->get_regular_price() - $product->get_sale_price() );
$price .= '&nbsp;<small class="sale-discount">' . sprintf( $message, $amount ) . '</small>';
@luizbills
luizbills / code.php
Last active July 11, 2017 15:06
Produces cleaner filenames for uploads
<?php
/**
* Produces cleaner filenames for uploads
*
* @author WP Artisan https://wpartisan.me/
*
* @param string $filename
* @return string
*/
@luizbills
luizbills / code.php
Created July 14, 2017 20:32
Mostrar o texto 'Grátis' quando produto tiver preço R$ 0,00 (zero reais)
<?php
/**
* @version 1.0.0
* @author Luiz Paulo Bills <[email protected]>
*/
add_filter( 'woocommerce_get_price_html', 'lpb_wc_display_free_price', 99, 2 );
function lpb_wc_display_free_price ( $price, $product ) {
if ( $product->get_price() == 0 ) {
$label = 'Grátis';
$template = '<span class="woocommerce-Price-amount amount free">%s</span>';
@luizbills
luizbills / code.php
Created July 22, 2017 22:26
Mostrar mais informações nos e-mails do WooCommerce
<?php
/**
* @author Luiz Paulo Bills <[email protected]>
* @version 1.0.0
*/
add_filter( 'woocommerce_email_customer_details_fields', 'lpb_email_with_extra_fields', 10, 3 );
function lpb_email_with_extra_fields ( $fields, $sent_to_admin, $order ) {
$order_id = $order->get_id();
$extra_fields = array(
'Celular' => 'billing_cellphone',
@luizbills
luizbills / functions.php
Created September 18, 2017 15:25 — forked from WooForce/functions.php
Introduce vendor names along with standard labels across shipping packages
define("PV_ATTRIBUTE", "vendor");
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
/**
* Check if WooCommerce is active
*/
if ( in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) ) {
if ( ! class_exists( 'TH_Shipping_Options' ) ) {
class TH_Shipping_Options {
/**
@luizbills
luizbills / woocommerce_admin_meta_boxes_variations_per_page.php
Created October 10, 2017 19:45
Mudar o número de variações que são mostradas no admin
<?php
add_filter( 'woocommerce_admin_meta_boxes_variations_per_page', 'lpb_woocommerce_admin_meta_boxes_variations_per_page' );
function lpb_woocommerce_admin_meta_boxes_variations_per_page ( $per_page ) {
return 12; // change this value
}
@luizbills
luizbills / code.php
Created November 29, 2017 12:05
Muda o preço do PAC
add_filter( 'woocommerce_package_rates', 'lpb_change_correios_pac_cost', 10, 2 );
function lpb_change_correios_pac_cost ( $rates, $package ) {
foreach ( $rates as $rate) {
if ( $rate->method_id === 'correios-pac' ) {
$rate->cost = 20;
}
}
return $rates;
}