Skip to content

Instantly share code, notes, and snippets.

View cagartner's full-sized avatar

Carlos Augusto Gartner cagartner

View GitHub Profile
@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 / 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 / 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 - 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 / 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 / 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 / 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 / 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 - Custom tag cloud shortcode
<?php
/**
* Custom WooCommerce tag cloud shortcode.
*
* Use the follow shortcode in your pages: [my_wc_tag_cloud]
*/
function my_custom_wc_tag_cloud_shortcode() {
return wp_tag_cloud( array( 'taxonomy' => 'product_tag', 'echo' => false ) );
}
@cagartner
cagartner / woocommerce-installments-example.php
Created July 18, 2016 01:54 — forked from claudiosanches/woocommerce-installments-example.php
WooCommerce - Displays the price in 3 installments without interest.
<?php
/**
* Plugin Name: WooCommerce Installments Example
* Plugin URI: http://claudiosmweb.com/
* Description: Added the price with 3 installments without interest.
* Author: claudiosanches
* Author URI: http://www.claudiosmweb.com/
* Version: 1.0
* License: GPLv2 or later
*/