Skip to content

Instantly share code, notes, and snippets.

Avatar

Thomas Le Coz ThomasLeCoz

View GitHub Profile
View zapier_python_content_curation_v2.py
import json
auth_token_sniply = 'YOUR_SNIPLY_AUTH_TOKEN'
campaign_id = 'YOUR_CAMPAIGN_ID'
headers = {'Authorization': 'Bearer ' + auth_token_sniply, 'Content-Type': 'application/json'}
payload = {'url': input['url'], 'campaign': campaign_id}
r = requests.post('https://snip.ly/api/v2/links/', data=json.dumps(payload), headers=headers)
View zapier_python_content_curation.py
import json
auth_token_sniply = 'YOUR_AUTH_TOKEN'
campaign_id = 'YOUR_CAMPAIGN_ID'
headers = {'Authorization': 'Bearer ' + auth_token_sniply, 'Content-Type': 'application/json'}
payload = {'url': input['url'], 'campaign': campaign_id}
r = requests.post('https://snip.ly/api/v2/links/', data=json.dumps(payload), headers=headers)
View give_course_access_func.php
function give_course_access( $user_id, $subscription_key ) {
// Get the course ID related to the subscription
$subscription = WC_Subscriptions_Manager::get_subscription( $subscription_key );
$courses_id = get_post_meta($subscription['product_id'], '_related_course', true);
$start_date = $subscription['start_date'];
error_log('Start Date :' . $start_date . ' Epoch: ' . strtotime($start_date));
// Update access to the courses
if ($courses_id && is_array($courses_id)) {
View send_receipt_func.php
function send_receipt($order_id){
//if($new_status == 'processing' && $status != 'completed' || $new_status == 'completed' && $status == 'processing'){
if($status != 'processing' && $status != 'completed') {
$order = new WC_Order($order_id);
$products = $order->get_items();
foreach($products as $product){
$courses_id = get_post_meta($product['product_id'], '_related_course', true);
if($courses_id && is_array($courses_id)){
foreach($courses_id as $cid) {
View coupon-generator.php
<?php
/** PHP Script to generate WooCommerce temporary coupon from ActiveCampaign **/
/** By Thomas Le Coz - http://thomaslecoz.com **/
/** Configuration **/
$key = "YOURSECRETKEY"; // Secret key you should add to the webhook URL too: http://yourwebsite.com/coupon-gen/coupon-generator.php?key=YOURSECRETKEY
$ck_woocommerce = 'YOUR_WOOCOMEMRCE_API_CLIENT_KEY'; // WooCommerce API client key
$cs_woocommerce = 'YOUR_WOOCOMEMRCE_API_SECRET_KEY'; // WooCommerce API secret key
// Catch Hook from ActiveCampaign & basic security check
@ThomasLeCoz
ThomasLeCoz / ld-wc-constructor.php
Created Feb 24, 2015
My active WCSubs hooks to sell LD Courses by installments
View ld-wc-constructor.php
function __construct() {
// [...]
add_action('cancelled_subscription', array($this, 'remove_course_access'), 10, 2);
add_action('subscription_put_on-hold', array($this, 'remove_course_access'), 10, 2);
add_action('activated_subscription', array($this, 'give_course_access'), 10, 2);
}
@ThomasLeCoz
ThomasLeCoz / remove-expiry-hook.php
Created Feb 24, 2015
Remove the expiry hook from LearnDash WooCommerce Add-on
View remove-expiry-hook.php
// Remove this line from the constructor
add_action('subscription_expired', array($this, 'remove_course_access'), 10, 2);
@ThomasLeCoz
ThomasLeCoz / ld_woosubs_course_access.php
Created Feb 15, 2015
Functions to give or remove access to LearnDash courses
View ld_woosubs_course_access.php
// Remove Access to the course linked to the subscription key
function remove_course_access( $user_id, $subscription_key ) {
// Get the course ID related to the subscription
$subscription = WC_Subscriptions_Manager::get_subscription( $subscription_key );
$courses_id = get_post_meta($subscription['product_id'], '_related_course', true);
// Update access to the courses
if ($courses_id && is_array($courses_id)) {
foreach ($courses_id as $course_id) {
@ThomasLeCoz
ThomasLeCoz / ld_woosubs_actions.php
Last active Aug 29, 2015
WooCommerce subscriptions hooks for LearnDash course access
View ld_woosubs_actions.php
function __construct() {
[...]
add_action('cancelled_subscription', array($this, 'remove_course_access'), 10, 2);
add_action('subscription_put_on-hold', array($this, 'remove_course_access'), 10, 2);
add_action('subscription_expired', array($this, 'remove_course_access'), 10, 2);
add_action('activated_subscription', array($this, 'give_course_access'), 10, 2);
}
@ThomasLeCoz
ThomasLeCoz / render_course_selector.php
Last active Aug 29, 2015
Display LearnDash Courses on Subscription Product
View render_course_selector.php
function render_course_selector() {
global $post;
$courses = $this->list_courses();
echo '<div class="options_group show_if_course show_if_simple">';
[...]
}