Title: Condition address shop
Last modified: April 6, 2021

---

# Condition address shop

 *  Resolved [josede](https://wordpress.org/support/users/josede/)
 * (@josede)
 * [5 years, 4 months ago](https://wordpress.org/support/topic/condition-address-shop/)
 * Hi! Its possible change the address shop details for the invoice generated based
   on the product selected?
    -  This topic was modified 5 years, 4 months ago by [josede](https://wordpress.org/support/users/josede/).

Viewing 11 replies - 1 through 11 (of 11 total)

 *  Plugin Contributor [Darren Peyou](https://wordpress.org/support/users/dpeyou/)
 * (@dpeyou)
 * [5 years, 4 months ago](https://wordpress.org/support/topic/condition-address-shop/#post-14283999)
 * Hi [@josede](https://wordpress.org/support/users/josede/),
 * It isn’t quite clear in what way you are trying to modify the address so I’ll
   have to take a guess: I’ll assume you just want to add some information at the
   end.
 * The following code snippet will check whether or not there’s a certain item in
   the order based on its ID:
 *     ```
       add_filter( 'wpo_wcpdf_after_shop_address', 'wpo_wcpdf_conditional_shop_address', 10, 2 );
       function wpo_wcpdf_conditional_shop_address( $template_type, $order ) {
   
       	// if order is empty, bail
       	if ( empty($order) ) {return;}
   
       	$conditional_id = '5';
   
       	foreach ( $order->get_items() as $item_id => $item ) {
   
       		// check product ID
       		$product_id = $item->get_product_id();
   
       		// change shop address if conditional product ID is found
       		if ($product_id == $conditional_id) {
       			echo 'More Shop Info';
       			return;
       		}
       	}
       }
       ```
   
 * The line “More Shop Info” is added at the end of the shop address if a product
   of ID ‘5’ – from `$conditional_id = 5` – is present.
    You can find the Product
   IDs in the Products menu, by highlighting an item with your mouse pointer. 🙂
 * If you haven’t used hooks before, please read this guide: [https://docs.wpovernight.com/general/how-to-use-filters/](https://docs.wpovernight.com/general/how-to-use-filters/)
    -  This reply was modified 5 years, 4 months ago by [Darren Peyou](https://wordpress.org/support/users/dpeyou/).
      Reason: additional instructions
 *  Thread Starter [josede](https://wordpress.org/support/users/josede/)
 * (@josede)
 * [5 years, 4 months ago](https://wordpress.org/support/topic/condition-address-shop/#post-14284572)
 * Thx so much.
    ¨I’ll assume you just want to add some information at the end¨ 
   Its not to add some information at the end. ¨wpo_wcpdf_after_shop_address¨ I 
   dont want add more info. I want to remove the shop address and add a new one.
 * Thx!
 *  Plugin Contributor [Darren Peyou](https://wordpress.org/support/users/dpeyou/)
 * (@dpeyou)
 * [5 years, 4 months ago](https://wordpress.org/support/topic/condition-address-shop/#post-14284822)
 * Hey [@josede](https://wordpress.org/support/users/josede/),
 * What is the nature of this new address you are trying to show?
    – Is it an address
   that is saved in WooCommerce somehow, like a custom field added by you or some
   external plugin? If yes, what is the name of this custom field? – If no, then
   you’ll have to enter this address manually. 🙂
 *  Thread Starter [josede](https://wordpress.org/support/users/josede/)
 * (@josede)
 * [5 years, 4 months ago](https://wordpress.org/support/topic/condition-address-shop/#post-14284859)
 * I want just a different address and company name for invoices that has a specific
   product.
 * If the product is A then “this address instead the default address”
 *  Plugin Contributor [Darren Peyou](https://wordpress.org/support/users/dpeyou/)
 * (@dpeyou)
 * [5 years, 4 months ago](https://wordpress.org/support/topic/condition-address-shop/#post-14285264)
 * Hey [@josede](https://wordpress.org/support/users/josede/),
 * You can use this snippet instead, including if you also need to change the shop
   name:
 *     ```
       add_action( 'wpo_wcpdf_before_shop_name', 'wpo_wcpdf_conditional_shop_address', 999, 2 );
       function wpo_wcpdf_conditional_shop_address( $template_type, $order ) {
   
       	// if order is empty, bail
       	if ( empty($order) ) {return;}
   
       	$conditional_id = '74';
       	$document = wcpdf_get_document( $template_type, $order );
   
       	foreach ( $order->get_items() as $item_id => $item ) {
   
       		// check product ID
       		$product_id = $item->get_product_id();
   
       		// change shop address if conditional product ID is found
       		if ($product_id == $conditional_id) {
   
       			// hide default shop name & address with CSS
       			echo '<style>' . '.shop-name, .shop-address {display: none;}' . '</style>';
   
       			// display new shop name
       			echo '<b>' . 'Alt Shop Name' . '</b>';
   
       			//display new shop address
       			echo 
       			'<div>' .
       				'Address Line 1' .
       				//insert line break
       				'<br>' .
       				'Address Line 2' .
       			'</div>';
   
       			return;
       		}
       	}
       }
       ```
   
 * This snippet assumes that your shop address is written on 2 lines — see “Address
   Line 1” & “Address Line 2”.
    Enter the alternate shop name where you see “Alt
   Shop Name”. 🙂
    -  This reply was modified 5 years, 4 months ago by [Darren Peyou](https://wordpress.org/support/users/dpeyou/).
      Reason: extra formating
 *  Thread Starter [josede](https://wordpress.org/support/users/josede/)
 * (@josede)
 * [5 years, 4 months ago](https://wordpress.org/support/topic/condition-address-shop/#post-14285592)
 * This works for pdf generation as well right? Thx
 *  Plugin Contributor [Darren Peyou](https://wordpress.org/support/users/dpeyou/)
 * (@dpeyou)
 * [5 years, 4 months ago](https://wordpress.org/support/topic/condition-address-shop/#post-14288249)
 * [@josede](https://wordpress.org/support/users/josede/),
 * I’m not sure what you mean. Have you tested the code? It fulfills the purpose
   on my end. 🙂
 *  Thread Starter [josede](https://wordpress.org/support/users/josede/)
 * (@josede)
 * [5 years, 4 months ago](https://wordpress.org/support/topic/condition-address-shop/#post-14289325)
 * Darren sorry for my english. Your code works. But I was looking not by product
   ID, for category from the product.
 * If a products/products, with specific category. Based on the category’s product
   bought.
 *  Plugin Contributor [Darren Peyou](https://wordpress.org/support/users/dpeyou/)
 * (@dpeyou)
 * [5 years, 4 months ago](https://wordpress.org/support/topic/condition-address-shop/#post-14290232)
 * Hey [@josede](https://wordpress.org/support/users/josede/),
 * I have an update, rejoice!
 * If you need it to be a category that triggers the change instead, here’s the 
   updated code:
 *     ```
       add_action( 'wpo_wcpdf_before_shop_name', 'wpo_wcpdf_conditional_shop_address', 999, 2 );
       function wpo_wcpdf_conditional_shop_address( $template_type, $order ) {
   
       	// if order is empty, bail
       	if ( empty($order) ) {return;}
   
       	$conditional_category = 'tshirts';
   
       	$document = wcpdf_get_document( $template_type, $order );
   
       	foreach ( $order->get_items() as $item_id => $item ) {
   
       		// get product ID
       		$product_id = $item->get_product_id();
       		// get the terms
       		$terms = get_the_terms($product_id, 'product_cat');
   
       		// define empty array to gather categories
       		$categories = [];
   
       		// populate the array of categories
       		for ( $n=0; $n < count($terms); $n++ ) {
       			array_push($categories, $terms[$n]->slug);
       		}
   
   
       		// change shop address if category is found
       		if ( in_array( strtolower($conditional_category), $categories) ) {
   
       			// hide default shop name & address with CSS
       			echo '<style>' . '.shop-name, .shop-address {display: none;}' . '</style>';
   
       			// display new shop name
       			echo '<b>' . 'Alt Shop Name' . '</b>';
   
       			//display new shop address
       			echo 
       			'<div>' .
       				'Address Line 1' .
       				//insert line break
       				'<br>' .
       				'Address Line 2' .
       			'</div>';
   
       			return;
       		}
       	}
       }
       ```
   
 * In this case, you will need to enter the slug of the category that you want to
   be the conditional category in the line `conditional_category = 'tshirts'`. 🙂
    -  This reply was modified 5 years, 4 months ago by [Darren Peyou](https://wordpress.org/support/users/dpeyou/).
 *  Thread Starter [josede](https://wordpress.org/support/users/josede/)
 * (@josede)
 * [5 years, 3 months ago](https://wordpress.org/support/topic/condition-address-shop/#post-14340642)
 * Darren How can I change the prefix of the invoice based with the same conditions.(
   Your code is fine) Just I need to change the prefix when $conditional_category
   = ‘tshirts’.
 *  Plugin Contributor [Darren Peyou](https://wordpress.org/support/users/dpeyou/)
 * (@dpeyou)
 * [5 years, 3 months ago](https://wordpress.org/support/topic/condition-address-shop/#post-14341958)
 * Hi [@josede](https://wordpress.org/support/users/josede/),
 * Since this is now something different you are talking about, could you create
   a new thread? Sorry if this sounds dismissive, it’s just to keep some order in
   the forums. 🙂
    In that new thread you create, could you specify whether you 
   are talking about invoice number or PDF filename. See you on the new thread!
    -  This reply was modified 5 years, 3 months ago by [Darren Peyou](https://wordpress.org/support/users/dpeyou/).

Viewing 11 replies - 1 through 11 (of 11 total)

The topic ‘Condition address shop’ is closed to new replies.

 * ![](https://ps.w.org/woocommerce-pdf-invoices-packing-slips/assets/icon-256x256.
   png?rev=2189942)
 * [PDF Invoices & Packing Slips for WooCommerce](https://wordpress.org/plugins/woocommerce-pdf-invoices-packing-slips/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/woocommerce-pdf-invoices-packing-slips/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/woocommerce-pdf-invoices-packing-slips/)
 * [Active Topics](https://wordpress.org/support/plugin/woocommerce-pdf-invoices-packing-slips/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/woocommerce-pdf-invoices-packing-slips/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/woocommerce-pdf-invoices-packing-slips/reviews/)

 * 11 replies
 * 2 participants
 * Last reply from: [Darren Peyou](https://wordpress.org/support/users/dpeyou/)
 * Last activity: [5 years, 3 months ago](https://wordpress.org/support/topic/condition-address-shop/#post-14341958)
 * Status: resolved