to add "Add to cart" button at product search result - wordpress

I m using the woocommerce, and at that i want to insert the add to cart button when the search result are display. Product are displayed bt with the product name ,"Add to cart" button to available with every product at search result.

Add to cart
use above code with your custom product id.For more details refer the link
https://businessbloomer.com/woocommerce-custom-add-cart-urls-ultimate-guide/

Use this:
<?php $id = get_the_ID(); ?>
Add to cart

Related

woocommerce_template_single_add_to_cart doesnt add <form> for variable product

I am using woocommerce_loop_add_to_cart_link to edit the add to cart sections of product-loop on an upsell section in my cart.
add_filter( 'woocommerce_loop_add_to_cart_link', 'add_quantity_fields', 10, 2 );
function add_quantity_fields($html, $product) {
if(is_cart()){
ob_start();
echo '<div class="add-to-cart-container">';
if ( !function_exists( 'woocommerce_template_single_add_to_cart' ) ) {
require_once '/includes/wc-template-functions.php';
}
woocommerce_template_single_add_to_cart();
echo '</div>';
ob_end_flush();
$html = '';
}
return $html;
}
On simple products everything works fine.
On variabe products everything works fine as long as the variable product is the second product in the loop. The <form> is printed and contains the variation dropdowns and the add to cart button.
As soon as the variable product is the only product in the loop or is the first product in the loop, the output of woocommerce_loop_add_to_cart_link doesn't include the variation <form>. Variation dropdowns and add to cart button are printed without being contained inside this <form>.
<form class="variations_form cart" action="" method="post" enctype="multipart/form-data" data-product_id="..." data-product_variations="..."></form>
If this <form> is missing, user can't add the product to the cart even though the variation dropdowns and the add to cart buttons are shown. When user selects the variation and clicks "add to cart" WooCommerce responds with an error message "Please choose product options by visiting %2$s.".
I tried a lot but couldn't get behind the reasoning of this.
Why are the dropdown and button shown without the <form>?
Theme is Flatsome, upsell plugin is WooCommerce Product Recommendations.
An obvious workaround is to include a dummy product and hide it with css, so that all other products are never the first in the loop. That worked as an ugly workaround.
You need to use ob_get_clean() instead of ob_end_flush() like that.
$html .= ob_get_clean();
The form should be printed right then. also make sure this js file is enqueued "add-to-cart-variation.js"

Shopify metafield product add to cart

I created a custom metafild in shopify to add a suggested product to the product page.
I have added the code to my product template and I am correctly displaying the suggested product.
I want to add the add to cart button for this suggested product so that the user can add the suggested product to the cart without entering the specific page.
<div class = "groups-btn">
{% if current_variant.available%}
<input data-btn-addToCart type = "submit" name = "add" class = "btn" id = "product-add-to-cart" value = "add" data-form-id = "# add-to- cart-form ">
{% endif%}
</div>
With this code, however, I add the main product (the one on the page) to the cart, not the suggested product.
How can I solve my problem?
Thanks
Adding products to the cart requires you to POST the ID of the variant and a quantity. Wire up the add to cart button for your secondary product to be an Ajax call and you're good to go.

How can i add a custom link field under the add to cart button?

I would like to add a custom link under add to cart for each product and I'm not sure how to do this. Each of my products has a PDF file and i would like to have the option available when i edit products so I can add the link to them. I don't want to ad it in the description just under the add to cart button.
You can use the woocommerce_after_add_to_cart_button hook to place content below the add to cart button:
function add_content_below_cart_button( ) {
// do something to add your link
};
add_action( 'woocommerce_after_add_to_cart_button', 'add_content_below_cart_button', 10, 0 );

woocommerce product attributes dropdown not appear

i can't select product color or size before add product to cart .
all attributes showing like text not selection
i need to show product attributes dropdown list (options)
i try :
// Remove additional information tab
add_filter( 'woocommerce_product_tabs', 'remove_additional_information_tab', 100, 1 );
function remove_additional_information_tab( $tabs ) {
unset($tabs['additional_information']);
return $tabs;
}
enter image description here
Once you’ve created attributes you’ll need to use those to create variations on your product. I assume what you’re saying is that you click on an attribute and it then takes you to a page showing you any product that is using that attribute.
once your attributes are added to the product follow the rest of this doc to get variations created. Then you’ll have drop down options for those variations on your product.

Add product category name on order page in admin

Is there a way to add product category name to the admin order page in Woocommerce?
Right now it only display the product name.
something like this??
add_action('woocommerce_before_order_itemmeta','woocommerce_before_order_itemmeta',10,3);
function woocommerce_before_order_itemmeta($item_id, $item, $product){
echo '<p>'.get_the_term_list($product->id, 'product_cat').'</p>';
}
this code will display category below the product name.

Resources