Solved

Overwrite Wordpress Function

Posted on 2014-09-10
5
304 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
Comment Utility
Where is this class defined?
0
 
LVL 108

Assisted Solution

by:Ray Paseur
Ray Paseur earned 166 total points
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

In order to have all security and back ups taken care of, WordPress users can sign up for services with WP Engine.
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 viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

763 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

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now