diff --git a/includes/Admin/Actions.php b/includes/Admin/Actions.php index 57a3042..78c140f 100644 --- a/includes/Admin/Actions.php +++ b/includes/Admin/Actions.php @@ -50,8 +50,9 @@ public static function add_campaign() { 'post_content' => $cause, 'post_status' => $status, 'meta_input' => array( - 'wcdm_goal_amount' => $goal_amount, - '_end_date' => $end_date, + 'wcdm_goal_amount' => $goal_amount, + '_end_date' => $end_date, + 'wcdm_goal_behavior' => ( ! empty( $_POST['goal_behavior'] ) ? sanitize_key( wp_unslash( $_POST['goal_behavior'] ) ) : get_option( 'wcdm_goal_behavior', 'continue' ) ), ), ); @@ -96,8 +97,9 @@ public static function edit_campaign() { 'post_content' => wp_kses_post( $cause ), 'post_status' => $status, 'meta_input' => array( - 'wcdm_goal_amount' => $goal_amount, - '_end_date' => $end_date, + 'wcdm_goal_amount' => $goal_amount, + '_end_date' => $end_date, + 'wcdm_goal_behavior' => ( ! empty( $_POST['goal_behavior'] ) ? sanitize_key( wp_unslash( $_POST['goal_behavior'] ) ) : get_option( 'wcdm_goal_behavior', 'continue' ) ), ), ); diff --git a/includes/Admin/Settings.php b/includes/Admin/Settings.php index 025e8fa..c7551e0 100644 --- a/includes/Admin/Settings.php +++ b/includes/Admin/Settings.php @@ -160,6 +160,18 @@ public function get_settings( $tab ) { 'default' => 'no', 'type' => 'checkbox', ), + array( + 'title' => __( 'Donation behaviour after goal completion', 'wc-donation-manager' ), + 'desc' => __( 'Define what should happen when a campaign reaches its goal.', 'wc-donation-manager' ), + 'id' => 'wcdm_goal_behavior', + 'type' => 'select', + 'default' => 'continue', + 'options' => array( + 'continue' => __( 'Continue accepting donations', 'wc-donation-manager' ), + 'close' => __( 'Close campaign automatically', 'wc-donation-manager' ), + 'soft_close' => __( 'Show as completed but still allow donations', 'wc-donation-manager' ), + ), + ), array( 'type' => 'sectionend', 'id' => 'advanced_options', diff --git a/includes/Admin/views/campaigns/add.php b/includes/Admin/views/campaigns/add.php index 4da3a78..b91cc01 100644 --- a/includes/Admin/views/campaigns/add.php +++ b/includes/Admin/views/campaigns/add.php @@ -72,6 +72,23 @@
+ ++ +
+', esc_html__( 'This campaign has reached its goal and is now closed.', 'wc-donation-manager' ), '
' ); + return; + } + if ( 'soft_close' === $behavior ) { + printf( '%1$s%2$s%3$s', '', esc_html__( 'This campaign has reached its goal but is still accepting donations.', 'wc-donation-manager' ), '
' ); + } + } + do_action( 'woocommerce_simple_add_to_cart' ); } diff --git a/includes/functions.php b/includes/functions.php index eaf7b95..07b3087 100644 --- a/includes/functions.php +++ b/includes/functions.php @@ -94,6 +94,20 @@ function wcdm_get_campaign_products( $campaign_id ) { return $query->posts; } +/** + * Get goal behavior for a campaign. + * + * @param int $campaign_id Campaign ID. + * @return string + */ +function wcdm_get_goal_behavior( $campaign_id ) { + $behavior = get_post_meta( $campaign_id, 'wcdm_goal_behavior', true ); + if ( ! $behavior ) { + $behavior = get_option( 'wcdm_goal_behavior', 'continue' ); + } + return $behavior; +} + /** * Get the post title. *