I have added a custom text field (named add_for_charity_field) in woocommerce. This filed is for adding desired amount for charity. I have used the WooCommerce Checkout Field Editor plugin to adding this field in checkout form. Now I need to add this field content to cart by add_fee function but I don't have access to the field content in php. Is there a solution for it ? I am not familiar with jQuery and I think that I must use jQuery.
I have use this code in function.php
function woo_add_cart_fee() {
global $woocommerce;
$woocommerce->cart->add_fee( __('Charity', 'woocommerce'), $_POST['add_for_charity_field'] );
}
add_action( 'woocommerce_cart_calculate_fees', 'woo_add_cart_fee' );
Related
How do I add a red asterisk to the end of all attributes labels in Woocommerce? It seems like it should be simple, but I'm having a hard time with figuring it out. Wouldn't it be in the functions.php file?
The required attributes are actually working because the Add to Cart button is grayed out until an option is selected. However, apparently my customers don't realize this because they are telling me my Add to Cart button doesn't work. So, if I could draw their attention to the variations dropdown menu maybe they would realize that an option must be chosen before they can add the item to their cart.
To add a red asterisk at then end of product attribute labels on single variable products, just like in required checkout fields, you can use the following very simple hooked function:
add_filter( 'woocommerce_attribute_label', 'filter_single_variable_product_attribute_label', 10, 3 );
function filter_single_variable_product_attribute_label( $label, $name, $product ) {
if ( is_product() ){
$label .= ' <abbr class="required" title="required" style="color:#FF3333;">*</abbr>';
}
return $label;
}
Code goes in functions.php file of the active child theme (or active theme). Tested and works.
I have created a custom theme and I have moved woocommerce folder to my current custom theme but once i came to checkout page there is a div name woocommerce is still showing as main div. I want to hide or rename this div but I don't have any idea what action or filter hooks will be use for that.
I have also attached a image that showing woocommerce class name on check out page.
ALso I have used below hook for change main woocommerce class before checkout form but that will not remove or replace that woocommerce class.
function action_woocommerce_before_checkout_form( $checkout ) {
echo '<div class="checkout_section">';
};
// add the action
add_action( 'woocommerce_before_checkout_form', 'action_woocommerce_before_checkout_form', 10, 1 );
function action_woocommerce_after_checkout_form( $checkout ) {
echo '</div>';
};
// add the action
add_action( 'woocommerce_after_checkout_form', 'action_woocommerce_after_checkout_form', 10, 1 );
Can anyone tell me which hook should i use for remove or replace that div?
I am stuck with trying to configure my website's checkout fields in woo commerce.It comes prefilled with values and doesnt get removed even after purging the cache.
https://shinujohn.com/checkout/ ...set as with the default shortcode
The country has 2 field boxes now...one is clickable drop down.
Server side caching is disabled.
The theme I'm using is Kallyas
I Have tried:-
Field editor : It does not even show the field ..say company name.and adding a new field is not reflected here.even if i add it to the billing or checkout fields
Adding code to functions.php
/returning woo commerce field as blank/
add_filter('woocommerce_checkout_get_value','__return_empty_string', 1, 1);
add_filter( 'woocommerce_checkout_fields' , 'custom_override_checkout_fields' );
add_filter( 'woocommerce_billing_fields' , 'custom_override_billing_fields' );
or
function custom_override_billing_fields( $fields ) {
unset($fields['billing_postcode']);
unset($fields['billing_state']);
unset($fields['billing_country']);
unset($fields['billing_address_1']);
return $fields;
}
neither work
3. issue persists with multiple browsers and unlogged users in different machines..
4. Within the theme's page editor... i can of course change front end ...but it doesnt reflect it after publishing.
I don't recommend you to use any extra plugin to edit the Woocommerce checkout fields. Here is the simple solution that you can easily customize the Woocommerce checkout fields.
add_filter( 'woocommerce_checkout_fields' , 'custom_override_billing_fields', 5);
function custom_override_billing_fields( $fields ) {
unset($fields['billing']['billing_postcode']);
unset($fields['billing']['billing_state']);
unset($fields['billing']['billing_country']);
unset($fields['billing']['billing_address_1']);
return $fields;
}
May this code helps you.
We use the Booster plugin which creates a unique WooCommerce order number such as WC-456544646. I now need to add the original order_id which still works in the background and with the WooCommerce API.
Booster provides a shortcode for the original order ID [wcj_order_id]
Here is the HTML for the custom Woo order number on the Edit Order page.
<h2 class="woocommerce-order-data__heading">
Order #WC-63872414 details</h2>
How can I insert a shortcode onto the 'Edit Order' page?
(Woocommerce/Orders/[Select Order/Order Details] eg /post.php?post=638&action=edit
I looked into Booster plugin code. It uses woocommerce_order_number filter hook to replace the order ID in WC edit order page and orders. In /woocommerce-jetpack/includes/class-wcj-order-numbers.php :
add_filter( 'woocommerce_order_number', array( $this, 'display_order_number' ), PHP_INT_MAX, 2 );
Since it's not passing the $instance of neither WCJ_Order_Numbers nor WC_Jetpack classes in any action hook, in order to remove this text and use a custom one, we can not use remove_filter function. So to override Booster plugin, we have to hook another function to woocommerce_order_number.
To add WC order_id to admin order pages:
add_action( 'admin_init', 'append_wc_order_id');
function append_wc_order_id()
{
add_filter('woocommerce_order_number', 'filter_wc_order_id', PHP_INT_MAX);
function filter_wc_order_id($order_id)
{
/* If you are using 'init' action hook, uncomment bellow line to apply this code only to your admin pages: */
//if (!is_admin()) return $order_id;
return $order_id . ' | #' . do_shortcode('[wcj_order_id]');
}
}
This code goes to your functions.php file of your theme.
Tested & Wordking:
Notes:
1. The filter hook in the Booster code, uses PHP_INT_MAX priority so in order to override this, we can not use bigger integer priority. Therefore I used admin_init action to hook my function to woocommerce_order_number, after other plugins done their job. It may function as you expected, without using init hooks, but it's not guaranteed. You can use init hook instead of admin_init to add the WC order_id on the front-end side of your site too (e.g. 'My Account' page). Read the comments inside the code.
2. To remove the order ID generated by Booster plugin on admin pages, you may change this line:
return $order_id . ' | #' . do_shortcode('[wcj_order_id]');
to:
return do_shortcode('[wcj_order_id]');
I've added a custom field to my product for admin only meta data, I have hidden it using CSS.
However it still shows up in emails. Is there any way I can create a custom field where the meta data only shows up in the admin orders page?
You could try to use woocommerce_email_order_meta_fields filter hook to remove this custom field from order metadata, using unset() php function this way:
add_filter( 'woocommerce_email_order_meta_fields', 'wc_email_order_meta_remove_custom_field', 10, 3 );
function wc_email_order_meta_remove_custom_field( $fields, $sent_to_admin, $order ) {
// Replace HERE 'meta_key' by your custom field meta key or slug.
unset($fields['meta_key']);
return $fields;
}
This code goes in function.php file of your active child theme (or theme) or also in any plugin file.
This should work, but not sure as you don't provide any information and code related to the way you have set this custom field.