Solved

Overwrite Wordpress Function

Posted on 2014-09-10
5
312 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 110

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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

This article discusses four methods for overlaying images in a container on a web page
This article shows the steps required to install WordPress on Azure. Web Apps, Mobile Apps, API Apps, or Functions, in Azure all these run in an App Service plan. WordPress is no exception and requires an App Service Plan and Database to install
The purpose of this video is to demonstrate how to Import and export files in WordPress. 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 : Click on Too…
The purpose of this video is to demonstrate how to set up an RSS Feed on a WordPress Website. This will be demonstrated using a Windows 8 PC. Feedburner will be used for this demonstration. Go to your WordPress login page. This will look like the…

696 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