• We’d like to be able to pull the short description into the popup window after adding the product to the cart.

    We found a function to pull it into the cart itself but we’d like to also include it in the popup:

    function customizing_cart_item_data( $cart_data, $cart_item ) {
    
        $custom_items = array();
        $label = __( 'Description', 'woocommerce' );
    
        // Get the product description
        $description = $cart_item['data']->get_short_description();
    
        // For product variations when description is empty
        if( $cart_item['data']->is_type('variation') && empty( $description ) ){
            // Get the parent variable product object
            $product = wc_get_product( $cart_item['data']->get_parent_id() );
            // Get the variable product short description
            $description = $product->get_short_description();
        }
    
        // If product or variation description exists we display it
        if( ! empty( $description ) ){
            $custom_items[] = array(
                'key'      => $label,
                'display'  => $description,
            );
        }
    
        // Merging description and product variation attributes + values
        if( ! empty( $cart_data ) ) $custom_items = array_merge( $custom_items, $cart_data );
    
        return $custom_items;
    }

    Would you be able to help?

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author YITHEMES

    (@yithemes)

    Hi,
    and thank you for writing in!

    You can achieve your goal by adding the following code snippet to your theme functions.php

    if ( ! function_exists( 'yith_wacp_customization_show_product_description' ) ) {
    	add_filter( 'woocommerce_add_to_cart_fragments', 'yith_wacp_customization_show_product_description', 999, 1 );
    	function yith_wacp_customization_show_product_description( $fragments ) {
    		$product = isset( $_REQUEST['product_id'] ) ? wc_get_product( intval( $_REQUEST['product_id'] ) ) : false;
    		if ( $product && ! empty( $fragments['yith_wacp_message'] ) ) {
    			$description = $product->get_short_description();
    			$description = "<div class='customization-product-description'>{$description}</div>";
    
    			$fragments['yith_wacp_message'] = preg_replace(
    					'/<\/div>\s+<div class=\"actions\">/',
    					$description . '</div><div class="actions">',
    					$fragments['yith_wacp_message'] );
    		}
    
    		return $fragments;
    	}
    }

    Please try this solution and let us know if everything works fine!

    Thread Starter pinkbirch

    (@pinkbirch)

    Thank you for your response!That doesn’t appear to be working though. I added to to the functions file and it’s not adding to the popup. Take a look:

    https://www.shopzhirnova.com/

    Plugin Author YITHEMES

    (@yithemes)

    Hi there,

    Can you check if the function “yith_wacp_customization_show_product_description” exists in your installation?

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Description’ is closed to new replies.