Changing a heading in Woo Commerce file - wordpress

The site is located at http://nancyhamiltonart.com/product/yellow-river/
Near the bottom, there's a "Related Products" text. I'm trying to change it to "Related Paintings".
I've narrowed down where I believe the string is, but when I updated and reload, it's not working.
Here's what I've changed (from wp-content/plugins/woocommerce/templates/single-product/related.php)
if ( $products->have_posts() ) : ?>
<div class="related products">
<h2><?php _e( 'Related Paintings', 'woocommerce' ); ?></h2>
<?php woocommerce_product_loop_start(); ?>
<?php while ( $products->have_posts() ) : $products->the_post(); ?>
<?php wc_get_template_part( 'content', 'product' ); ?>
<?php endwhile; // end of the loop. ?>
<?php woocommerce_product_loop_end(); ?>
</div>
Line 3 -
<h2><?php _e( 'Related Paintings', 'woocommerce' ); ?></h2>
is where I made the change, but nothing changed. Is there a different string that creates the output I'm referring to?
Thoughts one what I'm doing wrong?
UPDATE
I added the following in the functions.php file...
//Changes text "Related Products" to "Related Paintings
function my_text_strings( $translated_text, $text, $domain ) {
switch ( $translated_text ) {
case 'Related Products' :
$translated_text = __( 'Related Paintings', 'woocommerce' );
break;
}
return $translated_text;
}
add_filter( 'gettext', 'my_text_strings', 20, 3 );
Everything seems to work now...

Related

Add editable address fields to WooCommerce invoice page

Please forgive such a basic question. I'm relatively new to WooCommerce theme development and genuinely trying to understand how wordpress handles customer data so I can learn how to manipulate it. If this question is still too broad, (My previous question was closed for that reason) I'd even welcome a few links which help point me in the correct direction and explain the area I'm looking at.
What I am trying to do is add editable address fields to the page customers see when we email them an invoice. (form-pay.php)
Initially, I tried adding fields manually using variation on the following code for each field in functions.php and calling it in from order-pay.php:
<p class="form-row form-row-first">
<label for="billing_first_name"><?php _e( 'First name', 'woocommerce' ); ?><span class="required">*</span></label>
<input type="text" class="input-text" name="billing_first_name" id="billing_first_name" value="<?php if ( ! empty( $_POST['billing_first_name'] ) ) esc_attr_e( $_POST['billing_first_name'] ); ?>" />
</p>
However, when I do it this way, it adds the address details associated with my own WordPress login, rather than the customer's address associated with the invoice.
I have worked through the woocommerce codex on hooks and filters and also found the answer to this question which allowed the correct address fields to be added.
This is where my question seems to differ from a lot of the solutions I've found, in that most solutions are for updating the billing and shipping address of the current cart or logged in user, rather than that associated with a specific invoice.
Here's the fields I've added to form-pay.php.
<h2 class="woocommerce-column__title"><?php esc_html_e( 'Billing address', 'woocommerce' ); ?></h2>
<address>
<?php echo wp_kses_post( $order->get_formatted_billing_address( __( 'N/A', 'woocommerce' ) ) ); ?>
<?php if ( $order->get_billing_phone() ) : ?>
<p class="woocommerce-customer-details--phone"><?php echo esc_html( $order->get_billing_phone() ); ?></p>
<?php endif; ?>
<?php if ( $order->get_billing_email() ) : ?>
<p class="woocommerce-customer-details--email"><?php echo esc_html( $order->get_billing_email() ); ?></p>
<?php endif; ?>
</address>
<h2 class="woocommerce-column__title"><?php esc_html_e( 'Shipping address', 'woocommerce' ); ?></h2>
<address>
<?php echo wp_kses_post( $order->get_formatted_shipping_address( __( 'N/A', 'woocommerce' ) ) ); ?>
</address>
<!-- Form -->
<h3><?php _e( 'Billing details', 'woocommerce' ); ?></h3>
<?php do_action( 'woocommerce_before_checkout_billing_form', $order ); ?>
<div class="woocommerce-billing-fields__field-wrapper">
<?php
$fields = WC()->checkout->get_checkout_fields( 'billing' );
foreach ( $fields as $key => $field ) {
$field_name = $key;
if ( is_callable( array( $order, 'get_' . $field_name ) ) ) {
$field['value'] = $order->{"get_$field_name"}( 'edit' );
} else {
$field['value'] = $order->get_meta( '_' . $field_name );
}
woocommerce_form_field( $key, $field, $field['value'] );
}
?>
</div>
<?php do_action( 'woocommerce_after_checkout_billing_form', $order ); ?>
<h3><?php _e( 'Shipping details', 'woocommerce' ); ?></h3>
<?php do_action( 'woocommerce_before_checkout_shipping_form', $order ); ?>
<div class="woocommerce-shipping-fields__field-wrapper">
<?php
$fields = WC()->checkout->get_checkout_fields( 'shipping' );
foreach ( $fields as $key => $field ) {
$field_name = $key;
if ( is_callable( array( $order, 'get_' . $field_name ) ) ) {
$field['value'] = $order->{"get_$field_name"}( 'edit' );
} else {
$field['value'] = $order->get_meta( '_' . $field_name );
}
woocommerce_form_field( $key, $field, $field['value'] );
}
?>
</div>
<?php do_action( 'woocommerce_after_checkout_shipping_form', $order ); ?>
The fields correctly appear on the invoice page now which display all address details I have already added to the invoice. I just need to understand what logic I need to attach to a button to tell WooCommerce to update the record.
As I said, I recognise this is a fundamentally basic question, but so far I've failed to find an explanation that works specifically in the context of updating the invoice rather than the cart.

wordpress blog homepage customization

please don't give a negative feed like always and instead tell me the mistake.
I have a blog.
can i make the homepage display a summary of an article instead of the whole article?
if yes then where or how can i do it?
I have this pre-set in one of my WordPress sites. Here is what this looks like and it is in Appearance/Editor/Posts Page (home.php)
<div class="post-content">
<?php $content = get_the_content(); ?>
<?php echo wp_trim_words(strip_tags($content), 30); ?>
</div>
<a class="blog-post-read-more" href="<?php echo esc_url( get_the_permalink( get_the_ID() ) ); ?>"><?php echo esc_html( get_theme_mod( 'relia_blog_read_more', __( 'Read More', 'relia' ) ) ); ?></a>
</div>
So what this does is it will strip the words up to 30, wp_trim_words. And below that is the how to insert Read More.
Here are some links for you to check out:
https://codex.wordpress.org/Excerpt
https://codex.wordpress.org/Customizing_the_Read_More
Create one custom template that template you can assign your home page
/*
Template Name: Blog
*/
query_posts( array( 'post_type' => 'post', 'posts_per_page' => 6, 'paged' => ( get_query_var('paged') ? get_query_var('paged') : 1 ) ) );
<?php if ( have_posts() ) : ?>
<?php /* Start the Loop */ ?>
<?php while ( have_posts() ) : the_post(); ?>
<?php get_template_part( 'content', get_post_format()); ?>
<?php endwhile; ?>
<?php the_posts_navigation(); ?>
<?php else : ?>
<?php get_template_part( 'content', 'none' ); ?>
<?php endif; ?>
wp_reset_postdata();

Add comment date to comment author div wordpress

I'm trying to learn to use wordpress.
I'm trying to change comments layout and I want to join comment date to comment author data. But I am not getting it. For example, I have what is in first image but I want what it is in second. Can you help please? Thanks so much!
I think your main problem is that you want to customize the way the date is placed using only css but that's extremely hard.
The best thing for you to do is have your own custom comment code.
Wordpress let's you have your own comments code.
For example when you call the comment template code instead of doing this:
wp_list_comments( array(
'style' => 'ol',
'short_ping' => true,
'avatar_size' => 42,
) );
You can do something like this:
<ol class="commentlist">
<?php wp_list_comments( 'type=comment&callback=mytheme_comment' ); ?>
</ol>
And on the function.php file you can add the mytheme_comment function with the original comment code that wp has and reaarrange the classes and html code placement so you can have the date where you want.
function mytheme_comment($comment, $args, $depth) {
if ( 'div' === $args['style'] ) {
$tag = 'div';
$add_below = 'comment';
} else {
$tag = 'li';
$add_below = 'div-comment';
}
?>
<<?php echo $tag ?> <?php comment_class( empty( $args['has_children'] ) ? '' : 'parent' ) ?> id="comment-<?php comment_ID() ?>">
<?php if ( 'div' != $args['style'] ) : ?>
<div id="div-comment-<?php comment_ID() ?>" class="comment-body">
<?php endif; ?>
<div class="comment-author vcard">
<?php if ( $args['avatar_size'] != 0 ) echo get_avatar( $comment, $args['avatar_size'] ); ?>
<?php printf( __( '<cite class="fn">%s</cite> <span class="says">says:</span>' ), get_comment_author_link() ); ?>
</div>
<?php if ( $comment->comment_approved == '0' ) : ?>
<em class="comment-awaiting-moderation"><?php _e( 'Your comment is awaiting moderation.' ); ?></em>
<br />
<?php endif; ?>
<div class="comment-meta commentmetadata"><a href="<?php echo htmlspecialchars( get_comment_link( $comment->comment_ID ) ); ?>">
<?php
/* translators: 1: date, 2: time */
printf( __('%1$s at %2$s'), get_comment_date(), get_comment_time() ); ?></a><?php edit_comment_link( __( '(Edit)' ), ' ', '' );
?>
</div>
<?php comment_text(); ?>
<div class="reply">
<?php comment_reply_link( array_merge( $args, array( 'add_below' => $add_below, 'depth' => $depth, 'max_depth' => $args['max_depth'] ) ) ); ?>
</div>
<?php if ( 'div' != $args['style'] ) : ?>
</div>
<?php endif; ?>
<?php
}
In the default code you can see that the code:
<?php
/* translators: 1: date, 2: time */
printf( __('%1$s at %2$s'), get_comment_date(), get_comment_time() );
?>
is what gives you the date information.
Hope you understanded this.
Here's the original WP documentation about this:
wp list comments

WooCommerce: custom error message when cancelling bank payment

How can I display some custom error message when user clicks "place order" with card payment method selected, is redirected to the bank website, but then hits "cancel" and gets redirected back to WooCommerce thank you page?
The WooCommerce thank you page template code is summarized here (just in case I know how to add custom WooCommerce templates in my child theme):
if ( $order ) : ?>
<?php if ( $order->has_status( 'failed' ) ) : ?>
<p><?php _e( 'Unfortunately your order cannot be processed as the originating bank/merchant has declined your transaction.', 'woocommerce' ); ?></p>
<?php else : ?>
<p><?php echo apply_filters( 'woocommerce_thankyou_order_received_text', __( 'Thank you. Your order has been received.', 'woocommerce' ), $order ); ?></p>
<?php endif; ?>
<?php do_action( 'woocommerce_thankyou_' . $order->payment_method, $order->id ); ?>
<?php do_action( 'woocommerce_thankyou', $order->id ); ?>
<?php else : ?>
<p><?php echo apply_filters( 'woocommerce_thankyou_order_received_text', __( 'Thank you. Your order has been received.', 'woocommerce' ), null ); ?></p>
<?php endif; ?>
Where does the bank payment cancelling case is located in this code? And how to display a custom message like "you cancelled bank payment, your order has been cancelled"?
function wdm_my_custom_message( $order_id ){
global $woocommerce;
$order=new WC_Order($order_id);
if ( $order->has_status( 'failed' ) ) {
$woocommerce->add_error( __( 'you cancelled bank payment, your order has been cancelled.', 'woocommerce' ) );
}
}
add_action( 'woocommerce_thankyou','wdm_my_custom_message',10,1);
this will help you to achieve your purpose.

wordpress commenting system

I am trying to use wordpress's commenting system. Their documentation is very confusing and it is kind of a pain to work with. I am trying to use the same commenting system they have on the default twentytwelve theme. It seems to be the way I want it. But even when using the same code they have I do not get a list of previous comment.
This is my comments.php
if ( post_password_required() )
return;
?>
<div id="comments" class="comments-area">
<?php // You can start editing here -- including this comment! ?>
<?php if ( have_comments() ) : ?>
<h2 class="comments-title">
<?php
printf( _n( 'One thought on “%2$s”', '%1$s thoughts on “%2$s”', get_comments_number(), 'dogcompany' ),
number_format_i18n( get_comments_number() ), '<span>' . get_the_title() . '</span>' );
?>
</h2>
<ol class="commentlist">
<?php wp_list_comments( array( 'callback' => 'dogcompany_comment', 'style' => 'ol' ) ); ?>
</ol><!-- .commentlist -->
<?php if ( get_comment_pages_count() > 1 && get_option( 'page_comments' ) ) : // are there comments to navigate through ?>
<div id="comment-nav-below" class="navigation" role="navigation">
<h1 class="assistive-text section-heading"><?php _e( 'Comment navigation', 'dogcompany' ); ?></h1>
<div class="nav-previous"><?php previous_comments_link( __( '← Older Comments', 'dogcompany' ) ); ?></div>
<div class="nav-next"><?php next_comments_link( __( 'Newer Comments →', 'dogcompany' ) ); ?></div>
</div>
<?php endif; // check for comment navigation ?>
<?php
/* If there are no comments and comments are closed, let's leave a note.
* But we only want the note on posts and pages that had comments in the first place.
*/
if ( ! comments_open() && get_comments_number() ) : ?>
<p class="nocomments"><?php _e( 'Comments are closed.' , 'dogcompany' ); ?></p>
<?php endif; ?>
<?php endif; // have_comments() ?>
<?php comment_form(); ?>
</div><!-- #comments .comments-area -->
This is function.php
<?php
function dogcompany_setup(){
// Adds RSS feed links to <head> for posts and comments.
add_theme_support( 'automatic-feed-links' );
}
add_action( 'after_setup_theme', 'dogcompany_setup' );
function dogcompany_scripts_styles() {
global $wp_styles;
/*
* Adds JavaScript to pages with the comment form to support
* sites with threaded comments (when in use).
*/
if ( is_singular() && comments_open() && get_option( 'thread_comments' ) )
wp_enqueue_script( 'comment-reply' );
$protocol = is_ssl() ? 'https' : 'http';
}
add_action( 'wp_enqueue_scripts', 'dogcompany_scripts_styles' );
/*remove admin bar */
show_admin_bar(false);
if ( ! function_exists( 'dogcompany_comment' ) ) :
/**
* Template for comments and pingbacks.
*
* To override this walker in a child theme without modifying the comments template
* simply create your own dogcompany_comment(), and that function will be used instead.
*
* Used as a callback by wp_list_comments() for displaying the comments.
*
* #since Twenty Twelve 1.0
*/
function dogcompany_comment( $comment, $args, $depth ) {
$GLOBALS['comment'] = $comment;
switch ( $comment->comment_type ) :
case 'pingback' :
case 'trackback' :
// Display trackbacks differently than normal comments.
?>
<li <?php comment_class(); ?> id="comment-<?php comment_ID(); ?>">
<p><?php _e( 'Pingback:', 'dogcompany' ); ?> <?php comment_author_link(); ?> <?php edit_comment_link( __( '(Edit)', 'dogcompany' ), '<span class="edit-link">', '</span>' ); ?></p>
<?php
break;
default :
// Proceed with normal comments.
global $post;
?>
<li <?php comment_class(); ?> id="li-comment-<?php comment_ID(); ?>">
<article id="comment-<?php comment_ID(); ?>" class="comment">
<header class="comment-meta comment-author vcard">
<?php
echo get_avatar( $comment, 44 );
printf( '<cite class="fn">%1$s %2$s</cite>',
get_comment_author_link(),
// If current post author is also comment author, make it known visually.
( $comment->user_id === $post->post_author ) ? '<span> ' . __( 'Post author', 'dogcompany' ) . '</span>' : ''
);
printf( '<time datetime="%2$s">%3$s</time>',
esc_url( get_comment_link( $comment->comment_ID ) ),
get_comment_time( 'c' ),
/* translators: 1: date, 2: time */
sprintf( __( '%1$s at %2$s', 'dogcompany' ), get_comment_date(), get_comment_time() )
);
?>
</header><!-- .comment-meta -->
<?php if ( '0' == $comment->comment_approved ) : ?>
<p class="comment-awaiting-moderation"><?php _e( 'Your comment is awaiting moderation.', 'dogcompany' ); ?></p>
<?php endif; ?>
<section class="comment-content comment">
<?php comment_text(); ?>
<?php edit_comment_link( __( 'Edit', 'dogcompany' ), '<p class="edit-link">', '</p>' ); ?>
</section><!-- .comment-content -->
<div class="reply">
<?php comment_reply_link( array_merge( $args, array( 'reply_text' => __( 'Reply', 'dogcompany' ), 'after' => ' <span>↓</span>', 'depth' => $depth, 'max_depth' => $args['max_depth'] ) ) ); ?>
</div><!-- .reply -->
</article><!-- #comment-## -->
<?php
break;
endswitch; // end comment_type check
}
endif;
if ( ! function_exists( 'dogcompany_entry_meta' ) ) :
/**
* Prints HTML with meta information for current post: categories, tags, permalink, author, and date.
*
* Create your own dogcompany_entry_meta() to override in a child theme.
*
* #since Twenty Twelve 1.0
*/
function dogcompany_entry_meta() {
// Translators: used between list items, there is a space after the comma.
$categories_list = get_the_category_list( __( ', ', 'dogcompany' ) );
// Translators: used between list items, there is a space after the comma.
$tag_list = get_the_tag_list( '', __( ', ', 'dogcompany' ) );
$date = sprintf( '<time class="entry-date" datetime="%3$s">%4$s</time>',
esc_url( get_permalink() ),
esc_attr( get_the_time() ),
esc_attr( get_the_date( 'c' ) ),
esc_html( get_the_date() )
);
$author = sprintf( '<span class="author vcard"><a class="url fn n" href="%1$s" title="%2$s" rel="author">%3$s</a></span>',
esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ),
esc_attr( sprintf( __( 'View all posts by %s', 'dogcompany' ), get_the_author() ) ),
get_the_author()
);
// Translators: 1 is category, 2 is tag, 3 is the date and 4 is the author's name.
if ( $tag_list ) {
$utility_text = __( 'This entry was posted in %1$s and tagged %2$s on %3$s<span class="by-author"> by %4$s</span>.', 'dogcompany' );
} elseif ( $categories_list ) {
$utility_text = __( 'This entry was posted in %1$s on %3$s<span class="by-author"> by %4$s</span>.', 'dogcompany' );
} else {
$utility_text = __( 'This entry was posted on %3$s<span class="by-author"> by %4$s</span>.', 'dogcompany' );
}
printf(
$utility_text,
$categories_list,
$tag_list,
$date,
$author
);
}
endif;
Thank you,
I don't know exactly where you are mistaken. Use new wordpress pack comments.php and functions.php codes. I think it will be solve your problem.

Resources