Search
woogc/get_cart_from_session/validate_hash - WP Global Cart
16211
documentation-template-default,single,single-documentation,postid-16211,theme-awake,eltd-core-1.1,woocommerce-no-js,awake child-child-ver-1.0.0,awake-ver-1.0,eltd-smooth-scroll,eltd-smooth-page-transitions,eltd-mimic-ajax,eltd-grid-1200,eltd-blog-installed,eltd-default-style,eltd-fade-push-text-top,eltd-header-standard,eltd-sticky-header-on-scroll-down-up,eltd-default-mobile-header,eltd-sticky-up-mobile-header,eltd-menu-item-first-level-bg-color,eltd-dropdown-slide-from-top,eltd-,eltd-fullscreen-search eltd-search-fade,eltd-side-menu-slide-from-right,wpb-js-composer js-comp-ver-6.3.0,vc_responsive
 

woogc/get_cart_from_session/validate_hash

WP Global Cart / woogc/get_cart_from_session/validate_hash
Share on FacebookTweet about this on TwitterShare on Google+Share on LinkedInShare on TumblrPin on PinterestEmail this to someonePrint this page

woogc/get_cart_from_session/validate_hash

Name: woogc/get_cart_from_session/validate_hash
Type: Filter
Arguments: $force_validation, $values

When reconstructing the cart from session data, WooCommerce checks each of the products for validation. That includes existence, quantity, purchaseability, data hash. It happens, if a plugin implements a custom product type, if not active/available for a specific shop, the WooCommerce removes it from the cart. This is caused by a data hash that does not match anymore.

This filter can be used to force hash validity for specific products in the cart.

For example, if using the WooCommerce Bookings plugin on a shop, when checking the cart on other sites in the network, invalidates the item. To prevent that, while keeping the plugin active just on one site, the following code can be used:


    add_filter ( 'woogc/get_cart_from_session/validate_hash', '__woogc_get_cart_from_session_validate_hash', 10, 2 );
    function __woogc_get_cart_from_session_validate_hash( $force_validation, $values )
        {
            //check if the current product is a bookable product
            if ( metadata_exists ( 'post', $values['product_id'], '_wc_booking_availability' ) )
                $force_validation   =   TRUE;
            
            return $force_validation;
            
        }
    

The code should be placed inside a php file on wp-content/mu-plugins folder.

0
Would love your thoughts, please comment.x
()
x