WooCommerce
October 15, 2021

How to Add Custom Product Fields in WooCommerce

For add custom fields in woocommerce use following code in your current themes functions.php file.

‘custom_text_field_title’,
‘label’ => __( ‘Custom Text Field Title’, ‘cfwc’ ),
‘class’ => ‘cfwc-custom-field’,
‘desc_tip’ => true,
‘description’ => __( ‘Enter the title of your custom text field.’, ‘ctwc’ ),
);
woocommerce_wp_text_input( $args );
}

//Save custom field
add_action( ‘woocommerce_process_product_meta’, ‘wc_save_custom_field’ );

function wc_save_custom_field( $post_id ) {
$product = wc_get_product( $post_id );
$title = isset( $_POST[‘custom_text_field_title’] ) ? $_POST[‘custom_text_field_title’] : ”;
$product->update_meta_data( ‘custom_text_field_title’, sanitize_text_field( $title ) );
$product->save();
}

?>

This will display at admin product page.

ID );
$title = $product->get_meta( ‘custom_text_field_title’ );
if( $title ) {
printf(

‘,
esc_html( $title )
);
}
}

?>

This will display at single Product Page.

session->set( ‘custom_text_field_title’, $custom_item );
}
return $cart_item_data;
}

?>

__( “Custom text”, “woocommerce” ), “value” => $cart_item[‘custom_text_field_title’] );
}
return $custom_items;
}

?>

This will display at Cart and Checkout Page.

This will display at order received and admin order Page.

Related Post


How to disable all payment methods in WooCommerce

You will have the need to disable all payment gateways on the site, but just disabling them in WooCommerce > Settings > Payments will not work because then the customers will get an error message since there are no payment methods available. We’re going to be using a different method here. The way to go […]

How Create Custom Order in Woocommerce

Paste the code where you can get the customer data Here is the function for creating the order

Get product details from $product object WooCommerce

I am publish this article for get values from WooCommerce $product object. You can get all information of product from $product object. When we have $product object. Get $product object by $product_id. Get $order object by $order_id. Get products from $cart object.

Editing product data tabs on WooCommerce Product Page

You need to add the code to your child theme’s functions.php file or via a plugin that allows custom functions to be added, such as the Code snippets plugin. Please don’t add custom code directly to your parent theme’s functions.php file as this will be wiped entirely when you update the theme. Removing Tabs Use […]

Set cart item price from a hidden input field custom price in Woocommerce

First for testing purpose we add a price in the hidden input field as you don’t give the code that calculate the price: Then you will use the following to change the cart item price (WC_Session is not needed): Code goes in function.php file of your active child theme (or active theme). Tested and works.

Remove Product From Cart Programmatically Woocommerce

We can remove product from WooCommerce cart using remove_cart_item() function with $product_id. Code goes in function.php file of your active child theme (or active theme).


Leave a Reply

Your email address will not be published. Required fields are marked *