Skip to content

Instantly share code, notes, and snippets.

View claudiosanches's full-sized avatar
👨‍💻

Claudio Sanches claudiosanches

👨‍💻
View GitHub Profile
@claudiosanches
claudiosanches / functions.php
Last active June 1, 2022 17:20
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 ) {
@claudiosanches
claudiosanches / functions.php
Last active April 16, 2022 09:14
WooCommerce - Hide shipping rates when free shipping is available.
<?php
/**
* Hide shipping rates when free shipping is available.
* Updated to support WooCommerce 2.6 Shipping Zones.
*
* @param array $rates Array of rates found for the package.
* @return array
*/
function my_hide_shipping_when_free_is_available( $rates ) {
$free = array();
@claudiosanches
claudiosanches / functions.php
Created May 11, 2016 20:27
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 ) {
@claudiosanches
claudiosanches / options.sh
Created April 21, 2016 16:45
WooCommerce - Example of OPTIONS request in the new REST API
curl -X OPTIONS https://your-woo-store.com/wp-json/wc/v1/coupons
@claudiosanches
claudiosanches / coupons-schema.json
Created April 21, 2016 16:43
WooCommerce - Example of coupons schema
{
"namespace": "wc/v1",
"methods": [
"GET",
"POST"
],
"endpoints": [
{
"methods": [
"GET"
@claudiosanches
claudiosanches / orders.json
Created April 21, 2016 16:42
WooCommerce - Example of data returned in the new REST API
{
"id": 1
}
@claudiosanches
claudiosanches / orders.json
Last active April 21, 2016 16:42
WooCommerce - Example data returned in the API v3
{
"orders": {
"id": 1
}
}
@claudiosanches
claudiosanches / custom-my-account-endpoint.php
Last active April 30, 2024 03:05
Example of custom My Account endpoint.
<?php
class My_Custom_My_Account_Endpoint {
/**
* Custom endpoint name.
*
* @var string
*/
public static $endpoint = 'my-custom-endpoint';
@claudiosanches
claudiosanches / functions.php
Last active February 23, 2018 19:57
WooCommerce - Adding new "My account" registration fields
<?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 January 29, 2016 22:37
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;