Skip to content

Instantly share code, notes, and snippets.

View claudiosanches's full-sized avatar
👨‍💻

Claudio Sanches claudiosanches

👨‍💻
View GitHub Profile
@claudiosanches
claudiosanches / test.php
Last active February 22, 2024 19:39
Regex for test credit card brand
<?php
// Test cards
$cards = array(
'378282246310005', // American Express
'371449635398431', // American Express
'5078601870000127985', // Aura
'5078601800003247449', // Aura
'30569309025904', // Diners Club
'38520000023237', // Diners Club
@claudiosanches
claudiosanches / django-runserver-ssl.md
Last active February 20, 2024 09:59
Django - SSL with runserver

Instalation

[sudo] apt-get install stunnel

Configuration

cd path/to/django/project
@claudiosanches
claudiosanches / index.html
Last active January 18, 2024 19:59
HTML5 - Validar número de celular em São Paulo
<div class="form-group">
<label for="phone">Telefone <span class="required">*</span></label>
<input type="text" class="form-control" id="phone" name="phone" placeholder="(99) 9999-9999" pattern="(\([0-9]{2}\))\s([9]{1})?([0-9]{4})-([0-9]{4})" title="Número de telefone precisa ser no formato (99) 9999-9999" required="required" />
</div>
@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 / functions.php
Last active November 22, 2023 06:17
WooCommerce - Change ajax variation threshold
function custom_wc_ajax_variation_threshold( $qty, $product ) {
return 10;
}
add_filter( 'woocommerce_ajax_variation_threshold', 'custom_wc_ajax_variation_threshold', 10, 2 );
@claudiosanches
claudiosanches / custom-my-account-endpoint.php
Last active November 6, 2023 20:10
Example of custom My Account endpoint.
<?php
class My_Custom_My_Account_Endpoint {
/**
* Custom endpoint name.
*
* @var string
*/
public static $endpoint = 'my-custom-endpoint';
@claudiosanches
claudiosanches / functions.php
Created May 11, 2016 20:27
WooCommerce - Use "Starting at" prefix for variable price range
<?php
/**
* Custom variable price HTML.
* Shows "Starting at" prefix with when min price is different from max price.
*
* @param stirng $price Product price HTML
* @param WC_Product_Variable $product Product data.
* @return string
*/
function cs_my_wc_custom_variable_price_html( $price, $product ) {
@claudiosanches
claudiosanches / wc-products-disable-gutenberg.php
Last active November 6, 2023 20:09
Disable Gutenberg in Edit Product screen for WooCommerce 3.4.x or older
<?php
/**
* Plugin Name: No Gutenberg for old versins of WooCommerce
* Plugin URI: https://gist.github.com/claudiosanches/d0231798eb6041e4911b4bca409ec1ac
* Description: Disable Gutenberg in Edit Product screen for WooCommerce 3.4.x.
* Author: Claudio Sanches
* Author URI: https://claudiosanches.com
* Version: 1.0.0
* License: GPLv3
*
@claudiosanches
claudiosanches / functions.php
Created December 1, 2012 20:59
WooCommerce - Custom Simple Product price format.
<?php
/**
* Custom simple product price format.
*
* Adds credit cart parcels in price html.
*
* @param string $price Old price format.
*
* @return string Price format with credit card parcels.
*/
@claudiosanches
claudiosanches / add-to-cart.php
Last active October 18, 2023 14:02
WooCommerce - Template add-to-cart.php with quantity and Ajax!
<?php
/**
* Custom Loop Add to Cart.
*
* Template with quantity and ajax.
*/
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly.
global $product;