Custom text within open basket
-
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 );
- The topic ‘Custom text within open basket’ is closed to new replies.