Skip to content

Instantly share code, notes, and snippets.

@MindyPostoff
MindyPostoff / recurring-fees.php
Created December 31, 2015 19:44
Recurring Fees
<?php foreach ( $recurring_carts as $recurring_cart_key => $recurring_cart ) : ?>
<?php foreach ( $recurring_cart->get_fees() as $fee ) : ?>
<tr class="fee">
<th><?php echo esc_html( $fee->name ); ?></th>
<td data-title="<?php echo esc_html( $fee->name ); ?>"><?php wc_cart_totals_fee_html( $fee ); ?></td>
</tr>
<?php endforeach; ?>
<?php endforeach; ?>
@MindyPostoff
MindyPostoff / cart-surcharge.php
Created December 31, 2015 19:39
Add Surcharge to Cart
/**
* Add a 1% surcharge to your cart / checkout
* change the $percentage to set the surcharge to a value to suit
* Uses the WooCommerce fees API
*
* Add to theme functions.php
*/
add_action( 'woocommerce_cart_calculate_fees','woocommerce_custom_surcharge' );
function woocommerce_custom_surcharge( $cart ) {
if ( is_admin() && ! defined( 'DOING_AJAX' ) ) {
@MindyPostoff
MindyPostoff / order-notes-required.php
Last active July 31, 2020 13:16
Make the Order Notes field required in the WooCommerce Checkout
// Place this code in your theme's functions.php file
// Hook in
add_filter( 'woocommerce_checkout_fields' , 'custom_override_checkout_fields' );
// Our hooked in function - $fields is passed via the filter!
function custom_override_checkout_fields( $fields ) {
$fields['order']['order_comments']['required'] = true;
return $fields;
}
@MindyPostoff
MindyPostoff / WooCommerceAPI-attributes.php
Created August 12, 2015 18:31
WooCommerce API Attributes
'attributes' => array(
array(
'name' => 'Brand',
'slug' => 'pa_brand',
'options' => array(
'Kravet Basics'
),
'visible' => true
)
)
@MindyPostoff
MindyPostoff / hide-free-price-woocommerce.php
Created July 20, 2015 18:57
Hide Free Price - WooCommerce
add_filter( 'woocommerce_variable_free_price_html', 'hide_free_price_notice' );
add_filter( 'woocommerce_free_price_html', 'hide_free_price_notice' );
add_filter( 'woocommerce_variation_free_price_html', 'hide_free_price_notice' );
/**
* Hides the 'Free!' price notice
*/
function hide_free_price_notice( $price ) {
return '';
}
@MindyPostoff
MindyPostoff / variation-thumbnail.php
Last active September 27, 2015 13:44
Display product featured image in cart instead of variation thumbnail
// Add this to your child theme's functions.php file
function wc_custom_cart_thumb( $thumb, $cart_item ) {
return get_the_post_thumbnail( $cart_item['product_id'], 'shop_thumbnail' );
}
add_filter( 'woocommerce_cart_item_thumbnail', 'wc_custom_cart_thumb', 10, 2 );
@MindyPostoff
MindyPostoff / web.config
Created May 22, 2015 18:37
Windows Servers web.config for WooCommerce Endpoints
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<handlers accessPolicy="Read, Execute, Script" />
<rewrite>
<rules>
<rule name="wordpress" patternSyntax="Wildcard">
<match url="*" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
@MindyPostoff
MindyPostoff / add-to-cart.php
Created April 6, 2015 14:42
Override loop template and show quantities next to add to cart buttons
<?php
/**
* Loop Add to Cart
*/
global $product;
if( $product->get_price() === '' && $product->product_type != 'external' ) return;
?>
@MindyPostoff
MindyPostoff / remove-var-subs-price.php
Last active February 18, 2020 04:18
How to remove the price string from variable subscription products
/**
* Function to remove the variable subscription price string
* Add this to your child theme's functions.php file.
*/
function wc_remove_var_subscriptions_price() {
return '';
}
add_filter( 'woocommerce_variable_subscription_price_html', 'wc_remove_var_subscriptions_price' );
@MindyPostoff
MindyPostoff / gist:7fdb43fce328049de1b9
Created January 30, 2015 22:30
Using Bookings to Sell Limited Products Daily
/** Add this function to your theme's functions.php file
* to replace the "Persons" string in the Bookings form
* to be "Number of Loaves".
*/
function my_text_strings( $translated_text, $text, $domain ) {
switch ( $translated_text ) {
case 'Persons' :
$translated_text = __( 'Number of Loaves', 'woocommerce-bookings' );
break;
}