Skip to content

Instantly share code, notes, and snippets.

@swoboda
Last active January 16, 2019 16:03
Show Gist options
  • Save swoboda/6c7a5115d4daa9bf68e0c786774ef053 to your computer and use it in GitHub Desktop.
Save swoboda/6c7a5115d4daa9bf68e0c786774ef053 to your computer and use it in GitHub Desktop.
AutomateWoo - Custom Subscription Rule based on Parent Order Status
<?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_parent_order_status'] = dirname(__FILE__) . '/subscription-parent-order-status.php';
return $rules;
}
<?php
// Do NOT include the opening php tag
class WPDesk_AW_Rule_Subscription_Parent_Order_Status extends AutomateWoo\Rules\Abstract_Select {
public $data_item = 'subscription';
function init() {
$this->title = __( 'Subscription - Parent Order Status', 'wpdesk' );
$this->group = __( 'Subscription', 'wpdesk' );
}
/**
* @return array
*/
function load_select_choices() {
return wc_get_order_statuses();
}
/**
* @param \WC_Subscription $subscription
* @param $compare
* @param $value
* @return bool
*/
function validate( $subscription, $compare, $value ) {
$order = $subscription->get_parent();
return $this->validate_select( 'wc-' . $order->get_status(), $compare, $value );
}
}
return new WPDesk_AW_Rule_Subscription_Parent_Order_Status();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment