Solved

Overwrite Wordpress Function

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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
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 reset a WordPress password if you are locked out and cannot reset the password. A typical use would be if you cannot access the email to which WordPress would send the password recovery email to…
The purpose of this video is to demonstrate how to add AdSense Ads to a WordPress Website, and how to set up WordPress to automatically place Ads in Sidebars. This will be demonstrated using a Windows 8 PC. Log into your AdSense account. : Cli…

785 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