Created
June 17, 2015 15:26
-
-
Save growdev/74182260398e26615a85 to your computer and use it in GitHub Desktop.
Use WooCommerce Advanced Messages with WooCommerce Subscriptions
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 | |
/** | |
* This code snippet adds a "Active Subscriber" Yes/No to the conditional box of WooCommerce Advanced Messages. | |
* You can use this to display messages to customers with an active subscription. | |
*/ | |
/** | |
* Add the option to the condition drop down | |
* | |
* @param $conditions | |
* | |
* @return mixed | |
*/ | |
function custom_wcam_conditions( $conditions ) { | |
$conditions['User Details']['subscription'] = 'Active Subscriber'; | |
return $conditions; | |
} | |
add_filter( 'wcam_conditions', 'custom_wcam_conditions' ); | |
/** | |
* Add the options to the values drop down | |
* | |
* @param $values | |
* @param $condition | |
* | |
* @return mixed | |
*/ | |
function custom_wcam_values ( $values, $condition ){ | |
if ( 'subscription' == $condition ){ | |
$values['field'] = 'select'; | |
$values['options'] = array( | |
'yes' => __( 'Yes', 'woocommerce-advanced-messages' ), | |
'no' => __( 'No', 'woocommerce-advanced-messages' ), | |
); | |
} | |
return $values; | |
} | |
add_filter( 'wcam_values', 'custom_wcam_values', 10, 2); | |
/** | |
* See if current user is a subscriber | |
* | |
* @param $match | |
* @param $operator | |
* @param $value | |
* | |
* @return bool | |
*/ | |
function custom_wcam_match_condition_subscription( $match, $operator, $value ){ | |
if ( WC_Subscriptions_Manager::user_has_subscription(0, '', 'active')){ | |
return true; | |
} | |
} | |
add_filter( 'wcam_match_condition_subscription', 'custom_wcam_match_condition_subscription', 10, 3 ); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment