Can anyone direct me to where I can find the file where I can change the "State/County" and "Zip Code" titles in a woocommerce checkout page?
WooCommerce offers hooks for this:
please check Customizing checkout fields using actions and filters
as you'll see on that page you can hook a function (that you'll save in your childs functions.php for example ) to WooCommerce checkout page and change the data that is available.
so your code will look something like:
/ Hook in
add_filter( 'woocommerce_checkout_fields' , 'custom_override_checkout_fields' );
// Our hooked in function - $fields is passed via the filter!
function custom_override_checkout_fields( $fields ) {
$fields['shipping']['shipping_postcode']['label'] = 'My new postcode title';
$fields['shipping']['shipping_state']['label'] = 'My new state title';
return $fields;
}
other examples and fields on the linked page.
Related
I know it’s possible to send customer directly to the checkout page by appending “add-to-car=product_id” to the checkout endpoint like this:
yourwebsite.com/checkout/?add-to-cart=12345
I was wondering if it’s a way to do the same when a product has subscription options? I use Woocommerce Subscriptions plugin to manage subscriptions and it doesn't create a separate variant for subscription product.
Based on these answers:
Woocommerce add to cart button redirect to checkout
WooCommerce Subscriptions - Check if a product is a subscription product
You can create a PHP script to change the redirect url after adding a product to the cart (by checking the product class type).
Furthermore, using the woocommerce_add_to_cart_redirect hook you have two parameters: $url and $adding_to_cart (product object). Here you find the documentation.
Then:
// redirects to checkout if the product added to the cart is a subscription
add_filter( 'woocommerce_add_to_cart_redirect', 'redirect_to_checkout_if_product_is_subscription' );
function redirect_to_checkout_if_product_is_subscription( $url, $product ) {
if ( class_exists( 'WC_Subscriptions_Product' ) && WC_Subscriptions_Product::is_subscription( $product ) ) {
global $woocommerce;
$checkout_url = $woocommerce->cart->get_checkout_url();
return $checkout_url;
}
return $url;
}
The code must be added to your active theme's functions.php file.
I have installed WooCommerce Checkout & Account Field Editor plugin on my WordPress website for adding additional fields to my checkout page. The purpose of installing this plugin is to add three additional fields like how_you_heard_about_our_store, user_membership_level and user_refferer_name to the checkout page for getting additional details from my users.
This is working fine and the user can provide the required information as needed during checkout. However, there is one product Gift Certificate that I need to exclude these additional fields on it when this product is on the checkout page.
The purpose is to hide these fields on this product only. I have 4 different variations of this product and I need these fields to be hidden for each of its variations.
I have tried my following techniques but this is actually for default WooCommerce fields.
https://www.liquidweb.com/kb/way-conditionally-show-hide-checkout-fields-specific-products-product-categories-store/
Also, I have tried the following as well with no luck:
function custom_override_checkout_fields( $fields ) {
unset($fields['order']["how_heard"]);
unset($fields['order']["member_level"]);
return $fields;
}
Is there any specific action or filter for removing additional fields from my checkout page? Any help would highly be appreciated.
add_filter( 'woocommerce_checkout_fields' , 'hide_checkout_fields' );
function hide_checkout_fields( $fields ) {
foreach( WC()->cart->get_cart() as $cart_item_key => $cart_item ) {
$product = $cart_item['data'];
$id = $product->get_id();
$products = array(2516, 584, 2454); // Product Ids
if (in_array($id, $products))
{
unset($fields['order']['how_heard']);
unset($fields['order']['member_level']);
}
}
return $fields;
}
I want to edit, or add some fields to, woocommerce billing and shipping address in checkout page, profile page and everywhere in which the fields are displayed.
can anybody help me?
revving an old question but
function override_default_address_fields( $fields ) {
unset($fields['company']);
foreach($fields as $key => $value) {
$fields[$key]['label_class'] = 'sr-only';
}
return $fields;
}
add_filter( 'woocommerce_default_address_fields', 'override_default_address_fields' );
all the available fields can be found in includes/class-wc-countries.php -> public function get_default_address_fields()
It's very simple to edit or add new fields in woo commerce checkout page you can try with hard code and with woo commerce checkout field editor plugin
I am trying to send a email when a order is moved to a custom status in woocommerce. I have successfully created a plugin that creates a custom status and order is assigned to the custom status.
I have also successfully added a custom email template under Settings -> Emails in WooCommerce and written code which should send a email when the order is moved to that custom status.
However that code is not getting triggered and email is not getting sent.
Below is my code.
apply_filters( 'woocommerce_email_actions', array('woocommerce_order_status_processing_to_partial-shipment'));
// Trigger on new paid orders
add_action( 'woocommerce_order_status_processing_to_partial-shipment_notification', array( $this, 'trigger' ) );
the action never comes in the trigger function i have written. I am using wordpress 4.5.3 and woocommerce version 2.6.4.
Can anyone suggest as to what could be going wrong. Thanks.
Since WooCommerce 2.3, you can use 'woocommerce_email_actions' filter, so you can try this:
function new_woocommerce_email_actions( $actions ){
$actions[] = 'woocommerce_order_status_processing_to_partial-shipment_notification';
return $actions;
}
add_filter( 'woocommerce_email_actions', 'new_woocommerce_email_actions' );
Luck
Actually, I already got hook to customize the price in the cart page and all other page.
This is the hook to customize the product price
add_action( 'woocommerce_before_calculate_totals', 'add_custom_price' );
function add_custom_price( $cart_object ) {
$custom_price = 10; // This will be your custome price
foreach ( $cart_object->cart_contents as $key => $value ) {
$value['data']->price = $custom_price;
}
}
Actually, I am using woocommerce plugin. I want a hook to customize the product name displayed in the cart page and all other pages next to cart page.
I want to customize the Product name , i want to add the some static attributes to product name displayed in the cart page, order page ,order details page and all the pages next to cart page.
Thanks in advance
I wanted to share this as I managed to figure out something for my needs. (I only ever have a single item in the order as I've customised WooCommerce for holiday bookings.)
<?php
add_action( 'woocommerce_product_title', 'add_custom_name' );
function add_custom_name( $title ) {
return 'test name';
}
?>
Hopefully someone can elaborate on this further or take what has been done with the custom price code an properly re-purpose it for product names.