Custom Button in WooCommerce add order admin page - wordpress

I want to add a custom button in the page where admin can manually create new order (Admin Order page).
Admin -> Woocommerce -> order -> Add order
After i add product and when clicked edit button can i show a custom button near to Add Meta button ? I cannot find a hook to use.
add_action( 'woocommerce_after_order_itemmeta', 'editable_order_meta_general' );
function editable_order_meta_general(){
?>
<button class="add_values button"><?php _e( 'Add Custom', 'woocommerce' ); ?></button>
<?php
}
I have added the above code. I got the result but the button is displayed soon after i add the product. I only want the button to display when i click edit button.
This is my error
This is my requirement.
#UPDATE
When i added the following code, it worked. Is it the right way ? Since woocommerce button in the same field is set display:none; initially .
add_action( 'woocommerce_after_order_itemmeta', 'editable_order_meta_general' );
function editable_order_meta_general(){
?>
<div class="edit" style="display: none;">
<button class="add_values button"><?php _e( 'Add Custom', 'woocommerce' ); ?></button>
</div>
<?php
}
#Answer
As mentioned by Loiz in comment, there is no hook in WooCommerce to achieve this requirement. Have to change logic or something else.

The hook you're looking for is woocommerce_order_item_add_action_buttons()
I found this tutorial: https://hungred.com/how-to/woocommerce-hook-custom-button-admin-order-page/
Hope that helps

Related

Change woocommerce cart link in menu [duplicate]

On Woocommerce, how can we change the URLs on "View cart" and "Checkout" links on the drop down menu that show up on hover over the shopping cart icon on the the home page?
I have the "cart" and "checkout" pages setup but they are not linked to these.
I can view these pages directly with urls. http://mysite/cart and http://mysite/checkout
It seems that there is a problem somewhere with your theme (or in a plugin), as the minicart button links always point to the right cart and checkout pages.
The minicart buttons are hooked in woocommerce_widget_shopping_cart_buttons action hook (in the cart/mini-cart.php WooCommerce template). You will find the details HERE on includes/wc-template-hooks.php core file. It calls 2 functions that are displaying the buttons.
First you should try to refresh WordPress Permalinks, going on WP Settings > Permalinks:
Just at the end of the page click on "save". Empty your cart, and try it again to see if it changes something.
In the code below I remove first the original buttons and I replace them by the same ones where the links are customized. For each you can change the link to feet your needs (I have added in the links ?id=1 (at the end) just for testing purpose, to check changes):
add_action( 'woocommerce_widget_shopping_cart_buttons', function(){
// Removing Buttons
remove_action( 'woocommerce_widget_shopping_cart_buttons', 'woocommerce_widget_shopping_cart_button_view_cart', 10 );
remove_action( 'woocommerce_widget_shopping_cart_buttons', 'woocommerce_widget_shopping_cart_proceed_to_checkout', 20 );
// Adding customized Buttons
add_action( 'woocommerce_widget_shopping_cart_buttons', 'custom_widget_shopping_cart_button_view_cart', 10 );
add_action( 'woocommerce_widget_shopping_cart_buttons', 'custom_widget_shopping_cart_proceed_to_checkout', 20 );
}, 1 );
// Custom cart button
function custom_widget_shopping_cart_button_view_cart() {
$original_link = wc_get_cart_url();
$custom_link = home_url( '/cart/?id=1' ); // HERE replacing cart link
echo '' . esc_html__( 'View cart', 'woocommerce' ) . '';
}
// Custom Checkout button
function custom_widget_shopping_cart_proceed_to_checkout() {
$original_link = wc_get_checkout_url();
$custom_link = home_url( '/checkout/?id=1' ); // HERE replacing checkout link
echo '' . esc_html__( 'Checkout', 'woocommerce' ) . '';
}
Code goes in function.php file of your active child theme (or theme) or also in any plugin file.
All code is tested on Woocommerce 3+ and works.

How to add "show details" button near the cart button in Woocommerce

I want to add additional button in woocommerce single product. In which file I need to make changes?
Example on screen:
enter image description here
Try this code,
function wc_shop_demo_button() {
echo '<a class="button demo_button" style="padding-right: 0.75em;padding-left: 0.75em;margin-left: 8px; background-color: #0ebc30;" href="'.get_field( "url_demo" ).'" target="_blank">Show Details</a>';
}
add_action( 'woocommerce_after_shop_loop_item', 'wc_shop_demo_button', 20 );
add_action( 'woocommerce_after_add_to_cart_button', 'wc_shop_demo_button', 20 );
Hope this will helps you. For more details visit,
how to add button after woocommerce shop loop item
First of all, create a Custom Field using Advanced Custom Fields plugin for Woocommerce Product Page.
For creating a custom field using the ACF plugin, refer to the below article.
https://wpmayor.com/woocommerce-custom-fields-how-to-create-and-display-them/
To display the Custom Button in the frontend of the website, add the below code in functions.php file.
function rf_custom_product_button() {
echo '<a class="button custom_button" href="'.get_field( "custom_button" ).'" target="_blank">Click Here</a>';
}
add_action( 'woocommerce_after_add_to_cart_button', 'rf_custom_product_button', 20 );
add_action( 'woocommerce_after_shop_loop_item', 'rf_custom_product_button', 20 );
In the above code, Change the "custom_button" to the name of the field which you create using ACF.

Is there any way to display the WooCommerce mini-cart on my WordPress site?

I'm developing a website whereby I would like customers to be able to constantly view the contents of their cart so they can add/remove items on the fly (using WooCommerce).
The theme I'm currently using is Flatsome (with the UXBuilder)
I've noticed there is a template for the WooCommerce mini-cart in woocommerce/templates/mini-cart.php. This looks like what I want to be displayed on my page
I have a plugin called WooCommerce Product Tables that (I believe) displays this mini-cart like this
I was wondering if there is any way for me to display this as a fixed element (within a div perhaps) on my page?
I'm quite inexperienced, so any help is appreciated :)
As Bhoomi suggested, using woocommerce_mini_cart(); works however ajax cart doesn't update the minit cart.
Using this method I suggest to wrap mini_cart function with "widget_shopping_cart_content" woocommerce class, for example :
<div class="widget_shopping_cart_content"><?php woocommerce_mini_cart(); ?></div>
So with ajax add to cart, the mini cart is updated also.
First Create the shortcode on function.php
// Add Shortcode
function custom_mini_cart() {
echo '<a href="#" class="dropdown-back" data-toggle="dropdown"> ';
echo '<i class="fa fa-shopping-cart" aria-hidden="true"></i>';
echo '<div class="basket-item-count" style="display: inline;">';
echo '<span class="cart-items-count count">';
echo WC()->cart->get_cart_contents_count();
echo '</span>';
echo '</div>';
echo '</a>';
echo '<ul class="dropdown-menu dropdown-menu-mini-cart">';
echo '<li> <div class="widget_shopping_cart_content">';
woocommerce_mini_cart();
echo '</div></li></ul>';
}
add_shortcode( '[custom-techno-mini-cart]', 'custom_mini_cart' );
Then add this [custom-techno-mini-cart] short code anywhere on page.
Now add this inside your template
<?php echo do_shortcode(['custom-techno-mini-cart']); ?>
Hope This will help you.
Make your layout according to your requirement in first point.
ADD Like This ALSo using This
woocommerce_mini_cart()
You can use woocommerce_mini_cart() wherever you want to display your minicart.
This function loads the mini-cart.php template to display the mini cart.

How can I remove "View Cart" button that appears after adding a product in the cart on a custom page?

I have used the "add to cart" shortcode for a product on a custom page. But I want to remove the "View Cart" button that appears after clicking the "Add to Cart" link of the product.
add this code to function.php
add_action( 'woocommerce_init', 'remove_message_after_add_to_cart', 99);
function remove_message_after_add_to_cart(){
if( isset( $_GET['add-to-cart'] ) ){
wc_clear_notices();
}
}
Im no pro on this so I don't know how it might affect your code, but this is what I did to solve the issue.
Find the file: inc\woocommerce\woocommerce-config.php
Line 699 (in my case)
$array['view_cart'] = esc_attr__( 'View cart', 'oceanwp' );
Replace 'View cart' with ''

Text under Add to cart (woocommerce)

How can I add a text saying "Contact us for bulk purchase enquiry" under 'Add to cart' button for all woocommerce products.
Thanks
Try adding this code to your functions.php file :
add_action( 'woocommerce_after_add_to_cart_button', 'content_after_addtocart_button_func' );
function content_after_addtocart_button_func() {
// Echo content.
echo '<div style="font-size:10px;"><em>(*Contact us for bulk purchase enquiry)</em></div>';
}
Hope it helps!

Resources