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

kennydowuk on "[woocommerce] customizing messages by product category"

$
0
0

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 ) ) {

$categories = get_the_category( $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 ) ) ) ) );

	} else {
		<if($categories == 'gallery') {
			$added_text = sprintf(__( '"%s" add a mount' );
		}else{
			$added_text = sprintf( __( '"%s" was successfully added to your cart.', 'woocommerce' ), get_the_title( $product_id ) );
	}
	}

Viewing all articles
Browse latest Browse all 8245

Trending Articles