Skip to content

Instantly share code, notes, and snippets.

View cagartner's full-sized avatar

Carlos Augusto Gartner cagartner

View GitHub Profile
@cagartner
cagartner / functions.php
Created July 18, 2016 03:13 — forked from claudiosanches/functions.php
WooCommerce - Hide the "In stock" message on product page.
<?php
/**
* Hide the "In stock" message on product page.
*
* @param string $html
* @param string $text
* @param WC_Product $product
* @return string
*/
function my_wc_hide_in_stock_message( $html, $text, $product ) {
@cagartner
cagartner / functions.php
Created July 18, 2016 03:13 — forked from claudiosanches/functions.php
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 ) {
@cagartner
cagartner / plugin.php
Created July 18, 2016 03:14 — forked from claudiosanches/plugin.php
WordPress - Custom REST API endpoint example
<?php
add_action( 'rest_api_init', function() {
register_rest_route( 'my-route/v1', '/products/(?P<id>\d+)', array(
'methods' => 'GET',
'callback' => function( $data ) {
$product = wc_get_product( $data['id'] );
if ( empty( $product ) ) {
return null;
}
return $product;
@cagartner
cagartner / wc-remove-billing-fields.php
Created July 18, 2016 03:15 — forked from claudiosanches/wc-remove-billing-fields.php
WooCommerce - Remove billing address, fone and company fields
<?php
/**
* Plugin Name: WooCommerce Remove billing fields
* Description: Remove billing address, fone and company fields from WooCommerce checkout.
* Author: Claudio Sanches
* Author URI: https://claudiosmweb.com
* Version: 0.0.1
* License: GPLv2 or later
*/
@cagartner
cagartner / functions.php
Created July 18, 2016 03:15 — forked from claudiosanches/functions.php
WooCommerce - Make related posts randomly
<?php
function rand_related_products_query( $query ) {
$query['limits'] = ' ORDER BY RAND() ' . $query['limits'];
return $query;
}
add_filter( 'woocommerce_product_related_posts_query', 'rand_related_products_query' );
@cagartner
cagartner / pac-gratuito.php
Created July 18, 2016 03:15 — forked from claudiosanches/pac-gratuito.php
Exemplo completo de desenvolvimento de plugin
<?php
/**
* Plugin Name: PAC Gratuito
* Plugin URI: https://claudiosmweb.com/woocommerce/woocommerce-deixar-o-metodo-de-entrega-pac-dos-correios-gratuito/
* Description: Deixa o valor do PAC do WooCommerce Correios sempre como gratuito.
* Author: Claudio Sanches
* Author URI: http://claudiosmweb.com/
* Version: 1.0.0
*/
@cagartner
cagartner / functions.php
Created July 18, 2016 03:15 — forked from claudiosanches/functions.php
WooCommerce - Add Order Again button to My Orders actions
<?php
/**
* Add order again button in my orders actions.
*
* @param array $actions
* @param WC_Order $order
* @return array
*/
function cs_add_order_again_to_my_orders_actions( $actions, $order ) {
if ( $order->has_status( 'completed' ) ) {
@cagartner
cagartner / plugin.php
Created July 18, 2016 03:25 — forked from claudiosanches/plugin.php
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
@cagartner
cagartner / test.php
Created July 18, 2016 03:25 — forked from claudiosanches/test.php
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
@cagartner
cagartner / credit-card.md
Created July 18, 2016 03:25 — forked from claudiosanches/credit-card.md
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