Comments on: WooCommerce custom fields: how to create and display them [+video] https://pluginrepublic.com/woocommerce-custom-fields/ WooCommerce Plugins Fri, 13 Oct 2023 15:14:49 +0000 hourly 1 By: Gareth https://pluginrepublic.com/woocommerce-custom-fields/#comment-195190 Thu, 14 Sep 2023 11:15:16 +0000 https://pluginrepublic.com/?p=12049#comment-195190 In reply to samradhi mittal.

Hi

This is possible to do. Please raise a support ticket here, https://pluginrepublic.com/support/, and our team will be happy to help you further.

Thanks.

]]>
By: samradhi mittal https://pluginrepublic.com/woocommerce-custom-fields/#comment-195189 Thu, 14 Sep 2023 10:52:28 +0000 https://pluginrepublic.com/?p=12049#comment-195189 Hello,

I want to add custom field in product . and use that field in product search. I am using woocommerce for product. also i have triedit with ACT and ACF: Better Search plugin but it is not working

Can you please

]]>
By: Gareth https://pluginrepublic.com/woocommerce-custom-fields/#comment-194587 Thu, 01 Jun 2023 14:16:46 +0000 https://pluginrepublic.com/?p=12049#comment-194587 In reply to Sophie.

Hi Sophie

This would be possible with some custom JS. I’d be happy to discuss that with you directly if you like? You can contact me on hello[at]pluginrepublic.com

Thanks

]]>
By: Sophie https://pluginrepublic.com/woocommerce-custom-fields/#comment-194582 Wed, 31 May 2023 09:05:29 +0000 https://pluginrepublic.com/?p=12049#comment-194582 Hello,
Is it possible to display custom fields somewhere other than before the “add to cart” button? I would like to display these custom fields under the tabs.
Thank you for your help 🙂

]]>
By: Gareth https://pluginrepublic.com/woocommerce-custom-fields/#comment-194474 Wed, 17 May 2023 09:53:19 +0000 https://pluginrepublic.com/?p=12049#comment-194474 In reply to Zach Hayter.

Hi Zach

Thanks for sharing.

]]>
By: Zach Hayter https://pluginrepublic.com/woocommerce-custom-fields/#comment-194473 Wed, 17 May 2023 09:40:52 +0000 https://pluginrepublic.com/?p=12049#comment-194473 Since my last comment, I went ahead and hired a PHP guy to alter the code to get it to work for me. I have decided to share it here for others who may need it.

Spec:
All I wanted was to have a custom field I could enter unique HTML into for each unique product as required, and have the HTML render and display in an Astra theme hook on the single product page(s).

The following code does not include functionality for the above headers in this post:
– Adding custom values to the cart
– Displaying custom fields in the cart and checkout
– Displaying custom field values in the WooCommerce order and email confirmations

Here is the code, working in Woo version 7.7.0, WP version 6.2.1:

/**
* Add custom text field to product page
* Only for display on the front-end, not carried over to cart, checkout, or order meta
*/

// Add custom field to product in backend
add_action( ‘woocommerce_product_options_general_product_data’, ‘cfwc_create_vc_custom_field’ );
function cfwc_create_vc_custom_field() {
woocommerce_wp_textarea_input( array(
‘id’ => ‘view_collection_text_field’,
‘label’ => __( ‘View Collection’, ‘cfwc’ ),
‘class’ => ‘cfwc-vc-custom-field’,
‘desc_tip’ => true,
‘description’ => __( ‘Enter your data.’, ‘ctwc’ ),
) );
}

// Save custom field value
add_action( ‘woocommerce_process_product_meta’, ‘cfwc_save_vc_custom_field’ );
function cfwc_save_vc_custom_field( $post_id ) {
$product = wc_get_product( $post_id );
$view_collection_field_value = isset( $_POST[‘view_collection_text_field’] ) ? $_POST[‘view_collection_text_field’] : ”;
$product->update_meta_data( ‘view_collection_text_field’, wp_kses_post( $view_collection_field_value ) );
$product->save();
}

// Display custom field on single product pages
add_action( ‘astra_woo_single_title_after’, function() {
$view_collection_field_value = get_post_meta( get_the_ID(), ‘view_collection_text_field’, true );
if ( $view_collection_field_value ) {
echo ” . wp_kses_post( $view_collection_field_value ) . ”;
}
} );

]]>
By: Zach Hayter https://pluginrepublic.com/woocommerce-custom-fields/#comment-194472 Wed, 17 May 2023 09:34:44 +0000 https://pluginrepublic.com/?p=12049#comment-194472 In reply to Gareth.

My apologies, that part of my error log has already been overwritten, however I’m about to comment with the solution I found. Thanks for replying

]]>
By: Gareth https://pluginrepublic.com/woocommerce-custom-fields/#comment-194458 Thu, 11 May 2023 09:47:00 +0000 https://pluginrepublic.com/?p=12049#comment-194458 In reply to Zach Hayter.

Hi

Do have access to your error log? It would be helpful to know what error was reported.

Thanks.

]]>
By: Zach Hayter https://pluginrepublic.com/woocommerce-custom-fields/#comment-194454 Wed, 10 May 2023 17:00:27 +0000 https://pluginrepublic.com/?p=12049#comment-194454 Hi,
Great article. It seems that the code snippet under the 3rd header below is no longer working, I get a WordPress critical error:
– Adding a custom field in the back-end (works fine)
– Saving the custom field value (works fine)
– Displaying the custom field on the front-end (throws the Wordpress critical error)
Thank you

]]>
By: Palko https://pluginrepublic.com/woocommerce-custom-fields/#comment-180314 Thu, 28 Apr 2022 08:36:42 +0000 https://pluginrepublic.com/?p=12049#comment-180314 In reply to Gareth.

Hi,

I see. Thanks the answer.

]]>