0
votes

My website (http://www.chicagokaraokenight.com/wordpress) is a karaoke directory where bars can list karaoke nights for free OR upgrade to a premium or featured premium listing (paid packages) to receive a more robust profile.

As part of the benefit to upgrading to a paid package, I'd like to have some widgets disappear on the paid listings.

My theme author (Listify) recommended the plugin Widget Logic and said the following:

Use https://wordpress.org/plugins/widget-logic/ to show/hide a widget depending on certain criteria.

Using something like:

wc_paid_listings_get_user_package( $package_id )

I'm still a little unclear on exactly what I should edit the logic to say and hoping someone can help. I know how to get the package ID's (if I hover over the packages on the Product page I can see them).

The widgets I wish to hide based on a listing being a paid package are Google ads, recent listings, and featured listings.

Thanks!

UPDATE: The WC Paid Listing Plugin developer has given me this code and info after I mentioned the Free package ID is 971:

global $post;
$used_package = get_post_meta( $post->ID, '_package_id', true );
if ( 971 === $used_package ) {
// Free
}

You could wrap this in a custom function to use in widget logic:

function job_was_posted_with_package( $package_id ) {
global $post;
$used_package = get_post_meta( $post->ID, '_package_id', true );
return $package_id == $used_package;
}

Called via:

job_was_posted_with_package( 971 );

Do I have what I need now? Can someone help me identify what needs to go into functions.php, what should go in Widget Logic, etc?

2

2 Answers

0
votes

Widget Logic is pretty straight forward in form of inner workings.

I assume you have a widget already created what you would need to do is make or use a function that returns a Boolean

function is_paid_member(){
   // Verification Code here

   return TRUE;
}

Then place is_paid_member() in the widget logic field of the affected Widget.

If you can print some code for the verification method i can most likely edit the Answer to make it workable.

Please clarify the following, is the Widget always going to be available in the Administrative interface? If yes then it would go outside of the Widget Logic scope which affect mostly activated Widgets displaying on the frontend.

0
votes

Per Mike Jolley from WP Paid Listings, the correct code is:

function job_was_posted_with_package( $package_id ) {
global $post;
$used_package = get_post_meta( $post->ID, '_package_id', true );
return $package_id == $used_package;
}

which should be placed in the functions.php file.

And then:

( ! job_was_posted_with_package( ID ) && ! job_was_posted_with_package( ID ) )

or

job_was_posted_with_package( ID )

should be the condition entered into Widget Logic on the widget you want to show/hide.