Skip to content

Instantly share code, notes, and snippets.

@Lonsdale201
Created February 22, 2025 16:39
Show Gist options
  • Save Lonsdale201/52198a4c896c67cf12d8c00c163551ad to your computer and use it in GitHub Desktop.
Save Lonsdale201/52198a4c896c67cf12d8c00c163551ad to your computer and use it in GitHub Desktop.
FluentCRM List + programmed download link for woocommerce (Download myaccount section)
// place the code in the child theme functions.php or a custom code snippets plugin like Fluent Snippts etc..
// This code programmed for the user in the woocomemrce downloads page will add 1 (or more if you want) file
// that ppls can download, this differs in that he does not have to buy the product, in return the link does not
// point to the link in the woocommerce folder.
// if ($list->id == 5) { -> changen the ID with your own list id (fluentcrm)
add_filter( 'woocommerce_customer_get_downloadable_products', function( $downloads ) {
if ( ! is_user_logged_in() || ! function_exists( 'FluentCrmApi' ) ) {
return $downloads;
}
$user_id = get_current_user_id();
$contactApi = FluentCrmApi('contacts');
$contact = $contactApi->getCurrentContact();
if ( !$contact ) {
return $downloads;
}
$user_lists = $contact->lists;
$is_in_list = false;
foreach ($user_lists as $list) {
if ($list->id == 5) { // FluentCRM List ID: 5 -> replace with your own List ID
$is_in_list = true;
break;
}
}
// replace this with your own config like "product name" You don't need a
// real product name, but you should display something in that column as well
if ($is_in_list) {
$downloads[] = array(
'product_name' => 'Exclusive File for List 3 Members',
'download_name' => 'Download the file', // this will your download button label
'download_url' => 'add your link here', // add your media link here
);
}
return $downloads;
}, 9999);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment