I am very new to this community. kindly help me to get resolve form wordpress related query.
I am working on woocommerce website and need to add a service for ex:"electricity bill payment" . So, user has to dynamically add the amount and it should add to the card and reduced from his main wallet.
Is there any plugin or extension for this dynamically price added by this enduser ?
Plz suggest me and sorry for my bad english.
Many thanks,
sai
function woo_add_cart_fee() {
global $woocommerce;
$woocommerce->cart->add_fee( __('Custom', 'woocommerce'), 5 );
}
add_action( 'woocommerce_cart_calculate_fees', 'woo_add_cart_fee' );
Would you please add above code in your active theme functions.php ? but it will be applied on over all cart.
Related
I am struggling to know how WooCommerce initiate the saving of post and post meta from the dashboard? Please help me with this.
I was able to find the insert code here:
includes/class-wc-order.php
public function save() {
//statement
}
Thanks
May be this one can be helpful to others..
WooCommerce use post meta to add extra information on default WordPress post. Hence every time we update or create order from WordPress admin, WordPress initiate from this action...
add_action( 'save_post', array( $this, 'save_meta_boxes' ), 1, 2 );
Location: woocommerce/includes/class-wc-admin-meta-boxes.php
Everything happens from this hooks.
Note: As this is not related to aboven question but the best hooks to process any action on custom meta box is:
woocommerce_order_object_updated_props
Thanks
I'm currently working on a custom WooCommerce from a WordPress theme I have built from scratch. So far everything is working perfectly but I have come across an issue that I can't seem to get my head around. When I click on a product I am taken to the single product page, everything works as expected when I scroll down to the tabs section I am seeing the Description tab, but there is no reviews tab. I spent a big chunk of the weekend trying to find a solution to displaying this but I have been unsuccessful.
I have searched the project for the following lines to make sure I haven't disabled the functionality.
remove_action( 'woocommerce_product_tabs', 'woocommerce_product_reviews_tab', 30);
remove_action( 'woocommerce_product_tab_panels', 'woocommerce_product_reviews_panel', 30);
I am completely stumped now. I have tried Google to find a solution, but I can only find articles and forum posts for pre-existing bought themes. Now I'm left wondering if I have actually missed something. I can display the review stars and it is correctly displaying the number of reviews but when I click on the url to go to the reviews the address bar displays wp-lds-shop/product/happy-ninja/#reviews.
I would really appreciate any help or advice on this.
I have found the following solution, which worked for me.
You have to declare WooCommerce support, otherwise the "Review" tab will not show up.
I followed this link: https://github.com/woocommerce/woocommerce/wiki/Declaring-WooCommerce-support-in-themes and added this code at the bottom of my functions.php
function mytheme_add_woocommerce_support() {
add_theme_support( 'woocommerce' );
}
add_action( 'after_setup_theme', 'mytheme_add_woocommerce_support' );
I hope this works for you!
Please Check This:
Reviews are enabled in:
How to enable reviews remove Reviews tab
just add to function.php template
add_filter( 'woocommerce_product_tabs', 'yikes_remove_description_tab', 20, 1 );
function yikes_remove_description_tab( $tabs ) {
// Remove the description tab
if ( isset( $tabs['description'] ) ) unset( $tabs['description'] );
return $tabs;
}
So basically, what i want, to show product added in cart also on archive page. I did this functionality, you can refer with image (1 item- already in cart) but my code work on refresh the page. I want to show the same with ajax. As soon as "add to cart" clicked, the data added in mini cart, at same time data will show on product listing page. enter image description here
Go to
Woocommerce > Settings > Products > Enable AJAX add to cart buttons on archives
add_filter( 'wc_add_to_cart_message', 'custom_add_to_cart_message' );
function custom_add_to_cart_message() {
global $woocommerce;
$return_to = get_permalink(woocommerce_get_page_id('shop'));
$message = sprintf('%s %s', $return_to, __('Continue Shopping', 'woocommerce'), __('Product successfully added to your cart.', 'woocommerce') );
return $message;
}
If you want to add your product with quantity using Ajax then definitely WooCommerce default checkbox Enable AJAX to add to cart buttons on archives not works for quantity purpose.
There are many solutions to add this feature. I have implemented it earlier. You just need to add some classes, functions, and script to achieve this.
This is the link which is really helpful for me and you can go through it or you can also check this one. It's not complicated.
If you want to add this in your headers like a mini cart or something. So for that, this one is the best solution for you.
Hope this will helpful for you. Thanks.
First question so please be patient!
I'm using Sensei and Woocommerce for an LMS and payment portal site.
When the checkout is complete and a course (from Sensei) has been purchased I want to remove the notice created by Sensei and the top of the page.
It is added with this action.
add_action( 'template_redirect', array( 'Sensei_WC','course_link_from_order' ) );
Therefore, how do I remove or change this notice created by the action
I've tried this!
remove_action( 'template_redirect', array( 'Sensei_WC','course_link_from_order' ) );
in my functions file by alas, no success!
Thanks in advance
I would like to modify the products sorting on the shop page to product categories filter where the user can select the browse the products of categories from there.
I am a rookie in programming. I checked the WooCommerce directory to find the .php file I should work on. I got some clue it is in archive-product.php but I don't see the code which display the sorting dropdown.
Can anyone give me some clue to achieve this ? Or is there any workaround ? Thanks.
I added this in functions.php :
// remove default sorting dropdown
remove_action( 'woocommerce_before_shop_loop', 'woocommerce_catalog_ordering', 30 );
// now add the new dropdown
add_action( 'woocommerce_before_shop_loop', 'add_product_category_dropdown' );
function add_product_category_dropdown(){
print '<span class="woocommerce-ordering">'; // So it takes the same position as the default dropdown
the_widget( 'WC_Widget_Product_Categories', 'dropdown=1' );
print '</span>';
}
The reason you wouldn't see the code is that majority of what is generated by Woocommerce is handled by actions and hooks. In easier terms this means Woocommerce creates functions that spits out content and assigns them to different areas of the website.(For more information on Woocommerce actions and hooks, read here - https://docs.woothemes.com/document/introduction-to-hooks-actions-and-filters/ )
I'd recommend using the plugin below. It does exactly what you seem to be asking for and you can avoid having to play in parts you might not be comfortable with yet.
https://wordpress.org/plugins/yith-woocommerce-ajax-navigation/
Most awesome thing is that it's not one of those plugins that force you to get premium to actually get the desired effect.
I just found the solution few days ago. I use the function of WooCommerce product categories widget on the shop page.
This line of code will output the dropdown of product categories:
<?php the_widget( 'WC_Widget_Product_Categories', 'dropdown=1' ); ?>