Last active
October 25, 2019 05:18
-
-
Save PluginHive/824be297d2d1cbadda60c42ff6ea3d11 to your computer and use it in GitHub Desktop.
Hide quantity in cart , checkout, thank you page for bookable products
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//cart page | |
function hide_woocommerce_cart_item_quantity($product_quantity, $cart_item_key, $cart_item) { | |
$_product = apply_filters( 'woocommerce_cart_item_product', $cart_item['data'], $cart_item, $cart_item_key ); | |
$product_id = apply_filters( 'woocommerce_cart_item_product_id', $cart_item['product_id'], $cart_item, $cart_item_key ); | |
if($_product->is_sold_individually()) | |
{ | |
$product_type = $_product->get_type(); | |
if( $product_type == 'phive_booking' ) | |
{ | |
$product_quantity = sprintf( '%s <input type="hidden" name="cart[%s][qty]" value="1" />','', $cart_item_key ); | |
} | |
} | |
return $product_quantity; | |
} | |
add_filter( 'woocommerce_cart_item_quantity', 'hide_woocommerce_cart_item_quantity',10,3 ); | |
//checkout page | |
add_filter( 'woocommerce_checkout_cart_item_quantity', 'woocommerce_checkout_cart_item_quantity_ph',10,3 ); | |
function woocommerce_checkout_cart_item_quantity_ph($quantity_html,$cart_item,$key ) { | |
if(!empty($cart_item) && isset($cart_item['product_id']) && !empty($cart_item['product_id'])) | |
{ | |
$product=wc_get_product($cart_item['product_id']); | |
if(!empty($product) && !empty($product->get_type()) && $product->get_type()=='phive_booking') | |
{ | |
return ""; | |
} | |
} | |
return $quantity_html; | |
} | |
//thank you page | |
add_filter( 'woocommerce_order_item_quantity_html', 'woocommerce_order_item_quantity_html_ph',10,2 ); | |
function woocommerce_order_item_quantity_html_ph($quantity_html,$item ) { | |
if(!empty($item) && isset($item['product_id']) && !empty($item['product_id'])) | |
{ | |
$product=wc_get_product($item['product_id']); | |
if(!empty($product) && !empty($product->get_type()) && $product->get_type()=='phive_booking') | |
{ | |
return ""; | |
} | |
} | |
return $quantity_html; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment