I have to show the name of product and product attributes like that:
Product name
Color: Green
Size: XS.
My code of the loop now is like that. For each status, that's the example of 'completed', but with other statuses loops are the same
<section class="order">
<?php
$orders = wc_get_orders( array(
'numberposts' => -1,
'orderby' => 'date',
'order' => 'DESC',
'customer_id' => get_current_user_id(),
'status' => array('completed'),
) );
//* Loop through each WC_Order object
foreach( $orders as $order ){?>
<div class="order-wrapper product d-flex col-12">
<?php
$order_data = $order->get_data(); // The Order data
$order_id = $order_data['id'];
$order_currency = $order_data['currency'];
$order_status = $order_data['status'];
?>
<div class="order-number">#<?php echo $order_id;?></div>
<div class="order-inner">
<div class="order-inner-top">
<?php
foreach ($order->get_items() as $key => $lineItem) {
$product_id = $lineItem['product_id'];
$product = wc_get_product( $product_id );
$name = $lineItem->get_name();
$item_meta_data = $lineItem->get_meta_data();
?>
<div class="order-inner-top-inner">
<div class="order-slider-inner">
<div class="order-inner-left">
<div class="order-image">
<?php echo $product->get_image(['322', '304']);?>
</div>
</div>
<div class="order-inner-right">
<div class="order-info-item order-info-item-name">
<?php echo $name; ?>
</div>
<div class="order-info-item order-info-item ">
<span class="order-price"><?php echo $lineItem['total'] . $order_currency?></span>
</div>
<div class="order-item-quantity"><?php esc_html_e( 'Quantity', 'woocommerce' )?>: <?php echo $lineItem['qty']?></div>
</div>
</div>
</div>
<?php } ?>
</div>
<div class="order-inner-bottom">
<div class="d-flex justify-content-center">
<button class="order-total"><?php echo get_theme_mod('orders_total_button');?></button>
</div>
<div class="totals-toggle">
<div class="order-info-item bottom"> <span> <?php esc_html_e( 'Price', 'woocommerce' )?>:</span><span class="order-total-price"> <?php echo $order->get_total() . ' ' . $order_currency; ?></span></div>
<div class="order-info-item bottom"> <span> <?php esc_html_e( 'Quantity', 'woocommerce' )?>:</span> <?php echo $order->get_item_count(); ?></div>
<div class="order-info-item bottom"> <span><?php esc_html_e( 'Status', 'woocommerce' )?>:</span> <?php
if( 'completed'== $order->get_status() ) {
echo _x( 'Completed', 'Order status', 'woocommerce' );
}
?></div>
<div class="order-info-item bottom"> <span><?php esc_html_e( 'Order Date', 'woocommerce' )?></span> <?php
if( $date_created = $order->get_date_created() ){
// Display the localized formatted date
$formated_date_created = $date_created->date_i18n('d.m.Y ');
echo $formated_date_created;
}
?></div>
<div class="order-info-item bottom"> <span><?php echo get_theme_mod('delivery_date_text')?>: </span>
<?php
// The orders date
$date_created = $order->get_date_created();
$date_created = $date_created->date('d.m.Y');
// The order date + 5 days
$delivery_date = date_i18n( 'd.m.Y', strtotime( $date_created . ' +21 days' ));
echo $delivery_date;
?>
</div>
</div>
</div>
</div>
</div>
<?php }?>
</section>
The name in that way is showing like Name,Green,XS - as one string.
If to change $name = $lineItem->get_name(); to $name = $product->get_name(); it's showing only product name.
I tried to use
$name = $product->get_name();
$colormeta = $lineItem->get_meta( 'pa_color', true );
$sizemeta = $lineItem->get_meta( 'pa_size', true );
echo $name . ' <br>';
echo 'Color:'. ' ' . $colormeta;
But then attributes are showed not like Green,not by name, they show like green-en, green-ru = by slug, not by name.I use hyyyan polylang.
I've found the decision for the cart page, that I needed, I need the same for orders
function custom_product_variation_title($should_include_attributes, $product){
$should_include_attributes = false;
return $should_include_attributes;
}
add_filter( 'woocommerce_product_variation_title_include_attributes', 'custom_product_variation_title', 10, 2 );
How can I show the attributes in the order loop like
Product name
Color: Green
Size: XS
correctly?
Here is how you should access your order items:
foreach ( $order->get_items() as $item_id => $item ) {
$product_id = $item->get_product_id();
$product = $item->get_product();
$product_title = $product->get_title();
$output = array();
$output[] .= '<ul>';
$output[] .= '<li>'.$product_title.'</li>';
if( $product->is_type('variation') ){
// Get the variation attributes
$variation_attributes = $product->get_variation_attributes();
// Loop through each selected attributes
foreach($variation_attributes as $attribute_taxonomy => $term_slug ){
// Get product attribute name or taxonomy
$taxonomy = str_replace('attribute_', '', $attribute_taxonomy );
// The label name from the product attribute
$attribute_name = wc_attribute_label( $taxonomy, $product );
// The term name (or value) from this attribute
if( taxonomy_exists($taxonomy) ) {
$output[] .= '<li>'.$attribute_name.': '.get_term_by( 'slug', $term_slug, $taxonomy )->name.'</li>';
} else {
$output[] .= '<li>'.$attribute_name.': '.$term_slug.'</li>'; // For custom product attributes
}
}
}
$output[] .= '</ul>';
}
echo implode('',$output);
Credits also to - https://stackoverflow.com/a/48391504/13378498
Related
I've created a new tab in myaccount, where all customers have to see all their orders. It's custom, because the design is very not similar to default orders table.
Like admin I see all my orders. But when I try to register like a common user and make test-orders, the tab is empty. So orders display only if current user=admin. How to fix that moment?
/**
* 1. Register new endpoint slug to use for My Account page
*/
/**
* #important-note Resave Permalinks or it will give 404 error
*/
function ts_custom_add_my_purchases_endpoint() {
add_rewrite_endpoint( 'my_purchases', EP_ROOT | EP_PAGES );
}
add_action( 'init', 'ts_custom_add_my_purchases_endpoint' );
/**
* 2. Add new query var
*/
function ts_custom_my_purchases_query_vars( $vars ) {
$vars[] = 'my_purchases';
return $vars;
}
add_filter( 'woocommerce_get_query_vars', 'ts_custom_my_purchases_query_vars', 0 );
/**
* 3. Insert the new endpoint into the My Account menu
*/
function ts_custom_add_my_purchases_link_my_account( $items ) {
$items['my_purchases'] = 'My purchases';
return $items;
}
add_filter( 'woocommerce_account_menu_items', 'ts_custom_add_my_purchases_link_my_account' );
/**
* 4. Add content to the new endpoint
*/
function ts_custom_my_purchases_content() {?>
<section class="order">
<?php
$orders = wc_get_orders( array(
'numberposts' => -1,
'orderby' => 'date',
'order' => 'DESC',
'author' => get_current_user_id(),
) );
//* Loop through each WC_Order object
foreach( $orders as $order ){?>
<div class="order-wrapper product d-flex col-12">
<?php
$order_data = $order->get_data(); // The Order data
$order_id = $order_data['id'];
$order_currency = $order_data['currency'];
$order_status = $order_data['status']; ?>
<div class="order-number">#<?php echo $order_id;?></div>
<div class="order-inner">
<div class="order-inner-top">
<?php
foreach ($order->get_items() as $key => $lineItem) {
$product_id = $lineItem['product_id'];
$product = wc_get_product( $product_id );
$item_meta_data = $lineItem->get_meta_data();
$colormeta = $lineItem->get_meta( 'pa_color', true );
$sizemeta = $lineItem->get_meta( 'pa_size', true );
echo '<div class="order-inner-top-inner"><div class="order-slider-inner"> <div class="order-inner-left"><div class="order-image">' . $product->get_image(['322', '304']) . '</div></div>';
echo '<div class="order-inner-right"><div class="order-info-item order-info-item-name">' . $lineItem['name'] . '</div><div class="order-info-item order-info-item "><span class="order-price">' . $lineItem['total'] . ' ' . $order_currency . '</span></div><div class="order-item-quantity"> '. ' Quantity: ' . $lineItem['qty'] . '</div>';
echo '<div class="order-item-metas">' . $colormeta . ' , ' . $sizemeta . '</div>';
echo '</div></div></div>';} ?>
</div>
<div class="order-inner-bottom">
<div class="d-flex justify-content-center">
<button class="order-total"><?php echo get_theme_mod('orders_total_button');?></button>
</div>
<div class="totals-toggle">
<div class="order-info-item bottom"> <span>Total Price:</span><span class="order-total-price"> <?php echo $order->get_total() . ' ' . $order_currency; ?></span></div>
<div class="order-info-item bottom"> <span>Total Quantity:</span> <?php echo $order->get_item_count(); ?> item(s)</div>
<div class="order-info-item bottom"> <span>Status:</span> <?php echo $order_status;?></div>
<div class="order-info-item bottom"> <span>Order Date: </span> <?php echo $order->order_date; ?></div>
</div>
</div>
</div>
</div>
<?php }?>
</section>
<?php
}
add_action( 'woocommerce_account_my_purchases_endpoint', 'ts_custom_my_purchases_content' );
You don't see the orders being a non-admin user, because in the wc_get_orders args you specify that you want to get orders where the author is a current user.
In WooCommerce, users that made orders are not authors of the orders. If you want to get a current user's orders, you have to rewrite your wc_get-orders calling like this:
$orders = wc_get_orders( array(
'numberposts' => -1,
'orderby' => 'date',
'order' => 'DESC',
'customer_id' => get_current_user_id(),
) );
Firstly, I explain what do I want. I want to get product reviews from the product-bought customer on the order-details page. I copied the code from my current theme > woocommerce > single-product-reviews.php. After I pasted the code on order-details-item.php page.
I can pass the this if:
<?php if ( get_option( ‘woocommerce_review_rating_verification_required’ ) === ‘no’ || wc_customer_bought_product( ”, get_current_user_id(), $sub_product->get_id() ) ) : ?>
I coded similar the single-product-reviews.php but
comment_form( apply_filters( ‘woocommerce_product_review_comment_form_args’, $comment_form ) ); function is not working so the form didn’t come on the order-details-item.php
Whan can I do ?`
<?php
/**
* Order Item Details
*
* This template can be overridden by copying it to yourtheme/woocommerce/order/order-details-item.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/
* #package WooCommerce/Templates
* #version 3.7.0
*/
if (!defined('ABSPATH')) {
exit;
}
global $wp;
global $wpdb;
$current_url = home_url(add_query_arg(array(), $wp->request));
$order_items = $order->get_items(apply_filters('woocommerce_purchase_order_item_types', 'line_item'));
$main_order_id = wp_get_post_parent_id($order->get_id());
// set the meta_key to the appropriate custom field meta_key1 and meta_key2
$meta_key1 = $order->get_id();
$allmiles = $wpdb->get_var(
$wpdb->prepare(
"
SELECT item_qtys
FROM $wpdb->dokan_refund
WHERE order_id =%d
",
$meta_key1
)
);
if (empty($sub_orders)) {
if ($main_order_id!=0){
echo sprintf('
<a id="button-go"
href="' ."%s/hesabim/siparisi-goruntule/%d/". '"
style="border-radius: 4px;border:1px solid #92cecc; background-color: white;color:#92cecc;margin-top:5px;margin-bottom:5px;"
data-id="35375"
class="woocommerce-Button button woocommerce-column__title">%s</a>',
home_url(),wp_kses_post($main_order_id), 'Ana Siparişe Geri Dön');
}
foreach ($order_items as $item_id => $item) {
if (!apply_filters('woocommerce_order_item_visible', true, $item)) {
return;
}
$product_delivery_date = get_post_meta($item->get_product_id(), '_kargo_verilis_suresi', true);
$product_id=$item->get_product_id();
$sub_product=wc_get_product( $product_id );
$product_meta = get_post_meta($item->get_product_id());
$sub_refund_start = wc_get_order_item_meta($item_id, 'sub_status', true);
// $sub_item_status=wc_add_order_item_meta( $item_id, 'item_status_custom', $order->get_status(), $unique = false )
$tarih = explode('T', $order->get_date_completed());
$now = date("Y-m-d");
$origin = date_create($tarih[0]);
$target = date_create($now);
$interval = date_diff($origin, $target);
$iade_hakki = $interval->d;
$aide_yazi = '';
$refund = $item_id;
if (strpos($allmiles, strval($item_id)) > 0) {
$sub_item_status = $wpdb->get_var(
$wpdb->prepare(
"
SELECT status
FROM $wpdb->dokan_refund
WHERE order_id =%d
",
$meta_key1
)
);
switch ($sub_item_status) {
case "0":
$sub_item_status = 'Alıcı Iadesi Bekleniyor';
break;
case "1":
$sub_item_status = 'İade Onaylandı';
break;
case "2" :
$sub_item_status = 'İade Onaylanmadı';
break;
}
} else {
if (!empty($sub_refund_start)) {
$sub_item_status = $sub_refund_start;
} else {
$sub_item_status = $order->get_status();
}
}
?>
<?php
?>
<tr class="<?php echo esc_attr(apply_filters('woocommerce_order_item_class', 'woocommerce-table__line-item order_item', $item, $order)); ?>">
<div class="customer-order-detail-custom">
<div class="customer-order-detail-top-custom ">
<div class="left">
<div class="seller-custom-name">
<?php
$dizge = do_action('woocommerce_order_item_meta_start', $item_id, $item, $order, false);
// echo esc_html( $dizge);
?>
</div>
<div class="custom-sub-id">
Alt Sipariş No:
<span>
<?= wp_kses_post($order->get_id()) ?>
</span>
</div>
<div class="custom-sub-order-status">
Sipariş Durumu:
<span class="sub-order-status__<?= esc_attr__($order->get_status()) ?>">
<?= wp_kses_post(wc_get_order_status_name($order->get_status())) ?>
</span>
</div>
</div>
<div class="right">
<div class="custom-sub-order-total">
Tutar:
<span>
<?php
echo $order->get_formatted_line_subtotal($item);
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
?>
</span>
</div>
</div>
</div>
<div class="customer-order-detail-bottom-custom">
<!-- order image start-->
<div class="bottom-image-custom">
<?= wp_kses_post(wp_get_attachment_image($product_meta['_thumbnail_id'][0], 'full')) ?>
</div>
<!-- order image end-->
<!-- order desc start-->
<div class="bottom-desc-custom">
<div class="desc">
<?php
$is_visible = $product && $product->is_visible();
$product_permalink = apply_filters('woocommerce_order_item_permalink', $is_visible ? $product->get_permalink($item) : '', $item, $order);
echo apply_filters('woocommerce_order_item_name', $product_permalink ? sprintf('%s', $product_permalink, $item->get_name()) : $item->get_name(), $item, $is_visible); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
?>
</div>
<div class="sub-meta">
<div class="size">
Beden:
<span>Tek Ebat</span>
</div>
<div class="qty">
<?php
$qty = $item->get_quantity();
$refunded_qty = $order->get_qty_refunded_for_item($item_id);
if ($refunded_qty) {
$qty_display = '<del>' . esc_html($qty) . '</del> <ins>' . esc_html($qty - ($refunded_qty * -1)) . '</ins>';
} else {
$qty_display = esc_html($qty);
}
echo apply_filters('woocommerce_order_item_quantity_html', ' Adet: <strong class="product-quantity">' . sprintf('%s', $qty_display) . '</strong>', $item); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
?>
</div>
</div>
<?php
// wc_display_item_meta($item); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
do_action('woocommerce_order_item_meta_end', $item_id, $item, $order, false);
?>
</div>
<!--order desc end-->
<!--order button start-->
<!-- <div class="bottom-button-custom">-->
<!-- --><?php
// global $wp;
// $current_url = home_url(add_query_arg(array(), $wp->request));
// if ($sub_item_status=="completed") {
// if ($iade_hakki>=14){
// echo sprintf('
// <button id="button-sub-iade"
// style="border-radius: 4px;border:2px solid #92cecc; background-color: white;color:#92cecc"
// data-id="'.esc_attr__("%d").'"
// class="woocommerce-Button button woocommerce-column__title">
// %s </button>',
// wp_kses_post($order->get_id()), esc_html('İade Et'));
//
//
// } else{ }
// }
// elseif ($sub_item_status=="shipped" ){
// echo sprintf('
// <button id="button-sub-iade"
// style="border-radius: 4px;border:2px solid #FF9D78; background-color: white;color:#FF9D78"
// data-id="'.esc_attr__("%d").'"
// data-name="'.esc_attr__("%s").'"
// data-item="'.esc_attr__("%d").'"
// data-redirect="'.esc_url("%s").'"
// class="woocommerce-Button button woocommerce-column__title sub-iade">
// %s </button>',
// wp_kses_post($order->get_id()),wp_kses_post($item->get_name()),wp_kses_post($item_id) ,wp_kses_post($current_url),esc_html('İade Et'));
// }
//
// elseif ($sub_item_status=='on-hold' | $sub_item_status=='processing' ){
// echo sprintf('
// <button id="button-sub-iptal"
// style="border-radius: 4px;border:1px solid #92cecc; background-color: white;color:#92cecc"
// data-id="'.esc_attr__("%d").'"
// data-name="'.esc_attr__("%s").'"
// data-item="'.esc_attr__("%d").'"
// data-redirect="'.esc_url("%s").'"
// class="woocommerce-Button button woocommerce-column__title sub-iptal">
// %s </button>',
// wp_kses_post($order->get_id()),wp_kses_post($item->get_name()),wp_kses_post($item_id) ,wp_kses_post($current_url),esc_html('İptal Et'));
// }else{ echo '';}?>
<!---->
<!---->
<!---->
<!-- </div>-->
<!--order button end-->
</div>
<div class="customer-order-detail-bottom-custom mobile">
<div class="sub-order-total-text-mobile">
Tutar:
</div>
<div class="sub-order-total-digit-mobile">
<?php echo $order->get_formatted_line_subtotal($item); ?>
</div>
</div>
<?php if ($order->get_status() == 'refunded-customer' || $order->get_status() == 'shipped-refunded'): ?>
<div class="customer-refund-main">
<div class="refund-text">
<div class="custom-refund-text">
<?= esc_html_e('İade Talebi Oluşturuldu', 'yk-plugin') ?>
<p><?= esc_html_e('İade onaylandığında iade tutarı hesabınıza aktarılacaktır.', 'yk-plugin') ?></p>
</div>
<br>
<div class="refund-shipping-desc">
<?= _e('İade edeceğiniz ürünü <b>faturası ile birlikte</b> tek bir pakete koyunuz..', 'yk-plugin') ?>
<p><?= _e('Paketi iade kodunuzla birlikte <b>en geç 7 iş günü</b> içinde MNG Kargo’ya verin', 'yk-plugin') ?></p>
</div>
</div>
<div class="refund-shipped">
<div class="shipping-brand">
<div class="shipping-brand-text">
Kargo Firması
</div>
<div class="shipping-brand-img">
<img src="<?= esc_url('https://hstaging.yuvanikur.com/wp-content/plugins/yk-plugin-v1.3/inc/assets/svg/357048.svg') ?>"
alt="">
</div>
</div>
<div class="shipping-brand">
<div class="shipping-brand-text">
Kargo Iade Kodu
</div>
<div class="shipping-brand-code">
1234567891234
</div>
</div>
</div>
</div>
<?php endif; ?>
</div>
<div id="reviews" class="woocommerce-Reviews">
<div id="comments">
<h2 class="woocommerce-Reviews-title">
<?php
$count = $sub_product->get_review_count();
if ( $count && wc_review_ratings_enabled() ) {
/* translators: 1: reviews count 2: product name */
$reviews_title = sprintf( esc_html( _n( '%1$s review for %2$s', '%1$s reviews for %2$s', $count, 'woocommerce' ) ), esc_html( $count ), '<span>' . $sub_product->get_title(). '</span>' );
echo apply_filters( 'woocommerce_reviews_title', $reviews_title, $count, $sub_product ); // WPCS: XSS ok.
} else {
esc_html_e( 'Reviews', 'woocommerce' );
}
?>
</h2>
<?php if ( have_comments() ) : ?>
<ol class="commentlist">
<?php wp_list_comments( apply_filters( 'woocommerce_product_review_list_args', array( 'callback' => 'woocommerce_comments' ) ) ); ?>
</ol>
<?php
if ( get_comment_pages_count() > 1 && get_option( 'page_comments' ) ) :
echo '<nav class="woocommerce-pagination">';
paginate_comments_links(
apply_filters(
'woocommerce_comment_pagination_args',
array(
'prev_text' => is_rtl() ? '→' : '←',
'next_text' => is_rtl() ? '←' : '→',
'type' => 'list',
)
)
);
echo '</nav>';
endif;
?>
<?php else : ?>
<p class="woocommerce-noreviews"><?php esc_html_e( 'There are no reviews yet.', 'woocommerce' ); ?></p>
<?php endif; ?>
</div>
<?php if ( get_option( 'woocommerce_review_rating_verification_required' ) === 'no' || wc_customer_bought_product( '', get_current_user_id(), $sub_product->get_id() ) ) : ?>
<div id="review_form_wrapper">
<div id="review_form">
<?php
$commenter = wp_get_current_commenter();
$comment_form = array(
/* translators: %s is product title */
'title_reply' => have_comments() ? esc_html__( 'Add a review', 'woocommerce' ) : sprintf( esc_html__( 'Be the first to review “%s”', 'woocommerce' ), $sub_product->get_title() ),
/* translators: %s is product title */
'title_reply_to' => esc_html__( 'Leave a Reply to %s', 'woocommerce' ),
'title_reply_before' => '<span id="reply-title" class="comment-reply-title">',
'title_reply_after' => '</span>',
'comment_notes_after' => '',
'label_submit' => esc_html__( 'Submit', 'woocommerce' ),
'logged_in_as' => '',
'comment_field' => '',
);
$name_email_required = (bool) get_option( 'require_name_email', 1 );
$fields = array(
'author' => array(
'label' => __( 'Name', 'woocommerce' ),
'type' => 'text',
'value' => $commenter['comment_author'],
'required' => $name_email_required,
),
'email' => array(
'label' => __( 'Email', 'woocommerce' ),
'type' => 'email',
'value' => $commenter['comment_author_email'],
'required' => $name_email_required,
),
);
$comment_form['fields'] = array();
foreach ( $fields as $key => $field ) {
$field_html = '<p class="comment-form-' . esc_attr( $key ) . '">';
$field_html .= '<label for="' . esc_attr( $key ) . '">' . esc_html( $field['label'] );
if ( $field['required'] ) {
$field_html .= ' <span class="required">*</span>';
}
$field_html .= '</label><input id="' . esc_attr( $key ) . '" name="' . esc_attr( $key ) . '" type="' . esc_attr( $field['type'] ) . '" value="' . esc_attr( $field['value'] ) . '" size="30" ' . ( $field['required'] ? 'required' : '' ) . ' /></p>';
$comment_form['fields'][ $key ] = $field_html;
}
if ( wc_review_ratings_enabled() ) {
$comment_form['comment_field'] = '<div class="comment-form-rating"><label for="rating">' . esc_html__( 'Your rating', 'woocommerce' ) . ( wc_review_ratings_required() ? ' <span class="required">*</span>' : '' ) . '</label><select name="rating" id="rating" required>
<option value="">' . esc_html__( 'Rate…', 'woocommerce' ) . '</option>
<option value="5">' . esc_html__( 'Perfect', 'woocommerce' ) . '</option>
<option value="4">' . esc_html__( 'Good', 'woocommerce' ) . '</option>
<option value="3">' . esc_html__( 'Average', 'woocommerce' ) . '</option>
<option value="2">' . esc_html__( 'Not that bad', 'woocommerce' ) . '</option>
<option value="1">' . esc_html__( 'Very poor', 'woocommerce' ) . '</option>
</select></div>';
}
$comment_form['comment_field'] .= '<p class="comment-form-comment"><label for="comment">' . esc_html__( 'Your review', 'woocommerce' ) . ' <span class="required">*</span></label><textarea id="comment" name="comment" cols="45" rows="8" required></textarea></p>';
comment_form( apply_filters( 'woocommerce_product_review_comment_form_args', $comment_form ) );
?>
</div>
</div>
<?php else : ?>
<p class="woocommerce-verification-required"><?php esc_html_e( 'Only logged in customers who have purchased this product may leave a review.', 'woocommerce' ); ?></p>
<?php endif; ?>
<div class="clear"></div>
</div>
</tr>
<?php if ($show_purchase_note && $purchase_note) : ?>
<tr class="woocommerce-table__product-purchase-note product-purchase-note">
<td colspan="2"><?php echo wpautop(do_shortcode(wp_kses_post($purchase_note))); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?></td>
</tr>
<?php endif; ?>
<?php }
} ?>
I found my solution. I found my solution. Woocommerce does not allow review for the product on the account page. My solution is simple.
comment_form( apply_filters( ‘woocommerce_product_review_comment_form_args’, $comment_form ),$product_id );
I gave the product id to the function because woocommerce allow review on a single product page. It's a simple trick.
I've made a custom field for my product categories so that I could select icons accordingly using ACF plugin. I called all the categories like this (But the values of the custom fields return nothing as I've tried var_dumping it):
<?php
$orderby = 'date';
$order = 'DESC';
$hide_empty = false ;
$cat_args = array(
'orderby' => $orderby,
'order' => $order,
'hide_empty' => $hide_empty,
);
$product_categories = get_terms( 'product_cat', $cat_args );
if( !empty($product_categories) ){
foreach ($product_categories as $key => $category) {
$icon = get_field('icon_classname');
if (empty($icon)) { $icon = 'flaticon-002-coat'; }
?>
<div class="cat-item">
<div class="cat cat-1">
<div class="cat-wrap">
<a class="category" href="<?php echo get_term_link($category); ?>">
<i class="icon fimanager <?php echo $icon; ?>"></i>
<span class="cat-title"><?php echo $category->name; ?></span>
</a>
</div>
</div>
</div>
<?php
} wp_reset_postdata();
}
?>
please check it :
you should replace these two lines :
foreach( $product_categories as $cat) {
$icon = get_field('icon_classname', 'category_'.$cat->term_id);
I am green in wordpress.
I have create a widget call woocommerce-dropdown-cart.php and placed in the same folder with the theme I am using. But why I cant find this widget in my Appereance-->widget?
On the other hands, my menu bar have not any widget, how can I add this widget into or just before the menu bar?
Many thanks!
Here is my php code:
<?php class Woocommerce_Dropdown_Cart extends WP_Widget {
public function __construct() {
parent::__construct(
'woocommerce-dropdown-cart', // Base ID
'Woocommerce Dropdown Cart', // Name
array( 'description' => __( 'Woocommerce Dropdown Cart', 'jeffho' ), ) // Args
);
}
public function widget( $args, $instance ) {
global $post;
extract( $args );
echo $before_widget;
global $woocommerce;
global $qode_options_proya;
$cart_holder_class = 'header_cart';
if (isset($qode_options_proya['woo_cart_type'])){
$cart_type = $qode_options_proya['woo_cart_type'];
switch ($cart_type) {
case 'font-elegant':
$cart_holder_class = "header_cart cart_icon";
break;
default:
$cart_holder_class = "header_cart";
break;
}
}
?>
<div class="shopping_cart_outer">
<div class="shopping_cart_inner">
<div class="shopping_cart_header">
<a class="<?php echo esc_attr($cart_holder_class);?>" href="<?php echo $woocommerce->cart->get_cart_url(); ?>"><span class="header_cart_span"><?php echo $woocommerce->cart->cart_contents_count; ?></span></a>
<div class="shopping_cart_dropdown">
<div class="shopping_cart_dropdown_inner">
<?php
$cart_is_empty = sizeof( $woocommerce->cart->get_cart() ) <= 0;
$list_class = array( 'cart_list', 'product_list_widget' );
?>
<ul class="<?php echo implode(' ', $list_class); ?>">
<?php if ( !$cart_is_empty ) : ?>
<?php foreach ( $woocommerce->cart->get_cart() as $cart_item_key => $cart_item ) :
$_product = $cart_item['data'];
// Only display if allowed
if ( ! $_product->exists() || $cart_item['quantity'] == 0 ) {
continue;
}
// Get price
$product_price = get_option( 'woocommerce_tax_display_cart' ) == 'excl' ? $_product->get_price_excluding_tax() : $_product->get_price_including_tax();
$product_price = apply_filters( 'woocommerce_cart_item_price_html', woocommerce_price( $product_price ), $cart_item, $cart_item_key );
?>
<li>
<a itemprop="url" href="<?php echo get_permalink( $cart_item['product_id'] ); ?>">
<?php echo $_product->get_image(); ?>
<?php echo apply_filters('woocommerce_widget_cart_product_title', $_product->get_title(), $_product ); ?>
</a>
<?php echo $woocommerce->cart->get_item_data( $cart_item ); ?>
<?php echo apply_filters( 'woocommerce_widget_cart_item_quantity', '<span class="quantity">' . sprintf( '%s × %s', $cart_item['quantity'], $product_price ) . '</span>', $cart_item, $cart_item_key ); ?>
</li>
<?php endforeach; ?>
<?php else : ?>
<li><?php _e( 'No products in the cart.', 'woocommerce' ); ?></li>
<?php endif; ?>
</ul>
</div>
<?php if ( sizeof( $woocommerce->cart->get_cart() ) <= 0 ) : ?>
<?php endif; ?>
<a itemprop="url" href="<?php echo $woocommerce->cart->get_cart_url(); ?>" class="qbutton white view-cart"><?php _e( 'Cart', 'woocommerce' ); ?> <i class="fa fa-shopping-cart"></i></a>
<span class="total"><?php _e( 'Total', 'woocommerce' ); ?>:<span><?php echo $woocommerce->cart->get_cart_subtotal(); ?></span></span>
<?php if ( sizeof( $woocommerce->cart->get_cart() ) <= 0 ) : ?>
<?php endif; ?>
</div>
</div>
</div>
</div>
<?php
echo $after_widget;
}
public function update( $new_instance, $old_instance ) {
$instance = array();
return $instance;
}
}
add_action( 'widgets_init', create_function( '', 'register_widget( "Woocommerce_Dropdown_Cart" );' ) );
?>
<?php
add_filter('add_to_cart_fragments', 'woocommerce_header_add_to_cart_fragment');
function woocommerce_header_add_to_cart_fragment( $fragments ) {
global $woocommerce;
ob_start();
?>
<span class="header_cart_span"><?php echo $woocommerce->cart->cart_contents_count; ?></span>
<?php
$fragments['span.header_cart_span'] = ob_get_clean();
return $fragments;
}
?>
I am using theme called "Creativo 5.0" and I have added:
register_sidebar( array(
'name' => __( 'Header Sidebar', 'Creativo' ),
'id' => 'header-sidebar',
'before_widget' => '<div class="header _widget_content">',
'after_widget' => '</div>',
'before_title' => '<h2 class="header-widget-title">',
'after_title' => '</h2>',
) );
into function creativo_widgets_init()
what I want is to add the php widget into the menu bar.
I'm using the current version of the Divi 2.0 theme and Wordpress. The theme uses a filterable portfolio gallery that a user can click to filter between categories. The links are # and instead I think the click is passed using: data-category-slug="%1$s"
Where "%1$s" is the name of the category. I've tried adding "%1$s" to the end of the #link, but it doesn't work.
Theme function:
function et_pb_filterable_portfolio( $atts ) {
extract( shortcode_atts( array(
'module_id' => '',
'module_class' => '',
'fullwidth' => 'on',
'posts_number' => 10,
'include_categories' => '',
'show_title' => 'on',
'show_categories' => 'on',
'show_pagination' => 'on',
'background_layout' => 'light',
), $atts
) );
wp_enqueue_script( 'jquery-masonry-3' );
wp_enqueue_script( 'hashchange' );
$args = array();
if( 'on' === $show_pagination ) {
$args['nopaging'] = true;
} else {
$args['posts_per_page'] = (int) $posts_number;
}
if ( '' !== $include_categories ) {
$args['tax_query'] = array(
array(
'taxonomy' => 'project_category',
'field' => 'id',
'terms' => explode( ',', $include_categories ),
'operator' => 'IN',
)
);
}
$projects = et_divi_get_projects( $args );
$categories_included = array();
ob_start();
if( $projects->post_count > 0 ) {
while ( $projects->have_posts() ) {
$projects->the_post();
$category_classes = array();
$categories = get_the_terms( get_the_ID(), 'project_category' );
if ( $categories ) {
foreach ( $categories as $category ) {
$category_classes[] = 'project_category_' . urldecode( $category->slug );
$categories_included[] = $category->term_id;
}
}
$category_classes = implode( ' ', $category_classes );
?>
<div id="post-<?php the_ID(); ?>" <?php post_class( 'et_pb_portfolio_item ' . $category_classes ); ?>>
<?php
$thumb = '';
$width = 'on' === $fullwidth ? 1080 : 400;
$width = (int) apply_filters( 'et_pb_portfolio_image_width', $width );
$height = 'on' === $fullwidth ? 9999 : 284;
$height = (int) apply_filters( 'et_pb_portfolio_image_height', $height );
$classtext = 'on' === $fullwidth ? 'et_pb_post_main_image' : '';
$titletext = get_the_title();
$thumbnail = get_thumbnail( $width, $height, $classtext, $titletext, $titletext, false, 'Blogimage' );
$thumb = $thumbnail["thumb"];
if ( '' !== $thumb ) : ?>
<a href="<?php the_permalink(); ?>">
<?php if ( 'on' !== $fullwidth ) : ?>
<span class="et_portfolio_image">
<?php endif; ?>
<?php print_thumbnail( $thumb, $thumbnail["use_timthumb"], $titletext, $width, $height ); ?>
<?php if ( 'on' !== $fullwidth ) : ?>
<span class="et_overlay"></span>
</span>
<?php endif; ?>
</a>
<?php
endif;
?>
<?php if ( 'on' === $show_title ) : ?>
<h2><?php the_title(); ?></h2>
<?php endif; ?>
<?php if ( 'on' === $show_categories ) : ?>
<p class="post-meta"><?php echo get_the_term_list( get_the_ID(), 'project_category', '', ', ' ); ?></p>
<?php endif; ?>
</div><!-- .et_pb_portfolio_item -->
<?php
}
}
wp_reset_postdata();
$posts = ob_get_clean();
$categories_included = explode ( ',', $include_categories );
$terms_args = array(
'include' => $categories_included,
'orderby' => 'name',
'order' => 'ASC',
);
$terms = get_terms( 'project_category', $terms_args );
$category_filters = '<ul class="clearfix">';
$category_filters .= sprintf( '<li class="et_pb_portfolio_filter et_pb_portfolio_filter_all">%1$s</li>',
esc_html__( 'All', 'Divi' )
);
foreach ( $terms as $term ) {
$category_filters .= sprintf( '<li class="et_pb_portfolio_filter">%2$s</li>',
esc_attr( urldecode( $term->slug ) ),
esc_html( $term->name )
);
}
$category_filters .= '</ul>';
$class = " et_pb_bg_layout_{$background_layout}";
$output = sprintf(
'<div%5$s class="et_pb_filterable_portfolio %1$s%4$s%6$s" data-posts-number="%7$d"%10$s>
<div class="et_pb_portfolio_filters clearfix">%2$s</div><!-- .et_pb_portfolio_filters -->
<div class="et_pb_portfolio_items_wrapper %8$s">
<div class="column_width"></div>
<div class="gutter_width"></div>
<div class="et_pb_portfolio_items">%3$s</div><!-- .et_pb_portfolio_items -->
</div>
%9$s
</div> <!-- .et_pb_filterable_portfolio -->',
( 'on' === $fullwidth ? 'et_pb_filterable_portfolio_fullwidth' : 'et_pb_filterable_portfolio_grid clearfix' ),
$category_filters,
$posts,
esc_attr( $class ),
( '' !== $module_id ? sprintf( ' id="%1$s"', esc_attr( $module_id ) ) : '' ),
( '' !== $module_class ? sprintf( ' %1$s', esc_attr( $module_class ) ) : '' ),
esc_attr( $posts_number),
('on' === $show_pagination ? '' : 'no_pagination' ),
('on' === $show_pagination ? '<div class="et_pb_portofolio_pagination"></div>' : '' ),
is_rtl() ? ' data-rtl="true"' : ''
);
return $output;
}
localhost page source:
localhost page source:
<div class="et_pb_row">
<div class="et_pb_column et_pb_column_4_4">
<div class="et_pb_filterable_portfolio et_pb_filterable_portfolio_grid clearfix et_pb_bg_layout_light" data-posts-number="10">
<div class="et_pb_portfolio_filters clearfix"><ul class="clearfix"><li class="et_pb_portfolio_filter et_pb_portfolio_filter_all">All</li><li class="et_pb_portfolio_filter">4G LTE Smartphones</li><li class="et_pb_portfolio_filter">Specialty Devices</li></ul></div><!-- .et_pb_portfolio_filters -->
<div class="et_pb_portfolio_items_wrapper ">
<div class="column_width"></div>
<div class="gutter_width"></div>
<div class="et_pb_portfolio_items"> <div id="post-253" class="post-253 project type-project status-publish has-post-thumbnail hentry et_pb_portfolio_item project_category_verizon-4g-lte-smartphones">
<a href="http://localhost/project/galaxy-note-edge-by-samsung/">
<span class="et_portfolio_image">
<img src="http://localhost/wp-content/uploads/2015/02/devices-samsung-note-edge-thumb3-216x284.png" alt='Galaxy Note™ Edge by Samsung' width='400' height='284' /> <span class="et_overlay"></span>
</span>
</a>
<h2>Galaxy Note™ Edge by Samsung</h2>
<p class="post-meta">4G LTE Smartphones</p>
</div><!-- .et_pb_portfolio_item -->
<div id="post-97" class="post-97 project type-project status-publish has-post-thumbnail hentry et_pb_portfolio_item project_category_verizon-connected-devices">
<a href="http://localhost/project/lg-gizmopal/">
<span class="et_portfolio_image">
<img src="http://localhost/wp-content/uploads/2015/02/devices-gizmopal-thumb-216x284.png" alt='GizmoPal™ by LG' width='400' height='284' /> <span class="et_overlay"></span>
</span>
</a>
<h2>GizmoPal™ by LG</h2>
<p class="post-meta">Specialty Devices</p>
</div><!-- .et_pb_portfolio_item -->
</div><!-- .et_pb_portfolio_items -->
</div>
<div class="et_pb_portofolio_pagination"></div>
</div> <!-- .et_pb_filterable_portfolio -->
</div> <!-- .et_pb_column -->
</div> <!-- .et_pb_row -->
</div> <!-- .et_pb_section -->
</div> <!-- .entry-content -->
</article> <!-- .et_pb_post -->
</div>
I want to link from one page to the filtered portfolio with a filter already selected? Any help is appreciated.
-Ranks
I struggled with the same thing. Finally, I did a wonky workaround.
First, I added a custom script to the Divi > Theme Options > Integration > section in the area. In my exaple, the category is called 'available'.
<script>
function doAvailable() {
setTimeout( function() { document.querySelector('[data-category-slug="available"]').click(); }, 1000);
}
</script>
Then in the page I created I added a Code module at the bottom of the page to call the custom function.
<script>
doAvailable();
</script>
I wish I could have found a better way, but this does work for me.
The answer by Jordi appears to be incorrect and I don't want to mess around with javascript. I found that url/project/slug works fine i.e. mydomain.com/project/my-project
What I did is to generate a sitemap with google sitemap plugin and to select in the config menu "sitemap's content" the custom taxonomies. Then, I've checked the sitemap, and I've seen that the project categories are available under url/project_category/category_slug.