Solved

Overwrite Wordpress Function

Posted on 2014-09-10
5
309 Views
Last Modified: 2014-09-25
I want to overwrite / replace a Wordpress, WooCommerce function.

This is what I have:
class WC_Meta_Box_Order_Items {

	/**
	 * Output the metabox
	 */
	public static function output( $post ) {
		global $thepostid, $theorder;

		if ( ! is_object( $theorder ) ) {
			$theorder = wc_get_order( $thepostid );
		}

		$order = $theorder;
		$data  = get_post_meta( $post->ID );

		include( 'views/html-order-items.php' );
	}
}

Open in new window


I want to replace:       public static function output( $post ) {
with:       public static function myPersonalOutput( $post ) {
0
Comment
Question by:rgranlund
5 Comments
 
LVL 70

Expert Comment

by:Jason C. Levine
ID: 40315416
Where is this class defined?
0
 
LVL 109

Assisted Solution

by:Ray Paseur
Ray Paseur earned 166 total points
ID: 40315581
Jason can give you more of the details.  The theory is that you would extend the WC_Meta_Box_Order_Items class and add your own output() method.
0
 
LVL 70

Accepted Solution

by:
Jason C. Levine earned 167 total points
ID: 40315978
The theory is that you would extend the WC_Meta_Box_Order_Items class and add your own output() method.

Uh, maybe.  Depends on where that function lives...if it's part of the WooCommerce core package and you simply extend it, the changes will get blown away when WooCommerce updates (which they do a few times a year).  This is one of those questions where there is an actual "WordPress" way to do it but I need more information to give an actual, correct answer.

What I'm thinking is the output() function should be hook-able but not everything is....
0
 
LVL 18

Assisted Solution

by:Hube02
Hube02 earned 167 total points
ID: 40316754
More information is definitely needed, are you trying to change the template used for displaying the order, that's built into WooCommerce? If you need to change or add meta values then get_post_meta is hookable. There may also be hooks in WooCommerce that you can use to do what you need. Like others have commented, without knowing why you want to replace the class it's hard to find a solution that works within WP without hacks that will cause problems when you update WP or WC.
0
 
LVL 7

Author Comment

by:rgranlund
ID: 40317296
Ultimately what I am trying to do is to "hook" in from outside of WooCommerce through a custom-functions.php and replace this line:
include( 'views/html-order-items.php' );

with:
includes('MY_DIRECTORY/views/html-order-items.php');
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

So you have coded your own WordPress plugin and now you want to allow users to upload images to a folder in the plugin folder rather than the default media location? Follow along and this article will show you how to do just that!
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
The purpose of this video is to demonstrate how to set up the permalinks on a WordPress Website. This will be demonstrated using a Windows 8 PC. Go to your WordPress login page. This will look like the following: mywebsite.com/wp-login.php : Go t…
The is a quite short video tutorial. In this video, I'm going to show you how to create self-host WordPress blog with free hosting service.

827 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question