Custom Product in woocommerce

I was trying to create a custom shop page for a project where users can click on a product to view the details in a modal window and select some options on price variations.

What I want to do is to send the product details to checkout page upon chosen by the user.

Read More

Is it possible to do ? If so , how ?

Your help is appreciated. Thanks !

Related posts

2 comments

  1. I was able to accomplish it by myself. In my template:

    <a href="http:example.com/checkout/?add-to-cart=70&&price=28.45"> Custom product name </a>
    

    In my functions.php

    add_filter( 'woocommerce_add_cart_item' , 'set_woo_prices');
    add_filter( 'woocommerce_get_cart_item_from_session', 'set_session_prices' , 20 , 3 );
    
    function set_woo_prices( $woo_data ) {
    
      if ( ! isset( $_GET['price'] ) || empty ( $_GET['price'] )) { return $woo_data; }
    
      $woo_data['data']->set_price( $_GET['price'] );
      $woo_data['my_price'] = $_GET['price'];
      return $woo_data;
    }
    
    function  set_session_prices ( $woo_data , $values , $key ) {
        if ( ! isset( $woo_data['my_price'] ) || empty ( $woo_data['my_price'] ) ) { return $woo_data; }
        $woo_data['data']->set_price( $woo_data['my_price'] );
        return $woo_data;
    }
    
    function redirect_to_checkout() {
        return WC()->cart->get_checkout_url();
      }
    

    This actually does the trick. I know this is not a secured way. If someone could tell me the best approach that would be great !

  2. You can redirect user to checkout right after he uses the add to cart.

    To do so just paste this in your theme’s functions.php

      function redirect_to_checkout() {
        return WC()->cart->get_checkout_url();
      }
    

Comments are closed.