Skip to content

Instantly share code, notes, and snippets.

@mateusneves
mateusneves / functions.php
Last active July 3, 2018 19:43
Action para não permitir que uma conta seja cadastrada no Woocommerce com um CPF ou CNPJ já existente.
<?php
/*
Action para não permitir que uma conta seja cadastrada no Woocommerce com um CPF ou CNPJ já existente.
Esta action adiciona esta condicional para o campo de CPF ou CNPJ inserido pelo do plugin Extra Checkout Fields for Woocommerce
Você pode inserir este código no arquivo functions.php do seu tema.
*/
add_action('woocommerce_checkout_process', 'check_if_cpf_cnpj_exists');
function check_if_cpf_cnpj_exists() {
if( isset( $_POST['billing_cpf'] ) ){
@mateusneves
mateusneves / functions.php
Created May 16, 2018 13:46
Change WordPress permalink structure of the post_type post
<?php
/**
* Change permalink structure of the post_type post
*/
add_filter('pre_post_link', 'filter_post_link', 10, 2);
function filter_post_link($permalink, $post) {
if ($post->post_type != 'post')
return $permalink;
return 'blog'.$permalink;
}
@mateusneves
mateusneves / functions.php
Created May 14, 2018 17:19
Add featured image to WordPress feed
<?php
function featured_image_rss($content) {
global $post;
if ( has_post_thumbnail( $post->ID ) ){
$content = '' . get_the_post_thumbnail( $post->ID, 'thumbnail', array( 'style' => 'float:left; margin:0 15px 15px 0;' ) ) . '' . $content;
}
return $content;
}
add_filter('the_excerpt_rss', 'featured_image_rss');
@mateusneves
mateusneves / functions.php
Created May 8, 2018 14:40
Woocommerce fail order send email
<?php
/*
* Woocommerce send email to customer when order status is change to Failed
*/
add_action( 'woocommerce_order_status_failed', 'mysite_failed');
function mysite_failed($order_id) {
error_log("$order_id set to FAILED", 0);
$order = wc_get_order( $order_id );
@mateusneves
mateusneves / function.php
Last active April 30, 2018 03:01
Wordpress: Add Additional Image Sizes
<?php
if ( function_exists( 'add_image_size' ) ) {
add_image_size( 'blog-thumb', 400, 9999 ); // 400px de largura máxima (e altura ilimitada)
add_image_size( 'main-thumb', 300, 250, true ); // corte/crop
}
?>
@mateusneves
mateusneves / wp-config.php
Created April 30, 2018 01:02
WordPress: Disable file editor in admin panel
define( 'DISALLOW_FILE_EDIT', true );
@mateusneves
mateusneves / function.php
Created April 30, 2018 00:31
WordPress Snippet Hide Version
function gwp_remove_version() {
return '';
}
add_filter('the_generator', 'gwp_remove_version');
@mateusneves
mateusneves / functions.php
Created January 16, 2018 15:23
Whit this snippet you can add a percentage discount for payment with Bank Ticket for PagSeguro for Woocommerce plugin.
// Source: https://br.wordpress.org/support/topic/woocommerce-alterar-o-valor-do-pedido-apos-o-pagamento/
add_filter( 'woocommerce_pagseguro_payment_xml', function( $xml, $order ) {
$newxml = $xml;
if($newxml->method == 'boleto'){
$total = $order->total;
$discount_value = $total * 0.1;
$boleto_cost = 1;
/Applications/MAMP/Library/bin/mysql -uroot -p data_base_name < /Applications/MAMP/htdocs/path/dat_base_.sql
@mateusneves
mateusneves / xml-file.php
Created July 14, 2017 00:13
Generate XML with PHP
<?php
$xml = new SimpleXMLElement('<xml/>');
for ($i = 1; $i <= 8; ++$i) {
$track = $xml->addChild('track');
$track->addChild('path', "song$i.mp3");
$track->addChild('title', "Track $i - Track Title");
}