-
-
Save topmask/8606d0ee4c846573eee331677d610380 to your computer and use it in GitHub Desktop.
Product Key Features Field
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Display Input Field on Backend | |
add_action( 'woocommerce_product_options_general_product_data', function () { | |
global $woocommerce, $post; | |
echo '<div class="options_group">'; | |
woocommerce_wp_text_input( | |
array( | |
'id' => 'product_key_features', | |
'label' => __( 'Product Key Features', 'woocommerce' ), | |
'placeholder' => 'Enter product key features (3 words)', | |
'desc_tip' => 'true', | |
'description' => __( 'The product key features, keep it simple', 'woocommerce' ) | |
) | |
); | |
echo '</div>'; | |
} | |
); | |
// Save Input Field on Backend | |
add_action( 'woocommerce_process_product_meta', function ( $post_id ){ | |
$woocommerce_text_field = $_POST['product_key_features']; | |
if( !empty( $woocommerce_text_field ) ) | |
update_post_meta( $post_id, 'product_key_features', esc_attr( $woocommerce_text_field ) ); | |
} | |
); | |
// Display Input Field on Frontend | |
add_action('woocommerce_after_shop_loop_item_title', function (){ | |
$value = get_post_meta( get_the_ID(), 'product_key_features', true); | |
if(strlen($value) != null && strlen($value) > 0) { | |
echo '<p class="blc_description">'.get_post_meta( get_the_ID(), 'product_key_features', true ).'</p>'; | |
} | |
}, 22 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment