【发布时间】:2021-03-30 02:36:12
【问题描述】:
这是迄今为止我得到的最好的结果,但我遇到了很多错误。
从主要问题开始;它确实重定向到正确的 url,但页面没有显示任何内容。
这是我正在尝试的:Reference code
这是我的代码。
function pre_process_shortcode() {
if (!is_singular()) return;
global $post;
$user = wp_get_current_user();
$product_id = 27;
$product_bought = wc_customer_bought_product( $user->user_email, $user->ID , $product_id );
if (!empty($post->post_content)) {
$regex = get_shortcode_regex();
preg_match_all('/'.$regex.'/',$post->post_content,$matches);
if (!empty($matches[2]) && in_array('protactPage',$matches[2]) && $product_bought && is_user_logged_in()) {
wp_redirect('https://learndigital-mena.com/cart-2/');
exit();
} else {
// login form or redirect to login page
wp_redirect('https://learndigital-mena/my-account/');
exit();
}
}
}
add_action('template_redirect','pre_process_shortcode',1);
【问题讨论】:
-
奥马尔,您似乎没有正确添加链接,只有参考文本进入您的问题,请编辑您的问题并正确重新应用参考代码链接,确保添加了链接本身。
-
好的,我会为你添加到你的问题中。
-
请编辑您的问题并将任何文本编辑应用到您的链接内容;)只需点击问题底部的编辑按钮,然后添加或编辑我添加的文本/链接。
标签: php woocommerce product shortcode