Skip to content

Instantly share code, notes, and snippets.

:shipit:

Claudio Sanches claudiosanches

:shipit:
Block or report user

Report or block claudiosanches

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@claudiosanches
claudiosanches / functions.php
Created May 11, 2016
WooCommerce - Use "Starting at" prefix for variable price range
View functions.php
<?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 / options.sh
Created Apr 21, 2016
WooCommerce - Example of OPTIONS request in the new REST API
View options.sh
curl -X OPTIONS https://your-woo-store.com/wp-json/wc/v1/coupons
@claudiosanches
claudiosanches / coupons-schema.json
Created Apr 21, 2016
WooCommerce - Example of coupons schema
View coupons-schema.json
{
"namespace": "wc/v1",
"methods": [
"GET",
"POST"
],
"endpoints": [
{
"methods": [
"GET"
@claudiosanches
claudiosanches / orders.json
Created Apr 21, 2016
WooCommerce - Example of data returned in the new REST API
View orders.json
{
"id": 1
}
@claudiosanches
claudiosanches / orders.json
Last active Apr 21, 2016
WooCommerce - Example data returned in the API v3
View orders.json
{
"orders": {
"id": 1
}
}
@claudiosanches
claudiosanches / custom-my-account-endpoint.php
Last active Nov 30, 2019
Example of custom My Account endpoint.
View custom-my-account-endpoint.php
<?php
class My_Custom_My_Account_Endpoint {
/**
* Custom endpoint name.
*
* @var string
*/
public static $endpoint = 'my-custom-endpoint';
@claudiosanches
claudiosanches / functions.php
Last active Feb 23, 2018
WooCommerce - Adding new "My account" registration fields
View functions.php
<?php
/**
* Add new register fields for WooCommerce registration.
*/
function wooc_extra_register_fields() {
?>
<p class="form-row form-row-first">
<label for="reg_billing_first_name"><?php _e( 'First name', 'woocommerce' ); ?> <span class="required">*</span></label>
<input type="text" class="input-text" name="billing_first_name" id="reg_billing_first_name" value="<?php if ( ! empty( $_POST['billing_first_name'] ) ) esc_attr_e( $_POST['billing_first_name'] ); ?>" />
@claudiosanches
claudiosanches / plugin.php
Created Jan 29, 2016
WordPress - Custom REST API endpoint example
View plugin.php
<?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;
@claudiosanches
claudiosanches / wc-remove-billing-fields.php
Created Jan 27, 2016
WooCommerce - Remove billing address, fone and company fields
View wc-remove-billing-fields.php
<?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
*/
@claudiosanches
claudiosanches / plugin.php
Created Jan 25, 2016
WooCommerce - Add Saudi Riyal currency and symbol
View plugin.php
<?php
function wc_add_saudi_riyal_currency( $currencies ) {
$currencies['SAR'] = 'Saudi Riyal';
return $currencies;
}
add_filter( 'woocommerce_currencies', 'wc_add_saudi_riyal_currency' );
You can’t perform that action at this time.