Skip to content

Instantly share code, notes, and snippets.

@MindyPostoff
MindyPostoff / gist:9c7087e170f9cf327f26
Last active Aug 29, 2015
Display "Low Stock" Message on WooCommerce Product Page Instead of "Only # Left in Stock"
View gist:9c7087e170f9cf327f26
/* Change the 'Only # left in stock' message on the WooCommerce product page to
* simply show 'Low Stock'.
* Add to your theme's functions.php file
*/
function custom_stock_totals($availability_html, $availability_text, $product) {
if (substr($availability_text,0, 4)=="Only") {
$availability_text = "Low Stock";
}
$availability_html = '<p class="stock ' . esc_attr( $availability['class'] ) . '">' . esc_html( $availability_text ) . '</p>';
return $availability_html;
@MindyPostoff
MindyPostoff / gist:dd0662dccd8068035757
Last active Aug 29, 2015
Mini-Cart in PixelPress
View gist:dd0662dccd8068035757
<?php if ( is_woocommerce_activated() ) { ?>
<ul class="mini-cart">
<li>
<a href="<?php echo $woocommerce->cart->get_cart_url(); ?>" title="<?php _e('View your shopping cart', 'woothemes'); ?>" class="cart-parent">
<span>
<?php
echo $woocommerce->cart->get_cart_total();;
echo sprintf(_n('<mark>%d</mark>', '<mark>%d</mark>', $woocommerce->cart->cart_contents_count, 'woothemes'), $woocommerce->cart->cart_contents_count);
?>
</span>
View WooCommerceAPI-attributes.php
'attributes' => array(
array(
'name' => 'Brand',
'slug' => 'pa_brand',
'options' => array(
'Kravet Basics'
),
'visible' => true
)
)
@MindyPostoff
MindyPostoff / variation-thumbnail.php
Last active Sep 27, 2015
Display product featured image in cart instead of variation thumbnail
View variation-thumbnail.php
// 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 / add-to-cart.php
Created Apr 6, 2015
Override loop template and show quantities next to add to cart buttons
View add-to-cart.php
<?php
/**
* Loop Add to Cart
*/
global $product;
if( $product->get_price() === '' && $product->product_type != 'external' ) return;
?>
View cart-surcharge.php
/**
* 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' ) ) {
View recurring-fees.php
<?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 / disable-paypal-woocommerce
Last active Jan 16, 2017
Disable PayPal in WooCommerce Checkout for Certain Products
View disable-paypal-woocommerce
/*
* Disable PayPal payment method in the checkout if certain
* products are present in the cart.
*
* Add this to your theme's functions.php file
*/
add_filter( 'woocommerce_available_payment_gateways', 'filter_gateways', 1);
function filter_gateways( $gateways ){
global $woocommerce;
@MindyPostoff
MindyPostoff / gist:7fdb43fce328049de1b9
Created Jan 30, 2015
Using Bookings to Sell Limited Products Daily
View gist:7fdb43fce328049de1b9
/** 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;
}
@MindyPostoff
MindyPostoff / gist:469fb7b59e8d028a21e2
Created Jan 16, 2015
Remove Renew button from the My Account page for customers with a cancelled subscription - WooCommerce Subscriptions
View gist:469fb7b59e8d028a21e2
/**
* This stops the renew button from appearing in the My Account page once an order's been cancelled
* @param array $actions List of actions that subscriptions can do with each subscription (on top of
* WooCommerce)
* @param array $subscriptions List of subscriptions' data belonging to the current user
* @return array List of action buttons that can happen with each subscription
*/
function remove_renew( $actions, $subscriptions ) {
foreach ( $actions as $key => $action ) {
if ( array_key_exists( 'renew', $action ) ) {