Solved

Wordpress Filters

Posted on 2014-09-14
8
131 Views
Last Modified: 2014-09-25
Yesterday I asked a very similar  question but the answer does not work in this case.  I have a Wordpress Website that has a Core Function and I want to change a label inside of the function.  I have created my own custom-functions.php file.

The Core Wordpress File is as follows:
	public function get_columns(){

		$columns = array(
			'cb'                  => '<input type="checkbox" />',
			'status'              => __( 'Status', 'woocommerce-subscriptions' ),
			'title'               => __( 'Subscription', 'woocommerce-subscriptions' ),
			'user'                => __( 'User', 'woocommerce-subscriptions' ),
			'order_id'            => __( 'Order', 'woocommerce-subscriptions' ),
			'start_date'          => __( 'Start Date', 'woocommerce-subscriptions' ),
			'expiry_date'         => __( 'Expiration', 'woocommerce-subscriptions' ),
			'end_date'            => __( 'End Date', 'woocommerce-subscriptions' ),
			'trial_expiry_date'   => __( 'Trial End Date', 'woocommerce-subscriptions' ),
			'last_payment_date'   => __( 'Last Payment', 'woocommerce-subscriptions' ),
			'next_payment_date'   => __( 'Next Payment', 'woocommerce-subscriptions' ),
			'renewal_order_count' => __( 'Renewals', 'woocommerce-subscriptions' ),
		);

		return $columns;
	}

Open in new window

I'm trying to use the manage_edit function but I don't think I have it correct.  I want to change the Label 'Order' to 'My Orders':
add_filter ( 'manage_edit-get_columns', 'filter_order_id', 11 );
function filter_order_id( $columns)	{
	$columns['order_id'] = __( 'Policy Number', 'woocommerce-subscriptions' );
	return $columns;
}

Open in new window

0
Comment
Question by:rgranlund
  • 5
  • 3
8 Comments
 
LVL 18

Expert Comment

by:Hube02
ID: 40322101
This requires using the filter hook that's associated with the post type you're going to change. With WooCommerce, that means the post type name should be "product".

function alter_product_columns($columns) {
  // make modifications to the columns here
  return $columns
}
add_filter('manage_edit-product_columns', 'alter_product_columns', 99);

Open in new window


You may need to set a high priority to override the filter function used in WC, for example I used 99 above. You may need to look into the WC code the see what they are using and just use a bigger number.

The filter for changing columns is in the form:
manage_edit-{$POST_TYPE}_columns

Open in new window


and the filter for changing the content of columns is:
manage_{$POST_TYPE}_posts_custom_column

Open in new window

0
 
LVL 7

Author Comment

by:rgranlund
ID: 40322107
I'm not sure how to re-write my function above to match what you have offered.  Can you elaborate just a bit?
0
 
LVL 18

Expert Comment

by:Hube02
ID: 40322120
I think that what you have already should work

function alter_product_columns($columns) {
  $columns['order_id'] = __( 'Policy Number');
  return $columns
}
add_filter('manage_edit-product_columns', 'alter_product_columns', 20);

Open in new window


I removed the 'woocommerce-subscriptions' text domain from the __() function, I doubt that WC has that translated. I also changed the priority, did some digging around in WC and they are using the default, which is 10.
0
 
LVL 18

Expert Comment

by:Hube02
ID: 40322129
The only real problem with what you had was the hook you were using to call your function, sorry, I may have confused things by adding a lot of extra stuff.

The hook that's important is manage_edit-{$POST_TYPE}_columns
WC uses the post type of product
so you replace {$POST_TYPE} with product and the hook becomes manage_edit-product_columns
0
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
LVL 7

Author Comment

by:rgranlund
ID: 40322175
Sorry the following does not work:
function alter_product_columns($columns) {
  $columns['order_id'] = __( 'Policy Number');
  return $columns
}
add_filter('manage_edit-product_columns', 'alter_product_columns', 20);

Open in new window


What else can I supply to help us determine the issue?
0
 
LVL 18

Expert Comment

by:Hube02
ID: 40322216
what is the URL of the page with these columns?

I don't need your site URL, just the part past /wp-admin/
0
 
LVL 7

Author Comment

by:rgranlund
ID: 40323340
Thank you for your continued help:
wp-admin/admin.php?page=subscriptions
0
 
LVL 18

Accepted Solution

by:
Hube02 earned 500 total points
ID: 40324200
k, this is not a custom post type page, which is why the filter isn't working. This is a custom page associated with a premium subscriptions extension.  Looking at this documentation, http://docs.woothemes.com/document/subscriptions/develop/filter-reference/, it does not appear that WC supplies a hook that allows you to change these columns.

Really, the filter you were trying to use will only work if your on a CPT admin page.  I'm not not sure you can do what you want to do without direct modification of the extension code.
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
The purpose of this video is to demonstrate how to exclude a particular blog category from the main blog page. This is can be used when a category already has its own tab, or you simply want certain types of posts not to show up on the main blog. …
The viewer will learn how to dynamically set the form action using jQuery.

744 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

16 Experts available now in Live!

Get 1:1 Help Now