我正在使用一个名为 Pay for Post with Woocommerce 的插件,它隐藏了帖子或部分帖子,并允许您使用 woocommerce 产品出售对该帖子的访问权。插件作者向我发送了这个脚本,我可以用它来创建页面模板:
<?php
if(Woocommerce_Pay_Per_Post_Helper::is_protected()){
//Page is protected
if(Woocommerce_Pay_Per_Post_Helper::has_access()){
// Do what you want to do if they have access to the page
} else {
// the page is protected and the user does NOT have access
echo Woocommerce_Pay_Per_Post_Helper::get_no_access_content();
}
} else {
//Page is not protected do what you need to do.
}
我正在尝试根据产品是否已购买来创建页面的自定义版本,但我无法让我的高级自定义字段变量在我的页面模板中正确呈现。这是我为测试目的创建的。
<?php while ( have_posts() ) : the_post(); ?>
<?php
$video_screenshot = the_field("video_screenshot");
$video_link = the_field("video_link");
if(Woocommerce_Pay_Per_Post_Helper::is_protected()){
//Page is protected
if(Woocommerce_Pay_Per_Post_Helper::has_access()){
// Do what you want to do if they have access to the page
echo '<div class="container"><div class="row"><div class="col-12"><iframe width="560" height="315" src="{$video_link}" frameborder="0" allowfullscreen></iframe></div></div></div>';
} else {
// the page is protected and the user does NOT have access
echo Woocommerce_Pay_Per_Post_Helper::get_no_access_content();
echo '<div class="container"><div class="row"><div class="col-12"><img src="{$video_screenshot}" /></div></div></div>';
}
} else {
//Page is not protected do what you need to do.
}
?>
<?php endwhile; // end of the loop. ?>
在上面的示例中,当我查看尚未购买的页面时,它应该呈现一个链接,其中包含从帖子自定义字段生成的源,但它只是打印字符串内的值:
<img src="{$video_screenshot}">
我已经尝试了很多方法,但我无法确定如何将这些变量包含在字符串中并让它们按应有的方式打印。任何帮助将非常感激!
30秒到达战场