Quantcast
Channel: WordPress › Support » Forum: Hacks - Recent Topics
Viewing all articles
Browse latest Browse all 8245

kennydowuk on "customizing messages by product category in woocomerce"

$
0
0

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
posted this into the plugin forum to but not had a response yet

any thoughts?


Viewing all articles
Browse latest Browse all 8245

Trending Articles