0

Since I am new to PHP, i have a question.

I've searched a few days on the internet, but don't really find an answer. I have also tried a few plugin's, but nothing replies to my wish...

What I want to do:

I have two wordpress websites. One is with a product catalog and one, with exact same products is a webshop.

I want to create ONE dynamic link on the productpages on the catalog website which loads the product on the webshop (the second website). Domains are different, but i made shure the product (or post-) titles are exactly the same on both websites.

How do I create one universal URL which then loads post title from source site to the target site?

Example:

https://www.tapverhuuretten-leur.nl/product-a

I put the same link on EVERY product page, under a button, e.g. https://www.deparelevenementenservice.nl/page?name=post_title

Which then loads: https://www.deparelevenementenservice.nl/product-a

With product-b the same must happen, but then the output becomes: https://www.deparelevenementenservice.nl/product-b

In short: I want to create a single link to post on product pages, which then loads the particular product on the other domain with same product (post) title. So product-a is redirected to product a on the second domain. Product-b on catalog site will be linked to product-b on second domain, and so on..

My wish is pretty straightforward, but i think some pretty complex coding is involved?

Ofcourse I can link every product to the second domain manually for every product, but this is very time consuming. Secondly: when i update the products on the catalog site with an import from the webshop, the links will be gone and i then have to set these again.

I have no idea how to programm this. Forgive me if this is a silly question, i'm a beginner. I guess i must code it around the _get_the_title value?

If anyone knows the code, i will be very grateful.

Many thanks for understanding and helping me, in advance.

I have this code available:

    <?php
        woodmart_product_categories();
        woodmart_product_brands_links();
        woodmart_product_sku();
        woodmart_stock_status_after_title();
    ?>
    <?php if ( 0 < $product->get_average_rating() || woodmart_get_opt( 'show_empty_star_rating' ) ) : ?>
        <?php echo wp_kses_post( woodmart_get_product_rating() ); ?>
    <?php endif; ?>
    <?php
        /**
         * woocommerce_after_shop_loop_item_title hook
         *
         * @hooked woocommerce_template_loop_rating - 5
         * @hooked woocommerce_template_loop_price - 10
         */
        do_action( 'woocommerce_after_shop_loop_item_title' );
    ?>

    <?php do_action( 'woocommerce_after_shop_loop_item' ); ?>

    <?php if ( woodmart_loop_prop( 'progress_bar' ) ): ?>
        <?php woodmart_stock_progress_bar(); ?>
    <?php endif ?>

    <?php if ( woodmart_loop_prop( 'timer' ) ): ?>
        <?php woodmart_product_sale_countdown( array( 'products_hover' => 'button' ) ); ?>
    <?php endif ?>
<?php if ( woodmart_loop_prop( 'stretch_product_desktop' ) || woodmart_loop_prop( 'stretch_product_tablet' ) || woodmart_loop_prop( 'stretch_product_mobile' ) ) : ?>
</div>
<?php endif; ?>

Where can I insert the url safely to create the dynamic link (instead of the add to cart button)?

1 Answer 1

1

Relatively easy to achieve, just put this somewhere in your template within The Loop:

<a href="https://www.deparelevenementenservice.nl/<?php echo $post->post_name; ?>">Link text</a>
2
  • Oh, that is fairly simple indeed! Thank you very much for this information!
    – Nathan Kop
    Commented Nov 28 at 7:27
  • I have edited my question, see above. Can you tell me where I can insert the url? I've tried it in another template (woocommerce) but then I get a critical error on the site.
    – Nathan Kop
    Commented Dec 3 at 9:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.