Display Woocommerce Sorting Dropdown as a List - php

I'm trying to replace the woocommerce sorting dropdown with a list and I have this so far which works ok.
The problem is the options are not converted to clickable working links. Any ideas how I can do it ?
<div class="wrapper-dropdown">
<span>I'm kinda the label!</span>
<ul class="dropdown">
<?php
$catalog_orderby = apply_filters( 'woocommerce_catalog_orderby', array(
'menu_order' => __( 'Default sorting', 'woocommerce' ),
'popularity' => __( 'Sort by popularity', 'woocommerce' ),
'rating' => __( 'Sort by average rating', 'woocommerce' ),
'date' => __( 'Sort by newness', 'woocommerce' ),
'price' => __( 'Sort by price: low to high', 'woocommerce' ),
'price-desc' => __( 'Sort by price: high to low', 'woocommerce' )
) );
if ( get_option( 'woocommerce_enable_review_rating' ) == 'no' )
unset( $catalog_orderby['rating'] );
foreach ( $catalog_orderby as $id => $name )
echo '<li>' . esc_attr( $name ) . '</li>';
?>
</ul>
Thanks.

your li tag in the foreach loop should be something like this:
echo '<li><a href="' . get_permalink( woocommerce_get_page_id( 'shop' ) ) . '?orderby=' . $id . '" >' . esc_attr( $name ) . '</a></li>';

woocommerce_get_page_id() is depracted since WC 3.0
Use this code instead:
<ul class="woocommerce-ordering">
<?php
$term = get_queried_object();
$term_url = get_term_link($term->term_id);
?>
<?php foreach ($catalog_orderby_options as $id => $name) : ?>
<?php echo '<li>' . esc_attr( $name ) . '</li>'; ?>
<?php endforeach; ?>

Related

How to customize bank details styles in Woocommerce order emails?

This section within Woocommerce order emails comes from the code in woocommerce/includes/gateways/class-wc-gateway-bacs.php
/**
* Get bank details and place into a list format.
*
* #param int $order_id Order ID.
*/
private function bank_details( $order_id = '' ) {
if ( empty( $this->account_details ) ) {
return;
}
// Get order and store in $order.
$order = wc_get_order( $order_id );
// Get the order country and country $locale.
$country = $order->get_billing_country();
$locale = $this->get_country_locale();
// Get sortcode label in the $locale array and use appropriate one.
$sortcode = isset( $locale[ $country ]['sortcode']['label'] ) ? $locale[ $country ]['sortcode']['label'] : __( 'Sort code', 'woocommerce' );
$bacs_accounts = apply_filters( 'woocommerce_bacs_accounts', $this->account_details, $order_id );
if ( ! empty( $bacs_accounts ) ) {
$account_html = '';
$has_details = false;
foreach ( $bacs_accounts as $bacs_account ) {
$bacs_account = (object) $bacs_account;
if ( $bacs_account->account_name ) {
$account_html .= '<h3 class="wc-bacs-bank-details-account-name">' . wp_kses_post( wp_unslash( $bacs_account->account_name ) ) . ':</h3>' . PHP_EOL;
}
$account_html .= '<ul class="wc-bacs-bank-details order_details bacs_details">' . PHP_EOL;
// BACS account fields shown on the thanks page and in emails.
$account_fields = apply_filters(
'woocommerce_bacs_account_fields',
array(
'bank_name' => array(
'label' => __( 'Bank', 'woocommerce' ),
'value' => $bacs_account->bank_name,
),
'account_number' => array(
'label' => __( 'Account number', 'woocommerce' ),
'value' => $bacs_account->account_number,
),
'sort_code' => array(
'label' => $sortcode,
'value' => $bacs_account->sort_code,
),
'iban' => array(
'label' => __( 'IBAN', 'woocommerce' ),
'value' => $bacs_account->iban,
),
'bic' => array(
'label' => __( 'BIC', 'woocommerce' ),
'value' => $bacs_account->bic,
),
),
$order_id
);
foreach ( $account_fields as $field_key => $field ) {
if ( ! empty( $field['value'] ) ) {
$account_html .= '<li class="' . esc_attr( $field_key ) . '">' . wp_kses_post( $field['label'] ) . ': <strong>' . wp_kses_post( wptexturize( $field['value'] ) ) . '</strong></li>' . PHP_EOL;
$has_details = true;
}
}
$account_html .= '</ul>';
}
if ( $has_details ) {
echo '<section class="woocommerce-bacs-bank-details"><h2 class="wc-bacs-bank-details-heading">' . esc_html__( 'Our bank details', 'woocommerce' ) . '</h2>' . wp_kses_post( PHP_EOL . $account_html ) . '</section>';
}
}
}
How can I override this section styles (headings + list) without it affecting all headings as recommended here: How to stylize bank details in WooCommerce email?
Any help appreciated.

WooCommerce: How to change "Our Bank Details" heading?

In the email WooCommerce sends to customers if they ordered a product and picked bank transfer (BACS) as payment method, by default there is an h2 heading: "Our bank details". I want to change this wording.
I figure I best do this via functions.php, but I am not sure how to address this. Could someone please help me?
Alternative approaches to solve this problem are welcome, too.
The line I want to change is in this if-statement in class-wc-gateways-bacs.php:
if ( $has_details ) { echo '<section class="woocommerce-bacs-bank-details"><h2 class="wc-bacs-bank-details-heading">' . esc_html__( 'Our bank details', 'woocommerce' ) . '</h2>' . wp_kses_post( PHP_EOL . $account_html ) . '</section>';
Here is the complete function from within the class WC_Gateway_BACS extends WC_Payment_Gateway:
private function bank_details( $order_id = '' ) {
if ( empty( $this->account_details ) ) {
return;
}
// Get order and store in $order.
$order = wc_get_order( $order_id );
// Get the order country and country $locale.
$country = $order->get_billing_country();
$locale = $this->get_country_locale();
// Get sortcode label in the $locale array and use appropriate one.
$sortcode = isset( $locale[ $country ]['sortcode']['label'] ) ? $locale[ $country ]['sortcode']['label'] : __( 'Sort code', 'woocommerce' );
$bacs_accounts = apply_filters( 'woocommerce_bacs_accounts', $this->account_details, $order_id );
if ( ! empty( $bacs_accounts ) ) {
$account_html = '';
$has_details = false;
foreach ( $bacs_accounts as $bacs_account ) {
$bacs_account = (object) $bacs_account;
if ( $bacs_account->account_name ) {
$account_html .= '<h3 class="wc-bacs-bank-details-account-name">' . wp_kses_post( wp_unslash( $bacs_account->account_name ) ) . ':</h3>' . PHP_EOL;
}
$account_html .= '<ul class="wc-bacs-bank-details order_details bacs_details">' . PHP_EOL;
// BACS account fields shown on the thanks page and in emails.
$account_fields = apply_filters(
'woocommerce_bacs_account_fields',
array(
'bank_name' => array(
'label' => __( 'Bank', 'woocommerce' ),
'value' => $bacs_account->bank_name,
),
'account_number' => array(
'label' => __( 'Account number', 'woocommerce' ),
'value' => $bacs_account->account_number,
),
'sort_code' => array(
'label' => $sortcode,
'value' => $bacs_account->sort_code,
),
'iban' => array(
'label' => __( 'IBAN', 'woocommerce' ),
'value' => $bacs_account->iban,
),
'bic' => array(
'label' => __( 'BIC', 'woocommerce' ),
'value' => $bacs_account->bic,
),
),
$order_id
);
foreach ( $account_fields as $field_key => $field ) {
if ( ! empty( $field['value'] ) ) {
$account_html .= '<li class="' . esc_attr( $field_key ) . '">' . wp_kses_post( $field['label'] ) . ': <strong>' . wp_kses_post( wptexturize( $field['value'] ) ) . '</strong></li>' . PHP_EOL;
$has_details = true;
}
}
$account_html .= '</ul>';
}
if ( $has_details ) {
echo '<section class="woocommerce-bacs-bank-details"><h2 class="wc-bacs-bank-details-heading">' . esc_html__( 'Our bank details', 'woocommerce' ) . '</h2>' . wp_kses_post( PHP_EOL . $account_html ) . '</section>';
}
}
}
Please try this
function update_bank_details_heading($translated_text, $text, $domain) {
if ( did_action('woocommerce_email_before_order_table') ) {
switch ( $text ) {
case 'Our bank details' :
$translated_text = __( 'Bank Details Are...', 'woocommerce' );
break;
}
}
return $translated_text;
}
add_filter( 'gettext', 'update_bank_details_heading', 20, 3 );

Current cateogry in wordpress category menu

I have a little script that display any categories that contain posts and displays them (like a little menu)
<?php
$categories = get_categories( array(
'orderby' => 'name',
'order' => 'ASC'
) );
echo '<a class="blog-panel-cat-menu bg-color-1" href="' . get_permalink( get_option( 'page_for_posts' ) ) . '">All</a>';
foreach( $categories as $category ) {
if ($category->count > 0){
$category_link = sprintf(
'<a class="blog-panel-cat-menu bg-color-1" href="%1$s" alt="%2$s">%3$s</a>',
esc_url( get_category_link( $category->term_id ) ),
esc_attr( sprintf( __( 'View all posts in %s', 'textdomain' ), $category->name ) ),
esc_html( $category->name )
);
echo $category_link;
}
}
?>
When clicking on any link it will redirect to a page that show the posts for that category eg mywebsite/news/category/blog/ or mywebsite/news/category/news/ (mywebsite/news being the blog homepage which displays all categories)
When I'm on mywebsite/news/category/blog/ I want the "blog" link in the menu to have the class blog-cat-focus after the current class in the foreach loop like this <a class="blog-panel-cat-menu bg-color-1 blog-cat-focus" href="%1$s" alt="%2$s">%3$s</a>
Try this code. Added two more lines to check current category.
<?php
$categories = get_categories( array(
'orderby' => 'name',
'order' => 'ASC'
) );
$category = get_category( get_query_var( 'cat' ) );
echo $cat_id = $category->cat_ID;
echo '<a class="blog-panel-cat-menu bg-color-1" href="' . get_permalink( get_option( 'page_for_posts' ) ) . '">All</a>';
foreach( $categories as $category ) {
if ($category->count > 0){
$cust_class = '';
if($category->term_id==$cat_id){$cust_class = 'blog-cat-focus';}
$category_link = sprintf(
'<a class="blog-panel-cat-menu bg-color-1 %4$s>" href="%1$s" alt="%2$s">%3$s</a>',
esc_url( get_category_link( $category->term_id ) ),
esc_attr( sprintf( __( 'View all posts in %s', 'textdomain' ), $category->name ) ),
esc_html( $category->name ),
$cust_class
);
echo $category_link;
}
}
?>

get second to last comment php woo commerce followup email

I found this handy code to add order notes to the completed email. I really just want to add the last two notes if possible. Can someone tell me what I would need to tweak?
<?php
add_action( 'woocommerce_email_order_meta', 'woo_add_order_notes_to_email' );
function woo_add_order_notes_to_email() {
global $woocommerce, $post;
$args = array(
'post_id' => $post->ID,
'approve' => 'approve',
'type' => 'order_note'
);
$notes = get_comments( $args );
echo '<h2>' . __( 'Order Notes', 'woocommerce' ) . '</h2>';
echo '<ul class="order_notes">';
if ( $notes ) {
foreach( $notes as $note ) {
$note_classes = get_comment_meta( $note->comment_ID, 'is_customer_note', true ) ? array( 'customer-note', 'note' ) : array( 'note' );
?>
<li rel="<?php echo absint( $note->comment_ID ) ; ?>" class="<?php echo implode( ' ', $note_classes ); ?>">
<div class="note_content">
(<?php printf( __( 'added %s ago', 'woocommerce' ), human_time_diff( strtotime( $note->comment_date_gmt ), current_time( 'timestamp', 1 ) ) ); ?>) <?php echo wpautop( wptexturize( wp_kses_post( $note->comment_content ) ) ); ?>
</div>
</li>
<?php
}
} else {
echo '<li>' . __( 'There are no notes for this order yet.', 'woocommerce' ) . '</li>';
}
echo '</ul>';
}
?>
You can try use array_slice
After the if and before the foreach
$notes = array_slice($notes, 0, 2);

WordPress, A page of thumbnails and titles for a grid of taxonomies for a custom post type

I am able to list the taxonomy children:
<?php
$taxonomy = 'store_name';
$tax_terms = get_terms($taxonomy);
?>
<ul class="split-list2">
<?php
foreach ($tax_terms as $tax_term) {
echo '<li>' . '<a href="' . esc_attr(get_term_link($tax_term, $taxonomy)) . '" title="' . sprintf( __( "View all posts in %s" ), $tax_term->name ) . '" ' . '>' . $tax_term->name.'</a></li>';
}
</ul> ?>
And I found a plugin to make thumbnails for categories/taxonomies:
https://wordpress.org/plugins/taxonomy-images/
But I can't figure out how to add the code to include the thumbnails to the taxonomy category grids.
Does anyone know how to do this
Read the plugin doc perfactly it gives what you want
print apply_filters( 'taxonomy-images-list-the-terms', '', array(
'after' => '</div>',
'after_image' => '</span>',
'before' => '<div class="my-custom-class-name">',
'before_image' => '<span>',
'image_size' => 'detail',
'post_id' => 1234,
'taxonomy' => 'post_tag',
) );
Second parameter in apply_filters( 'taxonomy-images-get-terms', '' ); is array as show above
$terms = apply_filters( 'taxonomy-images-get-terms', '' );
if ( ! empty( $terms ) ) {
print '<ul>';
foreach( (array) $terms as $term ) {
print '<li><a href="' . esc_url( get_term_link( $term, $term->taxonomy ) ) . '">' . wp_get_attachment_image( $term->image_id, 'detail' ) . '</li>';
}
print '</ul>';
}

Categories