如何基于ACF数组值通过woocommerce成员资格强制公开内容

时间:2019-03-28 19:50:23

标签: wordpress advanced-custom-fields woocommerce-memberships

我正在尝试创建一个函数,如果某个帖子存在ACF值,它将强制woocommerce成员资格内容公开。

我能够在同事的帮助下创建一个单独的函数,该函数会检查该值并将HTML应用于content-single.php模板:

          <?php $status = get_field('status'); ?>
              <?php if( in_array('10', $status) ): ?>
                 <h2 class="HTML">HTML</h2>
              <?php endif; ?>

我还发现woocommerce-memberships功能,该功能可根据是否选中复选框将帖子设为公开。

public function output( \WP_Post $post ) {

    $this->post = $post;

    ?>
    <h4><?php esc_html_e( 'Content Restriction', 'woocommerce-memberships' ); ?></h4>

    <?php woocommerce_wp_checkbox( array(
        'id'          => '_wc_memberships_force_public',
        'class'       => 'js-toggle-rules',
        'label'       => __( 'Disable restrictions', 'woocommerce-memberships' ),
        'description' => __( 'Check this box if you want to force the content to be public regardless of any restriction rules that may apply now or in the future.', 'woocommerce-memberships' ),
    ) ); ?>

    <?php if ( 'yes' === wc_memberships_get_content_meta( $post, '_wc_memberships_force_public', true ) ) : ?>hide<?php endif; ?>">

最后一行包含我感兴趣的动作:

    wc_memberships_get_content_meta( $post, '_wc_memberships_force_public', true )

我不确定如何正确设置其格式,但目标是在更新帖子时发生类似的事情:

          /* If 10 is in $status array */
          <?php if( in_array('10', $status) ): ?>

          /* Then set the post _wc_memberships_force_public value to true */
             wc_memberships_get_content_meta( $post, '_wc_memberships_force_public', true )

          <?php endif; ?>

0 个答案:

没有答案