woocommerce - Product page reviews error - woocommerce

I am facing a weird error after working on woocommerce templates. Issue is that I am seeing same reviews (reviews belonging to one particular product) across all the products, what ever the product page I open the reviews are same that of one particular product.I tried trashing that one product but the pattern has not changed and reviews are caught up from another product.
What I changed:
Initially my aim was to load the woocommerce templates from the custom plugin I am working based on woocommerce, I have copied the woocommerce templates into my plugin folder and used below code to call each template file separately.
function intercept_wc_template_meta($template, $template_name, $template_path) {
if ($template_name == 'single-product/meta.php') {
$template = um_product_path.'woocommerce/single-product/meta.php';
}
return $template;
}
add_filter('woocommerce_locate_template', 'intercept_wc_template_meta', 20, 3);
What came up:
After doing this for all the files I tried testing with var_dump($template) and all the files are loading from my plugin successfully.
Finally there is an error in reviews part of product page.
For example if I have products A, B, C, D and there are 4 reviews for product A which are shown properly on product A page, the same 4 reviews of A are being displayed/overwritten for B, C, D also instead of their own reviews.
Have anyone faced this problem earlier? I am no sure what caused this error.

Consider to find out on which hook meta.php template part is added to page, unhook that and try to attach this template part on the same hook with late binding that is using priority > 10. woocommerce_locate_template does not work for every thing.

Related

Custom template for product detail page is blank - Woocommerce

This is sample url-https://www.inoventary.com/product/ipega-wireless-bluetooth-gamepad/
single product page on woocommerce store is showing only header and footer , not showing product or single product page template .
Log Error -2018-06-12T17:15:39+00:00 CRITICAL Call to undefined function dhvc_woo_get_product_formatted_name()
I don't know how to fix , your answer is very much appreciated
Seems like your theme is overriding default woocommerce template and there is some function being used which is not found.
You can do following:
Take fresh copy of single-product folder from wp-content/plugins/woocommerce/templates and upload that in your theme's woocommerce folder
Looking at name of undefined function, it shows that this function might have been there only for formatting product title, so if you don't want to follow step 1 then just trace this function in your code and comment it out.
Let me know if it helps

Wordpress: how to implement a sequence of pages other than template hierarchy

Being fairly new to Wordpress, I’m trying to understand how to implement a sequence of pages other than the sequence suggested by the template hierarchy.
Consider (as an example) a website where different products can be purchased. We have the custom post type “products”. Products can be selected and added to the cart. When the user wants to check out, he will be offered a sequence of pages for doing the checkout for one or more products.
What would be the best way to implement such a sequence? In normal websites, it is just a number of pages linking to each other. In Wordpress, at the time of writing the code the page id’s are unknown and will only be known after creating the pages in wp admin. After this, we can use the page id’s, but when rolling out to a different environment (for example from development to test or live), we have to create the pages again in wp admin, resulting in new page id’s. The page id’s will have to be altered in code. This is undesirable in my opinion, error prone, right?
Is there a way of dealing with this in Wordpress other than synchronizing databases? In other words, what is the best design for implementing a sequence of pages linking to each other, other than the normal wordpress template hierarchy flow?
As a solution I created a way to access permalinks based on logical id's both from php and javascript. When rolling out to a different environment only the mappings from logical id's to urls should be changed in one array in functions.php and you're done.
To enqueue your .js file in functions.php:
wp_register_script( 'aom_script', get_template_directory_uri() . '/script.js', array('jquery') );
wp_localize_script( 'aom_script', 'my_js_permalinks', aom_get_page_permalinks() );
wp_enqueue_script('aom_script');
Code in functions.php for storing and accessing the permalinks:
function aom_get_page_permalinks() {
$page_permalinks = array(
"home"=>get_bloginfo('url'),
"someurl"=>get_permalink(14),
"anotherurl"=>get_permalink(16)
);
return $page_permalinks;
}
function aom_get_page_permalink($page_id) {
$page_permalinks = aom_get_page_permalinks();
return $page_permalinks[$page_id];
}
Now if you need a permalink in php:
aom_get_page_permalink('someurl');
And if you need a permalink in javascript:
my_js_permalinks.someurl;

Wordpress WooCommerce : Showing recent and random products on same page

I am using woocommerce for my online store. I want to show 20 most recent products from a category and then random products of same category on same page. Actually I don't want my old products to hide. When I use two shortcodes on same page nothing is displayed but separately both shortcodes work fine. I searched over the internet and found nothing. Please help
if you want to sort from newest to oldest in your archive (since not specified, this is my guess) or somewhere else, just add this code to your functions.php
add_filter(‘woocommerce_get_catalog_ordering_args’,‘am_woocommerce_catalog_orderby’);
function am_woocommerce_catalog_orderby( $args ) {
$args[‘meta_key’] = ‘_price’;
$args[‘orderby’] = ‘meta_value_num’;
$args[‘order’] = ‘desc’;
return $args;
}
Hope this helps.

how to display woocommerce product tags on single product page.?

I'm looking like a crazy person if there is a way to display the tags of a product on the single product page with woocommerce ( wordpress plugin). I can not find anything about ti and I've been trying to tweak the code, but without success . . .
if anybody has some high lite, it will be wonderful,
thank you very much
Ok, so depending on the WordPress theme you use, they might show automatically (just checked and it works right away with the "official" Storefront theme).
If you're writing a plugin (or a theme) though, you're most likely to want the PHP solution. In that case, according to this, you should be good to go with the following:
global $product; // gets the Product object (correspoding to the single page)
$product->get_tags( $product ); // returns an array with product tags
According to this post, you have to use get_terms('product_tag').

Custom Order Action in WooCommerce

I am trying to add Custom Order Action in WooCommerce Orders Page.
I want to add two new options in Bulk Order Actions Dropdown in WooCommerce
Mark Refunded
Mark On- Hold
Any help in this regard is highly appreciated.
There are two parts to solve with this objective.
The first part is to get a custom Order Action in the metabox of the individual Orders Page. I was trying to accomplish the same thing, but didn't find anything definitive on it, so I created a tutorial here:
http://neversettle.it/add-custom-order-action-woocommerce/
The second part is to add a custom order action in the Bulk Actions drop-down of the main Orders page. Skyverge has an excellent tutorial on that here:
http://www.skyverge.com/blog/add-custom-bulk-action/
The only specific thing you will need to take note of is to use the correct post_type. For WooCommerce orders you will need to use this in place of the first example on that tutorial:
add_action('admin_footer-edit.php', 'custom_bulk_admin_footer');
function custom_bulk_admin_footer() {
global $post_type;
if($post_type == 'shop_order') {
?>
<script type="text/javascript">
jQuery(document).ready(function() {
jQuery('<option>').val('export').text('<?php _e('Export')?>').appendTo("select[name='action']");
jQuery('<option>').val('export').text('<?php _e('Export')?>').appendTo("select[name='action2']");
});
</script>
<?php
}
}
Notice the shop_order replaces the post for the condition checking which post_type to add the bulk actions to.
But fundamentally, #brasofilo is correct - for the most part WooCommerce uses standard WordPress structures, post_type mechanisms, and taxonomies. The process is the same for adding a bulk action to the Orders page as it is to the Posts page.
However, you are correct about the custom Order Actions on the individual Orders page - that is WooCommerce only and you'll need to reference the first tutorial on how to solve that part.

Resources