gocodebox / gocodebox/lifterlms

Proposal to expand is_lifterlms() to check for sales page

Open
#628 3 comments 0 reactions 0 assignees View on GitHub
good first issue hacktoberfest help wanted Type: Enhancement Type: Feature Request
Dominant language
PHP
Stars
212
Forks
140
Avg merge
2d 14h
Merged PRs (30d)
19

Description

Hi there, I would like to share a little piece of code that I would like to see implemented in LifterLMS but I didn't send a PR because the code is still really basic and it serve my needs.

Basically when I heard that was possible to set a specific landind page and use it as a sales page I was really happy about it because I think that this feature is really important to improve the course and membership pages but I was really surprised when I used the `is_lifterlms()` wrapper function and discovered that it didn't fire when I was on one of those pages.

I am usign the `is_lifterlms()` function to add a class at the body tag in order to simply override some LifterLMS styles and I think, at least in this use case, important to make the function work even on the sales pages because it should be common for those pages to insert LifterLMS data via shortcode as:
* access plan buttons
* course outline
* course syllabus
* courses
* pricing table
* ...

I think that a user could use any of the shortcodes dedicated to LifteLMS but even if I add them to the page the `is_lifterlms()` will not fire.

The code below satisfy my needs creating a simple `is_sales_page()` function that I added to the checks of `is_lifterlms()`. It is really basic but if you tell me that is the way to go I can attempt to create a complete solution and send you a PR.

```php
/**
* Is Sales Page
* @return bool
* @since 3.22.0
*/
if ( ! function_exists( 'is_sales_page' ) ) {

function is_sales_page() {
$post_id = get_the_ID();
$args = array(
'post_type' => array( 'course', 'llms_membership' ),
'meta_query' => array(
array(
'key' => '_llms_sales_page_content_page_id',
'value' => $post_id,
'compare' => '=',
)
)
);

$query_meta = new WP_Query( $args );

if( $query_meta->post_count > 0 ){
return true;
}

return false;
}
}
```

This is how I modified the `is_lifterlms()` to include the new function:
```php
if ( ! function_exists( 'is_lifterlms' ) ) {
function is_lifterlms() {
return apply_filters( 'is_lifterlms', ( is_courses() || is_course_taxonomy() || is_course() || is_lesson() || is_membership() || is_memberships() || is_quiz() || is_sales_page() ) );
}
}
```

Let me know if this is the way to go or if you are looking to find a different solution.

IMO I think that the solution I came up with is heavy on the database because for each page load it will check all the course and membership CPT to find a match. Maybe it will be better to insert a specific meta in the sales page when this is part of the same WordPress installation so we can get which course or membership is linked with this page in the same database call.

All the best and thank you for all your work!

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.