Exemplo n.º 1
0
/**
 * Admin Footer For Thickbox
 *
 * Prints the footer code needed for the Insert Download
 * TinyMCE button.
 *
 * @since 1.0
 * @global $pagenow
 * @global $typenow
 * @return void
 */
function edd_admin_footer_for_thickbox()
{
    global $pagenow, $typenow;
    // Only run in post/page creation and edit screens
    if (in_array($pagenow, array('post.php', 'page.php', 'post-new.php', 'post-edit.php')) && $typenow != 'download') {
        ?>
		<script type="text/javascript">
            function insertDownload() {
                var id = jQuery('#products').val(),
                    direct = jQuery('#select-edd-direct').val(),
                    style = jQuery('#select-edd-style').val(),
                    color = jQuery('#select-edd-color').is(':visible') ? jQuery('#select-edd-color').val() : '',
                    text = jQuery('#edd-text').val() || '<?php 
        _e("Purchase", "edd");
        ?>
';

                // Return early if no download is selected
                if ('' === id) {
                    alert('<?php 
        _e("You must choose a download", "edd");
        ?>
');
                    return;
                }

                if( '2' == direct ) {
                	direct = ' direct="true"';
                } else {
                	direct = '';
                }

                // Send the shortcode to the editor
                window.send_to_editor('[purchase_link id="' + id + '" style="' + style + '" color="' + color + '" text="' + text + '"' + direct +']');
            }
            jQuery(document).ready(function ($) {
                $('#select-edd-style').change(function () {
                    if ($(this).val() === 'button') {
                        $('#edd-color-choice').slideDown();
                    } else {
                        $('#edd-color-choice').slideUp();
                    }
                });
            });
		</script>

		<div id="choose-download" style="display: none;">
			<div class="wrap" style="font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;">
				<p><?php 
        echo sprintf(__('Use the form below to insert the short code for purchasing a %s', 'edd'), edd_get_label_singular());
        ?>
</p>
				<div>
					<?php 
        echo EDD()->html->product_dropdown(array('chosen' => true));
        ?>
				</div>
				<?php 
        if (edd_shop_supports_buy_now()) {
            ?>
					<div>
						<select id="select-edd-direct" style="clear: both; display: block; margin-bottom: 1em; margin-top: 1em;">
							<option value="0"><?php 
            _e('Choose the button behavior', 'edd');
            ?>
</option>
							<option value="1"><?php 
            _e('Add to Cart', 'edd');
            ?>
</option>
							<option value="2"><?php 
            _e('Direct Purchase Link', 'edd');
            ?>
</option>
						</select>
					</div>
				<?php 
        }
        ?>
				<div>
					<select id="select-edd-style" style="clear: both; display: block; margin-bottom: 1em; margin-top: 1em;">
						<option value=""><?php 
        _e('Choose a style', 'edd');
        ?>
</option>
						<?php 
        $styles = array('button', 'text link');
        foreach ($styles as $style) {
            echo '<option value="' . $style . '">' . $style . '</option>';
        }
        ?>
					</select>
				</div>
				<?php 
        $colors = edd_get_button_colors();
        if ($colors) {
            ?>
				<div id="edd-color-choice" style="display: none;">
					<select id="select-edd-color" style="clear: both; display: block; margin-bottom: 1em;">
						<option value=""><?php 
            _e('Choose a button color', 'edd');
            ?>
</option>
						<?php 
            foreach ($colors as $key => $color) {
                echo '<option value="' . str_replace(' ', '_', $key) . '">' . $color['label'] . '</option>';
            }
            ?>
					</select>
				</div>
				<?php 
        }
        ?>
				<div>
					<input type="text" class="regular-text" id="edd-text" value="" placeholder="<?php 
        _e('Link text . . .', 'edd');
        ?>
"/>
				</div>
				<p class="submit">
					<input type="button" id="edd-insert-download" class="button-primary" value="<?php 
        echo sprintf(__('Insert %s', 'edd'), edd_get_label_singular());
        ?>
" onclick="insertDownload();" />
					<a id="edd-cancel-download-insert" class="button-secondary" onclick="tb_remove();" title="<?php 
        _e('Cancel', 'edd');
        ?>
"><?php 
        _e('Cancel', 'edd');
        ?>
</a>
				</p>
			</div>
		</div>
	<?php 
    }
}
Exemplo n.º 2
0
/**
 * Render Disable Button
 *
 * @since 1.0
 * @param int $post_id Download (Post) ID
 * @return void
 */
function edd_render_disable_button($post_id)
{
    $hide_button = get_post_meta($post_id, '_edd_hide_purchase_link', true) ? 1 : 0;
    $behavior = get_post_meta($post_id, '_edd_button_behavior', true);
    ?>
	<p><strong><?php 
    _e('Button Options:', 'edd');
    ?>
</strong></p>
	<p>
		<label for="_edd_hide_purchase_link">
			<?php 
    echo EDD()->html->checkbox(array('name' => '_edd_hide_purchase_link', 'current' => $hide_button));
    ?>
			<?php 
    _e('Disable the automatic output of the purchase button', 'edd');
    ?>
		</label>
	</p>
	<?php 
    if (edd_shop_supports_buy_now()) {
        ?>
	<p>
		<label for="_edd_button_behavior">
			<?php 
        echo EDD()->html->select(array('name' => '_edd_button_behavior', 'options' => array('add_to_cart' => __('Add to Cart', 'edd'), 'direct' => __('Buy Now', 'edd')), 'show_option_all' => null, 'show_option_none' => null, 'selected' => $behavior));
        ?>
			<?php 
        _e('Purchase button behavior', 'edd');
        ?>
		</label>
	</p>
<?php 
    }
}
/**
 * Get Purchase Link
 *
 * Builds a Purchase link for a specified download based on arguments passed.
 * This function is used all over EDD to generate the Purchase or Add to Cart
 * buttons. If no arguments are passed, the function uses the defaults that have
 * been set by the plugin. The Purchase link is built for simple and variable
 * pricing and filters are available throughout the function to override
 * certain elements of the function.
 *
 * $download_id = null, $link_text = null, $style = null, $color = null, $class = null
 *
 * @since 1.0
 * @param array $args Arguments for display
 * @return string $purchase_form
 */
function edd_get_purchase_link($args = array())
{
    global $post, $edd_displayed_form_ids;
    $purchase_page = edd_get_option('purchase_page', false);
    if (!$purchase_page || $purchase_page == 0) {
        edd_set_error('set_checkout', sprintf(__('No checkout page has been configured. Visit <a href="%s">Settings</a> to set one.', 'easy-digital-downloads'), admin_url('edit.php?post_type=download&page=edd-settings')));
        edd_print_errors();
        return false;
    }
    $post_id = is_object($post) ? $post->ID : 0;
    $button_behavior = edd_get_download_button_behavior($post_id);
    $defaults = apply_filters('edd_purchase_link_defaults', array('download_id' => $post_id, 'price' => (bool) true, 'price_id' => isset($args['price_id']) ? $args['price_id'] : false, 'direct' => $button_behavior == 'direct' ? true : false, 'text' => $button_behavior == 'direct' ? edd_get_option('buy_now_text', __('Buy Now', 'easy-digital-downloads')) : edd_get_option('add_to_cart_text', __('Purchase', 'easy-digital-downloads')), 'style' => edd_get_option('button_style', 'button'), 'color' => edd_get_option('checkout_color', 'blue'), 'class' => 'edd-submit'));
    $args = wp_parse_args($args, $defaults);
    // Override the stright_to_gateway if the shop doesn't support it
    if (!edd_shop_supports_buy_now()) {
        $args['direct'] = false;
    }
    $download = new EDD_Download($args['download_id']);
    if (empty($download->ID)) {
        return false;
    }
    if ('publish' !== $download->post_status && !current_user_can('edit_product', $download->ID)) {
        return false;
        // Product not published or user doesn't have permission to view drafts
    }
    // Override color if color == inherit
    $args['color'] = $args['color'] == 'inherit' ? '' : $args['color'];
    $options = array();
    $variable_pricing = $download->has_variable_prices();
    $data_variable = $variable_pricing ? ' data-variable-price="yes"' : 'data-variable-price="no"';
    $type = $download->is_single_price_mode() ? 'data-price-mode=multi' : 'data-price-mode=single';
    $show_price = $args['price'] && $args['price'] !== 'no';
    $data_price_value = 0;
    $price = false;
    if ($variable_pricing && false !== $args['price_id']) {
        $price_id = $args['price_id'];
        $prices = $download->prices;
        $options['price_id'] = $args['price_id'];
        $found_price = isset($prices[$price_id]) ? $prices[$price_id]['amount'] : false;
        $data_price_value = $found_price;
        if ($show_price) {
            $price = $found_price;
        }
    } elseif (!$variable_pricing) {
        $data_price_value = $download->price;
        if ($show_price) {
            $price = $download->price;
        }
    }
    $args['display_price'] = $data_price_value;
    $data_price = 'data-price="' . $data_price_value . '"';
    $button_text = !empty($args['text']) ? '&nbsp;&ndash;&nbsp;' . $args['text'] : '';
    if (false !== $price) {
        if (0 == $price) {
            $args['text'] = __('Free', 'easy-digital-downloads') . $button_text;
        } else {
            $args['text'] = edd_currency_filter(edd_format_amount($price)) . $button_text;
        }
    }
    if (edd_item_in_cart($download->ID, $options) && (!$variable_pricing || !$download->is_single_price_mode())) {
        $button_display = 'style="display:none;"';
        $checkout_display = '';
    } else {
        $button_display = '';
        $checkout_display = 'style="display:none;"';
    }
    // Collect any form IDs we've displayed already so we can avoid duplicate IDs
    if (isset($edd_displayed_form_ids[$download->ID])) {
        $edd_displayed_form_ids[$download->ID]++;
    } else {
        $edd_displayed_form_ids[$download->ID] = 1;
    }
    $form_id = !empty($args['form_id']) ? $args['form_id'] : 'edd_purchase_' . $download->ID;
    // If we've already generated a form ID for this download ID, apped -#
    if ($edd_displayed_form_ids[$download->ID] > 1) {
        $form_id .= '-' . $edd_displayed_form_ids[$download->ID];
    }
    $args = apply_filters('edd_purchase_link_args', $args);
    ob_start();
    ?>
	<form id="<?php 
    echo $form_id;
    ?>
" class="edd_download_purchase_form edd_purchase_<?php 
    echo absint($download->ID);
    ?>
" method="post">

		<?php 
    do_action('edd_purchase_link_top', $download->ID, $args);
    ?>

		<div class="edd_purchase_submit_wrapper">
			<?php 
    $class = implode(' ', array($args['style'], $args['color'], trim($args['class'])));
    if (!edd_is_ajax_disabled()) {
        echo '<a href="#" class="edd-add-to-cart ' . esc_attr($class) . '" data-action="edd_add_to_cart" data-download-id="' . esc_attr($download->ID) . '" ' . $data_variable . ' ' . $type . ' ' . $data_price . ' ' . $button_display . '><span class="edd-add-to-cart-label">' . $args['text'] . '</span> <span class="edd-loading"><i class="edd-icon-spinner edd-icon-spin"></i></span></a>';
    }
    echo '<input type="submit" class="edd-add-to-cart edd-no-js ' . esc_attr($class) . '" name="edd_purchase_download" value="' . esc_attr($args['text']) . '" data-action="edd_add_to_cart" data-download-id="' . esc_attr($download->ID) . '" ' . $data_variable . ' ' . $type . ' ' . $button_display . '/>';
    echo '<a href="' . esc_url(edd_get_checkout_uri()) . '" class="edd_go_to_checkout ' . esc_attr($class) . '" ' . $checkout_display . '>' . __('Checkout', 'easy-digital-downloads') . '</a>';
    ?>

			<?php 
    if (!edd_is_ajax_disabled()) {
        ?>
				<span class="edd-cart-ajax-alert">
					<span class="edd-cart-added-alert" style="display: none;">
						<?php 
        echo '<i class="edd-icon-ok"></i> ' . __('Added to cart', 'easy-digital-downloads');
        ?>
					</span>
				</span>
			<?php 
    }
    ?>
			<?php 
    if (!$download->is_free($args['price_id'])) {
        ?>
				<?php 
        if (edd_display_tax_rate() && edd_prices_include_tax()) {
            echo '<span class="edd_purchase_tax_rate">' . sprintf(__('Includes %1$s&#37; tax', 'easy-digital-downloads'), edd_get_tax_rate() * 100) . '</span>';
        } elseif (edd_display_tax_rate() && !edd_prices_include_tax()) {
            echo '<span class="edd_purchase_tax_rate">' . sprintf(__('Excluding %1$s&#37; tax', 'easy-digital-downloads'), edd_get_tax_rate() * 100) . '</span>';
        }
        ?>
			<?php 
    }
    ?>
		</div><!--end .edd_purchase_submit_wrapper-->

		<input type="hidden" name="download_id" value="<?php 
    echo esc_attr($download->ID);
    ?>
">
		<?php 
    if ($variable_pricing && isset($price_id) && isset($prices[$price_id])) {
        ?>
			<input type="hidden" name="edd_options[price_id][]" id="edd_price_option_<?php 
        echo $download->ID;
        ?>
_1" class="edd_price_option_<?php 
        echo $download->ID;
        ?>
" value="<?php 
        echo $price_id;
        ?>
">
		<?php 
    }
    ?>
		<?php 
    if (!empty($args['direct']) && !$download->is_free($args['price_id'])) {
        ?>
			<input type="hidden" name="edd_action" class="edd_action_input" value="straight_to_gateway">
		<?php 
    } else {
        ?>
			<input type="hidden" name="edd_action" class="edd_action_input" value="add_to_cart">
		<?php 
    }
    ?>

		<?php 
    if (apply_filters('edd_download_redirect_to_checkout', edd_straight_to_checkout(), $download->ID, $args)) {
        ?>
			<input type="hidden" name="edd_redirect_to_checkout" id="edd_redirect_to_checkout" value="1">
		<?php 
    }
    ?>

		<?php 
    do_action('edd_purchase_link_end', $download->ID, $args);
    ?>

	</form><!--end #<?php 
    echo esc_attr($form_id);
    ?>
-->
<?php 
    $purchase_form = ob_get_clean();
    return apply_filters('edd_purchase_download_form', $purchase_form, $args);
}
 /**
  * Retrieve the purchase button behavior
  *
  * @since 2.2
  * @return string
  */
 public function get_button_behavior()
 {
     if (!isset($this->button_behavior)) {
         $this->button_behavior = get_post_meta($this->ID, '_edd_button_behavior', true);
         if (empty($this->button_behavior) || !edd_shop_supports_buy_now()) {
             $this->button_behavior = 'add_to_cart';
         }
     }
     return apply_filters('edd_get_download_button_behavior', $this->button_behavior, $this->ID);
 }
Exemplo n.º 5
0
/**
 * Render Disable Button
 *
 * @since 1.0
 * @param int $post_id Download (Post) ID
 * @return void
 */
function edd_render_disable_button($post_id)
{
    $hide_button = get_post_meta($post_id, '_edd_hide_purchase_link', true) ? 1 : 0;
    $behavior = get_post_meta($post_id, '_edd_button_behavior', true);
    ?>
	<p><strong><?php 
    _e('Button Options:', 'easy-digital-downloads');
    ?>
</strong></p>
	<p>
		<label for="_edd_hide_purchase_link">
			<?php 
    echo EDD()->html->checkbox(array('name' => '_edd_hide_purchase_link', 'current' => $hide_button));
    ?>
			<?php 
    _e('Disable the automatic output of the purchase button', 'easy-digital-downloads');
    ?>
			<span alt="f223" class="edd-help-tip dashicons dashicons-editor-help" title="<?php 
    _e('<strong>Automatic Output</strong>: By default, the purchase buttons will be displayed at the bottom of the download, when disabled you will need to use the Purchase link shortcode below to output the ability to buy the product where you prefer.', 'easy-digital-downloads');
    ?>
"></span>
		</label>
	</p>
	<?php 
    $supports_buy_now = edd_shop_supports_buy_now();
    ?>
	<p>
		<label for="_edd_button_behavior">
			<?php 
    $args = array('name' => '_edd_button_behavior', 'options' => array('add_to_cart' => __('Add to Cart', 'easy-digital-downloads'), 'direct' => __('Buy Now', 'easy-digital-downloads')), 'show_option_all' => null, 'show_option_none' => null, 'selected' => $behavior);
    if (!$supports_buy_now) {
        $args['disabled'] = true;
        $args['readonly'] = true;
    }
    ?>
			<?php 
    echo EDD()->html->select($args);
    ?>
			<?php 
    _e('Purchase button behavior', 'easy-digital-downloads');
    ?>
			<?php 
    if ($supports_buy_now) {
        ?>
				<span alt="f223" class="edd-help-tip dashicons dashicons-editor-help" title="<?php 
        _e('<strong>Button Behavior</strong>: Add to Cart buttons follow a traditional eCommerce flow. A Buy Now button bypasses most of the process, taking the customer directly from button click to payment, greatly speeding up the process of buying the product.', 'easy-digital-downloads');
        ?>
"></span>
			<?php 
    } else {
        ?>
				<span alt="f223" class="edd-help-tip dashicons dashicons-editor-help" title="<?php 
        _e('<strong>Button Behavior</strong>: Add to Cart buttons follow a traditional eCommerce flow. Buy Now buttons are only available for supported gateways and stores that do not use taxes.', 'easy-digital-downloads');
        ?>
"></span>
			<?php 
    }
    ?>

		</label>
	</p>
<?php 
}
/**
 * Deposit page shortcode
 *
 * @since       1.0.0
 * @param       array $atts Shortcode attributes
 * @param       string $content Shortcode content
 * @global      object $post The WordPress post object
 * @return      string Deposit page
 */
function edd_wallet_deposit_shortcode($atts, $content = null)
{
    global $post;
    $post_id = is_object($post) ? $post->ID : 0;
    $atts = shortcode_atts(array('button_text' => __('Make Deposit', 'edd-wallet'), 'button_style' => edd_get_option('button_style', 'button'), 'button_color' => edd_get_option('checkout_color', 'blue'), 'button_class' => 'edd-submit'), $atts, 'edd_deposit');
    // Override color if color == inherit
    if (isset($atts['button_color'])) {
        $atts['button_color'] = $atts['button_color'] == 'inherit' ? '' : $atts['button_color'];
    }
    // Setup straight to gateway if possible
    if (edd_shop_supports_buy_now()) {
        $atts['direct'] = true;
    } else {
        $atts['direct'] = false;
    }
    $levels = edd_get_option('edd_wallet_deposit_levels', array('20', '40', '60', '80', '100', '200', '500'));
    sort($levels);
    ob_start();
    ?>
	<form id="edd_wallet_deposit" class="edd_wallet_deposit_form" method="post">
		<?php 
    do_action('edd_wallet_deposit_page_top', $atts);
    ?>

		<div id="edd_wallet_deposit_amount_wrapper">
			<ul>
				<?php 
    foreach ($levels as $id => $level) {
        $checked = $id == 0 ? ' checked="checked"' : '';
        echo '<li>';
        echo '<label><input type="radio" id="edd_wallet_deposit_amount" name="edd_wallet_deposit_amount" value="' . $level . '"' . $checked . '> ' . edd_currency_filter(edd_format_amount($level)) . '</label>';
        echo '</li>';
    }
    if (edd_get_option('edd_wallet_arbitrary_deposits', false)) {
        echo '<li>';
        echo '<label><input type="radio" id="edd_wallet_deposit_amount" name="edd_wallet_deposit_amount" value="custom"' . $checked . '> ' . edd_get_option('edd_wallet_arbitrary_deposit_label', __('Custom Amount', 'edd-wallet')) . '</label>';
        echo '<input type="text" id="edd_wallet_custom_deposit" name="edd_wallet_custom_deposit" value="" style="display: none" />';
        echo '</li>';
    }
    ?>
			</ul>
		</div>

		<div class="edd_wallet_deposit_submit_wrapper">
			<div id="edd_wallet_error_wrapper" class="edd_errors edd-alert edd-alert-error" style="display: none"></div>

			<?php 
    $class = implode(' ', array($atts['button_style'], $atts['button_color'], trim($atts['button_class'])));
    wp_nonce_field('edd-wallet-deposit-nonce');
    echo '<input type="hidden" name="edd_action" value="wallet_process_deposit" />';
    echo '<input type="submit" class="edd-wallet-deposit ' . esc_attr($class) . '" name="edd_wallet_deposit" value="' . esc_attr($atts['button_text']) . '" />';
    ?>
		</div>
		<?php 
    do_action('edd_wallet_deposit_page_bottom', $atts);
    ?>
	</form>
	<?php 
    $deposit_form = ob_get_clean();
    return apply_filters('edd_wallet_deposit_form', $deposit_form, $atts);
}