I was translating the titles and sentences right on the editor. I don't know what went wrong, but when I hit upload I keep getting this:
Parse error: syntax error, unexpected 'Comentários' (T_STRING) in /home2/tkleinow/public_html/wp-content/themes/fashionistas/inc/template-tags.php on line 94
Then I tried to copy the original code for that section (template tags) on the zip files, but I keep getting the same error.
I pasted it on Excel to find what the line was, and this is wat I got:
<?php printf( __( '%s', 'athemes' ), sprintf( '<cite class="fn">%s</cite>', get_comment_author_link() ) ); ?>
My website was doing just fine, I don't know how I screwed it like that.
This is the whole thing:
<?php
/**
* Custom template tags for this theme.
*
* Eventually, some of the functionality here could be replaced by core features
*
* #package aThemes
*/
if ( ! function_exists( 'athemes_content_nav' ) ) :
/**
* Display navigation to next/previous pages when applicable
*/
function athemes_content_nav( $nav_id ) {
global $wp_query, $post;
// Don't print empty markup on single pages if there's nowhere to navigate.
if ( is_single() ) {
$previous = ( is_attachment() ) ? get_post( $post->post_parent ) : get_adjacent_post( false, '', true );
$next = get_adjacent_post( false, '', false );
if ( ! $next && ! $previous )
return;
}
// Don't print empty markup in archives if there's only one page.
if ( $wp_query->max_num_pages < 2 && ( is_home() || is_archive() || is_search() ) )
return;
$nav_class = ( is_single() ) ? 'post-navigation' : 'paging-navigation';
?>
<nav role="navigation" id="<?php echo esc_attr( $nav_id ); ?>" class="<?php echo $nav_class; ?>">
<h1 class="screen-reader-text"><?php _e( 'Post navigation', 'athemes' ); ?></h1>
<?php if ( is_single() ) : // navigation links for single posts ?>
<?php previous_post_link( '<div class="nav-previous"><span>Artigo Anterior</span>%link</div>', '<span class="meta-nav">' . _x( '←', 'Link do Post Anterior', 'athemes' ) . '</span> %title' ); ?>
<?php next_post_link( '<div class="nav-next"><span>Próximo Artigo</span>%link</div>', '%title <span class="meta-nav">' . _x( '→', 'Link para o próximo artigo', 'athemes' ) . '</span>' ); ?>
<?php elseif ( $wp_query->max_num_pages > 1 && ( is_home() || is_archive() || is_search() ) ) : // navigation links for home, archive, and search pages ?>
<?php if ( get_next_posts_link() ) : ?>
<div class="nav-previous"><?php next_posts_link( __( '<span class="meta-nav">←</span> Artigos Anteriores', 'athemes' ) ); ?></div>
<?php endif; ?>
<?php if ( get_previous_posts_link() ) : ?>
<div class="nav-next"><?php previous_posts_link( __( 'Artigos Recentes <span class="meta-nav">→</span>', 'athemes' ) ); ?></div>
<?php endif; ?>
<?php endif; ?>
</nav><!-- #<?php echo esc_html( $nav_id ); ?> -->
<?php
}
endif; // athemes_content_nav
if ( ! function_exists( 'athemes_comment' ) ) :
/**
* Template for comments and pingbacks.
*
* Used as a callback by wp_list_comments() for displaying the comments.
*/
function athemes_comment( $comment, $args, $depth ) {
$GLOBALS['comment'] = $comment;
if ( 'pingback' == $comment->comment_type || 'trackback' == $comment->comment_type ) : ?>
<li id="comment-<?php comment_ID(); ?>" <?php comment_class(); ?>>
<div class="comment-body">
<?php _e( 'Pingback:', 'athemes' ); ?> <?php comment_author_link(); ?> <?php edit_comment_link( __( 'Edit', 'athemes' ), '<span class="edit-link">', '</span>' ); ?>
</div>
<?php else : ?>
<li id="comment-<?php comment_ID(); ?>" <?php comment_class( empty( $args['has_children'] ) ? '' : 'parent' ); ?>>
<article id="div-comment-<?php comment_ID(); ?>" class="comment-body">
<footer class="clearfix comment-meta">
<div class="reply">
<?php comment_reply_link( array_merge( $args, array( 'add_below' => 'div-comment', 'depth' => $depth, 'max_depth' => $args['max_depth'] ) ) ); ?>
</div><!-- .reply -->
<div class="clearfix comment-author vcard">
<?php if ( 0 != $args['avatar_size'] ) echo get_avatar( $comment, $args['avatar_size'] ); ?>
<div class="comment-metadata">
<a href="<?php echo esc_url( get_comment_link( $comment->comment_ID ) ); ?>">
<time datetime="<?php comment_time( 'c' ); ?>">
<?php printf( _x( '%1$s', '1: date, 2: time', 'athemes' ), get_comment_date(), get_comment_time() ); ?>
</time>
</a>
</div><!-- .comment-metadata -->
<?php printf( __( '%s', 'athemes' ), sprintf( '<cite class="fn">%s</cite>', get_comment_author_link() ) ); ?>
</div><!-- .comment-author -->
<?php if ( '0' == $comment->comment_approved ) : ?>
<p class="comment-awaiting-moderation"><?php _e( 'Seu comentário será aprovado assim que passar pela moderação.', 'athemes' ); ?></p>
<?php endif; ?>
</footer><!-- .comment-meta -->
<div class="comment-content">
<?php comment_text(); ?>
</div><!-- .comment-content -->
</article><!-- .comment-body -->
<?php
endif;
}
endif; // ends check for athemes_comment()
if ( ! function_exists( 'athemes_the_attached_image' ) ) :
/**
* Prints the attached image with a link to the next attached image.
*/
function athemes_the_attached_image() {
$post = get_post();
$attachment_size = apply_filters( 'athemes_attachment_size', array( 1200, 1200 ) );
$next_attachment_url = wp_get_attachment_url();
/**
* Grab the IDs of all the image attachments in a gallery so we can get the
* URL of the next adjacent image in a gallery, or the first image (if
* we're looking at the last image in a gallery), or, in a gallery of one,
* just the link to that image file.
*/
$attachment_ids = get_posts( array(
'post_parent' => $post->post_parent,
'fields' => 'ids',
'numberposts' => -1,
'post_status' => 'inherit',
'post_type' => 'attachment',
'post_mime_type' => 'image',
'order' => 'ASC',
'orderby' => 'menu_order ID'
) );
// If there is more than 1 attachment in a gallery...
if ( count( $attachment_ids ) > 1 ) {
foreach ( $attachment_ids as $attachment_id ) {
if ( $attachment_id == $post->ID ) {
$next_id = current( $attachment_ids );
break;
}
}
// get the URL of the next image attachment...
if ( $next_id )
$next_attachment_url = get_attachment_link( $next_id );
// or get the URL of the first image attachment.
else
$next_attachment_url = get_attachment_link( array_shift( $attachment_ids ) );
}
printf( '%3$s',
esc_url( $next_attachment_url ),
the_title_attribute( array( 'echo' => false ) ),
wp_get_attachment_image( $post->ID, $attachment_size )
);
}
endif;
if ( ! function_exists( 'athemes_posted_on' ) ) :
/**
* Prints HTML with meta information for the current post-date/time and author.
*/
function athemes_posted_on() {
$time_string = '<time class="entry-date published" datetime="%1$s">%2$s</time>';
//if ( get_the_time( 'U' ) !== get_the_modified_time( 'U' ) )
//$time_string .= '<time class="updated" datetime="%3$s">%4$s</time>';
$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() )
);
printf( __( '<span class="posted-on">%1$s</span>', 'athemes' ),
sprintf( '%3$s',
esc_url( get_permalink() ),
esc_attr( get_the_time() ),
$time_string
)
);
}
endif;
/**
* Returns true if a blog has more than 1 category
*/
function athemes_categorized_blog() {
if ( false === ( $all_the_cool_cats = get_transient( 'all_the_cool_cats' ) ) ) {
// Create an array of all the categories that are attached to posts
$all_the_cool_cats = get_categories( array(
'hide_empty' => 1,
) );
// Count the number of categories that are attached to the posts
$all_the_cool_cats = count( $all_the_cool_cats );
set_transient( 'all_the_cool_cats', $all_the_cool_cats );
}
if ( '1' != $all_the_cool_cats ) {
// This blog has more than 1 category so athemes_categorized_blog should return true
return true;
} else {
// This blog has only 1 category so athemes_categorized_blog should return false
return false;
}
}
/**
* Flush out the transients used in athemes_categorized_blog
*/
function athemes_category_transient_flusher() {
// Like, beat it. Dig?
delete_transient( 'all_the_cool_cats' );
}
add_action( 'edit_category', 'athemes_category_transient_flusher' );
add_action( 'save_post', 'athemes_category_transient_flusher' );
Related
I want to add a number navigation in order to browse through the posts.
In the home of my theme I have this code that shows the posts.
<div class="container mt-80 mb-80">
<div class="card-columns">
<?php $args['tax_query'] = array(
array(
'taxonomy' => 'category',
'terms' => array('portfolio'),
'field' => 'slug',
'operator' => 'NOT IN',
),
);
query_posts($args);?>
<?php while(have_posts()) : the_post(); ?>
<div class="card">
<div class="card-body">
<a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>">
<?php the_post_thumbnail('full', array('class' => 'image-post card-img-top')); ?>
</a>
<h3 class="card-title"><?php the_title(); ?></h3>
<p class="card-text"><?php echo get_the_excerpt(); ?> ...</p>
<span class="entry-date"><?php echo get_the_date(); ?></span>
</div>
</div>
<?php endwhile; wp_reset_query(); ?>
</div>
</div>
To show the pagination I tried to add this code on the function.php
I want to insert the page numbers below the posts to browse them but I don't want to install any plugins.
function numeric_posts_nav() {
if( is_singular() )
return;
global $wp_query;
/** Stop execution if there's only 1 page */
if( $wp_query->max_num_pages <= 1 )
return;
$paged = get_query_var( 'paged' ) ? absint( get_query_var( 'paged' ) ) : 1;
$max = intval( $wp_query->max_num_pages );
/** Add current page to the array */
if ( $paged >= 1 )
$links[] = $paged;
/** Add the pages around the current page to the array */
if ( $paged >= 3 ) {
$links[] = $paged - 1;
$links[] = $paged - 2;
}
if ( ( $paged + 2 ) <= $max ) {
$links[] = $paged + 2;
$links[] = $paged + 1;
}
echo '<div class="navigation"><ul>' . "\n";
/** Previous Post Link */
if ( get_previous_posts_link() )
printf( '<li>%s</li>' . "\n", get_previous_posts_link() );
/** Link to first page, plus ellipses if necessary */
if ( ! in_array( 1, $links ) ) {
$class = 1 == $paged ? ' class="active"' : '';
printf( '<li%s>%s</li>' . "\n", $class, esc_url( get_pagenum_link( 1 ) ), '1' );
if ( ! in_array( 2, $links ) )
echo '<li>…</li>';
}
/** Link to current page, plus 2 pages in either direction if necessary */
sort( $links );
foreach ( (array) $links as $link ) {
$class = $paged == $link ? ' class="active"' : '';
printf( '<li%s>%s</li>' . "\n", $class, esc_url( get_pagenum_link( $link ) ), $link );
}
/** Link to last page, plus ellipses if necessary */
if ( ! in_array( $max, $links ) ) {
if ( ! in_array( $max - 1, $links ) )
echo '<li>…</li>' . "\n";
$class = $paged == $max ? ' class="active"' : '';
printf( '<li%s>%s</li>' . "\n", $class, esc_url( get_pagenum_link( $max ) ), $max );
}
/** Next Post Link */
if ( get_next_posts_link() )
printf( '<li>%s</li>' . "\n", get_next_posts_link() );
echo '</ul></div>' . "\n"; }
And this on the index.php
<?php numeric_posts_nav(); ?>
The navigation appears but does not work properly. Does anyone know why?
put below code in function.php file
function pagination_nav() {
global $wp_query;
if ( $wp_query->max_num_pages > 1 ) { ?>
<nav class="pagination" role="navigation">
<div class="nav-previous"><?php next_posts_link( '← Older posts' ); ?></div>
<div class="nav-next"><?php previous_posts_link( 'Newer posts →' ); ?></div>
</nav>
}
}
and this code in index.php file :
pagination_nav();
Add below thing in the argument
$args = array(
'post_per_page' => 10,
'paged'=> 'paged', //'paged' for the home page and for other pages we need to set 'page',
'tax_query'=> array(
'taxonomy' => 'category',
'terms' => array('portfolio'),
'field' => 'slug',
'operator' => 'NOT IN',
),
);
And add the function just after your loop ends
<?php numeric_posts_nav(); ?>
<?php
$paged = ( get_query_var( 'paged' ) ) ? absint( get_query_var( 'paged' ) ) : 1;
$args = array(
'post_per_page' => 10,
'paged'=> $paged,
'tax_query'=> array(
'taxonomy' => 'category',
'terms' => array('portfolio'),
'field' => 'slug',
'operator' => 'NOT IN',
),
); ?>
<?php $wp_query = new WP_Query($args); ?>
<?php if ($wp_query->have_posts()) : ?>
<?php while ( $wp_query -> have_posts() ) : $wp_query->the_post(); ?>
// Post content goes here...
<?php endwhile; ?>
<?php numeric_posts_nav(); ?>
<?php endif; ?>
<?php wp_reset_postdata(); ?>
Currently, my theme displays the most recently added WooCommerce products in a section on the homepage. What I would like is to instead show a random list of products instead of the same ones.
I've found the function that displays the products, but am unsure where I need to change the orderby.
Below is the function that writes the products to the page.
function hestia_shop_content() {
?>
<div class="hestia-shop-content">
<?php
$hestia_shop_shortcode = get_theme_mod( 'hestia_shop_shortcode' );
if ( ! empty( $hestia_shop_shortcode ) ) {
echo do_shortcode( $hestia_shop_shortcode );
echo '</div>';
return;
}
$hestia_shop_items = get_theme_mod( 'hestia_shop_items', 4 );
$args = array(
'post_type' => 'product',
);
$args['posts_per_page'] = ! empty( $hestia_shop_items ) ? absint( $hestia_shop_items ) : 4;
$hestia_shop_categories = get_theme_mod( 'hestia_shop_categories' );
if ( sizeof( $hestia_shop_categories ) >= 1 && ! empty( $hestia_shop_categories[0] ) ) {
$args['tax_query'] = array(
array(
'taxonomy' => 'product_cat',
'field' => 'term_id',
'terms' => $hestia_shop_categories,
),
);
}
$hestia_shop_order = get_theme_mod( 'hestia_shop_order', 'DESC' );
if ( ! empty( $hestia_shop_order ) ) {
$args['order'] = $hestia_shop_order;
}
$loop = new WP_Query( $args );
if ( $loop->have_posts() ) {
$i = 1;
echo '<div class="row">';
while ( $loop->have_posts() ) {
$loop->the_post();
global $product;
global $post;
?>
<div class="col-ms-6 col-sm-6 col-md-3 shop-item">
<div class="card card-product">
<?php
$thumbnail = hestia_shop_thumbnail( null, 'hestia-shop' );
if ( empty( $thumbnail ) && function_exists( 'wc_placeholder_img' ) ) {
$thumbnail = wc_placeholder_img();
}
if ( ! empty( $thumbnail ) ) {
?>
<div class="card-image">
<a href="<?php echo esc_url( get_permalink() ); ?>"
title="<?php the_title_attribute(); ?>">
<?php echo $thumbnail; ?>
</a>
<div class="ripple-container"></div>
</div>
<?php
}
?>
<div class="content">
<?php
if ( function_exists( 'wc_get_product_category_list' ) ) {
$prod_id = get_the_ID();
$product_categories = wc_get_product_category_list( $prod_id );
} else {
$product_categories = $product->get_categories();
}
if ( ! empty( $product_categories ) ) {
$allowed_html = array(
'a' => array(
'href' => array(),
'rel' => array(),
),
);
echo '<h6 class="category">';
echo wp_kses( $product_categories, $allowed_html );
echo '</h6>';
}
?>
<h4 class="card-title">
<a class="shop-item-title-link" href="<?php the_permalink(); ?>"
title="<?php the_title_attribute(); ?>"><?php esc_html( the_title() ); ?></a>
</h4>
<?php
if ( $post->post_excerpt ) {
?>
<div class="card-description"><?php echo apply_filters( 'woocommerce_short_description', $post->post_excerpt ); ?></div>
<?php
}
?>
<div class="footer">
<?php
$product_price = $product->get_price_html();
if ( ! empty( $product_price ) ) {
echo '<div class="price"><h4>';
echo wp_kses(
$product_price, array(
'span' => array(
'class' => array(),
),
'del' => array(),
)
);
echo '</h4></div>';
}
?>
<div class="stats">
<?php hestia_add_to_cart(); ?>
</div>
</div>
</div>
</div>
</div>
<?php
if ( $i % 4 == 0 ) {
echo '</div><!-- /.row -->';
echo '<div class="row">';
}
$i ++;
}
wp_reset_postdata();
echo '</div>';
}
?>
</div>
<?php
}
Use order by rand in your query like this
$args = array(
'post_type' => 'product',
'orderby'=> 'rand'
);
I'd like to hide the Status columns within My Accounts - Orders (where it shows processing, refunded, etc...).
Does anyone know how I can do that?
Here is a screenshot showing the account status column:
Thanks.
Here is the code that's currently in my file (my-orders.php)
<?php
/**
* My Orders
*
* Shows recent orders on the account page.
*
* This template can be overridden by copying it to yourtheme/woocommerce/myaccount/my-orders.php.
*
* HOWEVER, on occasion WooCommerce will need to update template files and you (the theme developer).
* will need to copy the new files to your theme to maintain compatibility. We try to do this.
* as little as possible, but it does happen. When this occurs the version of the template file will.
* be bumped and the readme will list any important changes.
*
* #see http://docs.woothemes.com/document/template-structure/
* #author WooThemes
* #package WooCommerce/Templates
* #version 2.5.0
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
$my_orders_columns = apply_filters( 'woocommerce_my_account_my_orders_columns', array(
'order-number' => __( 'Order', 'woocommerce' ),
'order-date' => __( 'Date', 'woocommerce' ),
'order-status' => __( 'Status', 'woocommerce' ),
'order-total' => __( 'Total', 'woocommerce' ),
'order-actions' => ' ',
) );
$customer_orders = get_posts( apply_filters( 'woocommerce_my_account_my_orders_query', array(
'numberposts' => $order_count,
'meta_key' => '_customer_user',
'meta_value' => get_current_user_id(),
'post_type' => wc_get_order_types( 'view-orders' ),
'post_status' => array_keys( wc_get_order_statuses() )
) ) );
/**
* This is the entire "Recent Orders" section below my subscriptions. It has been commented out
*
if ( $customer_orders ) : ?>
<h2><?php echo apply_filters( 'woocommerce_my_account_my_orders_title', __( 'Recent Orders', 'woocommerce' ) ); ?></h2>
<table class="shop_table shop_table_responsive my_account_orders">
<thead>
<tr>
<?php foreach ( $my_orders_columns as $column_id => $column_name ) : ?>
<th class="<?php echo esc_attr( $column_id ); ?>"><span class="nobr"><?php echo esc_html( $column_name ); ?></span></th>
<?php endforeach; ?>
</tr>
</thead>
<tbody>
<?php foreach ( $customer_orders as $customer_order ) :
$order = wc_get_order( $customer_order );
$item_count = $order->get_item_count();
?>
<tr class="order">
<?php foreach ( $my_orders_columns as $column_id => $column_name ) : ?>
<td class="<?php echo esc_attr( $column_id ); ?>" data-title="<?php echo esc_attr( $column_name ); ?>">
<?php if ( has_action( 'woocommerce_my_account_my_orders_column_' . $column_id ) ) : ?>
<?php do_action( 'woocommerce_my_account_my_orders_column_' . $column_id, $order ); ?>
<?php elseif ( 'order-number' === $column_id ) : ?>
<a href="<?php echo esc_url( $order->get_view_order_url() ); ?>">
<?php echo _x( '#', 'hash before order number', 'woocommerce' ) . $order->get_order_number(); ?>
</a>
<?php elseif ( 'order-date' === $column_id ) : ?>
<time datetime="<?php echo date( 'Y-m-d', strtotime( $order->order_date ) ); ?>" title="<?php echo esc_attr( strtotime( $order->order_date ) ); ?>"><?php echo date_i18n( get_option( 'date_format' ), strtotime( $order->order_date ) ); ?></time>
<?php elseif ( 'order-status' === $column_id ) : ?>
<?php echo wc_get_order_status_name( $order->get_status() ); ?>
<?php elseif ( 'order-total' === $column_id ) : ?>
<?php echo sprintf( _n( '%s for %s item', '%s for %s items', $item_count, 'woocommerce' ), $order->get_formatted_order_total(), $item_count ); ?>
<?php elseif ( 'order-actions' === $column_id ) : ?>
<?php
$actions = array(
'pay' => array(
'url' => $order->get_checkout_payment_url(),
'name' => __( 'Pay', 'woocommerce' )
),
'view' => array(
'url' => $order->get_view_order_url(),
'name' => __( 'View', 'woocommerce' )
),
'cancel' => array(
'url' => $order->get_cancel_order_url( wc_get_page_permalink( 'myaccount' ) ),
'name' => __( 'Cancel', 'woocommerce' )
)
);
if ( ! $order->needs_payment() ) {
unset( $actions['pay'] );
}
if ( ! in_array( $order->get_status(), apply_filters( 'woocommerce_valid_order_statuses_for_cancel', array( 'pending', 'failed' ), $order ) ) ) {
unset( $actions['cancel'] );
}
if ( $actions = apply_filters( 'woocommerce_my_account_my_orders_actions', $actions, $order ) ) {
foreach ( $actions as $key => $action ) {
echo '' . esc_html( $action['name'] ) . '';
}
}
?>
<?php endif; ?>
</td>
<?php endforeach; ?>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<?php endif; ?>
**/
You need to override myaccount/orders.php WooCommerce via your active theme.
For that, if not done, you will need to copy from woocommerce plugin folder, a subfolder named templates to your active child theme (or theme) and to rename it woocommerce (see this related docs).
After that you find inside that new woocommerce folder in myaccount subfolder a template named orders.php.
Open/edit orders.php template and replace the code by this:
<?php
/**
* Orders
*
* Shows orders on the account page.
*
* This template can be overridden by copying it to yourtheme/woocommerce/myaccount/orders.php.
*
* HOWEVER, on occasion WooCommerce will need to update template files and you
* (the theme developer) will need to copy the new files to your theme to
* maintain compatibility. We try to do this as little as possible, but it does
* happen. When this occurs the version of the template file will be bumped and
* the readme will list any important changes.
*
* #see https://docs.woocommerce.com/document/template-structure/
* #author WooThemes
* #package WooCommerce/Templates
* #version 2.6.0
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
do_action( 'woocommerce_before_account_orders', $has_orders ); ?>
<?php if ( $has_orders ) : ?>
<table class="woocommerce-MyAccount-orders shop_table shop_table_responsive my_account_orders account-orders-table">
<thead>
<tr>
<?php foreach ( wc_get_account_orders_columns() as $column_id => $column_name ) :
if( $column_name != 'Status' ){ // added this line
?>
<th class="<?php echo esc_attr( $column_id ); ?>"><span class="nobr"><?php echo esc_html( $column_name ); ?></span></th>
<?php
} // and this too
endforeach; ?>
</tr>
</thead>
<tbody>
<?php foreach ( $customer_orders->orders as $customer_order ) :
$order = wc_get_order( $customer_order );
$item_count = $order->get_item_count();
?>
<tr class="order">
<?php foreach ( wc_get_account_orders_columns() as $column_id => $column_name ) :
if( $column_name != 'Status' ){ // added this line
?>
<td class="<?php echo esc_attr( $column_id ); ?>" data-title="<?php echo esc_attr( $column_name ); ?>">
<?php if ( has_action( 'woocommerce_my_account_my_orders_column_' . $column_id ) ) : ?>
<?php do_action( 'woocommerce_my_account_my_orders_column_' . $column_id, $order ); ?>
<?php elseif ( 'order-number' === $column_id ) : ?>
<a href="<?php echo esc_url( $order->get_view_order_url() ); ?>">
<?php echo _x( '#', 'hash before order number', 'woocommerce' ) . $order->get_order_number(); ?>
</a>
<?php elseif ( 'order-date' === $column_id ) : ?>
<time datetime="<?php echo date( 'Y-m-d', strtotime( $order->order_date ) ); ?>" title="<?php echo esc_attr( strtotime( $order->order_date ) ); ?>"><?php echo date_i18n( get_option( 'date_format' ), strtotime( $order->order_date ) ); ?></time>
<?php elseif ( 'order-status' === $column_id ) : ?>
<?php echo wc_get_order_status_name( $order->get_status() ); ?>
<?php elseif ( 'order-total' === $column_id ) : ?>
<?php echo sprintf( _n( '%s for %s item', '%s for %s items', $item_count, 'woocommerce' ), $order->get_formatted_order_total(), $item_count ); ?>
<?php elseif ( 'order-actions' === $column_id ) : ?>
<?php
$actions = array(
'pay' => array(
'url' => $order->get_checkout_payment_url(),
'name' => __( 'Pay', 'woocommerce' )
),
'view' => array(
'url' => $order->get_view_order_url(),
'name' => __( 'View', 'woocommerce' )
),
'cancel' => array(
'url' => $order->get_cancel_order_url( wc_get_page_permalink( 'myaccount' ) ),
'name' => __( 'Cancel', 'woocommerce' )
)
);
if ( ! $order->needs_payment() ) {
unset( $actions['pay'] );
}
if ( ! in_array( $order->get_status(), apply_filters( 'woocommerce_valid_order_statuses_for_cancel', array( 'pending', 'failed' ), $order ) ) ) {
unset( $actions['cancel'] );
}
if ( $actions = apply_filters( 'woocommerce_my_account_my_orders_actions', $actions, $order ) ) {
foreach ( $actions as $key => $action ) {
echo '' . esc_html( $action['name'] ) . '';
}
}
?>
<?php endif; ?>
</td>
<?php
} // added this too
endforeach; ?>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<?php do_action( 'woocommerce_before_account_orders_pagination' ); ?>
<?php if ( 1 < $customer_orders->max_num_pages ) : ?>
<div class="woocommerce-Pagination">
<?php if ( 1 !== $current_page ) : ?>
<a class="woocommerce-Button woocommerce-Button--previous button" href="<?php echo esc_url( wc_get_endpoint_url( 'orders', $current_page - 1 ) ); ?>"><?php _e( 'Previous', 'woocommerce' ); ?></a>
<?php endif; ?>
<?php if ( $current_page !== intval( $customer_orders->max_num_pages ) ) : ?>
<a class="woocommerce-Button woocommerce-Button--next button" href="<?php echo esc_url( wc_get_endpoint_url( 'orders', $current_page + 1 ) ); ?>"><?php _e( 'Next', 'woocommerce' ); ?></a>
<?php endif; ?>
</div>
<?php endif; ?>
<?php else : ?>
<div class="woocommerce-Message woocommerce-Message--info woocommerce-info">
<a class="woocommerce-Button button" href="<?php echo esc_url( apply_filters( 'woocommerce_return_to_shop_redirect', wc_get_page_permalink( 'shop' ) ) ); ?>">
<?php _e( 'Go Shop', 'woocommerce' ) ?>
</a>
<?php _e( 'No order has been made yet.', 'woocommerce' ); ?>
</div>
<?php endif; ?>
<?php do_action( 'woocommerce_after_account_orders', $has_orders ); ?>
Save, you are done. This code is tested and working.
Update: for prior versions of woocommerce 2.5.x, the template file is named my-orders.php and you have just to comment one line in template code:
// 'order-status' => __( 'Status', 'woocommerce' ),
Here is an extract of this template with the commented line in the code:
<?php
/**
* My Orders
*
* Shows recent orders on the account page.
*
* This template can be overridden by copying it to yourtheme/woocommerce/myaccount/my-orders.php.
*
* HOWEVER, on occasion WooCommerce will need to update template files and you (the theme developer).
* will need to copy the new files to your theme to maintain compatibility. We try to do this.
* as little as possible, but it does happen. When this occurs the version of the template file will.
* be bumped and the readme will list any important changes.
*
* #see http://docs.woothemes.com/document/template-structure/
* #author WooThemes
* #package WooCommerce/Templates
* #version 2.5.0
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
$my_orders_columns = apply_filters( 'woocommerce_my_account_my_orders_columns', array(
'order-number' => __( 'Order', 'woocommerce' ),
'order-date' => __( 'Date', 'woocommerce' ),
// 'order-status' => __( 'Status', 'woocommerce' ),
'order-total' => __( 'Total', 'woocommerce' ),
'order-actions' => ' ',
) );
Reference: Template Structure + Overriding Templates via a Theme
The easiest approach would probably be just to hide that column via CSS -- If that column has a unique ID or the TD's have a class you could target with display:none, that'd probably take care of what you'd need.
Alternatively, you could probably also hide it by hooking into the woocommerce_my_account_my_orders_columns filter.
Something like this (untested)
add_filter('woocommerce_my_account_my_orders_columns', 'my_custom_function_name', 10);
function my_custom_function_name($order){
unset($order['order-status']);
return $order;
}
I'm sure that exact code won't work, but I'll bet it gets you pretty close.
In a WordPress website running WooCommerce, the user can login in his (default) personal area and display information like:
Orders history
Download
Addresses
Edit info
Logout
In the orders tab, a table is presented by default, showing a list of all orders, with a View button which redirects to the full detail page of that order.
What I'm trying to do is showing that table view in a modal window.
I don't have any problem in showing the modal with the target url loaded in it.
The real problem is that the targeted url is that of the full page which is showing like in an <iframe>, and is not what I want.
I think there is some shortcode allowing to load just that table, or maybe some woocommerce function like load_order_content_by_id($id)?
Can anybody point me in the right direction?
Thanks
===SOLVED===
Thanks to Raunak Gupta for pointing me to the right function.
I override the orders.php template, added Modal window html and edited $actions:
'view' => array(
'url' => 'javascript:;',
'data' => [
'order-number' => $order->get_order_number()
],
'name' => __( 'View', 'woocommerce' )
),
and on same file:
foreach ( $actions as $key => $action ) {
echo '<a href="' . esc_url( $action['url'] ) . '" class="button ' . sanitize_html_class( $key ) . '"';
if(isset($action['data']) && is_array($action['data'])){
foreach($action['data'] AS $data_attr=>$data_value){
echo 'data-' . sanitize_html_class($data_attr) .'="' .esc_html($data_value) . '" ';
}
}
echo '>' . esc_html( $action['name'] ) . '</a>';
}
A little JS
$('.woocommerce-MyAccount-orders .button.view').on('click', function(e){
e.preventDefault();
var data = {};
data.action = 'modal_order';
data.order_number = $(this).data('order-number');
$.get( ajax_script.ajax_url, data, function(response) {
$('#modalOrderDetail').modal('show').find('.modal-body').html(response);
});
});
and hooked into wordpress by function.php
function modal_order() {
if(is_user_logged_in()) {
$order_number = $_GET['order_number'];
woocommerce_order_details_table($order_number);
}
}
add_action('wp_ajax_modal_order', 'modal_order');
add_action('wp_ajax_nopriv_modal_order', 'modal_order');
Here is the complete code to display curent customer orders in a modal window. Its based on a classic query to get current user orders and on the template my-account/orders.php (lightly customized)…
<?php
if(is_user_logged_in()):
// The query
$args = array(
// WC orders post type
'post_type' => 'shop_order',
'numberposts' => -1,
// for current user id
'meta_key' => '_customer_user',
'meta_value' => get_current_user_id(),
// get orders statuses
'post_status' => array_keys(wc_get_order_statuses()),
);
// Get all customer orders
$customer_orders = get_posts( $args );
$count_ord = 0;
if (!empty($customer_orders))
foreach ( $customer_orders as $custo_order )
$count_ord++;
if ( $count_ord > 0 )
$has_orders = true;
else
$has_orders = false;
// the template my-account/orders.php ?>
<?php do_action( 'woocommerce_before_account_orders', $has_orders ); ?>
<?php if ( $has_orders ) : ?>
<table class="woocommerce-MyAccount-orders shop_table shop_table_responsive my_account_orders account-orders-table">
<thead>
<tr>
<?php foreach ( wc_get_account_orders_columns() as $column_id => $column_name ) : ?>
<th class="<?php echo esc_attr( $column_id ); ?>"><span class="nobr"><?php echo esc_html( $column_name ); ?></span></th>
<?php endforeach; ?>
</tr>
</thead>
<tbody>
<?php foreach ( $customer_orders as $customer_order ) :
$order = wc_get_order( $customer_order );
$item_count = $order->get_item_count();
?>
<tr class="order">
<?php foreach ( wc_get_account_orders_columns() as $column_id => $column_name ) : ?>
<td class="<?php echo esc_attr( $column_id ); ?>" data-title="<?php echo esc_attr( $column_name ); ?>">
<?php if ( has_action( 'woocommerce_my_account_my_orders_column_' . $column_id ) ) : ?>
<?php do_action( 'woocommerce_my_account_my_orders_column_' . $column_id, $order ); ?>
<?php elseif ( 'order-number' === $column_id ) : ?>
<a href="<?php echo esc_url( $order->get_view_order_url() ); ?>">
<?php echo _x( '#', 'hash before order number', 'woocommerce' ) . $order->get_order_number(); ?>
</a>
<?php elseif ( 'order-date' === $column_id ) : ?>
<time datetime="<?php echo date( 'Y-m-d', strtotime( $order->order_date ) ); ?>" title="<?php echo esc_attr( strtotime( $order->order_date ) ); ?>"><?php echo date_i18n( get_option( 'date_format' ), strtotime( $order->order_date ) ); ?></time>
<?php elseif ( 'order-status' === $column_id ) : ?>
<?php echo wc_get_order_status_name( $order->get_status() ); ?>
<?php elseif ( 'order-total' === $column_id ) : ?>
<?php echo sprintf( _n( '%s for %s item', '%s for %s items', $item_count, 'woocommerce' ), $order->get_formatted_order_total(), $item_count ); ?>
<?php elseif ( 'order-actions' === $column_id ) : ?>
<?php
$actions = array(
'pay' => array(
'url' => $order->get_checkout_payment_url(),
'name' => __( 'Pay', 'woocommerce' )
),
'view' => array(
'url' => $order->get_view_order_url(),
'name' => __( 'View', 'woocommerce' )
),
'cancel' => array(
'url' => $order->get_cancel_order_url( wc_get_page_permalink( 'myaccount' ) ),
'name' => __( 'Cancel', 'woocommerce' )
)
);
if ( ! $order->needs_payment() ) {
unset( $actions['pay'] );
}
if ( ! in_array( $order->get_status(), apply_filters( 'woocommerce_valid_order_statuses_for_cancel', array( 'pending', 'failed' ), $order ) ) ) {
unset( $actions['cancel'] );
}
if ( $actions = apply_filters( 'woocommerce_my_account_my_orders_actions', $actions, $order ) ) {
foreach ( $actions as $key => $action ) {
echo '' . esc_html( $action['name'] ) . '';
}
}
?>
<?php endif; ?>
</td>
<?php endforeach; ?>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<?php do_action( 'woocommerce_before_account_orders_pagination' ); ?>
<?php if ( 1 < $customer_orders->max_num_pages ) : ?>
<div class="woocommerce-Pagination">
<?php if ( 1 !== $current_page ) : ?>
<a class="woocommerce-Button woocommerce-Button--previous button" href="<?php echo esc_url( wc_get_endpoint_url( 'orders', $current_page - 1 ) ); ?>"><?php _e( 'Previous', 'woocommerce' ); ?></a>
<?php endif; ?>
<?php if ( $current_page !== intval( $customer_orders->max_num_pages ) ) : ?>
<a class="woocommerce-Button woocommerce-Button--next button" href="<?php echo esc_url( wc_get_endpoint_url( 'orders', $current_page + 1 ) ); ?>"><?php _e( 'Next', 'woocommerce' ); ?></a>
<?php endif; ?>
</div>
<?php endif; ?>
<?php else : ?>
<div class="woocommerce-Message woocommerce-Message--info woocommerce-info">
<a class="woocommerce-Button button" href="<?php echo esc_url( apply_filters( 'woocommerce_return_to_shop_redirect', wc_get_page_permalink( 'shop' ) ) ); ?>">
<?php _e( 'Go Shop', 'woocommerce' ) ?>
</a>
<?php endif; ?>
<?php _e( 'No order has been made yet.', 'woocommerce' ); ?>
</div>
<?php do_action( 'woocommerce_after_account_orders', $has_orders ); ?>
<?php endif; ?>
You will have to add existing css rules to your modal window and/or customized that css rules.
This code is tested and fully functional.
woocommerce_order_details_table( $order_id )
This WooCommerce function returns the full order details in HTML form by $order_id
There isn't a single function that I'm aware of that can get all of the order details that you need in one go however you can call WC_Order class to get what you need. Making some calls methods similar to these would get you the info you need. You will likely need to make calls to more than just the get_items() method depending on the exact info you need. Generally they return objects similar in structure to post objects.
$order = new WC_Order($post->ID);
$_order = $order->get_items();
Look here under the 'inherited methods' section to find the methods you might need to call to get all the info you need. https://docs.woocommerce.com/wc-apidocs/class-WC_Order.html
I am adding the register_sidebar function to my functions.php file as shown below:
<?php
add_action( 'after_setup_theme', 'handheld_setup' );
if ( ! function_exists( 'handheld_setup' ) ){
function handheld_setup(){
global $et_mobile_theme_options;
load_theme_textdomain( 'HandHeld', TEMPLATEPATH . '/languages' );
add_action( 'wp_ajax_nopriv_et_show_ajax_posts', 'et_show_ajax_posts' );
add_action( 'wp_ajax_et_show_ajax_posts', 'et_show_ajax_posts' );
if ( isset( $et_mobile_theme_options['bg_color'] ) && '' != $et_mobile_theme_options['bg_color'] ) add_action( 'wp_head','et_add_bgcolor' );
add_filter( 'template_include', 'et_check_homepage_static' );
add_action( 'wp_head', 'et_add_apple_touch_images', 7 );
}
}
function et_add_apple_touch_images(){
global $et_mobile_theme_options;
$webpage_icon_small = isset( $et_mobile_theme_options['webpage_icon_small'] ) && '' != $et_mobile_theme_options['webpage_icon_small'] ? $et_mobile_theme_options['webpage_icon_small'] : get_template_directory_uri() . '/images/ios_icons/apple-touch-icon-precomposed.png';
$webpage_icon_big = isset( $et_mobile_theme_options['webpage_icon_big'] ) && '' != $et_mobile_theme_options['webpage_icon_big'] ? $et_mobile_theme_options['webpage_icon_big'] : get_template_directory_uri() . '/images/ios_icons/apple-touch-icon.png';
$splash_image = isset( $et_mobile_theme_options['splash_image'] ) && '' != $et_mobile_theme_options['splash_image'] ? $et_mobile_theme_options['splash_image'] : get_template_directory_uri() . '/images/ios_icons/splash.png';
echo '<link rel="apple-touch-icon-precomposed" href="' . esc_url( $webpage_icon_small ) . '" />';
echo '<link rel="apple-touch-icon-precomposed" sizes="114x114" href="' . esc_url( $webpage_icon_big ) . '" />';
echo '<link rel="apple-touch-startup-image" href="' . esc_url( $splash_image ) . '" />';
}
function et_check_homepage_static( $template ){
# if static homepage is set ( WP-Admin / Settings / Reading ) and we're on the homepage, load home.php
if ( is_front_page() && ! is_home() ) $template = get_home_template();
return $template;
}
function et_add_bgcolor(){
global $et_mobile_theme_options;
echo '<style>body{ background-color: #'. esc_html( str_replace( '#', '', $et_mobile_theme_options['bg_color'] ) ) .'; }</style>';
}
if ( ! function_exists( 'et_mobile_custom_comments_display' ) ) :
function et_mobile_custom_comments_display($comment, $args, $depth) {
$GLOBALS['comment'] = $comment; ?>
<li <?php comment_class(); ?> id="li-comment-<?php comment_ID() ?>">
<article id="comment-<?php comment_ID(); ?>" class="text_block comment clearfix">
<div class="avatar-box">
<?php echo get_avatar($comment,$size='37'); ?>
<span class="avatar-overlay"></span>
</div> <!-- end .avatar-box -->
<?php printf('<span class="fn">%s</span>', get_comment_author_link()) ?>
<div class="comment-content clearfix">
<?php if ($comment->comment_approved == '0') : ?>
<em class="moderation"><?php esc_html_e('Your comment is awaiting moderation.','HandHeld') ?></em>
<br />
<?php endif; ?>
<?php comment_text() ?>
</div> <!-- end comment-content-->
<div class="comment-meta clearfix">
<span class="comment-date"><?php if ( 1 == $depth ) printf( __( 'Posted on %1$s', 'HandHeld' ), get_comment_date() ); else echo get_comment_date(); ?></span>
<?php
$et_comment_reply_link = get_comment_reply_link( array_merge( $args, array('reply_text' => esc_attr__('Reply','HandHeld'),'depth' => $depth, 'max_depth' => $args['max_depth'])) );
if ( $et_comment_reply_link ) echo '<div class="reply-container">' . $et_comment_reply_link . '</div>';
?>
</div> <!-- end .comment-meta -->
</article>
<?php }
endif;
if ( ! function_exists( 'et_list_pings' ) ){
function et_list_pings($comment, $args, $depth) {
$GLOBALS['comment'] = $comment; ?>
<li id="comment-<?php comment_ID(); ?>"><?php comment_author_link(); ?> - <?php comment_excerpt(); ?>
<?php }
}
if ( ! function_exists( 'et_mobile_regular_post' ) ){
function et_mobile_regular_post(){
global $post; ?>
<article class="post text_block clearfix">
<?php
$thumb = '';
$width = 72;
$height = 72;
$classtext = '';
$titletext = get_the_title();
$thumbnail = et_get_thumbnail($width,$height,$classtext,$titletext,$titletext,false,'Entry');
$thumb = $thumbnail["thumb"];
?>
<?php if( $thumb <> '' ){ ?>
<div class="post-thumb">
<a href="<?php the_permalink(); ?>">
<?php et_print_thumbnail($thumb, $thumbnail["use_timthumb"], $titletext, $width, $height, $classtext); ?>
<span class="overlay"></span>
</a>
<span class="comment_count"><?php comments_popup_link( 0, 1, '%' ); ?></span>
</div> <!-- end .post-thumb -->
<?php } ?>
<div class="post-content">
<h1><?php the_title(); ?></h1>
<p class="meta-info"><?php esc_html_e('Posted on','HandHeld'); ?> <time datetime="<?php the_time( 'Y-m-d' ); ?>" pubdate><?php the_time( 'F jS' ); ?></time></p>
</div> <!-- end .post-content -->
<?php esc_html_e('Read more','HandHeld'); ?>
</article> <!-- end .post -->
<?php }
}
if ( ! function_exists('register_sidebar') ) {
// Register Sidebar
function register_sidebar() {
$args = array(
'id' => 'mobile-sidebar',
'name' => 'Mobile',
'description' => __( 'Sidebar for mobile', 'text_domain' ),
'before_title' => '<h4 class="widgettitle">',
'after_title' => '</h4>',
'before_widget' => '<li id="%1$s" class="widget %2$s">',
'after_widget' => '</li>',
);
register_sidebar( $args );
}
// Hook into the 'widgets_init' action
add_action( 'init', 'register_sidebar' );
}
if ( ! function_exists( 'et_mobile_gallery_post' ) ){
function et_mobile_gallery_post(){
global $post; ?>
<a href="<?php the_permalink(); ?>" class="project">
<?php
$thumb = '';
$width = 70;
$height = 70;
$classtext = '';
$titletext = get_the_title();
$thumbnail = et_get_thumbnail($width,$height,$classtext,$titletext,$titletext,false,'Project');
$thumb = $thumbnail["thumb"];
?>
<?php et_print_thumbnail($thumb, $thumbnail["use_timthumb"], $titletext, $width, $height, $classtext); ?>
<span></span>
</a>
<?php }
}
add_action( 'template_redirect', 'et_mobile_load_ajax_scripts' );
function et_mobile_load_ajax_scripts(){
wp_enqueue_script( 'et_home_load_more', get_template_directory_uri() . '/js/custom.js', array( 'jquery' ) );
wp_localize_script( 'et_home_load_more', 'etmobile', array( 'ajaxurl' => admin_url( 'admin-ajax.php' ), 'et_load_nonce' => wp_create_nonce( 'et_load_nonce' ) ) );
}
function et_show_ajax_posts() {
global $et_mobile_theme_options;
if ( ! wp_verify_nonce( $_POST['et_load_nonce'], 'et_load_nonce' ) ) die(-1);
$posts_num = (int) $_POST['et_posts_num'];
$posts_offset = (int) $_POST['et_posts_offset'];
$gallery = (int) $_POST['et_gallery'];
$args = array(
'posts_per_page' => $posts_num,
'offset' => $posts_offset,
'post_status' => 'publish'
);
if ( isset( $et_mobile_theme_options['home_blog_categories'] ) && !empty( $et_mobile_theme_options['home_blog_categories'] ) && 0 == $gallery )
$args['category__in'] = $et_mobile_theme_options['home_blog_categories'];
if ( 0 != $gallery && isset( $et_mobile_theme_options['home_project_categories'] ) && !empty( $et_mobile_theme_options['home_project_categories'] ) )
$args['category__in'] = $et_mobile_theme_options['home_project_categories'];
ob_start();
$the_query = new WP_Query( $args );
while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
<?php if ( 0 == $gallery ) { ?>
<?php et_mobile_regular_post(); ?>
<?php } else { ?>
<?php et_mobile_gallery_post(); ?>
<?php } ?>
<?php endwhile;
wp_reset_postdata();
$posts = ob_get_clean();
$last_query = ( $the_query->found_posts - $posts_offset ) > $posts_num ? false : true;
echo json_encode( array( 'posts' => $posts, 'last_query' => $last_query ) );
die();
} ?>
The register_sidebar function is declared at line 114.
In my home.phpfile, I am trying to call the sidebar as shown below:
<?php dynamic_sidebar( 'mobile-sidebar' ); ?>
But the sidebar never gets displayed.
What am I missing?
Thanks
Code in Functions.php
if ( function_exists('register_sidebar') ) {
register_sidebar(array(
'name' => 'Homepage Sidebar',
'id' => 'homepage-sidebar',
'description' => 'Appears as the sidebar on the custom homepage',
'after_widget' => '</li>',
'before_title' => '<h2 class="widgettitle">',
'after_title' => '</h2>',
));
}
Code in your home.php
<?php get_sidebar('homepage'); ?>
Create a file "sidebar-homepage.php"
Paste this code:
<div class="custom">
<?php
if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar('homepage-sidebar') ) :
endif; ?>
</div>
Go to widgets and add some Text... Enjoy..