Skip to content

Instantly share code, notes, and snippets.

View claudiosanches's full-sized avatar
👨‍💻

Claudio Sanches claudiosanches

👨‍💻
View GitHub Profile
@claudiosanches
claudiosanches / gist:fa02e18296e5a1a7ecf6
Last active August 29, 2015 14:26 — forked from ezimuel/gist:9135151
Tesing SimpleXML and DOMDocument to prevent XXE attacks on XML
<?php
// The libxml entity loader is disabled by default
// even setting the libxml_disable_entity_loader to false doesn't works!
//
// @see http://uk3.php.net/manual/en/function.libxml-disable-entity-loader.php
// @see http://stackoverflow.com/a/10213239
$dir = __DIR__;
$content = 'This is a remote content!';
file_put_contents('content.txt', $content);
@claudiosanches
claudiosanches / index.php
Last active February 23, 2018 19:58
WooCommerce 2.4 - Example of how generate an URL for the API Auth endpoint
<?php
$store_url = 'http://example.com';
$endpoint = '/wc-auth/v1/authorize';
$params = array(
'app_name' => 'My App Name',
'scope' => 'write',
'user_id' => 123,
'return_url' => 'http://app.com',
'callback_url' => 'https://app.com'
);
@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 / functions.php
Created July 13, 2015 04:20
WooCommerce - Change variations per page on admin screen
function custom_wc_admin_variations_per_page( $qty ) {
return 20;
}
add_filter( 'woocommerce_admin_meta_boxes_variations_per_page', 'custom_wc_admin_variations_per_page' );
@claudiosanches
claudiosanches / 000-default.conf
Created June 5, 2015 17:53
Apache2 local conf
<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot /var/www
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
@claudiosanches
claudiosanches / plugin.php
Created May 28, 2015 17:49
WooCommerce - Custom templates in plugin
function cs_woocommerce_locate_template( $template, $template_name, $template_path ) {
global $woocommerce;
$_template = $template;
if ( ! $template_path ) {
$template_path = $woocommerce->template_url;
}
$plugin_path = untrailingslashit( plugin_dir_path( __FILE__ ) ) . '/templates/';
// Look within passed path within the theme - this is priority
@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 / functions.php
Created April 29, 2015 21:31
WooCommerce MercadoPago - Exclude Ticket from payment options
function wc_mercadopago_exclude_ticket( $args ) {
$args['payment_methods'] = array( array( 'excluded_payment_types' => array( 'id' => 'ticket' ) ) );
return $args;
}
add_filter( 'woocommerce_mercadopago_args', 'wc_mercadopago_exclude_ticket' );
@claudiosanches
claudiosanches / credit-card.md
Created April 29, 2015 15:59
Credit Card - Snippets

Credit Card

Credit Card numbers for test

Credit card type EBANX payment type code Credit card numbers
American Express amex 378282246310005 or 371449635398431
Aura aura 5078601870000127985 or 5078601800003247449
Diners Club diners 30569309025904 or 38520000023237
Discover discover 6011111111111117
@claudiosanches
claudiosanches / bin-cc.md
Last active July 18, 2016 03:26 — forked from arlm/bin-cc.md

Validação para cartão de crédito.

Bin e padrões para validação de cartão de crédito.

Bandeira Começa com Máximo de número Máximo de número cvc Regex
Visa 4 13,16 3 ^4[0-9]{12}(?:[0-9]{3})
Mastercard 5 16 3 ^5[1-5][0-9]{14}
Diners 301,305,36,38 link 14,16 3 `^3(?:0[0-5]