Guest User

Untitled

a guest
Apr 20th, 2018
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.91 KB | None | 0 0
  1. add_action( 'added_post_meta', 'sliced_woocommerce_set_subscription_terms', 10, 4 );
  2. function sliced_woocommerce_set_subscription_terms( $meta_id, $post_id, $meta_key, $meta_value ) {
  3.  
  4. if ( $meta_key !== '_sliced_invoice_woocommerce_order' ) {
  5. return;
  6. }
  7.  
  8. // this is your woocommerce order number... use it to get any details you need from the order
  9. $order_number = $meta_value;
  10.  
  11. // add your subscription details here... here's a list of all the possible ones, use only what you need
  12. $subscription_meta = array(
  13.  
  14. // status - this is important, must be either "pending" (customer still needs to submit credit card info and start subscription), "active" (customer has already started subscription), or "cancelled".
  15. '_sliced_subscription_status' => 'pending',
  16.  
  17. // amount - this is the recurring amount fully formatted, including currency symbol (ex. $115.00)
  18. '_sliced_subscription_amount' => sliced_get_invoice_total( $post_id ),
  19.  
  20. // amount_raw — this is the recurring amount numbers only (ex. 115)
  21. '_sliced_subscription_amount_raw' => sliced_get_invoice_total_raw( $post_id ),
  22.  
  23. // interval_number — any number. For example, if the subscription is to charge once every month for 6 months, you would enter 1 here and "months" for interval_type
  24. '_sliced_subscription_interval_number' => 1,
  25.  
  26. // interval_type — can be "days", "months", or "years"
  27. '_sliced_subscription_interval_type' => "months",
  28.  
  29. // cycles_count — only if above is "fixed", then enter the number of cycles here. otherwise leave blank. For example, if the subscription is to charge once every month for 6 months, you would enter 6 here.
  30. '_sliced_subscription_cycles_count' => 6,
  31.  
  32. // cycles_type — can be either "fixed" (a set number of charges), or "infinite" (charge until cancelled)
  33. '_sliced_subscription_cycles_type' => "fixed",
  34.  
  35. // trial — if you want a trial period, put 1 here. otherwise leave blank.
  36. '_sliced_subscription_trial' => 1,
  37.  
  38. // trial_interval_number — any number
  39. '_sliced_subscription_trial_interval_number' => 7,
  40.  
  41. // trial_interval_type — "days", "months", or "years"
  42. '_sliced_subscription_trial_interval_type' => "days",
  43.  
  44. // trial_cycles_count — any number
  45. '_sliced_subscription_trial_cycles_count' => 1,
  46.  
  47. // trial_amount — any amount
  48. '_sliced_subscription_trial_amount' => 0,
  49.  
  50. // receipts — put 1 if you want receipt invoices to be created for each successive payment, otherwise blank
  51. '_sliced_subscription_receipts' => 1,
  52.  
  53. // receipts_auto_send — can be either "yes" or "no".
  54. '_sliced_subscription_receipts_auto_send' => "yes",
  55.  
  56. // braintree_plan - required only if planning to use Braintree for payments
  57. '_sliced_subscription_braintree_plan' => "xyzzy123",
  58.  
  59. );
  60.  
  61. foreach ( $subscription_meta as $key => $value ) {
  62. update_post_meta( $post_id, $key, $value );
  63. }
  64.  
  65. }
Add Comment
Please, Sign In to add comment