function print_eStore_buy_now_button($id, $button = '', $nggImage = '')
{
    global $wpdb;
    $products_table_name = WP_ESTORE_PRODUCTS_TABLE_NAME;
    $ret_product = $wpdb->get_row("SELECT * FROM {$products_table_name} WHERE id = '{$id}'", OBJECT);
    if (!$ret_product) {
        return eStore_wrong_product_id_error_msg($id);
    }
    if (is_numeric($ret_product->available_copies)) {
        if ($ret_product->available_copies < 1) {
            return eStore_get_sold_out_button();
        }
    }
    $paypal_email = get_option('cart_paypal_email');
    if (!empty($ret_product->currency_code)) {
        $paypal_currency = $ret_product->currency_code;
    } else {
        $paypal_currency = get_option('cart_payment_currency');
    }
    $return = get_option('cart_return_from_paypal_url');
    // Find out if the product should be delivered automatically through a notify email
    if (get_option('eStore_auto_product_delivery') == '') {
        $notify = '';
    } else {
        if (WP_ESTORE_ENABLE_NEW_CHECKOUT_REDIRECTION === '1') {
            $notify = WP_ESTORE_WP_SITE_URL . '/?estore_pp_ipn=process';
        } else {
            $notify = WP_ESTORE_URL . '/paypal.php';
        }
    }
    if (!empty($notify)) {
        $urls .= '<input type="hidden" name="notify_url" value="' . $notify . '" />';
    }
    if (!empty($ret_product->return_url)) {
        $urls .= '<input type="hidden" name="return" value="' . $ret_product->return_url . '" />';
    } else {
        if (!empty($return)) {
            $urls .= '<input type="hidden" name="return" value="' . $return . '" />';
        }
    }
    $cancel_url = get_option('cart_cancel_from_paypal_url');
    if (!empty($cancel_url)) {
        $urls .= '<input type="hidden" name="cancel_return" value="' . $cancel_url . '" />';
    }
    if (empty($button)) {
        $button = $ret_product->button_image_url;
    }
    if (!empty($button)) {
        $button_type .= '<input type="image" src="' . $button . '" class="eStore_buy_now_button" alt="' . WP_ESTORE_BUY_NOW . '"/>';
    } else {
        $button_type .= '<input type="submit" class="eStore_buy_now_button" value="' . WP_ESTORE_BUY_NOW . '" />';
    }
    $sandbox_enabled = get_option('eStore_cart_enable_sandbox');
    /* === PayPal Buy Now Button Form === */
    $output = "";
    $output .= '<div class="eStore_button_wrapper eStore_pp_buy_now_wrapper">';
    if ($sandbox_enabled) {
        $output .= '<form action="' . PAYPAL_SANDBOX_URL . '" method="post" onsubmit="return ReadForm1(this, 2);">';
    } else {
        $output .= '<form action="' . PAYPAL_LIVE_URL . '" method="post" onsubmit="return ReadForm1(this, 2);">';
    }
    $line_break = true;
    //Variation code
    $output .= get_variation_and_input_code($ret_product, $line_break, 2);
    //Custom price
    if ($ret_product->custom_price_option == '1') {
        $currSymbol = get_option('cart_currency_symbol');
        $output .= WP_ESTORE_YOUR_PRICE . ': ' . $currSymbol . '<input type="text" name="custom_price" size="3" value="" />&nbsp;';
        if ($line_break) {
            $output .= '<br />';
        }
    }
    //Show qty field if set in the product
    if ($ret_product->show_qty == '1') {
        $output .= eStore_get_default_purchase_qty_input_data("quantity", "1");
        if ($line_break) {
            $output .= '<br />';
        }
    }
    if (!empty($nggImage->alttext)) {
        $output .= '<input type="hidden" name="product_name_tmp1" value="' . htmlspecialchars($nggImage->alttext) . '" /><input type="hidden" name="price_tmp1" value="' . $ret_product->price . '" />';
    } else {
        $output .= '<input type="hidden" name="product_name_tmp1" value="' . htmlspecialchars($ret_product->name) . '" /><input type="hidden" name="price_tmp1" value="' . $ret_product->price . '" />';
    }
    if (defined('WP_ESTORE_FORCE_LANGUAGE_OF_PAYPAL_PAGE') && WP_ESTORE_FORCE_LANGUAGE_OF_PAYPAL_PAGE !== '0') {
        //Set the country/region preference by force.
        $output .= '<input type="hidden" name="lc" value="' . WP_ESTORE_FORCE_LANGUAGE_OF_PAYPAL_PAGE . '" />';
    }
    $output .= '<input type="hidden" name="cmd" value="_xclick" />';
    $output .= '<input type="hidden" name="charset" value="utf-8" />';
    if (!empty($ret_product->paypal_email)) {
        $output .= "<input type=\"hidden\" name=\"business\" value=\"{$ret_product->paypal_email}\" />";
    } else {
        $output .= "<input type=\"hidden\" name=\"business\" value=\"{$paypal_email}\" />";
    }
    if (!empty($nggImage->alttext)) {
        $output .= '<input type="hidden" name="item_name" value="' . htmlspecialchars($nggImage->alttext) . '" />';
        //$output .= "<input type=\"hidden\" name=\"item_name\" value=\"$nggImage->alttext\" />";
    } else {
        $output .= '<input type="hidden" name="item_name" value="' . htmlspecialchars($ret_product->name) . '" />';
        //$output .= "<input type=\"hidden\" name=\"item_name\" value=\"$ret_product->name\" />";
    }
    $output .= "<input type=\"hidden\" name=\"amount\" value=\"{$ret_product->price}\" />";
    $output .= "<input type=\"hidden\" name=\"currency_code\" value=\"{$paypal_currency}\" />";
    $output .= "<input type=\"hidden\" name=\"item_number\" value=\"{$id}\" />";
    if (!get_option('eStore_paypal_profile_shipping')) {
        if (!empty($ret_product->shipping_cost)) {
            $baseShipping = get_option('eStore_base_shipping');
            $postage_cost = round($ret_product->shipping_cost + $baseShipping, 2);
            $output .= "<input type=\"hidden\" name=\"shipping\" value='" . $postage_cost . "' />";
            $output .= "<input type=\"hidden\" name=\"no_shipping\" value='2' />";
        } else {
            $output .= "<input type=\"hidden\" name=\"no_shipping\" value='1' />";
        }
    } else {
        if (!empty($ret_product->weight)) {
            $output .= "<input type=\"hidden\" name=\"weight\" value='" . $ret_product->weight . "' />";
            $output .= "<input type=\"hidden\" name=\"weight_unit\" value=\"lbs\" />";
        }
    }
    if (get_option('eStore_enable_tax')) {
        if (!empty($ret_product->tax)) {
            $tax = round($ret_product->price * $ret_product->tax / 100, 2);
            $output .= "<input type=\"hidden\" name=\"tax\" value='" . $tax . "' />";
        } else {
            $tax_rate = get_option('eStore_global_tax_rate');
            $tax = round($ret_product->price * $tax_rate / 100, 2);
            $output .= "<input type=\"hidden\" name=\"tax\" value='" . $tax . "' />";
        }
    } else {
        if ($ret_product->tax == '0') {
            $output .= "<input type=\"hidden\" name=\"tax\" value='0' />";
        }
    }
    $output .= $urls;
    $output .= '<input type="hidden" name="mrb" value="3FWGC6LFTMTUG" />';
    $returnButtonText = get_option('eStore_paypal_return_button_text');
    $output .= '<input type="hidden" name="cbt" value="' . $returnButtonText . '" />';
    $page_style_name = get_option('eStore_paypal_co_page_style');
    $output .= '<input type="hidden" name="page_style" value="' . $page_style_name . '" />';
    if (get_option('eStore_display_tx_result')) {
        $output .= '<input type="hidden" name="rm" value="1" />';
    }
    if (empty($ret_product->ref_text)) {
        if (!empty($nggImage->pid)) {
            $custom_field_val = eStore_get_custom_field_value();
            $custom_field_val = append_values_to_custom_field('ngg_pid', $nggImage->pid);
            $output .= '<input type="hidden" name="custom" value="' . $custom_field_val . '" id="eStore_custom_values" />';
        } else {
            $output .= aff_add_custom_field();
        }
    } else {
        $custom_field_val = eStore_get_custom_field_value();
        $custom_field_val = append_values_to_custom_field('subsc_ref', $ret_product->ref_text);
        $output .= '<input type="hidden" name="custom" value="' . $custom_field_val . '" id="eStore_custom_values" />';
    }
    if (get_option('eStore_show_t_c_for_buy_now')) {
        $output .= eStore_show_terms_and_cond();
    }
    $output .= $button_type;
    $output .= '</form>';
    $output .= '</div>';
    /* = end of paypal form = */
    return $output;
}
Example #2
0
function eStore_get_custom_field_value()
{
    $output = '';
    $_SESSION['eStore_custom_values'] = '';
    if (!empty($_SESSION['ap_id'])) {
        $name = 'ap_id';
        $value = $_SESSION['ap_id'];
        $custom_field_val = append_values_to_custom_field($name, $value);
    } else {
        if (isset($_COOKIE['ap_id'])) {
            $name = 'ap_id';
            $value = $_COOKIE['ap_id'];
            $custom_field_val = append_values_to_custom_field($name, $value);
        }
    }
    if (isset($_COOKIE['c_id'])) {
        $name = 'c_id';
        $value = $_COOKIE['c_id'];
        $custom_field_val = append_values_to_custom_field($name, $value);
    }
    if (!empty($_SESSION['eStore_coupon_code']) && $_SESSION['discount_applied_once'] == 1) {
        $name = 'coupon';
        $value = $_SESSION['eStore_coupon_code'];
        $custom_field_val = append_values_to_custom_field($name, $value);
    }
    if (function_exists('wp_eMember_install')) {
        $emember_auth = Emember_Auth::getInstance();
        $user_id = $emember_auth->getUserInfo('member_id');
        if (!empty($user_id)) {
            $name = 'eMember_id';
            $custom_field_val = append_values_to_custom_field($name, $user_id);
        }
    }
    $clientip = $_SERVER['REMOTE_ADDR'];
    if (!empty($clientip)) {
        $name = 'ip';
        $value = $clientip;
        $custom_field_val = append_values_to_custom_field($name, $value);
    }
    if (!empty($_SESSION['eStore_selected_shipping_option'])) {
        $name = 'ship_option';
        $value = $_SESSION['eStore_selected_shipping_option'];
        $custom_field_val = append_values_to_custom_field($name, $value);
    }
    if (isset($_SESSION['eStore_store_pickup_checked']) && $_SESSION['eStore_store_pickup_checked'] == '1') {
        $name = 'store_pickup';
        $value = 'yes';
        $custom_field_val = append_values_to_custom_field($name, $value);
    }
    $custom_field_val = apply_filters('eStore_custom_field_value_filter', $custom_field_val);
    return $custom_field_val;
}