We use cookies to ensure that we give you the best experience on our website. If you continue to use this site we will assume that you are happy with it.

Puzzle Order Button same TAB

Home Forums General Questions Puzzle Order Button same TAB

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #31755
    kubuz
    Customer

    Hi Guys,
    Very short and simple question.
    Is there a way to have the woo-commerce place order puzzle to open in the same tab.
    There is really no need to open it in a seperate tab.

    btw, I managed to drop the custom price the default cart.
    https://www.thecustomshop.be/custom-lamp-configurator/

    muchas gracias.

    #31761

    Hi,

    Awesome news! what plugin are you using for custom price?

    Is there a way to have the woo-commerce place order puzzle to open in the same tab.

    In fact, you can use just the puzzle send data to invoke that link (e.g. https://www.thecustomshop.be/winkelmand/?add-to-cart=1360)
    This way your page won’t be reloaded.

    Chief 3D Verger | LinkedIn | Twitter

    #31771
    kubuz
    Customer

    Awesome news! what plugin are you using for custom price?

    I was lucky that a good friend came to help me with this.
    Its a small piece of custom code in functions.php and a piece in MyAwesomeApp.js

    Basicly its pretty simple, I use a small custom script to create and update a cookie in the MyAwesomeApp.js

    function prepareExternalInterface(app) {
      app.ExternalInterface.setCookie = function setCookie(numericArg) {
        var d = new Date();
        d.setTime(d.getTime() + (5*24*60*60*1000));
        var expires = "expires="+ d.toUTCString();
        document.cookie = "Price" + "=" + numericArg + ";" + expires + ";path=/";
      }

    This cookie is being picked up by the script when entering the woocommerce cart page

    // PART 1, CHANGE PRICE OR CUSTOM PRODUCT ON THE CHECKOUT PAGE
    // ADD TO FUNCTIONS.PHP
    
    function custom_shop_price( $cart ) {
    
        $customshop_product_ids = 1360;
     
        if ( is_admin() && ! defined( 'DOING_AJAX' ) ) return;
     
     
        // LOOP THROUGH CART ITEMS, FIND CUSTOM MADE PRODUCT, GET THE PRICE
      
    		
    		foreach (  WC()->cart->get_cart() as $cart_item_key => $cart_item ) {
    			$product = $cart_item['data'];
    
    			// CHECK IF PRODUCT IS CUSTOM SHOP ITEM
    			if($product->id ==  $customshop_product_id && isset($_COOKIE['Price'])){
    				$cart_item['data']->set_price( $_COOKIE['Price'] );
    
    			// SET PRICE TO CUSTOM PRODUCT PRICE
    			// TODO: FIND THE STORED PRICE: SESSION, COOKIE, URL VARIABLE, ...??
    
    				$cart_item['data']->set_price( $_COOKIE['Price'] );
    			}
    		}
    	
     
    };
    add_action( 'woocommerce_before_calculate_totals', 'custom_shop_price' );
    
    // Clear Cart URL command
    function woocommerce_clear_cart_url() {
    	if ( isset( $_GET['add-to-cart'] ) ) {
    		WC()->cart->empty_cart();
    	}
    }
    add_action( 'init', 'woocommerce_clear_cart_url' );

    Now I still needs an update to handle multiple products.
    So we need to make this piece looping trough multiple products.

    #31773

    I see. Glad you worked it out, and thanks for sharing your solution! :good:

    Chief 3D Verger | LinkedIn | Twitter

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.