• Resolved fifthcloud

    (@fifthcloud)


    I have a JavaScript click event that renders a preview per item that the user wants to see more information. Upon my click event I send all details to the function called “More Info”

    Within that More Info function I want to put the shortcode [wp_cart_button name=”PRODUCT-NAME” price=”${data[“price”]}”]

    ${data[“price”]} has the information on the price of the product. However, when I insert this into page I keep getting the “Error! You must specify a price for your product in the shortcode.”

    I don’t know what I need to do. Is there a way I can just send the string “[wp_cart_button name=”PRODUCT-NAME” price=”PRODUCT-PRICE”]” with the correct values? Will WordPress render the button then?

    The reason why I can’t hardcode the values is my website sells large quantity of products anywhere from 100,000 – 120,000. Having to update these pages is not practical in my case. This the reason why I believe this plugin so far is my closest solution.

    Any suggestions how to render the shortcodes dynamically?

    Thank you!

Viewing 6 replies - 1 through 6 (of 6 total)
  • Thread Starter fifthcloud

    (@fifthcloud)

    I am so close, but I am not figuring out this last bit. I have taken a look at your code and tried recreating the shortcode into html as you have done. My only issue is the hash. I am following how you create the hash but they are not matching up for some reason. I don’t know why. I have spent hours just trying to figure this out to no avail.

    Are you storing the hash values in order to compare against? Or are you re-creating them and comparing them that they should match? I am not understanding.

    Basically have created the hashes as you have and posted the html into my form. This is the line of code I keep failing at in your plugin. Don’t know how to make them equal. Any thoughts?

    
    if ($hash_once_p != $hash_one_cm) {//Security check failed. Price field has been tampered. Fail validation.
                    wp_die('Error! The price field may have been tampered. Security check failed.');
                }
    
    Thread Starter fifthcloud

    (@fifthcloud)

    To be complete I forgot to post my code that I am reproducing in yours.

    
    //$totalprice is the value from database for the users selection. 
    $unique_id_price = uniqid('', true);
    			$hash_one_cm = md5($unique_id_price . '|' . $totalprice);
    			$unique_id_shipping = uniqid('', true);
    			$hash_two_cm = md5($unique_id_shipping . '|' . 0);
    
    return "<div class=\"wp_cart_button_wrapper\"><form method=\"post\" class=\"wp-cart-button-form\" action=\"\" style=\"display:inline\" onsubmit=\"return ReadForm(this, true);\"><input type=\"hidden\" id=\"_wpnonce\" name=\"_wpnonce\" value=\"ae57cedc7d\"><input type=\"hidden\" name=\"_wp_http_referer\" value=\"$returnURL/\"><input type=\"submit\" class=\"wspsc_add_cart_submit\" name=\"wspsc_add_cart_submit\" value=\"Add to Cart\"><input type=\"hidden\" name=\"wspsc_product\" value=\"Diamond\"><input type=\"hidden\" name=\"price\" value=\"$totalprice\"><input type=\"hidden\" name=\"shipping\" value=\"0\"><input type=\"hidden\" name=\"addcart\" value=\"1\"><input type=\"hidden\" name=\"cartLink\" value=\"$myURL\"><input type=\"hidden\" name=\"product_tmp\" value=\"PRODUCTNAME\"><input type=\"hidden\" name=\"item_number\" value=\"\"><input type=\"hidden\" name=\"hash_one\" value=\"$hash_one_cm\"><input type=\"hidden\" name=\"hash_two\" value=\"$hash_two_cm\"></form></div>"
    

    This DIV is then returned into my wordpress and does indeed render the add button. But upon button event click I get the error. Hopefully, this will help you to see why I can’t get those hashes to match up. What am I missing?

    Very sleep deprived at the moment.

    Thank you.

    If you can execute the following PHP code (using AJAX maybe), then it will generate a valid button code for you.

    <?php
    $name = “My Test Product”;
    $price = “19.90”;
    echo print_wp_cart_button_for_product($name, $price);
    ?>

    Executing the following code will work too:

    
    <?php
    echo do_shortcode('[wp_cart_button name="Test Product" price="25"]');
    ?>
    
    Thread Starter fifthcloud

    (@fifthcloud)

    Thanks for the suggestion. Tried using your suggestion and I get this error.

    
    Call to undefined function print_wp_cart_button_for_product() in...
    

    I thought then if I were to include your php file where it is defined and took me some time to figure out why nothing is happening. Looks like it was exiting and not executing anymore. It turns out in your code…

    
    if (!defined('ABSPATH')) {//Exit if accessed directly
        exit;
    }
    

    Do you have any other suggestions?

    Thread Starter fifthcloud

    (@fifthcloud)

    Thank you for your help so far. It seems as though there are a few obstacles with the plugin that still need to fleshed out.

    But I decided upon going making the changes directly by using the PayPal API, namely, using their RESTful API. From the trial that I have done, I was able to achieve the results I wanted.

    Further, I was not able to dive too deeply into your code, but I have a suspicion that your hashing may not be the best way to see if people are tampering with the price amount. Just have this feeling that if someone can put the correct the hash and price they can successfully modify that value. Again, I have not looked to deeply at your code, but that was one thing that stood out at me as not liking that way for security.

Viewing 6 replies - 1 through 6 (of 6 total)

The topic ‘Dynamically Render Short Codes, Is this possible?’ is closed to new replies.