Custom Field HTML formatting
-
I am using a custom field for an alternative out of stock message for products.
I obviously want a visible message to the user, but would also like to do some html formatting such as a “… Learn more” link.
But all html formatting is stripped out. I think at the time of saving.Should the field be of a different type to allow and save HTML formatting?
/** * Display the custom text field * @since 1.0.0 * custom text field for An alternative out of stock text * Displayed in Product -> Inventory */ function cfwc_create_custom_field() { $args = array( 'id' => 'AltOutOfStockText', 'label' => __( 'Alt Out of Stock Notice', 'cfwc' ), 'class' => 'cfwc-custom-field', 'desc_tip' => true, 'description' => __( 'Alternative Text displayed when out of stock. Displayed when out of stock. Use when closing bookings and displaying the text out of stock is not desirable. Leave empty if store default "out of stock" is desired', 'ctwc' ), ); woocommerce_wp_text_input( $args ); } add_action( 'woocommerce_product_options_inventory_product_data', 'cfwc_create_custom_field' );
/** * Save the custom field * @since 1.0.0 * custom text field for An alternative out of stock text * Displayed in Product -> Inventory */ function cfwc_save_custom_field( $post_id ) { $product = wc_get_product( $post_id ); $title = isset( $_POST['AltOutOfStockText'] ) ? $_POST['AltOutOfStockText'] : ''; $product->update_meta_data( 'AltOutOfStockText', sanitize_text_field( $title ) ); $product->save(); } add_action( 'woocommerce_process_product_meta', 'cfwc_save_custom_field' ); // Custom out of stock message, from custom product field // Product field = 'AltOutOfStockText' add_filter( 'woocommerce_get_availability', 'wcs_custom_get_availability', 1, 2); function wcs_custom_get_availability( $availability, $_product ) {
Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
- The topic ‘Custom Field HTML formatting’ is closed to new replies.