WPPizza – A Restaurant Plugin for WordPress › Support › General Support › The wppizza_filter_orderhistory_order_info breaks order history overview
- AuthorPosts
- 16 April, 2019 at 10:45 am #42619
Hi Olly,
I am trying to update the order history view by adding an Id from a service I am using to the Order history info. I found a thread where adding a total sum beneath the order update info that seemd would do the trick but when I applay this filter all the orders in order history disappear.
public function my_orderinfo_add_id($markup, $order_id, $customer_details, $order_details){ $markup['last_update'] .='<span>test</span>'; return $markup; }
And I call it like so
$this->loader->add_action('wppizza_on_order_execute', $plugin_admin, 'get_wppizza_order', 10, 3); $this->loader->add_filter( 'wppizza_filter_orderhistory_order_info', $plugin_admin, 'my_orderinfo_add_id', 10, 4 );
When I comment out the add_filter the orders show up again.
Any ideas?
Best regards
16 April, 2019 at 1:39 pm #42620have you enabled debug ?
i am pretty certain it will tell you what the issue is
https://docs.wp-pizza.com/troubleshooting/in short, this is not how you use filters
you either doadd_filter( 'wppizza_filter_orderhistory_order_info', 'my_orderinfo_add_id', 10, 4 );
or
add_filter( 'wppizza_filter_orderhistory_order_info', array($this/*or some distinct class*/, 'my_orderinfo_add_id'), 10, 4 );
depending on where/how you use it
17 April, 2019 at 9:42 am #42640Hi Olly and thanks responding so quickly! 😀
Yes I had debugging on but locally I’m not getting any errors. I did do a test on a live staging server and I do get an error claiming that I have only passed 2 arguments but 4 are needed. Strange because as you can see in my code snippet above I have 4 arguments lined up.I did try another thing and that was to declare 2 arguments in the add_filter method and then pass only 2 arguments to the function and then It worked for my purposes for now.
add_filter( 'wppizza_filter_orderhistory_order_info', 'my_orderinfo_add_total', 10, 2); function my_orderinfo_add_total($markup, $order_id){ $markup['order_update'] .='<div>test</div>'; return $markup; }
Like I said this works with the above solution but perhaps there is something going on under the hood that needs investigating so below is the error I get when using 4 suggested arguments.
Error with 4 arguments:
Fatal error: Uncaught ArgumentCountError: Too few arguments to function my_orderinfo_add_total(), 1 passed in /www/wp-includes/class-wp-hook.php on line 288 and exactly 4 expected in /www/wp-content/themes/shakepizza/functions.php:390 Stack trace: #0 /www/wp-includes/class-wp-hook.php(288): my_orderinfo_add_total(Array) #1 /www/wp-includes/plugin.php(208): WP_Hook->apply_filters(Array, Array) #2 /www/wp-content/plugins/wppizza/classes/modules/mod.orderhistory.orderhistory.php(1393): apply_filters(‘wppizza_filter_…’, Array, Array) #3 /www/wp-content/plugins/wppizza/classes/modules/mod.orderhistory.orderhistory.php(652): WPPIZZA_MODULE_ORDERHISTORY_ORDERHISTORY->order_history_markup() #4 /www/wp-includes/class-wp-hook.php(286): WPPIZZA_MODULE_ORDERHISTORY_ORDERHISTORY->order_history_results(”) #5 /www/wp-includes/class-wp-hook.php(310): WP_Hook->apply_filters(”, Array) #6 /www/wp-includes/plugin.php(465): WP_Hook->do_action(Array) #7 /www/wp-content/plugins/wppizza/classes/subpages/subpage.order_history.php(243): do_act in /www/wp-content/themes/shakepizza/functions.php on line 39017 April, 2019 at 11:51 am #42654In essence, you found some old codesnippet (somewhere on here i guess) that was related to wppizza v2.x.
The “official” documentation – if you will – for v3.x can be found here https://docs.wp-pizza.com/That said, not all the snippets that were mentioned here on this forum in the past have yet been copied/updated there (some do not even exist in v3.x anymore anyway but were accurate at the time before v3.x).
The docs will always be work in progress I suppose and will be amended on “as needed” / “as requested” basis.In any event, the error you were getting is “correct” in so far that in v3 only 2 arguments are now passed on as the 2nd one contains all data now that was previously passed on in the additional arguments (there were actually 7 altogether)
So cutting a long story short: yes, there are now only 2 parameters so the filter should indeed be something like
add_filter( 'wppizza_filter_orderhistory_order_info', 'my_function', 10, 2);
or
add_filter( 'wppizza_filter_orderhistory_order_info', array($this/*or some distinct class*/, 'my_function'), 10, 2);
I hope that clears things up somewhat
cheers
18 April, 2019 at 8:20 am #42662Thats great and clarified! Thank you for all your help!
cheers
- AuthorPosts
- The topic ‘The wppizza_filter_orderhistory_order_info breaks order history overview’ is closed to new replies.