• Resolved mredzovic

    (@mredzovic)


    Hello Pinal!

    I’ve just about got this plugin completely setup!
    I’m just having troubles including some data from the check-out fields into the email notification.

    I have copied the request-new-quote.php to the correct folder and have made some changes that are applying, but am getting “Internal Server Error” when I try creating the variables. When I remove the variables that I add, the “Internal Server Error” goes away, and the process works, but without the data from the fields that I’d like in the email notification.

    Any assistance would be a great help!

    Here is my code thus far:

    <?php
    /**
     * Request New Quote email
     *
     * @package Quotes for WooCommerce/Email Templates
     */
    
    $order_obj = new WC_order( $order->order_id );
    // translators: Billing Name.
    $opening_paragraph = __( 'A request for quote has been made by %s and is awaiting your attention. The details of the order are as follows:', 'quote-wc' );
    ?>
    
    <?php do_action( 'woocommerce_email_header', $email_heading ); ?>
    
    <?php
    $billing_first_name = ( version_compare( WOOCOMMERCE_VERSION, '3.0.0' ) < 0 ) ? $order_obj->billing_first_name : $order_obj->get_billing_first_name();
    $billing_last_name  = ( version_compare( WOOCOMMERCE_VERSION, '3.0.0' ) < 0 ) ? $order_obj->billing_last_name : $order_obj->get_billing_last_name();
    
    //START - (New Fields) These were added in order to include the Rental Start Date, Rental Term, and Quote Notes variables
    $start_date = ( version_compare( WOOCOMMERCE_VERSION, '3.0.0' ) < 0 ) ? $order_obj->start_date : $order_obj->get_start_date();
    $rental_term = ( version_compare( WOOCOMMERCE_VERSION, '3.0.0' ) < 0 ) ? $order_obj->rental_term : $order_obj->get_rental_term();
    $order_comments = ( version_compare( WOOCOMMERCE_VERSION, '3.0.0' ) < 0 ) ? $order_obj->order_comments : $order_obj->get_order_comments();
    //END - (New Fields)
    
    if ( $order && $billing_first_name && $billing_last_name ) :
    	?>
    	<p><?php echo sprintf( esc_html( $opening_paragraph ), esc_html( $billing_first_name . ' ' . $billing_last_name ) ); ?></p>
    <?php endif; ?>
    
    <table cellspacing="0" cellpadding="6" style="width: 100%; border: 1px solid #eee;" border="1" bordercolor="#eee">
    	<tbody>
    		<tr>
    			<th style="text-align:left; border: 1px solid #eee;"><?php esc_html_e( 'Product', 'quote-wc' ); ?></th>
    			<th style="text-align:left; border: 1px solid #eee;"><?php esc_html_e( 'Quantity', 'quote-wc' ); ?></th>
    			<th style="text-align:left; border: 1px solid #eee;"><?php esc_html_e( 'Product Price', 'quote-wc' ); ?></th>
    
    		</tr>
    		<?php
    		foreach ( $order_obj->get_items() as $items ) {
    			?>
    			<tr>
    				<td style="text-align:left; border: 1px solid #eee;"><?php echo wp_kses_post( $items->get_name() ); ?></td>
    				<td style="text-align:left; border: 1px solid #eee;"><?php echo esc_attr( $items->get_quantity() ); ?></td>
    				<td style="text-align:left; border: 1px solid #eee;"><?php echo wp_kses_post( $order_obj->get_formatted_line_subtotal( $items ) ); ?></td>
    			</tr>
    			<?php
    		}
    		?>
    	</tbody>
    </table>
    
    <!-- START - (New Field Data Insertion) Rental Start Date, Rental Term, and Quote Notes fields placed in email notification here. -->
    <br>
    <p><?php echo "Requested Start Date: ";?><?php echo esc_html( $start_date );?></p>
    <p><?php echo "Rental Term: ";?><?php echo esc_html( $rental_term );?></p>
    <p><?php echo "Additional Notes: ";?><?php echo esc_html( $order_comments );?></p>
    <!-- END - (New Field Data Insertion) Rental Start Date, Rental Term, and Quote Notes fields placed in email notification here. -->
    
    <p><?php esc_html_e( 'This order is awaiting a quote.', 'quote-wc' ); ?></p>
    <p>
    	<?php
    	// translators: Admin Url for payment.
    	echo wp_kses_post( make_clickable( sprintf( __( 'You can view and edit this order in the dashboard here: %s', 'quote-wc' ), esc_url( admin_url( 'post.php?post=' . $order->order_id . '&action=edit' ) ) ) ) );
    	?>
    </p>
    <?php do_action( 'woocommerce_email_customer_details', $order_obj, $sent_to_admin, $plain_text, $email ); ?>
    <?php do_action( 'woocommerce_email_footer' ); ?>
Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author Pinal Shah

    (@pinalshah)

    Hi @mredzovic,

    Can you kindly confirm that the new variables which you are trying to insert using the code are available?

    I mean are these returning a valid value?

    $order_obj->get_start_date();
    $order_obj->get_rental_term();
    $order_obj->get_order_comments();

    Another thing to check would be to set default values in the code for the new variables and see if they are displayed. This will also confirm that the issue is in fetching the values for those variables.

    Please let me know.

    Thanks,
    Pinal

    Thread Starter mredzovic

    (@mredzovic)

    Hey! Thank you for the reply!

    I’m not entirely sure if the set & get have been inserted anywhere other than if they are in the email notification template (request-new-quote.php). That’s as far as I’ve got so far. Although I wish I were, I unfortunately am not a php pro 🙁 haha.

    The “order_comments” is a field name that was already part of the checkout page in woocommerce. The other two (start_date & rental_term) are two I’ve added with your plug-in 🙂

    Is there any way to get/set those values in the request-new-quote.php file alone.. so that they can display in the email notification? Or would it require modifying anything else like the functions.php file? If so, would you be so kind in assisting me?

    Thanks!!
    -M

    Plugin Author Pinal Shah

    (@pinalshah)

    Hi @mredzovic,

    Please accept my apologies for the delay in response.

    The correct way to get the customer order notes (entered by the customer on the Checkout page) is as below:

    $order_obj->get_customer_note();

    https://woocommerce.github.io/code-reference/classes/WC-Order.html#method_get_customer_note

    As for the custom fields, I think the best way to fetch the data in these fields would be get them directly from the DB. It depends on whether they are saved as item meta or order meta.

    I hope this helps. In case if you have any further queries, please feel free to get in touch.

    Thanks,
    Pinal

    • This reply was modified 3 years, 7 months ago by Pinal Shah.
    Thread Starter mredzovic

    (@mredzovic)

    Pinal!

    Thank you that worked beautifully 🙂

    Something else came up that I’m hoping you can help with!
    We’ve been having an issue with our site displaying sitemap’s.
    So we’ve finally setup a staging site where our live site is cloned to.
    I deactivated all of the plugins and saw that the sitemap was working.
    Upon activating each plugin one by one, when activating QuotesForWooCommerce it says:

    “The plugin generated 2 characters of unexpected output during activation. If you notice “headers already sent” messages, problems with syndication feeds or other issues, try deactivating or removing this plugin”

    The sitemap then stops working. When I go to the Yoast SEO plugin and try to view the sitemaps I get the following:

    “This page contains the following errors:
    error on line 2 at column 6: XML declaration allowed only at the start of the document
    Below is a rendering of the page up to the first error.”

    Nothing shows below that message.

    Is there something I should do on my end?
    I have checked my functions.php file for any empty lines at the top or bottom, as well as my wp-config.php and all are well.
    Tried clearing site cache, but no luck.

    Any guidance/assistance would be greatly appreciated!

    Thanks again!
    -M

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Data from Check-out fields not showing in Email Notification’ is closed to new replies.