im trying to detect a product category when the user adds an item to the cart in woocommerce. So that they get a different ‘added to cart’ message depending on the product they add

the idea is that if they add a picture from the gallery it points them towards mounting services, but if they add a mounting service it gives the standard message

this is the code i have so far it just skips the category filter and runs the standard message.

function wc_add_to_cart_message( $product_id ) {
if ( is_array( $product_id ) ) {
    $titles = array();
    foreach ( $product_id as $id ) {
        $titles[] = get_the_title( $id );
    }
    $added_text = sprintf( __( 'Added "%s" to your cart.', 'woocommerce' ), join( __( '" and "', 'woocommerce' ), array_filter( array_merge( array( join( '", "', array_slice( $titles, 0, -1 ) ) ), array_slice( $titles, -1 ) ) ) ) );
} elseif ( is_product_category( 'gallery') ) {
    $added_text = sprintf(  'add a mount.' );
}else {
    $added_text = sprintf( __( '"%s" was successfully added to your cart.', 'woocommerce' ), get_the_title( $product_id ) );
}

Never really dug this deep into the code before so im at a bit of a loss right now

any thoughts?

Read more here: woocommerce custom added to cart message determined by product category


Solution:

If you know the solution of this issue, please leave us a reply in Comment section, to update the question.

Related Wordpress search:

, , , , , , ,

Wordpress related questions and answers: