• Resolved darkgr33n

    (@darkgr33n)


    Hi,
    so far am loving the ease of the setup and it seems to work really well.
    however, i now need to be able to show some custom text within the basket and am not sure if there is any hook or anything that i can use to be able to add it in?

    for our products, if you order 6 you get a 10% discount. ideally i’d like to be able to see that the current product in the basket has a quantity of below 6 and if so add a small line that says ‘add another X products to save 10%’.

    i think i can do this on the normal woocommerce basket with a function from within the theme functions file, but is it possible to achieve this using WPC please ?

    Failing that, am i able to just add a line of text that says ‘add 6 to get 10% off’ regardless of current quantity – so just a hardcoded line of simple text ?

    I can update the default woocommerce cart using the following, hopefully we’re able to do something similar for WPC ?

    function custom_message() {
        // Initialize
        $message = __( 'Default message', 'woocommerce' );
        
        // True
        if ( WC()->cart ) {
            // Get number of items in the cart.
            $items_count = WC()->cart->get_cart_contents_count();
            $min_count   = 6;
    
            if ( $items_count < $min_count ) {
                $message = sprintf( __( '%s products more for discount', 'woocommerce' ), $min_count - $items_count );
            } else {
                $message = __( 'Some message', 'woocommerce' );
            }
        }
        
        return $message;
    }
    
    // Refreshing on cart ajax events
    function filter_woocommerce_add_to_cart_fragments( $fragments ) {    
        $fragments['div.display-message'] = '<div class="display-message">' . custom_message() . '</div>';
        
        return $fragments;        
    }
    add_filter( 'woocommerce_add_to_cart_fragments', 'filter_woocommerce_add_to_cart_fragments', 10, 1 );
Viewing 2 replies - 1 through 2 (of 2 total)
  • Henry N

    (@henrynguyen259)

    Try this:

    // Add message to Fly cart
    add_filter( 'woofc_above_bottom_content', function($html){
    
        return  $html . custom_message();    
    
    }, 10, 1 );
    Thread Starter darkgr33n

    (@darkgr33n)

    Thanks Henry, that helped me get a lot further ??
    I’m now able to show a message if the cart count is less than X, in my case 6
    Not sure how clean the code is but it seems to work.
    Just in case it helps anyone else:

    // Add message to Fly cart
    add_filter( 'woofc_above_bottom_content', function(){
    	$count_contents = WC()->cart->get_cart_contents_count();
    	if ($count_contents < 6) {
        return  '<div class="woofc-data fw-bold">BUY 6 BOTTLES GET 10% OFF</div>';    
    	}
    }, 10, 1 );
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Custom text within open basket’ is closed to new replies.