I'm trying to remove the order date from the woocommerce emails, but as I'm not that confident in PHP I'm finding myself a bit stuck.
Below is some code I've found to a similar question (instead removing the order number but leaving the date...I want to do the opposite.
<?php
// Targetting specific email notificatoins
$email_ids = array('new_order', 'customer_on_hold_order');
$date = sprintf( '<time datetime="%s">%s</time>', $order->get_date_created()->format( 'c' ), wc_format_datetime( $order->get_date_created() ) );
// Displaying order number except for "New Order" and "Customer On Hold Order" notifications
if( ! in_array($email->id, $email_ids) ){
$order_number = sprintf( __( 'Order #%s', 'woocommerce' ), $order->get_order_number() );
$date = '('.$date.')';
} else {
$date = __('Order date:', 'woocommerce') . ' ' . $date;
$order_number = '';
}
if ( $sent_to_admin ) {
$before = '<a class="link" href="' . esc_url(
$order->get_edit_order_url() ) . '">';
$after = '</a> ';
} else {
$before = '';
$after = ' ';
}
?>
<h2><?php echo $before . $order_number . $after . $date; ?></h2>
Managed to figure this one out myself...(although not sure it's good practice...but it works!)
Simply added a class to the h2 tag within your-child-theme/woocommerce/emails/email-order-details.php, like below:
<h2 class="fbc-time">
<?php
if ( $sent_to_admin ) {
$before = '<a class="link" href="' . esc_url( $order->get_edit_order_url() ) . '">';
$after = '</a>';
} else {
$before = '';
$after = '';
}
/* translators: %s: Order ID. */
echo wp_kses_post( $before . sprintf( __( 'Order #%s', 'woocommerce' ) . $after . ' <time datetime="%s">%s</time>', $order->get_order_number(), $order->get_date_created()->format( 'c' ), wc_format_datetime( $order->get_date_created() ) ) );
?>
Then selected the class in email-styles.php and used display: none
Related
I am editing code in template tags to show the last modified date on my WordPress website, what I mean is if I update the post, it should conditionally show update and ignore "Published", and if I do not, it should leave as is.
I got it to work, the problem I have is "Published On" appearing on all my post: http://prntscr.com/nn9hfl, this is my code so far
function chicken_wings_posted_on() {
/**
* Function to show last updated date
*/
$u_time = get_the_time('U');
$u_modified_time = get_the_modified_time('U');
if ($u_modified_time >= $u_time + 86400) {
echo '<p class = "last-updated-up">Last updated on ';
the_modified_time('F jS, Y');
echo "</p> "; }
else {
echo '<p class = "entry-date published">Published on ';
the_time('F jS, Y');
echo "</p> "; }
$time_string = sprintf( $time_string,
esc_attr( get_the_date( 'c' ) ),
esc_html( get_the_date() ),
esc_attr( get_the_modified_date( 'c' ) ),
esc_html( get_the_modified_date() )
);
$posted_on = sprintf(
/* translators: %s: post date. */
esc_html_x( 'Published on %s', 'post date', 'chicken-wings' ),
'' . $time_string . ''
);
I expect the result to be showing Updated Date only if a post is updated only
I can spot the problem is between the $posted_on = sprintf(, and I can see that is including permalink on the actual date, how do I correct the code to include the permalink in the updated date if post updated, and the actual date if not updated.
Thanks.
I have reformatted your code to display the post date and updated date with conditional. Also I have added correct link for the published date and also updated date. Please check following.
function chicken_wings_posted_on() {
$u_time = get_the_time('U');
$u_modified_time = get_the_modified_time('U');
if ($u_modified_time >= $u_time + 86400) {
echo '<p class="last-updated-up">Last updated on ';
echo '<a href="' . esc_url( get_day_link( get_the_modified_time( 'Y' ), get_the_modified_time( 'm' ), get_the_modified_time( 'd' ) ) ) . '">';
the_modified_time('F jS, Y');
echo '</a>';
echo "</p> ";
} else {
echo '<p class="entry-date published">Published on ';
echo '<a href="' . esc_url( get_day_link( false, false, false ) ) . '">';
the_time('F jS, Y');
echo '</a>';
echo "</p> ";
}
}
I want to accomplish 2 things in my woocommerce checkout form:
1. Put some text between some groups of fields, for example (h3):
<h3>my custom heading</h3>
<p class="form-row form-row validate-required">
<input type="email">...
</p>
<h3>my other custom heading</h3>
<p class="form-row form-row validate-required">
<input type="text">...
</p>
<p class="form-row form-row validate-required">
<input type="text">...
</p>
2. Display input tag first and label tag as second in html (woocommerce display label before input by default)
I figured out that checkout form is displayed by this code (for billing):
<?php foreach ( $checkout->checkout_fields['billing'] as $key => $field ) : ?>
<?php woocommerce_form_field( $key, $field, $checkout->get_value( $key ) ); ?>
<?php endforeach; ?>
How can I customize it in way I described?
I'm not sure on part 1, but for part 2, you can modify the output of woocommerce_form_field() by filtering woocommerce_form_field_$type.
So your part 2 can be solved like so:
function so_39267627_form_field( $field, $key, $args, $value ){
if ( $args['required'] ) {
$args['class'][] = 'validate-required';
$required = ' <abbr class="required" title="' . esc_attr__( 'required', 'woocommerce' ) . '">*</abbr>';
} else {
$required = '';
}
$args['maxlength'] = ( $args['maxlength'] ) ? 'maxlength="' . absint( $args['maxlength'] ) . '"' : '';
$args['autocomplete'] = ( $args['autocomplete'] ) ? 'autocomplete="' . esc_attr( $args['autocomplete'] ) . '"' : '';
if ( is_string( $args['label_class'] ) ) {
$args['label_class'] = array( $args['label_class'] );
}
if ( is_null( $value ) ) {
$value = $args['default'];
}
// Custom attribute handling
$custom_attributes = array();
// Custom attribute handling
$custom_attributes = array();
if ( ! empty( $args['custom_attributes'] ) && is_array( $args['custom_attributes'] ) ) {
foreach ( $args['custom_attributes'] as $attribute => $attribute_value ) {
$custom_attributes[] = esc_attr( $attribute ) . '="' . esc_attr( $attribute_value ) . '"';
}
}
$field = '';
$label_id = $args['id'];
$field_container = '<p class="form-row %1$s" id="%2$s">%3$s</p>';
$field .= '<input type="' . esc_attr( $args['type'] ) . '" class="input-text ' . esc_attr( implode( ' ', $args['input_class'] ) ) .'" name="' . esc_attr( $key ) . '" id="' . esc_attr( $args['id'] ) . '" placeholder="' . esc_attr( $args['placeholder'] ) . '" ' . $args['maxlength'] . ' ' . $args['autocomplete'] . ' value="' . esc_attr( $value ) . '" ' . implode( ' ', $custom_attributes ) . ' />';
if ( ! empty( $field ) ) {
$field_html = '';
$field_html .= $field;
if ( $args['description'] ) {
$field_html .= '<span class="description">' . esc_html( $args['description'] ) . '</span>';
}
if ( $args['label'] && 'checkbox' != $args['type'] ) {
$field_html .= '<label for="' . esc_attr( $label_id ) . '" class="' . esc_attr( implode( ' ', $args['label_class'] ) ) .'">' . $args['label'] . $required . '</label>';
}
$container_class = 'form-row ' . esc_attr( implode( ' ', $args['class'] ) );
$container_id = esc_attr( $args['id'] ) . '_field';
$after = ! empty( $args['clear'] ) ? '<div class="clear"></div>' : '';
$field = sprintf( $field_container, $container_class, $container_id, $field_html ) . $after;
}
return $field;
}
add_filter( 'woocommerce_form_field_password', 'so_39267627_form_field', 10, 4 );
add_filter( 'woocommerce_form_field_text', 'so_39267627_form_field', 10, 4 );
add_filter( 'woocommerce_form_field_email', 'so_39267627_form_field', 10, 4 );
add_filter( 'woocommerce_form_field_tel', 'so_39267627_form_field', 10, 4 );
add_filter( 'woocommerce_form_field_number', 'so_39267627_form_field', 10, 4 );
You would need to write a few more functions (mostly I copied and pasted whole swaths of code from WooCommerce and then just swapped the label part around ) for other other field types, but this should serve as an example.
For the first one you can do the following to display single input field
<?php
woocommerce_form_field(
"billing_first_name",
$checkout->checkout_fields['billing']['billing_first_name'],
$checkout->get_value( 'billing_first_name' )
);
?>
where you can replace first_name with any key of the checkout billing fields
So for your example it will be something like this
<h3>my custom heading</h3>
<p class="form-row form-row validate-required">
<?php woocommerce_form_field( "billing_email", $checkout->checkout_fields['billing']['billing_email'], $checkout->get_value( 'billing_email' ) ); ?>
</p>
As for the second I'm not sure how you can achieve that. I needed something similar and i used javascript to reposition the labels.
something like :
jQuery('form.checkout label').each(function(){
jQuery(this).insertAfter(jQuery(this).parent().find('input'));
})
As far as I think, woo commerce does not support html, there's a plugin known as woocommerce checkout field editor, see if it solves your issue.
Let me say about the condition I need to ask:
I display the start sale and end sale for a product on WooCommerce. The code on loop like this:
<?php $thepostid = get_the_ID();
if ( $date = get_post_meta( $thepostid, '_sale_price_dates_from', true ) ) {
$sale_price_dates_from =
'<div class="fromsale">' .
'<span class="promodesc">' . esc_html__( 'Sale start:', 'mytheme' ). '</span>' .
'<span class="m">' . date_i18n( 'M', $date ) . '</span> ' .
'<span class="d">' . date_i18n( 'j', $date ) . '</span> ' .
'</div>'
;
} else {
$sale_price_dates_from =
'<div class="endsale">' .
'<span class="promodesc">' . esc_html__( 'No Schedule', 'mytheme' ). '</span> ' .
'</div>'
; }
echo $sale_price_dates_from ;
?>
<?php $thepostid = get_the_ID();
if ( $date = get_post_meta( $thepostid, '_sale_price_dates_to', true ) ) {
$sale_price_dates_to =
'<div class="endsale">' .
'<span class="promodesc">' . esc_html__( 'Sale end:', 'mytheme' ). '</span>' .
'<span class="m">' . date_i18n( 'M', $date ) . '</span> ' .
'<span class="d">' . date_i18n( 'j', $date ) . '</span> ' .
'</div>'
;
} else {
$sale_price_dates_to =
'<div class="endsale">' .
'<span class="promodesc">' . esc_html__( 'No Schedule', 'mytheme' ). '</span> ' .
'</div>'
; }
echo $sale_price_dates_to ;
?>
The result is like this:
Sale start: May 13
Sale end: May 22
I am curious, how to get times range between the start and the end? In this case I want to display the countdown like this (for example):
Sale will be end: 7days 20hours 33minutes 22seconds.
Can anyone help me?
Thank for any kind of helps.
I have wordpress theme with woocommerce. Every single product have in description category like categories : new, books. I want to exclude one category(new) and make it not clickable(remove a hrev) I found line of this tag but dont know how to edit right. Any ideas? THANKS!
<?php echo $product->get_categories( ', ', '<span class="posted_in">' . _n( 'Category:', 'Categories:', $cat_count, 'woocommerce' ) . ' ', '.</span>' ); ?>
woocommerce plugin
replace this line:
<?php echo $product->get_categories( ', ', '<span class="posted_in">' . _n( 'Category:', 'Categories:', $cat_count, 'woocommerce' ) . ' ', '.</span>' ); ?>
with this:
$terms = get_the_terms( $post->ID, 'product_cat' );
echo '<span class="posted_in">';
foreach ( $terms as $term ) {
$term_link = get_term_link( $term );
if( $term->name == 'New' ){
echo ' ' . $term->name;
}else{
echo ' ' . $term->name . '';
}
}
echo '</span>';
You can customize it according to your requirements. May be this will help.
I am new to woocommerce and wordpress and what I am trying to achieve is display instructions on thank you page for download-able products only.
May be I am wrong but I have this file I am looking at woocommerce->templates->order->order-details.php and it has the following piece of code that outputs the download links on thankyou page (i assume as i am not able to find another file that does this job).
if ( $_product && $_product->exists() && $_product->is_downloadable() && $order->is_download_permitted() ) {
echo 'Click the links below to access your courses. You will also receive an email shortly with the links to download your products.';
$download_files = $order->get_item_downloads( $item );
$i = 0;
$links = array();
foreach ( $download_files as $download_id => $file ) {
$i++;
$links[] = '<small style="font-size: 15pt !important;">' . sprintf( __( 'Download file%s', 'woocommerce' ), ( count( $download_files ) > 1 ? ' ' . $i . ': ' : ': ' ) ) . esc_html( $file['name'] ) . '</small>';
}
echo '<br/>' . implode( '<br/>', $links );
}
Now all I want is to echo a text here for downloadable products only. But it does not display the text.
The text I want to echo is as following where the red arrow is pointing
Click the links below to access your courses. You will also receive an email shortly with the links to download your products.;
I will really appreciate if anyone can help me in this.
First of all make sure you have added downloadable file(s) from the back end. My guess is, you have not added file. So add any file from the back end in order to see the message that you have inserted.
See below pic and make sure you have both the things that is shown in below pic with square box :
After doing that, you will be able to see that message.
My code is in same file :
<td class="product-name">
<?php
if ( $_product && ! $_product->is_visible() )
echo apply_filters( 'woocommerce_order_item_name', $item['name'], $item );
else
echo apply_filters( 'woocommerce_order_item_name', sprintf( '%s', get_permalink( $item['product_id'] ), $item['name'] ), $item );
echo apply_filters( 'woocommerce_order_item_quantity_html', ' <strong class="product-quantity">' . sprintf( '× %s', $item['qty'] ) . '</strong><br>', $item );
$item_meta->display();
if ( $_product && $_product->exists() && $_product->is_downloadable() && $order->is_download_permitted() ) {
echo "Click below link to download the file<br>";
$download_files = $order->get_item_downloads( $item );
$i = 0;
$links = array();
foreach ( $download_files as $download_id => $file ) {
$i++;
$links[] = '<small>' . sprintf( __( 'Download file%s', 'woocommerce' ), ( count( $download_files ) > 1 ? ' ' . $i . ': ' : ': ' ) ) . esc_html( $file['name'] ) . '</small>';
}
echo '<br/>' . implode( '<br/>', $links );
}
?>
</td>
Let me know if you have any doubt.