Forum Replies Created

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

    (@allmighty2026)

    Thank you very much for your response!

    I threw the question of dynamic product because I myself am a php programmer. My work has always been in coding. So I thought I might create a customized product page to process the 1,000 photos like I used to do.

    I experimented with short-code and add code snippert to WordPress. I was able to create code that display a category of photos dynamically by selecting a theme, using content in the filename, say, “tree,” “water,” etc.

    Each of the page should have a Buy Print page that leads to the product (which is the photo) page and users select a size and price, and then click “Add to Cart.”

    I tried to do this but my short code caused the site crash. I removed hte short code. the site is back. I’m careful now where I’ll put the code.

    My question: does it work the time and effort to create a customized dynamic Buy Print page (purchase page)? I might have to create a product for each photo — that’s repetitive. Anyhope that I can do it dynamically without paying the expert?

    Thread Starter allmighty2026

    (@allmighty2026)

    My site is up now, after removing the bad code snippert from the phpAdmin database.

    I’ve been experimenting with WooCommerce product. There is a way to upload many photos (30,000) and for each photo WooCommerce creates a product.

    I prefer not to have so many products in WooCommerce. Some of hte photos might never be purchase. I’d like to have dynamic product template. each time calling hte product page, the photo filename is passed from the previous page, and this product template displays the photo, and offers three size and prices for physical print. Then an “Add to Cart” button take the purchase to the cart.

    I read about the steps: changes in function.php, creation of a hidden product in WooCommerce, then change of product (photo name each time going in). Is that a good approach?

    Thanks!

    Thread Starter allmighty2026

    (@allmighty2026)

    Thanks for your patience.

    Called GoDaddy to uninstalled code snippet and woocommerce. The site was up. I intalled them again. the site crashed. Call Godaddy to do the same. Site up. Intalled code snippet and woocommerce. Site down.

    I was able to access Setting (not the WP dashboard), and there was the phpAdmin database. I found the snippet datatable, and the snippet I added yesterday. I deleted the snippet. This was the only way to remove it, and I didn’t know if it worked. After I removed it, I installed code snippet. it crashed again.

    Called Godaddy to bring hte site up. They did and warned me not to install code-snippet. I said I had to have it because I needed it to do the dynamic page. Then on the internet, I found someone suggesting going to mydomain/admin and running it in safe mode to reload. I did that. Then the snippet was back in WordPress (I didn’t install again), and the one snippet that worked before yestersday was work. Teh bad one was gone.

    I need to have a more stable way to deal with this matter.

    Will update on the next step.

    Thread Starter allmighty2026

    (@allmighty2026)

    I haven’t incorporated the code into WordPress yet. I added a snippet (which I posted earlier). When I saved it, the site crashed. The snippet was used in any page yet. Isn’t that interesting. In the past, errors showed on the page it had problems, it wouldn’t crash the whole site. And in this case, I haven’t plugged into the WordPress page. Simply creating it would cause an error like that.

    Here is the scenario: I have tons of images. I moved 100 to the Media Library in WordPress. Each image has title, filename, caption, description, etc.

    Using <mla_gallery> tag, I selected 25 images with “clouds” in the file name. I displayed the the thumbnails of these 25 in a page called “Photo.” I deliberatly call the page “Photo” because I’ll use the same page to display “Sunshine” using the same method.

    On the Clouds page, clicking on a thumbnail would opens the Photo page that dispalys a large image of hte photo, with a button that says “Buy photo.” Here is the snippet:

    function get_display_photo_shortcode() {

    $name = isset($_GET['image_name']) ? sanitize_text_field($_GET['image_name']) : '';
    $page = isset($_GET['from']) ? sanitize_text_field($_GET['from']) : '';
    $caption = isset($_GET['caption']) ? sanitize_text_field($_GET['caption']) : '';

    ob_start();
    ?>

    <div>

    <img src="https://mysite/wp-content/uploads/2026/05//<?php echo esc_html($name); ?>" alt="Description of the image">
    <p><?php echo esc_html($caption); ?></p>
    <!-- <p>Page: <?php echo esc_html($page); ?></p>-->
    <p> <a href="/buy-photo/?file=<?php echo urlencode($name); ?>">
    Buy photo
    </a>(coming soon) &nbsp;&nbsp;
    <a href="/cloud_static/">Purchase Test</a>&nbsp;&nbsp;
    <a href="https://mysite/<?php echo esc_html($page); ?>">Back</a>
    </div>

    <?php
    return ob_get_clean();
    }

    On hte Buy photo page, I’d like to display three options of sizes and their prices of the physical print of the photo. Then display a “Add to Cart” button, which I was hopeing to use the above snippet. The “Add to Cart” takes the flow to WooCommerce. The Buy photo page should work for all images. The “Purhcase Test” link (<a href=”/cloud_static/”>Purchase Test</a> works because it was pointing to a product (static) registered in the WooCommerce product list. I’d like Buy photo link works for all images dynamically.

    Does it make sense?

    Thread Starter allmighty2026

    (@allmighty2026)

    $product_id = 123;

    $add_to_cart_url = wc_get_cart_url() .
    '?add-to-cart=' . $product_id .
    '&image_file=' . urlencode($filename);

    ?>

    <a href="<?php echo esc_url($add_to_cart_url); ?>" class="button">
    Add To Cart
    </a>

    The above is the code. I realize one problem is that $add_to_cart_url is not ready yet.

    There are suggestions to add a delay to call wc_get_cart_url()

    add_action( 'template_redirect', 'my_custom_redirect_function' );

    function my_custom_redirect_function() {
    // WordPress is fully loaded now
    $cart_url = wc_get_cart_url();
    // ... your other code here
    }

    Does it look right? Any help will be greatly appreciated!

    Thread Starter allmighty2026

    (@allmighty2026)

    Allen and threadi,

    Thank you both for reply. I’m back to the site and dashboard. I was able to locate the error message in the error log:

    PHP Fatal error: Uncaught Error: Call to a member function get_page_permastruct() on null in /dom1149977/wp-includes/link-template.php:435
    Stack trace: 0 /dom1149977/wp-includes/link-template.php(397): _get_page_link(Object(WP_Post), false, false) 1 /dom1149977/wp-includes/link-template.php(197): get_page_link(Object(WP_Post), false, false) 2 /dom1149977/wp-content/plugins/woocommerce/includes/wc-page-functions.php(98): get_permalink(Object(WP_Post)) 3 /dom1149977/wp-content/plugins/woocommerce/includes/wc-core-functions.php(1410): wc_get_page_permalink(‘cart’) 4 /dom1149977/wp-content/plugins/code-snippets/php/snippet-ops.php(663) : eval()’d code(4): wc_get_cart_url() 5 /dom1149977/wp-content/plugins/code-snippets/php/snippet-ops.php(663): eval() 6 /dom1149977/wp-content/plugins/code-snippets/php/evaluation/class-evaluate-functions.php(170): Code_Snippets\execute_snippet(‘\n$product_id = …’, 9) 7 /dom1149977/wp-content/plugins/code-snippets/php/evaluation/class-evaluate-functions.php(150): Evaluation\Evaluate_Functions->evaluate_db_snippets() 8 /dom1149977/wp-includes/class-wp-hook.php(341): Evaluation\Evaluate_Functions->evaluate_early(”) 9 /dom1149977/wp-includes/class-wp-hook.php(365): WP_Hook->apply_filters(NULL, Array) 10 /dom1149977/wp-includes/plugin.php(522): WP_Hook->do_action(Array) 11 /dom1149977/wp-settings.php(593): do_action(‘plugins_loaded’) 12 /dom1149977/wp-config.php(54): require_once(‘/dom1149977/wp-…’) 13 /dom1149977/wp-load.php(50): require_once(‘/dom1149977/wp-…’) 14 /dom1149977/wp-admin/admin.php(35): require_once(‘/dom1149977/wp-…’) 15 /dom1149977/wp-admin/plugins.php(10): require_once(‘/dom1149977/wp-…’) 16 {main}

    thrown in /dom1149977/wp-includes/link-template.php on line 435

    I am still looking for a way to access the php code. I can see in the phpAdmin database the entry of the php code. On hte internet, there are suggestions saying code is bad, trying to call the function wc_get_car_url() before the plugin was loaded…

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