• Resolved EraMikkola

    (@eramikkola)


    Hello, thank you for the valuable plugin. I am using tabs for showing additional information and features of products. I started to use WooCommerce Print Products-plugin (Version 1.3.3 | By DB-Dzine) for printing out “mini brochures” of the products. WPP finds YIKES as custom meta key but when clicked the PDF result shows only the word “array”.

    I am not a coding guy but as far as I understand, some code might be needed to get the tabs linked to another plugin. Can you help me? I don’t know where to start but this would be a lifesaver here ??

    Thanks!

Viewing 15 replies - 1 through 15 (of 16 total)
  • Plugin Contributor yikesitskevin

    (@yikesitskevin)

    Hi @eramikkola,

    I could not find any developer information about WooCommerce Print Products. Do you know if they have filters you can use for the fields? You’ll need to use a filter to loop through the data. I can write the code if you can help locate where to put it (i.e. a filter that lets you hook into a field).

    Unfortunately it’s a paid plugin so I can’t download and test it out myself.

    Let me know,
    Kevin.

    Thread Starter EraMikkola

    (@eramikkola)

    OK, hold on – I will send them a message ?? Thanks!

    Thread Starter EraMikkola

    (@eramikkola)

    Thread Starter EraMikkola

    (@eramikkola)

    Hello Kevin, Db-Dzine replied:

    Hi there,
    as we use the native “get_post_meta” function your deveoper could hook into the get_post_metadata filter:

    add_filter(‘get_post_metadata’, ‘yikes_woo_products_tabs’, 10, 4);

    Then of course he has to check if $_GET[‘print-product’] == “pdf”.

    Plugin Contributor yikesitskevin

    (@yikesitskevin)

    Ahh, that’s what I was looking for. I’m still not 100% sure how to approach this because ideally we want to return an array (e.g. multiple tabs and multiple titles). I guess we can initially try this by returning a single string with all of the tab titles and content. Let me know how this works…

    Try this snippet – you can add it to your functions.php file.

    add_filter( 'get_post_metadata', 'add_yikes_woo_product_tabs_to_pdf', 10, 4 );
    
    function add_yikes_woo_product_tabs_to_pdf( $null, $post_id, $meta_key, $single ) {
    
    	if ( ! isset( $_GET['print-product'] ) || isset( $_GET['print-product'] ) && $_GET['print-product'] !== 'pdf' || $meta_key !== 'yikes_woo_products_tabs' ) {
    		return $null;
    	}
    
    	$product_tabs = get_post_meta( $post_id, 'yikes_woo_products_tabs', true );
    
    	$html = '';
    
    	foreach( $product_tabs as $tab ) {
    
    		if ( ! empty( $tab['title'] ) ) {
    			$html .= '<h2>' . $tab['title'] . '</h2>';
    		}
    
    		if ( ! empty( $tab['content'] ) ) {
    			$html .= '<div class="yikes-print-product-tabs">' . $tab['content'] . '</div>';
    		} 
    	}
    
    	return $html;
    }

    Cheers,
    Kevin.

    Thread Starter EraMikkola

    (@eramikkola)

    I added this on theme functions.php (Avada).
    No changes. The same text “array”. I know there function.php’s here and there. Did I place it in a wrong one?

    Plugin Contributor yikesitskevin

    (@yikesitskevin)

    If Avada is your active theme, then the code is in the right place. I figured this might take some iterations. I think the issue is with the ‘scoping.’ We have a few things to try still. Try this:

    add_filter( 'get_post_metadata', 'add_yikes_woo_product_tabs_to_pdf', 10, 4 );
    
    function add_yikes_woo_product_tabs_to_pdf( $null, $post_id, $meta_key, $single ) {
    
    	if ( ( ! isset( $_GET['print-product'] ) ) || ( isset( $_GET['print-product'] ) && $_GET['print-product'] !== 'pdf' ) || ( $meta_key !== 'yikes_woo_products_tabs' ) ) {
    		return $null;
    	}
    
    	$product_tabs = get_post_meta( $post_id, 'yikes_woo_products_tabs', true );
    
    	$html = '';
    
    	foreach( $product_tabs as $tab ) {
    
    		if ( ! empty( $tab['title'] ) ) {
    			$html .= '<h2>' . $tab['title'] . '</h2>';
    		}
    
    		if ( ! empty( $tab['content'] ) ) {
    			$html .= '<div class="yikes-print-product-tabs">' . $tab['content'] . '</div>';
    		} 
    	}
    
    	return $html;
    }
    Thread Starter EraMikkola

    (@eramikkola)

    I changed the theme to its child and added the code to its functions.php.

    But no changes, not yet ??

    Plugin Contributor yikesitskevin

    (@yikesitskevin)

    I’m questioning if the $_GET['print-product'] == 'pdf' was the correct flag to check…

    Let’s try again…

    add_filter( 'get_post_metadata', 'add_yikes_woo_product_tabs_to_pdf', 10, 4 );
    
    function add_yikes_woo_product_tabs_to_pdf( $null, $post_id, $meta_key, $single ) {
    
    	if ( ! isset( $_GET['print-product'] ) || $meta_key !== 'yikes_woo_products_tabs' ) {
    		return $null;
    	}
    
    	$product_tabs = get_post_meta( $post_id, 'yikes_woo_products_tabs', true );
    
    	$html = '';
    
    	foreach( $product_tabs as $tab ) {
    
    		if ( ! empty( $tab['title'] ) ) {
    			$html .= '<h2>' . $tab['title'] . '</h2>';
    		}
    
    		if ( ! empty( $tab['content'] ) ) {
    			$html .= '<div class="yikes-print-product-tabs">' . $tab['content'] . '</div>';
    		} 
    	}
    
    	return $html;
    }
    Thread Starter EraMikkola

    (@eramikkola)

    Would you like to see WPP files? I think they would get mad if I share some files privately with you ??

    Plugin Contributor yikesitskevin

    (@yikesitskevin)

    Email me at kevin at yikesinc .com

    Thread Starter EraMikkola

    (@eramikkola)

    You have an email.

    Plugin Contributor yikesitskevin

    (@yikesitskevin)

    Agh, the key is print-products, not print-product.

    Try this:

    add_filter( 'get_post_metadata', 'add_yikes_woo_product_tabs_to_pdf', 10, 4 );
    
    function add_yikes_woo_product_tabs_to_pdf( $null, $post_id, $meta_key, $single ) {
    
    	if ( ( ! isset( $_GET['print-products'] ) ) || ( isset( $_GET['print-products'] ) && $_GET['print-products'] !== 'pdf' ) || ( $meta_key !== 'yikes_woo_products_tabs' ) ) {
    		return $null;
    	}
    
    	$product_tabs = get_post_meta( $post_id, 'yikes_woo_products_tabs', true );
    
    	$html = '';
    
    	foreach( $product_tabs as $tab ) {
    
    		if ( ! empty( $tab['title'] ) ) {
    			$html .= '<h2>' . $tab['title'] . '</h2>';
    		}
    
    		if ( ! empty( $tab['content'] ) ) {
    			$html .= '<div class="yikes-print-product-tabs">' . $tab['content'] . '</div>';
    		} 
    	}
    
    	return $html;
    }
    Thread Starter EraMikkola

    (@eramikkola)

    OK, now something happens:

    Internal Server Error

    The server encountered an internal error or misconfiguration and was unable to complete your request.

    Thread Starter EraMikkola

    (@eramikkola)

    Thank you Kevin. After removing the infinite loop it works like a charm ?? Wonderful!

Viewing 15 replies - 1 through 15 (of 16 total)
  • The topic ‘Tabs with WooCommerce Print Products-plugin’ is closed to new replies.