• Hi there,

    Why is the add action below not working? I would like it to display on the single page below the course description. I have tried various add_actions and none seems to work.

    add_action( 'learn-press/after-main-content', 'display_custom_acf_data', 25 ); 
    function display_custom_acf_data() {
    global $post;

    // Fetch field values
    $prerequisites = get_field('recommended_prerequisites', $post->ID);
    $reference_material = get_field('reference_material', $post->ID);

    // Display Recommended Prerequisites if not empty
    if ( $prerequisites ) {
    echo '<div class="custom-meta-info prerequisites-info">' . esc_html($prerequisites) . '</div>';
    }

    // Display Reference Material if not empty
    if ( $reference_material ) {
    echo '<div class="custom-meta-info reference-material-info">' . esc_html($reference_material) . '</div>';
    }
    }

    Thanks!

    • This topic was modified 1 day, 13 hours ago by MyWorldz.
Viewing 1 replies (of 1 total)
  • Plugin Support brianvu-tp

    (@briantp)

    Hi MyWorldz,

    Thank you for reaching out to us!

    The hook you are currently using learn-press/after-main-content is not suitable for your requirements. This hook executes after the entire single course page content and sidebar, meaning your content would appear at the very bottom of the page rather than directly below the course description.

    To display your custom ACF data directly below the course description in the ‘Overview’ tab, you should use the ‘learn-press/after-single-course-description’ hook (located in ‘wp-content/plugins/learnpress/templates/single-course/tabs/overview.php’).

    Step 1:
    Replace your current code with the following snippet: You can add it to your child theme’s functions.php file:

    /**
    * Display custom ACF data below LearnPress course description
    */
    add_action('learn-press/after-single-course-description', 'display_custom_acf_data', 25);

    function display_custom_acf_data()
    {
    global $post;

    // Ensure it only runs on the single course page
    if (! is_singular('lp_course')) {
    return;
    }

    // Get field values
    $prerequisites = get_field('recommended_prerequisites', $post->ID);
    $reference_material = get_field('reference_material', $post->ID);

    // Display Recommended Prerequisites if not empty
    if ($prerequisites) {
    echo '<div class="custom-meta-info prerequisites-info">' . esc_html($prerequisites) . '</div>';
    }

    // Display Reference Material if not empty
    if ($reference_material) {
    echo '<div class="custom-meta-info reference-material-info">' . esc_html($reference_material) . '</div>';
    }
    }

    Step 2:
    You can configure your Advanced Custom Fields (ACF) by filling in the information as follows:

    • Go to ACF > Field Groups > Add New.
    • Create fields with names like this:
      • Field Label: Recommended Prerequisites
      • Field Name: recommended_prerequisites
      • Field Type: Text
      • Create the same for the ‘Reference Material’ field.
      • In the Location Rules section, set it to: Post Type is equal to Course (lp_course).
      • Save changes.

    Once you have done this, go to your course editor page, fill in the values for these new fields and click ‘Update’.

    The content will now be rendered right beneath the course description.

    Please try this and let us know if it works perfectly for you!

    Best regards,
    Brianvu-tp

Viewing 1 replies (of 1 total)

You must be logged in to reply to this topic.