/**
  * Returns settings array.
  * @return array settings
  */
 public function get_settings($settings, $current_section)
 {
     if ($current_section !== 'deposits') {
         return $settings;
     }
     $payment_gateways = WC()->payment_gateways->payment_gateways();
     $payment_gateway_options = array();
     foreach ($payment_gateways as $gateway) {
         $payment_gateway_options[$gateway->id] = $gateway->get_title();
     }
     $plans = WC_Deposits_Plans_Manager::get_plan_ids();
     return apply_filters('woocommerce_deposits_get_settings', array(array('name' => __('Sitewide Deposits Configuration', 'woocommerce-deposits'), 'type' => 'title', 'desc' => __('These settings affect all products sitewide. You can override these settings on a per product basis to make exceptions.', 'woocommerce-deposits'), 'id' => 'deposits_defaults'), array('name' => __('Enable Deposits by Default', 'woocommerce-deposits'), 'type' => 'select', 'desc' => __('You must set a default amount below if setting this option to "yes".', 'woocommerce-deposits'), 'default' => 'no', 'id' => 'wc_deposits_default_enabled', 'desc_tip' => true, 'options' => array('optional' => __('Yes - deposits are optional', 'woocommerce-deposits'), 'forced' => __('Yes - deposits are required', 'woocommerce-deposits'), 'no' => __('No', 'woocommerce-deposits'))), array('name' => esc_html__('Default Deposit Type', 'woocommerce-deposits'), 'type' => 'select', 'desc' => esc_html__('The default way for customers to pay for this product using a deposit.', 'woocommerce-deposits'), 'default' => 'percent', 'desc_tip' => true, 'id' => 'wc_deposits_default_type', 'options' => array('none' => esc_html__('None', 'woocommerce-deposits'), 'percent' => esc_html__('Percentage', 'woocommerce-deposits'), 'fixed' => esc_html__('Fixed Amount', 'woocommerce-deposits'), 'plan' => esc_html__('Payment Plan', 'woocommerce-deposits'))), array('name' => __('Default Deposit Amount (%)', 'woocommerce-deposits'), 'type' => 'text', 'desc' => __('The default deposit amount percentage.', 'woocommerce-deposits'), 'default' => '', 'placeholder' => __('n/a', 'woocommerce-deposits'), 'id' => 'wc_deposits_default_amount', 'desc_tip' => true), array('name' => esc_html__('Default Payment Plan', 'woocommerce-deposits'), 'type' => 'multiselect', 'class' => 'wc-enhanced-select', 'css' => 'width: 450px;', 'desc' => esc_html__('The default payment plans to use.', 'woocommerce-deposits'), 'default' => '', 'id' => 'wc_deposits_default_plans', 'desc_tip' => true, 'options' => $plans), array('name' => __('Disable Payment Gateways', 'woocommerce-deposits'), 'type' => 'multiselect', 'class' => 'wc-enhanced-select', 'css' => 'width: 450px;', 'desc' => __('Select payment gateways that should be disabled when accepting deposits.', 'woocommerce-deposits'), 'default' => '', 'id' => 'wc_deposits_disabled_gateways', 'desc_tip' => true, 'options' => $payment_gateway_options), array('type' => 'sectionend', 'id' => 'deposits_defaults')));
 }
 /**
  * Triggered when adding an item in the backend.
  *
  * If deposits are forced, set all meta data.
  */
 public function ajax_add_order_item_meta($item_id, $item)
 {
     if (WC_Deposits_Product_Manager::deposits_forced($item['product_id'])) {
         $product = wc_get_product(absint($item['variation_id'] ? $item['variation_id'] : $item['product_id']));
         woocommerce_add_order_item_meta($item_id, '_is_deposit', 'yes');
         woocommerce_add_order_item_meta($item_id, '_deposit_full_amount', $item['line_total']);
         woocommerce_add_order_item_meta($item_id, '_deposit_full_amount_ex_tax', $item['line_total']);
         if ('plan' === WC_Deposits_Product_Manager::get_deposit_type($item['product_id'])) {
             $plan_id = current(WC_Deposits_Plans_Manager::get_plan_ids_for_product($item['product_id']));
             woocommerce_add_order_item_meta($item_id, '_payment_plan', $plan_id);
         } else {
             $plan_id = 0;
         }
         // Change line item costs
         $deposit_amount = WC_Deposits_Product_Manager::get_deposit_amount($product, $plan_id, 'order', $item['line_total']);
         wc_update_order_item_meta($item_id, '_line_total', $deposit_amount);
         wc_update_order_item_meta($item_id, '_line_subtotal', $deposit_amount);
     }
 }
 /**
  * Get Zones to display
  */
 public function prepare_items()
 {
     $this->_column_headers = array($this->get_columns(), array(), array());
     $this->items = WC_Deposits_Plans_Manager::get_plans();
 }
コード例 #4
0
echo esc_attr(implode(',', $default_payment_plans));
?>
" />
		<input type="hidden" class="_wc_deposits_default_amount_field" value="<?php 
echo esc_attr(get_option('wc_deposits_default_amount'));
?>
" />


		<p class="form-field _wc_deposit_payment_plans_field">
			<label for="_wc_deposit_payment_plans"><?php 
_e('Payment Plans', 'woocommerce-deposits');
?>
</label>
			<?php 
$plan_ids = WC_Deposits_Plans_Manager::get_plan_ids();
if (!$plan_ids) {
    echo __('You have not created any payment plans yet.', 'woocommerce-deposits');
    echo ' <a href="' . esc_url(admin_url('edit.php?post_type=product&page=deposit_payment_plans')) . '" class="button button-small" target="_blank">' . __('Create a Payment Plan', 'woocommerce-deposits') . '</a>';
} else {
    ?>
				<select id="_wc_deposit_payment_plans<?php 
    echo $variation_id ? "[{$loop}]" : '';
    ?>
" name="_wc_deposit_payment_plans<?php 
    echo $variation_id ? "[{$loop}]" : '';
    ?>
[]" class="wc-enhanced-select" style="min-width: 50%;" multiple="multiple" placeholder="<?php 
    _e('Choose some plans', 'woocommerce-deposits');
    ?>
">
 /**
  * Output the deposits product tab
  */
 public function output()
 {
     global $wpdb, $post;
     // To ensure views have access to the product type...
     if ($post) {
         $product_terms = wp_get_object_terms($post->ID, 'product_type');
         if ($product_terms) {
             $product_type = sanitize_title(current($product_terms)->name);
         } else {
             $product_type = apply_filters('default_product_type', 'simple');
         }
     } else {
         $product_type = false;
     }
     wp_enqueue_script('woocommerce-deposits-payment-plans');
     if (!empty($_POST)) {
         $result = $this->maybe_save_plan();
         if (is_wp_error($result)) {
             echo '<div class="error"><p>' . $result->get_error_message() . '</p></div>';
         } elseif ($result) {
             echo '<div class="updated success"><p>' . __('Plan saved successfully', 'woocommerce-deposits') . '</p></div>';
         }
     }
     if (!empty($_GET['delete_plan']) && !empty($_GET['_wpnonce']) && wp_verify_nonce($_GET['_wpnonce'], 'delete_plan')) {
         $deleting_id = absint($_GET['delete_plan']);
         $wpdb->delete($wpdb->wc_deposits_payment_plans, array('ID' => $deleting_id));
         $wpdb->delete($wpdb->wc_deposits_payment_plans_schedule, array('plan_id' => $deleting_id));
         echo '<div class="updated success"><p>' . __('Plan deleted successfully', 'woocommerce-deposits') . '</p></div>';
     }
     $plan_name = '';
     $plan_description = '';
     $payment_schedule = array((object) array('amount' => 0));
     if (!empty($_REQUEST['plan_id'])) {
         $editing = absint($_REQUEST['plan_id']);
         $plan = WC_Deposits_Plans_Manager::get_plan($editing);
         $plan_name = $plan->get_name();
         $plan_description = $plan->get_description();
         $payment_schedule = $plan->get_schedule();
         $plan_type = $plan->get_type();
         include 'views/html-edit-payment-plan.php';
     } else {
         $editing = false;
         $plan_type = 'percentage';
         // default to percent for new items
         include 'views/html-payment-plans.php';
     }
 }
コード例 #6
0
</label></li>
		</ul>
	<?php 
}
?>

	<?php 
if ('plan' === WC_Deposits_Product_Manager::get_deposit_type($post->ID)) {
    ?>
		<ul class="wc-deposits-payment-plans">
			<?php 
    $plans = WC_Deposits_Plans_Manager::get_plans_for_product($post->ID, true);
    foreach ($plans as $key => $plan) {
        ?>
				<li class="wc-deposits-payment-plan <?php 
        WC_Deposits_Plans_Manager::output_plan_classes($plan);
        ?>
">
					<input type="radio" name="wc_deposit_payment_plan" <?php 
        checked($key, 0);
        ?>
 value="<?php 
        echo esc_attr($plan->get_id());
        ?>
" id="wc-deposits-payment-plan-<?php 
        echo esc_attr($plan->get_id());
        ?>
" /><label for="wc-deposits-payment-plan-<?php 
        echo esc_attr($plan->get_id());
        ?>
">
 /**
  * Get payment plan if used
  * @return bool or object
  */
 public static function get_payment_plan($item)
 {
     $payment_plan = !empty($item['payment_plan']) ? absint($item['payment_plan']) : 0;
     return $payment_plan ? WC_Deposits_Plans_Manager::get_plan($payment_plan) : false;
 }