This commit is contained in:
Prospress Inc
2016-09-08 09:19:32 +02:00
committed by I
parent 084aa2976e
commit 3c13d0a95f
26 changed files with 776 additions and 483 deletions

View File

@@ -77,6 +77,8 @@ class WC_Subscriptions_Admin {
add_action( 'woocommerce_process_product_meta_variable-subscription', __CLASS__ . '::process_product_meta_variable_subscription' ); // WC < 2.4
add_action( 'woocommerce_ajax_save_product_variations', __CLASS__ . '::process_product_meta_variable_subscription' );
add_action( 'woocommerce_subscription_pre_update_status', __CLASS__ . '::check_customer_is_set', 10, 3 );
add_action( 'product_variation_linked', __CLASS__ . '::set_variation_meta_defaults_on_bulk_add' );
add_filter( 'woocommerce_settings_tabs_array', __CLASS__ . '::add_subscription_settings_tab', 50 );
@@ -242,7 +244,7 @@ class WC_Subscriptions_Admin {
woocommerce_wp_checkbox( array(
'id' => '_subscription_one_time_shipping',
'label' => __( 'One Time Shipping', 'woocommerce-subscriptions' ),
'description' => __( 'Shipping for subscription products is normally charged on the initial order and all renewal orders. Enable this to only charge shipping once on the initial order. Note: for shipping to be charged on the initial order, the subscription must not have a free trial.', 'woocommerce-subscriptions' ),
'description' => __( 'Shipping for subscription products is normally charged on the initial order and all renewal orders. Enable this to only charge shipping once on the initial order. Note: for this setting to be enabled the subscription must not have a free trial or a synced renewal date.', 'woocommerce-subscriptions' ),
'desc_tip' => true,
) );
@@ -620,6 +622,36 @@ class WC_Subscriptions_Admin {
}
/**
* Make sure when saving a subscription via the admin to activate it, it has a valid customer set on it.
*
* When you click "Add New Subscription", the status is already going to be pending to begin with. This will prevent
* changing the status to anything else besides pending if no customer is specified, or the customer specified is
* not a valid WP_User.
*
* Hooked into `woocommerce_subscription_pre_update_status`
*
* @param string $old_status Previous status of the subscription in update_status
* @param string $new_status New status of the subscription in update_status
* @param WC_Subscription $subscription The subscription being saved
*
* @return null
* @throws Exception in case there was no user found / there's no customer attached to it
*/
public static function check_customer_is_set( $old_status, $new_status, $subscription ) {
global $post;
if ( is_admin() && 'active' == $new_status && ! empty( $post ) && 'shop_subscription' === $post->post_type ) {
$customer_user = ( isset( $_POST['customer_user'] ) ) ? sanitize_text_field( $_POST['customer_user'] ) : ''; // csrf in core wp save post function
$user = new WP_User( $customer_user );
if ( 0 === $user->ID ) {
throw new Exception( sprintf( __( 'Unable to change subscription status to "%s". Please assign a customer to the subscription to activate it.', 'woocommerce-subscriptions' ), $new_status ) );
}
}
}
/**
* Set default values for subscription dropdown fields when bulk adding variations to fix issue #1342
*
@@ -664,14 +696,15 @@ class WC_Subscriptions_Admin {
$dependencies[] = 'wc-admin-variation-meta-boxes';
$script_params = array(
'productType' => WC_Subscriptions::$name,
'trialPeriodSingular' => wcs_get_available_time_periods(),
'trialPeriodPlurals' => wcs_get_available_time_periods( 'plural' ),
'subscriptionLengths' => wcs_get_subscription_ranges(),
'trialTooLongMessages' => self::get_trial_period_validation_message( 'separate' ),
'bulkEditPeriodMessage' => __( 'Enter the new period, either day, week, month or year:', 'woocommerce-subscriptions' ),
'bulkEditLengthMessage' => __( 'Enter a new length (e.g. 5):', 'woocommerce-subscriptions' ),
'bulkEditIntervalhMessage' => __( 'Enter a new interval as a single number (e.g. to charge every 2nd month, enter 2):', 'woocommerce-subscriptions' ),
'productType' => WC_Subscriptions::$name,
'trialPeriodSingular' => wcs_get_available_time_periods(),
'trialPeriodPlurals' => wcs_get_available_time_periods( 'plural' ),
'subscriptionLengths' => wcs_get_subscription_ranges(),
'trialTooLongMessages' => self::get_trial_period_validation_message( 'separate' ),
'bulkEditPeriodMessage' => __( 'Enter the new period, either day, week, month or year:', 'woocommerce-subscriptions' ),
'bulkEditLengthMessage' => __( 'Enter a new length (e.g. 5):', 'woocommerce-subscriptions' ),
'bulkEditIntervalhMessage' => __( 'Enter a new interval as a single number (e.g. to charge every 2nd month, enter 2):', 'woocommerce-subscriptions' ),
'oneTimeShippingCheckNonce' => wp_create_nonce( 'one_time_shipping' ),
);
} else if ( 'edit-shop_order' == $screen->id ) {
$script_params = array(