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


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 […]

Get Currency symbol WooCommerce

You can get current currency in woocommerce using get_woocommerce_currency_symbol(); function.

Reordering Cross-Sells and Up-Sells in WooCommerce

Cross-sells and Up-sells in WooCommerce are a very powerful tool to give suggestions to your customers. You might know that most people who buy product A will probably need product B as well, and you want the customer to know that. How do you do it? You use cross-sells and up-sells. These products are shown […]

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 […]

Add an Empty Cart button in WooCommerce

WooCommerce default not provide Empty Cart button but we can two simple steps to add Empty Cart button on cart page. The first one is to add below code in your functions.php file (this file is located in your theme folder): Second step is to add Empty Cart Button after Apply Coupon button. This code […]


Leave a Reply

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