Skip to content

Instantly share code, notes, and snippets.

@hiddenkirby
Created July 10, 2016 22:01
Show Gist options
  • Save hiddenkirby/e45c2a59b190beeeadf27af0128d6105 to your computer and use it in GitHub Desktop.
Save hiddenkirby/e45c2a59b190beeeadf27af0128d6105 to your computer and use it in GitHub Desktop.
// hooking woocommerce purchase to updating the users sub level
function woocommerce_subscription_update_hook($order_id = 0){
$user_id = get_current_user_id();
//get product slug from order_id
$order = new WC_Order( $order_id );
$items = $order->get_items();
$product_slug = '';
foreach ( $items as $item ){
$product_slug = $item['name'];
}
// need $wc_package_title from wc slug
$wc_package_title = get_package_title_from_product_slug($product_slug);
$packages = Horizon_Packages_Logic::get_packages_choices();
foreach ( $packages as $package_key => $package_value ){
if ($wc_package_title == $package_value){
_log('Setting ' . $user_id . '\'s package to: ' . $wc_package_title);
//$user_id, $package_id required
do_action('horizon_update_user_subscription', $user_id, $package_key );
}
}
}
add_action('woocommerce_payment_complete', 'woocommerce_subscription_update_hook');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment