Skip to:
Content
Pages
Categories
Search
Top
Bottom

Email template with loop statement


  • Dipesh Kakadiya
    Participant

    @dipeshkakadiya

    Hey,

    I am using BuddyPress email template feature which is release in 2.5.
    I want to customise my custom invoice mail but i did’t add loop inside email template.

    will I be able to use foreach loop inside the email template?
    So that I could iterate and print all the product info in the mail template. Can anyone help?

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

  • Paul Wong-Gibbs
    Keymaster

    @djpaul

    You can add whatever custom PHP you want inside the email template, yes. I would suggest for now you pass the product info as a custom token to your email, and write a PHP loop to render whatever you want.


    Dipesh Kakadiya
    Participant

    @dipeshkakadiya

    @PaulGibbs
    hey
    I tried with php loop but it’s print as it is. Can you give me example ?
    this is my email template

    <table id="invoice-table" >
    	<thead>
    		<tr>
    			<td>
    				<?php
    				$logo_id		 = boss_get_option( 'boss_logo', 'id' );
    				$site_title = get_bloginfo( 'name' );
    				$logo_large	 = ( $logo_id ) ? wp_get_attachment_image( $logo_id, 'full', '', array( 'class' => 'boss-logo large' ) ) : '<span class="bb-title-large">' . $site_title . '</span>';
    				?>
    				<a href="<?php echo esc_url( home_url( '/' ) ); ?>" rel="home">
    					<?php echo $logo_large; ?>
    				</a>
    				<address>
    				<div><?php esc_html_e( 'lavozdelmuro SL', Lavozdelmuro_payments()->domain ) ?></div>
    				<div><?php esc_html_e( 'B13571013', Lavozdelmuro_payments()->domain ) ?></div>
    				<div><?php esc_html_e( 'Calle Andalucia 47 Ciudad Reak', Lavozdelmuro_payments()->domain ) ?></div>
    				<div><?php esc_html_e( 'Spain', Lavozdelmuro_payments()->domain ) ?></div>
    				</address>
    			</td>
    			<td>
    				<div><?php echo esc_html( $username ); ?></div>
    				<div><?php echo esc_html( $real_name ); ?></div>
    				<div><?php echo esc_html( $surname ); ?></div>
    				<div><?php echo esc_html( $address ); ?></div>
    				<div><?php echo esc_html( $country ); ?></div>
    				<div></div>
    			</td>
    		</tr>
    	</thead>
    	<tbody>
    		<tr>
    			<td></td>
    			<td>
    				<div><strong>REF:</strong> : <?php echo esc_html( $ref_invoice ); ?></div>
    				<div><strong>Date of Payment:</strong> : <?php echo esc_html( date( 'd M Y', strtotime( $payment_date ) ) ); ?></div>
    			</td>
    		</tr>
    		<tr>
    			<td>Invoice period from <?php echo  esc_html( date( 'd M Y', strtotime( $min_date ) ) ); ?> to <?php echo  esc_html( date( 'd M Y', strtotime( $max_date ) ) ); ?></td>
    			<td></td>
    		</tr>
    		<tr class="top-border">
    			<td><strong>posts</strong></td>
    			<td><strong>Amount</strong></td>
    		</tr>
    		<?php if ( ! empty( $payment_posts ) ) {
    			foreach ( $payment_posts as $post ) { ?>
    				<tr>
    					<td><?php echo esc_html( $post['title'] ); ?></td>
    					<td><span><?php echo esc_html( $post['amount'] ); ?></span>&euro;</td>
    				</tr>
    			<?php }
    		}  ?>
    		<?php if ( 'Spain' == $country ) { ?>
    			<tr class="top-border">
    				<td><strong>sum:</strong></td>
    				<td><span><?php echo esc_html( $amout_total ); ?></span>&euro;</td>
    			</tr>
    			<tr class="top-border">
    				<td><strong>Tax ( Spain VAT <?php echo esc_attr( $tax_rate ); ?>% ):</strong></td>
    				<td><span><?php echo esc_html( $amount_tax ); ?></span>&euro;</td>
    			</tr>
    		<?php } ?>
    		<tr class="top-border">
    			<td><strong>Total:</strong></td>
    			<td><span><?php echo esc_html( $amout_pay ); ?></span>&euro;</td>
    		</tr>
    	</tbody>
    </table>

    Dipesh Kakadiya
    Participant

    @dipeshkakadiya

    I need something like this

    
    <!-- BEGIN PRODUCT LOOP // -->
       {{#each products}}
       <tr class="item">
            <td valign="top" class="textContent">
                <img src="{{img}}" width="50" height="75" class="itemImage" />
                <h4 class="itemName">{{name}}</h4>
                <span class="contentSecondary">Qty: {{qty}} x ${{price}}/each</span><br />
                <span class="contentSecondary sku"><em>{{sku}}</em></span><br />
                <span class="contentSecondary itemDescription">{{description}}</span>
            </td>
            <td valign="top" class="textContent alignRight priceWidth">
                ${{ordPrice}}
            </td>
        </tr>
        {{/each}}
    <!-- // END PRODUCT LOOP -->
Viewing 3 replies - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.
Skip to toolbar