Skip to content

Instantly share code, notes, and snippets.

@tdmrhn
Created September 5, 2021 15:48
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save tdmrhn/3e526a3de77f9dc30f00c3474def958a to your computer and use it in GitHub Desktop.
Save tdmrhn/3e526a3de77f9dc30f00c3474def958a to your computer and use it in GitHub Desktop.
Product Key Features Field
<?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