Skip to content

Instantly share code, notes, and snippets.

View vtsara's full-sized avatar

sara lloyd vtsara

View GitHub Profile
@vtsara
vtsara / woo-prevent-checkout-conditional
Created May 30, 2018 22:32
Renders a notice and prevents checkout if the cart contains products in certain combination of categories | woocommerce
/**
* LG :: Renders a notice and prevents checkout if the cart contains products in catering AND non-catering
*/
function lg_wc_prevent_checkout_for_category() {
// If the cart is empty, then we bail out of this function
if (WC()->cart->is_empty()) {
return;
}
@vtsara
vtsara / woo-max-quantities.php
Created May 22, 2018 23:38
simple max quantity for certain categories | woocommerce
<?php
// add maximum quantity for cafe pickup items
add_filter( 'woocommerce_quantity_input_args', 'lg_woocommerce_quantity_input_args', 10, 2 );
function lg_woocommerce_quantity_input_args( $args, $product ) {
if ( has_term( 'pastries', 'product_cat' ) || has_term( 'case', 'product_cat' ) || has_term( 'lunch', 'product_cat' ) ) {
@vtsara
vtsara / optional-delivery-fee.php
Last active May 22, 2018 23:39
Optional fee at checkout if certain categories are present in cart | woocommerce
<?php
// add optional catering delivery fee to cart page IF catering product is in cart
add_action('woocommerce_cart_totals_after_shipping', 'lg_catering_delivery_info_at_cart');
function lg_catering_delivery_info_at_cart() {
// set category check flag to be false until we find a product in that category
$cat_check = false;
// check each cart item for catering category