Skip to content

Instantly share code, notes, and snippets.

@swoboda
Last active February 13, 2019 20:59
Show Gist options
  • Save swoboda/fa3f9e11dd296602821ac7c7ab24291d to your computer and use it in GitHub Desktop.
Save swoboda/fa3f9e11dd296602821ac7c7ab24291d to your computer and use it in GitHub Desktop.
AutomateWoo - Custom Subscription Rule based on Billing Period
<?php
// Do NOT include the opening php tag
add_filter( 'automatewoo/rules/includes', 'wpdesk_automatewoo_rules' );
/**
* Custom Rules
*
*/
function wpdesk_automatewoo_rules( $rules ) {
$rules['subscription_billing_period'] = dirname(__FILE__) . '/subscription-billing-period.php';
return $rules;
}
<?php
// Do NOT include the opening php tag
class WPDesk_AW_Rule_Subscription_Billing_Period extends AutomateWoo\Rules\Abstract_Select {
public $data_item = 'subscription';
function init() {
$this->title = __( 'Subscription - Billing Period', 'wpdesk' );
$this->group = __( 'Subscription', 'wpdesk' );
}
/**
* @return array
*/
function load_select_choices() {
return wcs_get_subscription_period_strings();
}
/**
* @param \WC_Subscription $subscription
* @param $compare
* @param $value
* @return bool
*/
function validate( $subscription, $compare, $value ) {
return $this->validate_select( $subscription->get_billing_period(), $compare, $value );
}
}
return new WPDesk_AW_Rule_Subscription_Billing_Period();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment