I am working in e-commerce website, i made my own theme and I installed the woocommerce plugin. but there is a problem displaying the products reviews.
the code below is in the woocommerce/single-product/tabs/tabs.php
<?php
/**
* Single Product tabs
*
* This template can be overridden by copying it to yourtheme/woocommerce/single-product/tabs/tabs.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.8.0
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/**
* Filter tabs and allow third parties to add their own.
*
* Each tab is an array containing title, callback and priority.
*
* #see woocommerce_default_product_tabs()
*/
$product_tabs = apply_filters( 'woocommerce_product_tabs', array() );
if ( ! empty( $product_tabs ) ) : ?>
<div class="woocommerce-tabs wc-tabs-wrapper" >
<ul class="tabs wc-tabs" role="tablist">
<?php foreach ( $product_tabs as $key => $product_tab ) : ?>
<li class="<?php echo esc_attr( $key ); ?>_tab" id="tab-title-<?php echo esc_attr( $key ); ?>" role="tab" aria-controls="tab-<?php echo esc_attr( $key ); ?>">
<a href="#tab-<?php echo esc_attr( $key ); ?>">
<?php echo wp_kses_post( apply_filters( 'woocommerce_product_' . $key . '_tab_title', $product_tab['title'], $key ) ); ?>
</a>
</li>
<?php endforeach; ?>
<li class="reviews_tab" id="tab-title---><?php //echo esc_attr( $key ); ?><!--" role="tab" aria-controls="tab---><?php //echo esc_attr( $key ); ?><!--">
<a href="#tab-reviews">
Reviews
</a>
</li>
</ul>
<?php foreach ( $product_tabs as $key => $product_tab ) : ?>
<div class="woocommerce-Tabs-panel woocommerce-Tabs-panel--<?php echo esc_attr( $key ); ?> panel entry-content wc-tab" id="tab-<?php echo esc_attr( $key ); ?>" role="tabpanel" aria-labelledby="tab-title-<?php echo esc_attr( $key ); ?>">
<?php
if ( isset( $product_tab['callback'] ) ) {
call_user_func( $product_tab['callback'], $key, $product_tab );
}
?>
</div>
<?php endforeach; ?>
<div class="woocommerce-Tabs-panel woocommerce-Tabs-panel--reviews panel entry-content wc-tab" id="tab-reviews" role="tabpanel" aria-labelledby="tab-title-reviews">
<div id="reviews">
<?php
woocommerce_get_template_part( 'single-product-reviews' );
?>
</div>
</div>
<?php do_action( 'woocommerce_product_after_tabs' ); ?>
</div>
<?php endif; ?>
I have spent the past 2 days in this problem and couldn't figure out why its not showing the reviews
In order to display the Product Reviews you need to ensure a couple of things
In WooCommerce --> Settings on the Products tab under General, ensure that you have ticked "Enable product reviews"
In the actual products under "Advanced" tick "Enable reviews"
Also when setting up a custom theme if you are overriding the default template for single product you need to ensure that you include the woocommerce_after_single_product_summary action as it includes the woocommerce_output_product_data_tabs that includes displaying the product Reviews
/**
* Hook: woocommerce_after_single_product_summary.
*
* #hooked woocommerce_output_product_data_tabs - 10
* #hooked woocommerce_upsell_display - 15
* #hooked woocommerce_output_related_products - 20
*/
do_action( 'woocommerce_after_single_product_summary' );
Here's a link to an article with images explaining steps 1 and 2 further
Reviews not showing on product page
I've moved the Stock.PHP and Price.PHP files from Templates into my theme WooCommerce -> Single Product folder. Now, I've tried to move this line of code from Stock.PHP into Price.PHP:
<p class="stock <?php echo esc_attr( $class ); ?>"><?php echo wp_kses_post( $availability ); ?></p>
This is my Stock.PHP file now.
<?php
/**
* Single Product stock.
* #version 3.0.0
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
?>
<!-- <p class="stock <?php echo esc_attr( $class ); ?>"><?php echo wp_kses_post( $availability ); ?></p> -->
And this is my Price.PHP file.
<?php
/**
* Single Product Price
* #version 3.0.0
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
global $product;
?>
<p class="price"><?php echo $product->get_price_html(); ?></p>
<p class="stock <?php echo esc_attr( $class ); ?>"><?php echo wp_kses_post( $availability ); ?></p>
But for no reason, the Stock is not getting the esc_attr value and the availability of the product. How come this paragraph does get the class and the availability inside the Stock file but not inside the Price file?
Thanks,
Lucian
I am using Wordpress with woocommerce and trying to set up some variable products. But variable products show the "In Stock" messages directly below the input/select field. I want it to be shown below the "Add to cart" button.
I am using a child theme for the files, simple.php, variable.php and variation.php.
Feel free to look at the picture to see what I want to do.
http://art-wood.de/instock-move.png
Currently my variable.php looks like this:
<?php
/**
* Variable product add to cart
*
* This template can be overridden by copying it to yourtheme/woocommerce/single-product/add-to-cart/variable.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;
}
global $product;
$attribute_keys = array_keys( $attributes );
do_action( 'woocommerce_before_add_to_cart_form' ); ?>
<form class="variations_form cart" method="post" enctype='multipart/form-data' data-product_id="<?php echo absint( $product->id ); ?>" data-product_variations="<?php echo htmlspecialchars( json_encode( $available_variations ) ) ?>">
<?php do_action( 'woocommerce_before_variations_form' ); ?>
<?php if ( empty( $available_variations ) && false !== $available_variations ) : ?>
<div class="stock out-of-stock"><?php _e( 'This product is currently out of stock and unavailable.', 'woocommerce' ); ?></div>
<?php else : ?>
<span class="variations" cellspacing="0">
<?php foreach ( $attributes as $attribute_name => $options ) : ?>
<label class="label" for="<?php echo sanitize_title( $attribute_name ); ?>"><?php echo wc_attribute_label( $attribute_name ); ?></label>
<div class="value">
<?php
$selected = isset( $_REQUEST[ 'attribute_' . sanitize_title( $attribute_name ) ] ) ? wc_clean( $_REQUEST[ 'attribute_' . sanitize_title( $attribute_name ) ] ) : $product->get_variation_default_attribute( $attribute_name );
wc_dropdown_variation_attribute_options( array( 'options' => $options, 'attribute' => $attribute_name, 'product' => $product, 'selected' => $selected ) );
echo end( $attribute_keys ) === $attribute_name ? apply_filters( 'woocommerce_reset_variations_link', '<a class="reset_variations" href="#">' . __( 'Clear', 'woocommerce' ) . '</a>' ) : '';
?>
</div>
<?php endforeach;?>
</span>
<?php do_action( 'woocommerce_before_add_to_cart_button' ); ?>
<div class="single_variation_wrap">
/**
* woocommerce_before_single_variation Hook.
*/
do_action( 'woocommerce_before_single_variation' );
/**
* woocommerce_single_variation hook. Used to output the cart button and placeholder for variation data.
* #since 2.4.0
* #hooked woocommerce_single_variation - 10 Empty div for variation data.
* #hooked woocommerce_single_variation_add_to_cart_button - 20 Qty and cart button.
*/
do_action( 'woocommerce_single_variation' );
/**
* woocommerce_after_single_variation Hook.
*/
do_action( 'woocommerce_after_single_variation' );
?>
</div>
<?php do_action( 'woocommerce_after_add_to_cart_button' ); ?>
<?php endif; ?>
<?php do_action( 'woocommerce_after_variations_form' ); ?>
</form>
<?php do_action( 'woocommerce_after_add_to_cart_form' ); ?>
Does somebody know how to move the message down below the Add to cart button? This would be amazing! May its a simple add to the functions.php maybe its a switch in the variable.php... I don't know that. Otherwise I wouldn't ask :)
I found the solution by myself. Maybe its useful for someone so here it is ;)
Simply add this to your functions.php
remove_action( 'woocommerce_single_variation' , 'woocommerce_single_variation', 10);
add_action( 'woocommerce_single_variation', 'woocommerce_single_variation', 20 );
After the last WooCommerce update, the order details no longer displayed on the Thank You page. Since then, I have developed a child theme using the WooCommerce Storefront theme. No matter what I have tried, All I see is the 'thank you' message on the thank you page.
What I have tried so far:
Troubleshooting the entire process to find anything that might be wrong.
This included the following:
Checked for wc template function that calls the order-details template and it related action hook (both exist)
Making sure my child-theme's WooCommerce directory was correctly structured. Everything else works correctly, including my custom template fragments and their hooks.
Paying careful attention to syntax errors, including those that might silently fail.
Copied the WooCommerce directory from the plugin into the child theme. This yielded the same exact result--no order details on thank you page.
Eliminated WordPress Thank You page and used the default WooCommerce endpoint ('order-received'). NOTE: Due to the way this affected layout and display, I reverted back to my original WooCommerce directory structure, which is identical to the WooCommerce template directory, minus some of the sub-directories. (UPDATE: I actually am still using the copied WooCommerce directory)
Wrote a custom function with action hook in child theme's functions.php file, with no change in output.
In thankyou.php, created an action hook and wrote a function that used wc_get_template to call order-details, but it didn't work (silent fail)
Updated WordPress from 4.5 to 4.6.1, Updated the Storefront theme, and updated any outdated WooCommerce template files in my child theme.
Code:
**storefront-child/woocommerce/wc-template-functions.php**
if ( ! function_exists( 'woocommerce_order_details_table' ) ) {
/**
* Displays order details in a table.
*
* #param mixed $order_id
* #subpackage Orders
*/
function woocommerce_order_details_table( $order_id ) {
if ( ! $order_id ) return;
wc_get_template( 'order/order-details.php', array(
'order_id' => $order_id
) );
}
}
**storefront-child/woocommerce/wc-template-hooks.php
/**
* Order details.
*
* #see woocommerce_order_details_table()
* #see woocommerce_order_again_button()
*/
add_action( 'woocommerce_view_order', 'woocommerce_order_details_table', 10 );
add_action( 'woocommerce_thankyou', 'woocommerce_order_details_table', 10 );
add_action( 'woocommerce_order_details_after_order_table', 'woocommerce_order_again_button' );
**storefront-child/woocommerce/checkout/thankyou.php**
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
if ( $order ) : ?>
<?php if ( $order->has_status( 'failed' ) ) : ?>
<p class="woocommerce-thankyou-order-failed"><?php _e( 'Unfortunately your order cannot be processed as the originating bank/merchant has declined your transaction. Please attempt your purchase again.', 'woocommerce' ); ?></p>
<p class="woocommerce-thankyou-order-failed-actions">
<?php _e( 'Pay', 'woocommerce' ) ?>
<?php if ( is_user_logged_in() ) : ?>
<?php _e( 'My Account', 'woocommerce' ); ?>
<?php endif; ?>
</p>
<?php else : ?>
<p class="woocommerce-thankyou-order-received"><?php echo apply_filters( 'woocommerce_thankyou_order_received_text', __( 'Thank you. Your order has been received.', 'woocommerce' ), $order ); ?></p>
<ul class="woocommerce-thankyou-order-details order_details">
<li class="order">
<?php _e( 'Order Number:', 'woocommerce' ); ?>
<strong><?php echo $order->get_order_number(); ?></strong>
</li>
<li class="date">
<?php _e( 'Date:', 'woocommerce' ); ?>
<strong><?php echo date_i18n( get_option( 'date_format' ), strtotime( $order->order_date ) ); ?></strong>
</li>
<li class="total">
<?php _e( 'Total:', 'woocommerce' ); ?>
<strong><?php echo $order->get_formatted_order_total(); ?></strong>
</li>
<?php if ( $order->payment_method_title ) : ?>
<li class="method">
<?php _e( 'Payment Method:', 'woocommerce' ); ?>
<strong><?php echo $order->payment_method_title; ?></strong>
</li>
<?php endif; ?>
</ul>
<div class="clear"></div>
<?php endif; ?>
<?php do_action( 'woocommerce_thankyou_' . $order->payment_method, $order->id ); ?>
<?php do_action( 'woocommerce_thankyou', $order->id ); ?>
<p class="woocommerce-thankyou-order-received"><?php echo apply_filters( 'woocommerce_thankyou_order_received_text', __( 'Thank you. Your order has been received.', 'woocommerce' ), null ); ?></p>
<?php endif;
?>
**storefront-child/woocommerce/order/order-details.php**
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
$order = wc_get_order( $order_id );
$show_purchase_note = $order->has_status( apply_filters( 'woocommerce_purchase_note_order_statuses', array( 'completed', 'processing' ) ) );
$show_customer_details = is_user_logged_in() && $order->get_user_id() === get_current_user_id();
?>
<h2><?php _e( 'Order Details', 'woocommerce' ); ?></h2>
<table class="shop_table order_details">
<thead>
<tr>
<th class="product-name"><?php _e( 'Product', 'woocommerce' ); ?></th>
<th class="product-total"><?php _e( 'Total', 'woocommerce' ); ?></th>
</tr>
</thead>
<tbody>
<?php
foreach( $order->get_items() as $item_id => $item ) {
$product = apply_filters( 'woocommerce_order_item_product', $order->get_product_from_item( $item ), $item );
wc_get_template( 'order/order-details-item.php', array(
'order' => $order,
'item_id' => $item_id,
'item' => $item,
'show_purchase_note' => $show_purchase_note,
'purchase_note' => $product ? get_post_meta( $product->id, '_purchase_note', true ) : '',
'product' => $product,
) );
}
?>
<?php do_action( 'woocommerce_order_items_table', $order ); ?>
</tbody>
<tfoot>
<?php
foreach ( $order->get_order_item_totals() as $key => $total ) {
?>
<tr>
<th scope="row"><?php echo $total['label']; ?></th>
<td><?php echo $total['value']; ?></td>
</tr>
<?php
}
?>
</tfoot>
<?php if ( $show_customer_details ) : ?>
<?php wc_get_template( 'order/order-details-customer.php', array( 'order' => $order ) ); ?>
<?php endif; ?>
**Rendered HTML**
<div class="entry-content">
<div class="mailmunch-forms-before-post" style="display: none !important;"></div>
<div class="woocommerce">
<p class="woocommerce-thankyou-order-received">Thank you. Your order has been received.</p>
</div>
<!-- This is where the order details should be -->
<p> </p>
<div class="mailmunch-forms-in-post-middle" style="display: none !important;"></div>
<div class="mailmunch-forms-after-post" style="display: none !important;"></div>
</div>
Am I missing something here, or is there something going on with WooCommerce? Any help would be greatly appreciated:)
UPDATE: Found that I have two versions of jQuery running: v1.11.3, and v1.12.4. There are also two different versions of jQueryUI loading: v1.10.4, and v1.11.4. Currently disabling WordPress plugins and noting what jquery versions are loading in the browser.
UPDATE: Found one plugin using jQueryUI v1.10.4. Still looking for the others.
UPDATE: Finished toubleshooting all the plugins, except WooCommerce (WSOD). MailChimp MailMunch plugin was making the google api call to the older jquery version (v1.11.3), while the Spider Player was calling the older version of jQueryUI. De-activated both plugins, and STILL the same result.
It's as if WooCommerce is simply ignoring the order details in the middle of the thankyou.php template.
Any thoughts or ideas? I am really at a loss now. I can fix the jquery issues in the disabled plugins, but that won't fix my pressing issue with the Thank You page.
Any help would be greatly appreciated:)
UPDATE: After a lot more work, I have determined that WooCommerce IS using the child theme thankyou.php. Further troubleshooting also revealed that $order is false. This is why I am not seeing order details on the thank you page. Next: Figure why $order is false (It is an instance of WC_Order).
UPDATE: I did a stacktrace:
#0 /home/onyour6test/www/wp-content/plugins/woocommerce/includes/wc-core-functions.php(203): include()
#1 /home/onyour6test/www/wp-content/plugins/woocommerce/includes/shortcodes/class-wc-shortcode-checkout.php(212): wc_get_template('checkout/thanky...', Array)
#2 /home/onyour6test/www/wp-content/plugins/woocommerce/includes/shortcodes/class-wc-shortcode-checkout.php(59): WC_Shortcode_Checkout::order_received(NULL)
#3 /home/onyour6test/www/wp-content/plugins/woocommerce/includes/class-wc-shortcodes.php(71): WC_Shortcode_Checkout::output('')
#4 /home/onyour6test/www/wp-content/plugins/woocommerce/includes/class-wc-shortcodes.php(138): WC_Shortcodes::shortcode_wrapper(Array, '')
#5 /home/onyour6test/www/wp-includes/shortcodes.php(326): WC_Shortcodes::checkout('', '', 'woocommerce_che...')
#6 [internal function]: do_shortcode_tag(Arr in /home/onyour6test/www/wp-content/themes/storefront-child/woocommerce/checkout/thankyou.php on line 77
I think the culprit may be in stacktrace #2: ...WC_Shortcode_Checkout::order_received(NULL).
Stacktrace #6 seems to confirm this, with do_shortcode_tag. Line 77 refers to where the call to $order fails, specifically here:
<strong><? php _e( 'Order Number:', 'woocommerce' ); ?></strong>
I managed to get this particular line of code to display, but it showed only "Order" in "Order Number", followed by a 500 internal server error. None of the rest of the remaining HTML or order-detail variables rendered on the page.
UPDATE: This appears to be something with the WooCommerce code itself. $order_id is empty, causing $order to return NULL. This prevents the order details from being displayed. This should display by default, with an option to turn it off in WooCommerce settings.
The problem is $show_customer_details in order/order-details.php is set to false if the customer is not logged in.
I modified the customer check in my theme copy of order-details.php to also check if the order key (post password) matches the key that's provided as a URL parameter. This is the same check that WooCommerce performs when working out if it's okay to show the order info on the thank you page:
$order_key = apply_filters( 'woocommerce_thankyou_order_key', empty( $_GET['key'] ) ? '' : wc_clean( $_GET['key'] ) );
$show_customer_details = $order_key == $order->get_order_key() || (is_user_logged_in() && $order->get_user_id() === get_current_user_id());
It's not pretty but it works.
I need a quantity selection block in the add to cart loop on the product list page in woocommerce. Woocommerce codex has a page which allows me to do it by basically putting this block of code instead of the existing one:
<form action="<?php echo esc_url( $product->add_to_cart_url() ); ?>" class="cart" method="post" enctype='multipart/form-data'>
<?php woocommerce_quantity_input(); ?>
<button type="submit" class="button alt"><?php echo $label; ?></button>
</form>
However, that form doesn't add to my current AJAX setup and other nice tricks that come with my original add to cart button.
This is the original code of the add to cart button, which works like i want it, except for missing the quantity input:
<?php
/**
* Loop Add to Cart
*
* #author WooThemes
* #package WooCommerce/Templates
* #version 2.1.0
*/
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
global $product, $jckqv;
$jckqv->displayBtn($product->id);
echo '<div class="product-buttons">';
echo apply_filters( 'woocommerce_loop_add_to_cart_link',
sprintf( '%s',
esc_url( $product->add_to_cart_url() ),
esc_attr( $product->id ),
esc_attr( $product->get_sku() ),
$product->is_purchasable() ? 'add_to_cart_button' : '',
esc_attr( $product->product_type ),
esc_html( $product->add_to_cart_text() )
),
$product );
echo do_shortcode('[yith_compare_button]');
echo do_shortcode('[yith_wcwl_add_to_wishlist]');
echo '</div>';
I need to somehow put the woocommerce_quantity_input in this code, to retain the current functionality, but to add the quantity input. I tried to do it in many various ways, but unfortunately my PHP skills lack.
Please help.
Thank you
For anybody who might still need to use this
<?php woocommerce_quantity_input(); ?>
You need to echo it. As easy as that