Is it possible to add custom text notice below the email field in the checkout page?
Yes, below code should do it.
add_filter( 'woocommerce_form_field' , 'so_27270883_woocommerce_form_field', 10, 2 );
function so_27270883_woocommerce_form_field( $field, $key) {
if ( is_checkout() ) {
if ($key == 'billing_email') {
$field .= '<p class="form-row">CUSTOM TEXT HERE</p>';
}
}
return $field;
}
Related
WooCommerce has a product option to “allow backorder but inform customer” which shows a notice on the frontend product page. How can I change the text of this notice?
I have seen this helpful post https://storepro.io/learn/how-to-change-out-of-stock-text-in-woocommerce/ sharing how to change "out of stock" text, but that is different from the "backorder allowed" text.
Code snippet for function.php from the above linked page:
add_filter('woocommerce_get_availability_text', 'themeprefix_change_soldout', 10, 2 );
/* Change Sold Out Text to Something Else */
function themeprefix_change_soldout ( $text, $product) {
if ( !$product->is_in_stock() ) {
$text = '<div class="">My custom sold out message.</div>';
}
return $text;
}
You can copy the code from original source code for the backorder validation and rewrite the status text and return it from the function.
Here is the code:
function vh_wc_custom_get_availability_text( $availability, $_product ) {
if ( $_product->managing_stock() && $_product->is_on_backorder( 1 ) ) {
$availability = $_product->backorders_require_notification() ? __( 'Your new text goes here', 'your-child-theme-text-domain' ) : '';
} elseif ( ! $_product->managing_stock() && $_product->is_on_backorder( 1 ) ) {
$availability = __( 'Your new text goes here', 'your-child-theme-text-domain' );
}
return $availability;
}
add_filter( 'woocommerce_get_availability_text', 'vh_wc_custom_get_availability_text', 10, 2 );
You can check this page for more detail on woocommerce_get_availability_text filter hook.
How do I customize woocommerce_email_order_meta to hide the SKU?
I see snippets like this but it also hides them in the product page. I only want to hide the SKU in New Order email.
function sv_remove_product_page_skus( $enabled ) {
if ( ! is_admin() && is_product() ) {
return false;
}
return $enabled;
}
add_filter( 'wc_product_sku_enabled', 'sv_remove_product_page_skus' );
Let me know your thoughts, thank you!!
Look in email-order-items.php
You see this line
// SKU.
if ( $show_sku && $sku ) {
echo wp_kses_post( ‘ (#’ . $sku . ‘)’ );
}
You can comment out the echo line with // so:
// SKU.
if ( $show_sku && $sku ) {
// echo wp_kses_post( ' (#' . $sku . ')' );
}
Using the the wpcf7 hook wpcf7_special_mail_tags() I want to get the cart contents and return the output, but WC()->cart object is null in this hook, I cant access any methods on WC()->cart as its a call to an undefined method. I cant work out how to get access to WC()->cart in this hook.
I can access WC()->cart fine in the WPCF7 hook wpcf7_add_form_tag()
The wpcf7_special_mail_tags() works fine and inserts other data into email, I just want cart data though.
Thanks for any help.
function my_special_mail_tag( $output, $name, $html ) {
if ( 'mytag' == $name ) {
$cart = WC()->cart;
if(!WC()->cart->is_empty()) {
// do something with output
}
}
return $output;
}
add_filter( 'wpcf7_special_mail_tags', 'my_special_mail_tag', 10, 3 );
Here you go. I'm ok with this.
function my_special_mail_tag( $output, $name, $html ) {
if ( 'mytag' == $name ) {
$cart = WC()->cart;
if(!WC()->cart->is_empty()) {
// do something with output
}
}
return $output;
}
add_filter( 'wpcf7_special_mail_tags', 'my_special_mail_tag', 10, 3 );
I want to add a comment to individual products in the cart page. I am new to woocommerce wordpress plugin so I have no idea how to do.
I have done some research. In that tutorial, I found that I can use woocommerce_add_cart_item_data hook this way:
add_filter( 'woocommerce_add_cart_item_data', 'add_comment', 10, 3 );
function add_comment( $cart_item_data, $product_id, $variation_id ) {
$cart_item_data['comment'] = 'This is comment';
return $cart_item_data;
}
but this does not work in my case.
I attach the Cart page image so you can understand.
I hope you guys understand what I want?
Thank you.
Below code will add a custom text to an item in cart:
You need to create a custom field "comment" for the product to use it here.
add_filter( 'woocommerce_add_cart_item_data', 'add_comment', 10, 3 );
function add_comment( $cart_item_data, $product_id, $variation_id ) {
$cart_item_data['comment'] = 'This is comment';
return $cart_item_data;
}
Add a Custom text/comment before Cart table in Cart Page:
add_action( 'woocommerce_before_cart_table', 'add_comment' );
function add_comment()
{
echo '<div class="woocommerce-info">This is comment</div>';
}
Add a Custom text/comment after Cart table in Cart Page:
add_action( 'woocommerce_after_cart_table', 'add_comment' );
function add_comment() {
echo '<div class="woocommerce-info">This is comment</div>';
}
HOW TO ADD AN INPUT FIELD TO WOOCOMMERCE CART ITEMS & Let users update input fields in the cart
https://pluginrepublic.com/how-to-add-an-input-field-to-woocommerce-cart-items/
Refer this link for a working solution to similar request:
https://stackoverflow.com/a/21818028/12291365
If you are okay with using the plugin, then this plugin will do the trick:
https://wordpress.org/plugins/wc-fields-factory/
Use code snippet below for adding custom values for each cart item.
Please add your logic for attaching values for each item
// Add custom value into cart item
add_filter('woocommerce_add_cart_item_data','sub_add_item_data',1,2);
if(!function_exists('sub_add_item_data'))
{
function sub_add_item_data($cart_item_data,$product_id)
{
// use condition for adding custom value here
$new_value = array(
'sub_custom_value' => 'custom value',
);
return array_merge($cart_item_data,$new_value);
}
}
// Extract custom values
add_filter('woocommerce_get_cart_item_from_session', 'sub_get_cart_items_from_session', 1, 3 );
if(!function_exists('sub_get_cart_items_from_session'))
{
function sub_get_cart_items_from_session($item,$values,$key)
{
if (array_key_exists( 'sub_custom_value', $values ) )
{
$item['sub_custom_value'] = $values['sub_custom_value'];
}
return $item;
}
}
// display in cart and checkout
add_filter('woocommerce_checkout_cart_item_quantity','sub_add_user_custom_option_from_session_into_cart',1,3);
add_filter('woocommerce_cart_item_price','sub_add_user_custom_option_from_session_into_cart',1,3);
if(!function_exists('sub_add_user_custom_option_from_session_into_cart'))
{
function sub_add_user_custom_option_from_session_into_cart($product_name, $values, $cart_item_key )
{
if(isset( $values['sub_custom_value'] ) && '' != $values['sub_custom_value'] )
{
$return_string = $product_name . "</a><dl class='variation'>";
$return_string .= "<table class='sub_options_table' id='" . $values['product_id'] . "'>";
$return_string .= "<tr><td>" . $values['sub_custom_value'] . "</td></tr>";
$return_string .= "</table></dl>";
return $return_string;
}
else
{
return $product_name;
}
}
}
I have a wordpress website with customs posts and metas boxes.
One of these manage some pictures and I want to force the title of the post.
It should be the same as the name of the media uploaded.
Is it possible ? And how ?
Thank's
Manipulate the post title with a filter.
function change_post_title( $title, $id = null ) {
if ( is_single() ) {
$title = 'new title';
}
return $title;
}
add_filter( 'the_title', 'change_post_title', 10, 2 );
Thanks all for your help.
I have used a filter but this one :
function modify_post_title($data){
if($data['post_type'] == 'fcfm_photos' && isset($_POST['image'])) {
$data['post_title'] = substr($_POST['image'], -(strpos(strrev($_POST['image']),'/')));
}
return $data;
}
add_filter( 'wp_insert_post_data' , 'modify_post_title' , '99', 1 );
And when I save the post, the post title change automatically. This is what i want.