Skip to content

Instantly share code, notes, and snippets.

View fmurdeni's full-sized avatar
🇵🇸
Stand With Palestine

Feri Murdeni fmurdeni

🇵🇸
Stand With Palestine
View GitHub Profile
@fmurdeni
fmurdeni / functions.php
Created October 19, 2022 08:02 — forked from tripflex/functions.php
Programmatically create a WooCommerce Subscription and associated WooCommerce Order
<?php
public function give_user_subscription( $product, $user_id, $note = '' ){
// First make sure all required functions and classes exist
if( ! function_exists( 'wc_create_order' ) || ! function_exists( 'wcs_create_subscription' ) || ! class_exists( 'WC_Subscriptions_Product' ) ){
return false;
}
$order = wc_create_order( array( 'customer_id' => $user_id ) );