disable add to cart if custom options are required.Magento - php

in my current product view http://goo.gl/pgdoUl I have all required custom options with a pop up windows that show up in case the value is wrong eg. Track/Pole Length - Finished Curtain Drop. If in the text file all the information are wrong it's still possible to add to cart the product.
How in this case it's possible to disable add to cart?

Currently magento uses prototype/validation.js which is the default way magento uses validations. What you need to do here is write jQuery or plain JavaScript function to validate all your entries and on the bind this function to the click event of add to cart button, only if the validation succeeds the add to cart (which is a form) should get submitted.

Related

Woocommerce -- Adding Products with Javascript/PHP

I have a custom form that users make various selections before being presented with products they can buy. I need to add some logic that if an input has been selected when the user adds a product to the cart, it will also add an additional product to the cart.
The input is 3 radio check boxes. Somehow I need to hook into the add to cart click and check the page to see if one of the radios has been selected and then add the appropriate product but I'm not sure where to start.
I know I'll need to have an action that runs something like:
WC()->cart->add_to_cart( 'product_id', 'quantity');
But I'm not sure how to hook into the initial add to cart click and how to check for the radios on the page.
Thank you for your help.
Not a lot of information to go off of here, but here is a few useful WooCommerce hooks to give you a starting point/ order of operations. When overriding any native action in WordPress or its plugins. You should use the hooks if available.
Add the radio inputs to the single product before the add to cart is added (hook):
add_action("woocommerce_before_add_to_cart_button", "your_input_render_function_here");
Add the new input data from the radio buttons to the cart item (filter):
add_filter("woocommerce_add_cart_item_data", "your_filter_function_to_capture_data_here");
Capture the data and render in cart (filter):
add_filter("woocommerce_get_item_data", "your_cart_render_function");
Finally, save the newly aquired data to the order (hook):
add_action("woocommerce_checkout_create_order_line_item", "your_function_to_add_to_order")
This is one of many directions you can take, depending on your requirements. I recommend giving it a shot, and if you still have issues return with an example of your code.

Change order in Woocommerce checkout

I need to change the layout of the Woocommerce checkout page. I need to move the payment option box along with the terms&conditions checkobox ABOVE the order-review table. The "Place Order" button should stay at the bottom though.
I know I need to override the template in my childtheme, but I just can't get this to work as the payment box is combined together with the order-review table. Or is this somehow possible via a function?
Thank you!

Add Custom Input Field on Woocommerce Cart Page

I've been developing a WooCommerce site and I have a task where I have stuck. I need to add an extra custom input field into the cart items table.
Like for example, if a person orders '2000 youtube views' package, then right below the item name, I want the user to input his Youtube video URL.
I know I can add custom input fields on Product Page and can simply make them display on the Cart Page. But I want to take user input data onto the Cart Page. Each cart item will have a custom input field. So far, I have researched a lot but didn't have any success for my solution. All I found that to print the custom input field data onto the cart page added on the Product Page.
Any help would be appreciated
I've had this problem also. I've solved it with this. Adding the fields on the cart page like you did but with jQuery receive those values and dynamicly transfer them with a GET request, ( adding them to the submit button ) and $_GET fill them in the checkout page in a hidden input type.

Magento - Display product and category body page for each design in admin

I need to identify the add to cart button and disabled it (js and php) based on product id(this is not the real aim of the question, the bold is the real one)
Since I haven't found any solution I have thought to let the admin press the button in the admin section dedicated tomy extension and capture the button information with js and then save them later.
To do so I would like to display the main body of the product page and the one of a category for each theme in the design section.
This is how I retrieve the themes and packages:
//Main package/theme
Mage::getStoreConfig('design/package/name')
//Reegex theme
$ob=unserialize(Mage::getStoreConfig('design/package/ua_regexp'));
foreach($ob as $key)
echo $key['value'];
My main concern is about the bold part, is if it is possible? How do I do it?
Just to be clear: I need only the red rectangle:
Above it there is the breadcrumbs and on the right the sidebar
MORE DETAILS
When the admin creates/edit a product, it can select or not the countries where the item can be selled.
What happens: when a page load the system check if the item is merchantable in the costumers country otherwise it removes the button.
Now this bring some problems:
Wide theme support: I'm not sure the button html is the same of the default one
In the same page can exist merchantable and not-merchantable products: identify the button of the correct item in the category page where there are multiple of them, to do so I check the button behaviour: usually it contains: /checkout/cart/ plus the product id in the onlick attribute or the button submits a form, I think that if the admin "shows" me what happens and, after an analysis, I will be able to identify the button and replace it using the id (secure) or class ( not so certain), since not all the stores use the default btn-cart class
Cache/FPC system that fetch the page: I don't know if they will catch the js that disable the button or if the customer has disbaled any script (probably it can't even use the site), however usualy the add to cart block is not cached by those programs (sometimes if the item is not available the button is hidden)
SEO problem: guest aren't forced to select a country, but I try to identify it with some external service using the ip, so probably it will also detect the bots as users, I don't know if it will be a problem (I don't think so), otherwise I have to use JS to do an AJAX call and then hide the button
I would like to avoid any edit to any template file and create a very simple way for the user to set up the module( click a button is less complicated than the whole procedure to create an attribute, the relatives options and associate it to the sets)
Basically: How can I display the product and category page in the backend?
What about using next logic for removing button from product page:
Add new attribute (for example: hide_button, type Yes/No) to products in Catalog > Attributes > Manage Attributes. By default it will be 'no', so all products has the button. Admin can set attribute to 'Yes' for needed products.
Create observer which will catch catalog_product_load_after event:
public function checkProduct(Varien_Event_Observer $observer){
Mage::register('hide_button', $observer->getEvent()->getProduct()->getData('hide_button'));
return $this;
}
Create observer which will catch controller_action_layout_generate_blocks_after event and inject your js code to all themes:
public function injectScript(Varien_Event_Observer $observer){
if (Mage::registry('hide_button' == 1) {
$head = $observer->getEvent()->getLayout()->getBlock('head');
$head->addItem('js', 'hide-button.js');
}
return $this;
}
Create file js/hide-button.js which will remove buttons with class 'btn-cart' from page:
Event.observe(window, 'load', function() {
$$("button.btn-cart").remove();
});
I didn't test the code, it's just an idea.

Woocommerce Custom Add to Cart URL

I have a question with adding a product to the cart via a url. Right now I can use http://example.com/cart/?add-to-cart=49 and it will add the item to the cart. I'm using a plugin that adds a custom text input to each product. The plugin is WooCommerce Extra Product Options on codecanyon.
I need to add a parameter to my add to cart url where I can add an item to the cart but also pass a value to that custom input through the url as well. Ideally my url would look something like http://example.com/cart/?add-to-cart=49&textbox=myvalue. I'm really not sure the best way to approach this. I'm not against not using that plugin either if there is a better way to make this work. Thanks for your help.

Categories