最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Load Woocommerce and Wordpress Functions Outside

programmeradmin0浏览0评论

I have this structure on my website:

And inside the game folder (the index.php file) I'm trying to call WooCommerce and WordPress functions, to see if the user has a membership (I'm using WooCommerce Membership plugin).

With this code:

require_once('../wp-load.php' );

if (wc_memberships_is_post_content_restricted($id) && !wc_memberships_is_user_member() && !current_user_can('administrator')) {
     header("Location: https:/localhost/mywebsite");
}

wc_memberships_is_post_content_restricted(); is a WooCommerce Membership function... on the localserver (wampserver) it's working, but when I try to run on my online host the functions do not work.

I also used var_dump( get_defined_functions() ); to see if the functions are properly load, and it's...

I have this structure on my website:

And inside the game folder (the index.php file) I'm trying to call WooCommerce and WordPress functions, to see if the user has a membership (I'm using WooCommerce Membership plugin).

With this code:

require_once('../wp-load.php' );

if (wc_memberships_is_post_content_restricted($id) && !wc_memberships_is_user_member() && !current_user_can('administrator')) {
     header("Location: https:/localhost/mywebsite");
}

wc_memberships_is_post_content_restricted(); is a WooCommerce Membership function... on the localserver (wampserver) it's working, but when I try to run on my online host the functions do not work.

I also used var_dump( get_defined_functions() ); to see if the functions are properly load, and it's...

Share Improve this question edited Jan 21, 2021 at 7:43 Tony Djukic 2,2774 gold badges18 silver badges34 bronze badges asked Jan 20, 2021 at 14:01 Jonathan A.Jonathan A. 111 bronze badge 1
  • 1 "...and it's..." what? The SkyVerge team are really good about providing support so you should reach out to them to ask about functions that exist within their plugin. Third-Party plugins and WooCommerce are off-topic on WPSE. – Tony Djukic Commented Jan 20, 2021 at 15:22
Add a comment  | 

1 Answer 1

Reset to default 0

When I am using a php script in my Wordpress installation, I have special functions in the child theme, in functions.php So I have to require that as well.

Also you want to make sure that SHORTINIT is not defined as TRUE, or else you lose many Wordpress functions.

Here is how I do it.

ignore_user_abort(true);
$path = $_SERVER['DOCUMENT_ROOT'];
require( $path.'/wp-load.php' );
require_once( get_stylesheet_directory() . '/../Divi-child/functions.php' );
// now all my functions are loaded
发布评论

评论列表(0)

  1. 暂无评论