Last active
January 16, 2019 16:03
-
-
Save swoboda/6c7a5115d4daa9bf68e0c786774ef053 to your computer and use it in GitHub Desktop.
AutomateWoo - Custom Subscription Rule based on Parent Order Status
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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