Place custom field data in header section - wordpress

I'm a newbie to the Wordpress Customization and learning plugin development from a YouTube videos.
Below is the code snippet from my custom plugin that adds the two custom fields meta_title and meta_description in the example create/ edit form.
function ideapro_custom_posttype() {
register_post_type( 'Example',
array(
'labels'=>array(
'name' =>__('Examples'),
'singular_name' => __('Example'),
'add_new' => __('Add New Example'),
'add_new_item' => __('Add New Example'),
'edit_item' => __('Edit Example'),
'search_items' => __('Search Examples')
),
'menu_postion' => 5,
'public' =>true,
'exclude_from_search' => true,
'has_archives'=>false,
'register_meta_box_cb' => 'metaField_metabox',
'supports' => array('title', 'editor', 'thumbnail')
)
);
}
/** Add new custom fields to create post form*/
function metaField_metabox() {
add_meta_box( 'meta_fields', 'Meta Fields', 'display_metaFields', 'example','normal','high' );
}
function display_metaFields(){
global $post;
$meta_title = get_post_meta($post->ID,'meta_title', true);
$meta_description = get_post_meta($post->ID,'meta_description', true);
?>
<label>Meta Title</label>
<input type="text" name="meta_title" placeholder="Meta Title" class="widefat" value="<?php print $meta_title?>">
</br>
</br>
<label>Meta Description</label>
<input type="text" name="meta_description" placeholder="Meta Description"class="widefat" value="<?php print $meta_description?>">
<?php
}
add_action( 'add_meta_box','metaField_metabox' );
/** save custom field data to posts table */
function saveMetaFields($post_id){
$is_autosave = wp_is_post_autosave($post_id );
$is_revision = wp_is_post_revision( $post_id );
if( $is_autosave || $is_revision){
return;
}
$post = get_post($post_id);
if ($post->post_type == "example") {
if (array_key_exists('meta_title', $_POST)) {
update_post_meta( $post_id, 'meta_title',$_POST['meta_title']);
}
if (array_key_exists('meta_description', $_POST)) {
update_post_meta( $post_id, 'meta_description',$_POST['meta_description']);
}
}
}
add_action( 'save_post','saveMetaFields' );
With the above code I'm successful to add custom field data in the posts table.
Now I want to place the meta_title and meta_description of a each post in the header section of a post. Like:
<meta name="title">....</title>
<meta name="description">....</title>

Use wp_head action:
function myAction() {
if(is_single('Example'):
$postID = get_the_ID();
$title = get_post_meta($postID,'meta_title',true);
$desc = get_post_meta($postID,'meta_description',true);
?>
<meta name="title" content="<?php echo $title; ?>" />
<meta name="description" content="<?php echo $desc; ?>"/>
<?php
endif;
}
add_action( 'wp_head', 'myAction' );

Related

Can't add content to woocommerce_after_shop_loop

I'm trying to add a second product description to my WooCommerce page: https://alvinecph.dk/kategori/to-go/ from the guide from https://www.businessbloomer.com/woocommerce-add-a-second-content-box-product-category-pages/ .
I do however experience an issue, that the second description isn't showing for the hook woocommerce_after_shop_loop. I've tried to change the hook to woocommerce_before_shop_loop_item, and this seems to work, showing the text. So it could seem like woocommerce_after_shop_loop isn't present on the page.
I'm using the Divi theme, and have created a template for the category/archive page with their builder. To this template I've the Woo Product block. So I'm really baffled about this.
Is there something I'm missing. I've also tried to disable all plugins.
BR
Martin
// 1. Display field on "Add new product category" admin page
add_action( 'product_cat_add_form_fields', 'bbloomer_wp_editor_add', 10, 2 );
function bbloomer_wp_editor_add() {
?>
<div class="form-field">
<label for="seconddesc"><?php echo __( 'Second Description', 'woocommerce' ); ?></label>
<?php
$settings = array(
'textarea_name' => 'seconddesc',
'quicktags' => array( 'buttons' => 'em,strong,link' ),
'tinymce' => array(
'theme_advanced_buttons1' => 'bold,italic,strikethrough,separator,bullist,numlist,separator,blockquote,separator,justifyleft,justifycenter,justifyright,separator,link,unlink,separator,undo,redo,separator',
'theme_advanced_buttons2' => '',
),
'editor_css' => '<style>#wp-excerpt-editor-container .wp-editor-area{height:175px; width:100%;}</style>',
);
wp_editor( '', 'seconddesc', $settings );
?>
<p class="description"><?php echo __( 'This is the description that goes BELOW products on the category page', 'woocommerce' ); ?></p>
</div>
<?php
}
// ---------------
// 2. Display field on "Edit product category" admin page
add_action( 'product_cat_edit_form_fields', 'bbloomer_wp_editor_edit', 10, 2 );
function bbloomer_wp_editor_edit( $term ) {
$second_desc = htmlspecialchars_decode( get_woocommerce_term_meta( $term->term_id, 'seconddesc', true ) );
?>
<tr class="form-field">
<th scope="row" valign="top"><label for="second-desc"><?php echo __( 'Second Description', 'woocommerce' ); ?></label></th>
<td>
<?php
$settings = array(
'textarea_name' => 'seconddesc',
'quicktags' => array( 'buttons' => 'em,strong,link' ),
'tinymce' => array(
'theme_advanced_buttons1' => 'bold,italic,strikethrough,separator,bullist,numlist,separator,blockquote,separator,justifyleft,justifycenter,justifyright,separator,link,unlink,separator,undo,redo,separator',
'theme_advanced_buttons2' => '',
),
'editor_css' => '<style>#wp-excerpt-editor-container .wp-editor-area{height:175px; width:100%;}</style>',
);
wp_editor( $second_desc, 'seconddesc', $settings );
?>
<p class="description"><?php echo __( 'This is the description that goes BELOW products on the category page', 'woocommerce' ); ?></p>
</td>
</tr>
<?php
}
// ---------------
// 3. Save field # admin page
add_action( 'edit_term', 'bbloomer_save_wp_editor', 10, 3 );
add_action( 'created_term', 'bbloomer_save_wp_editor', 10, 3 );
function bbloomer_save_wp_editor( $term_id, $tt_id = '', $taxonomy = '' ) {
if ( isset( $_POST['seconddesc'] ) && 'product_cat' === $taxonomy ) {
update_woocommerce_term_meta( $term_id, 'seconddesc', esc_attr( $_POST['seconddesc'] ) );
}
}
// ---------------
// 4. Display field under products # Product Category pages
add_action( 'woocommerce_after_shop_loop', 'bbloomer_display_wp_editor_content', 5 );
function bbloomer_display_wp_editor_content() {
if ( is_product_taxonomy() ) {
$term = get_queried_object();
if ( $term && ! empty( get_woocommerce_term_meta( $term->term_id, 'seconddesc', true ) ) ) {
echo '<p class="term-description">' . wc_format_content( htmlspecialchars_decode( get_woocommerce_term_meta( $term->term_id, 'seconddesc', true ) ) ) . '</p>';
}
}
}

Create the custom payment gateway intregation in woocommerce

I am creating a custom gateway plugin for woocommerce for which I need the following workflow:
When customers click on the PLACE ORDER button on the checkout page
they need to be directed to the bank's hosted payment page to enter the card details and make the
payment. Once the payment is made, the bank sends the success/fail
response, and then only the order status is updated to
complete/canceled.
Also, the bank needs some information like merchant ID and other fields to process the payment.
I have created the plugin which adds hidden fields in the checkout page with necessary data that needs to be sent to the bank's payment page but I am having difficulties passing the data to the hosted payment page. Below is my full code
<?php
/*
** Check if Woocommerce is active
**
*/
if ( ! in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) ) return;
// create custom plugin settings menu
add_action('admin_menu', 'create_custom_menu');
function create_custom_menu() {
//create new top-level menu
add_menu_page('Plugin page Settings', 'Plugin Settings', 'administrator', __FILE__, 'plugin_settings_page' , plugins_url('/images/icon.png', __FILE__) );
//call register settings function
add_action( 'admin_init', 'register_plugin_settings' );
}
function register_plugin_settings() {
//register our settings
register_setting( 'plugin-settings-group', 'shop_id' );
register_setting( 'plugin-settings-group', 'shared_secret' );
register_setting( 'plugin-settings-group', 'currency_code' );
}
function plugin_settings_page() {
?>
<div class="wrap">
<form method="post" action="options.php">
<?php settings_fields( 'plugin-settings-group' ); ?>
<?php do_settings_sections( 'plugin-settings-group' ); ?>
<table class="form-table">
<tr valign="top">
<th scope="row">Shop ID</th>
<td><input type="text" name="shop_id" value="<?php echo esc_attr( get_option('shop_id') ); ?>" /></td>
</tr>
<tr valign="top">
<th scope="row">Shared Secret</th>
<td><input type="text" name="shared_secret" value="<?php echo esc_attr( get_option('shared_secret') ); ?>" /></td>
</tr>
<tr valign="top">
<th scope="row">Currency Code</th>
<td><input type="text" name="currency_code" value="<?php echo esc_attr( get_option('currency_code') ); ?>" disabled/><br></td>
</tr>
</table>
<?php submit_button(); ?>
</form>
</div>
<?php }
add_action( 'woocommerce_after_order_notes', 'add_custom_checkout_hidden_field' );
function add_custom_checkout_hidden_field( $checkout ) {
$shop_id = esc_attr( get_option('shop_id') );
$sharedSecret = esc_attr( get_option('shared_secret') );
$currency = "826";
// Output the hidden field
echo '<input type="hidden" name="shop_id" value="'.$shop_id.'" />
<input type="hidden" name="shop_id" value="'.$sharedSecret.'" />
<input type="hidden" name="shop_id" value="'.$currency.'" />
';
}
add_filter( 'woocommerce_payment_gateways', 'add_custom_gateway_class' );
function add_custom_gateway_class( $gateways ) {
$gateways[] = 'Custom_Gateway';
return $gateways;
}
add_action( 'plugins_loaded', 'plugin_init_gateway_class' );
function plugin_init_gateway_class() {
class Custom_Gateway extends WC_Payment_Gateway {
/**
* Class constructor
*/
public function __construct() {
$this->id = 'custom_gateway_id'; // payment gateway plugin ID
$this->icon = ''; // URL of the icon that will be displayed on checkout page near your gateway name
$this->has_fields = true; // in case you need a custom credit card form
$this->method_title = 'Custom Gateway';
$this->method_description = 'Description of Custom payment gateway'; // will be displayed on the options page
// Method with all the options fields
$this->init_form_fields();
// Load the settings.
$this->init_settings();
$this->title = $this->get_option( 'title' );
$this->description = $this->get_option( 'description' );
$this->enabled = $this->get_option( 'enabled' );
$this->shop_id = $this->get_option( 'shop_id' );
$this->test_mode = $this->get_option( 'test_mode' );
// This action hook saves the settings
add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) );
}
public function getDateTime(){
date_default_timezone_set('Europe/London');
$dateTime = date("Y:m:d-H:i:s");
global $dateTime;
return $dateTime;
}
public function createHash($chargetotal, $currency){
$storeId = $this->get_option( 'shop_id' );
$sharedSecret = $this->get_option( 'shared_secret' );
$stringToHash = $storeId.getDateTime().$chargetotal.$currency.$sharedSecret;
$ascii = bin2hex($stringToHash);
return hash("sha256", $ascii);
}
public function init_form_fields(){
$this->form_fields = array(
'enabled' => array(
'title' => 'Enable/Disable',
'label' => 'Enable Custom Gateway',
'type' => 'checkbox',
'description' => '',
'default' => 'no'
),
'title' => array(
'title' => 'Title',
'type' => 'text',
'description' => 'This controls the title which the user sees during checkout.',
'default' => 'Debit/Credit Card',
'desc_tip' => true,
),
'description' => array(
'title' => 'Description',
'type' => 'textarea',
'description' => 'This controls the description which the user sees during checkout.',
'default' => 'Pay with your debit/credit card.',
),
'test_mode' => array(
'title' => 'Test Mode',
'type' => 'checkbox',
'description' => 'Check this option to enable the test mode.',
'default' => 'yes',
)
);
}
public function process_payment( $order_id ) {
global $woocommerce;
$order = new WC_Order( $order_id );
$environment = $this->get_option( 'test_mode' );
if ($environment === 'yes') {
// TEST MODE
$redirect_url = 'https://mytesturl.com';
} else{
// PRODUCTION MODE
$redirect_url = 'https://myproductionurl.com';
}
return array(
'result' => 'success',
'redirect' => $redirect_url
);
}
}
}
Can someone assist me please, how can I pass the required data to the hosted payment page and update the order status once the response is received from the bank?

Add image upload custom field at dokan template new-product.php

I am using dokan plugin for a multivendor website, I want to add image upload custom field in the template
new-product.php, I used CMB2 plugin to create image upload custom field with WooCommerce like this
function themebox_metaboxes() {
// Start with an underscore to hide fields from custom fields list
$prefix = 'themebox_met_';
// Product Settings
$header_settings = new_cmb2_box( array(
'id' => 'Extra_settings',
'title' => esc_html__( 'Extra Settings', 'themebox' ),
'object_types' => array( 'product'), // Post type
'context' => 'normal',
'priority' => 'high',
'show_names' => true,
) );
$header_settings->add_field( array(
'name' => esc_html__( 'Add Image Detail size 590x300 px', 'themebox' ),
'id' => $prefix . 'img_detail',
'type' => 'file'
) );
}
I want to add this custom image upload field in template form new-product.php and when save form in dokan
the image upload custom field update with an image added in dokan .....exactly like featured product image in WooCommerce
You can override the new-product.php and new-product-single.php file and then add your field on the product upload/edit file. To add new field for product edit/add the template you will have to add a new field in this template (Override via child-theme) - dokan-lite/templates/products/new-product-single.php. However, there are some other steps required to successfully save them.
You need to modify the Dokan product upload template and then you have to add an extra field by overriding the template. After adding the input filed you have to save the value of the field. On that place you have to use do_action( 'dokan_new_product_added', $product_id, $post_data ); this hook to save the field data.
When you will edit the product that time you have to use do_action( 'dokan_product_updated', $post_id ); to re-save.
Thanks :)
function save_add_product_meta($product_id, $postdata){
if ( ! dokan_is_user_seller( get_current_user_id() ) ) {
return;
}
if ( ! empty( $postdata['title'] ) ) {
update_post_meta( $product_id, 'title', $postdata['title'] );
}
if ( ! empty( $postdata['subtitle'] ) ) {
update_post_meta( $product_id, 'subtitle', $postdata['subtitle'] );
}
if ( ! empty( $postdata['subdescription'] ) ) {
update_post_meta( $product_id, 'subdescription', $postdata['subdescription'] );
}
if ( ! empty( $postdata['vidimg'] ) ) {
update_post_meta( $product_id, 'vidimg', $postdata['vidimg'] );
}
}
/*
* Showing field data on product edit page
*/
add_action('dokan_product_edit_after_product_tags','show_on_edit_page',99,8);
function show_on_edit_page($post, $post_id){
$subtitle = get_post_meta( $post_id, 'subtitle', true );
$title = get_post_meta( $post_id, 'title', true );
$subdesc = get_post_meta( $post_id, 'subdescription', true );
$vidimg = get_post_meta( $post_id, 'vidimg', true );
?>
<div class="dokan-form-group">
<h6 class="auto">Ajoutez du contenu pour mettre en valeur cette oeuvre !</h6>
<input type="hidden" name="title" id="dokan-edit-product-id" value="<?php echo esc_attr( $post_id ); ?>"/>
<label for="new_field" class="form-label"><?php esc_html_e( 'Autre Titre', 'dokan-lite' ); ?></label>
<?php dokan_post_input_box( $post_id, 'title', array( 'placeholder' => __( 'product code', 'dokan-lite' ), 'value' => $title ) ); ?>
<p class="help-block">50 caractères maximum (conseillé)</p>
</div>
<div class="dokan-form-group">
<input type="hidden" name="subtitle" id="dokan-edit-product-id" value="<?php echo esc_attr( $post_id ); ?>"/>
<label for="subtitle" class="form-label"><?php esc_html_e( 'Sous titre', 'dokan-lite' ); ?></label>
<?php dokan_post_input_box( $post_id, 'subtitle', array( 'placeholder' => __( 'product code', 'dokan-lite' ), 'value' => $subtitle ) ); ?>
<p class="help-block">80 caractères maximum (conseillé)</p>
</div>
<div class="dokan-form-group">
<label for="subdescription" class="form-label">Paragraphe d'introduction</label>
<div class="dokan-rich-text-wrap">
<?php dokan_post_input_box( $post_id, 'subdescription', array('placeholder' => 'ajouter une description', 'value' => $subdesc ), 'textarea' ); ?>
</div>
</div>
<div class="dokan-feat-image-upload">
<?php
$wrap_class = ' dokan-hide';
$instruction_class = '';
$feat_image_id = 0;
if (!empty($vidimg) ) {
$wrap_class = '';
$instruction_class = ' dokan-hide';
$imaid =attachment_url_to_postid($vidimg);
}
?>
<div class="instruction-inside<?php echo esc_attr( $instruction_class ); ?>">
<input type="hidden" name="vidimg" class="dokan-feat-image-id" value="<?php echo esc_attr($vidimg ); ?>">
<i class="fa fa-cloud-upload"></i>
<?php esc_html_e( 'Upload a product cover image', 'dokan-lite' ); ?>
</div>
<div class="image-wrap<?php echo esc_attr( $wrap_class ); ?>">
<a class="close dokan-remove-feat-image">×</a>
<?php if ( ! empty($vidimg) ) { ?>
<img src="<?php echo esc_url(wp_get_attachment_url($vidimg ) ); ?>" alt="">
<?php } else { ?>
<img height="" width="" src="" alt="">
<?php } ?>
</div>
</div><!-- .dokan-feat-image-upload -->
<?php
}

Save Selected Option in Meta Box

i am going to build my own theme
I try to add select to post_type meta box, but every update post my select not on selected option but show the first option (blank value)
here is my code
function mhs_data() {
global $post;
echo '<input type="hidden" name="eventmeta_noncename" id="eventmeta_noncename" value="' .
wp_create_nonce( plugin_basename(__FILE__) ) . '" />';
$nisn = get_post_meta($post->ID, '_nisn', true);
$rel = get_post_meta($post->ID, '_rel', true);
}
echo '<p>NISN</p>';
echo '<input type="text" name="_nisn" value="' . $nisn . '" class="widefat" />';
echo '<p>Relationship</p>'; ?>
<select name="_rel" id="_rel">
<option value="">Relationship</option>
<option value="Single" <?php selected( $rel, 'Single' ); ?>>Single</option>
<option value="Marry" <?php selected( $rel, 'Marry' ); ?>>Marry</option>
</select>
<?php
}
function mhs_data_meta($post_id, $post) {
if ( !wp_verify_nonce( $_POST['eventmeta_noncename'], plugin_basename(__FILE__) )) {
return $post->ID;
}
if ( !current_user_can( 'edit_post', $post->ID ))
return $post->ID;
$events_meta['_nisn'] = $_POST['_nisn'];
$events_meta['_rel'] = $_POST['_rel'];
foreach ($events_meta as $key => $value) {
if( $post->post_type == 'revision' ) return;
$value = implode(',', (array)$value);
if(get_post_meta($post->ID, $key, FALSE)) {
update_post_meta($post->ID, $key, $value);
} else {
add_post_meta($post->ID, $key, $value);
}
if(!$value) delete_post_meta($post->ID, $key);
}
}
add_action('save_post', 'mhs_data_meta', 1, 2);
Please help me to correct my code
Using Codestar Framework its very simple tu add metaboxes to your custom post, create configuration page, plugins, taxonomies and use the customizer if you prefer use it instead of a configuration page. see the documentation here for more information.
in your example, to add a select metabox shuld use a code similar to:
load the framework on your functions.php
require_once __DIR__ . '/'.$FRAMEWORK_PATH.'/cs-framework/cs-framework.php';
edit the cs-framekork.php configuration file to active only the features you need:
defined('CS_ACTIVE_FRAMEWORK') or define('CS_ACTIVE_FRAMEWORK', false); // if you need it for plugin or configuration page
defined('CS_ACTIVE_METABOX') or define('CS_ACTIVE_METABOX', true); // if you only need it for metabox
defined('CS_ACTIVE_TAXONOMY') or define('CS_ACTIVE_TAXONOMY', false);
defined('CS_ACTIVE_SHORTCODE') or define('CS_ACTIVE_SHORTCODE', false);
defined('CS_ACTIVE_CUSTOMIZE') or define('CS_ACTIVE_CUSTOMIZE', false);
and then in your function.php or as I prefer on another file included in your function.php register your metabox
function register_this_metabox($options)
{
$options = array(); // this will clean the default cs-framework configuration
$options[] = array(
'id' => 'the_metabox',
'title' => 'Meta Box title',
'post_type' => 'post', // the post type where the metabox appears
'context' => 'side', // metabox position
'priority' => 'high',
'sections' => array( // metabox fields, see the documentation
array(
'name' => 'the_metabox_fields',
'fields' => array(
array(
'id' => 'the_metabox_select_field',
'type' => 'select',
'title' => 'Select Field',
'options' => array(
'opt1' => 'Option 1',
'opt2' => 'Option 2',
'opt3' => 'Option 3',
),
'default_option' => 'Select a option',
),
),
),
),
);
return $options;
}
add_filter('cs_metabox_options', 'register_this_metabox');
And now you only have to get the values in your theme:
$post_metabox = get_post_meta($post->ID, 'the_metabox', true);
$selected_option = $post_metabox['the_metabox_select_field']

Losing post id wordpress

I am losing the post id when I am doing a wp-query. I need to have it where I am inserting a record, and before if it finds an existing record, as I am using it to find custom fields attached to the post. I am using a page template here and advanced custom fields.
Post Id being lost
<?php
/**
* Template Name: Well Being Page Template
*
* #package WordPress
* #subpackage Twenty_Fourteen
* #since Twenty Fourteen 1.0
*/
?>
<?php get_header(); ?>
<?php
$ip = getenv('HTTP_CLIENT_IP')?:
getenv('HTTP_X_FORWARDED_FOR')?:
getenv('HTTP_X_FORWARDED')?:
getenv('HTTP_FORWARDED_FOR')?:
getenv('HTTP_FORWARDED')?:
getenv('REMOTE_ADDR');
// args
$args = array(
'numberposts' => -1,
'post_type' => 'wellbeing',
'post_status' => 'publish',
'meta_key' => 'ip',
'meta_value' => $ip
);
// query
$the_query = new WP_Query( $args );
// I HAVE THE POST ID HERE SO THAT I CAN REFERENCE IT IF THERE IS A RECORD FOUND USE THE POST ID FROM THE POST ?
$isFound=false;
?>
<?php
$count = $the_query->found_posts;
while ( $the_query->have_posts() ) : $the_query->the_post();
if(count==1)
{
$dateJoined = new DateTime($dateJoined);
$expiredate = new DateTime($expiredate);
$diff = $dateJoined->diff($expiredate);
echo 'Days to end'.$diff->days;
}
endwhile;
if ($count==0)
{
// Gather post data.
$my_post = array(
'post_title' => 'Opt In',
'post_content' => 'This is my post.',
'post_type' => 'wellbeing',
'meta_key' => 'ip',
'meta_value' => $ip,
'post_status' => 'publish',
'post_author' => 1,
'post_category' => array( 8,39 )
);
// Insert the post into the database.
$post_id = wp_insert_post( $my_post );
// I HAVE THE POST ID HERE OK BUT I ALSO NEED IT ABOVE AT THE WP_QUERY
$date = new DateTime();
$date->modify('+2 week');
$currentdate = date('m/d/Y h:i:s', time());
// save a basic text value
$field_key = "expirey_date";
$twoweeksaway = $date->format('m/d/Y h:i:s');;
update_field( $field_key, $twoweeksaway, $post_id );
// save a basic text value
$field_key = "date_joined";
$value = $currentdate;
update_field( $field_key, $value, $post_id );
$current_user = wp_get_current_user();
// save a basic text value
$field_key = "ip";
$value = $ip;
update_field( $field_key, $value, $post_id );
// save a basic text value
$field_key = "email";
$value = wpse_email();
update_field( $field_key, $value, $post_id );
$dateJoined=the_field('date_joined', $post_id );
$expiredate=the_field('expirey_date', $post_id );
$dateJoined = new DateTime($dateJoined);
$expiredate = new DateTime($expiredate);
$diff = $dateJoined->diff($expiredate);
echo 'Days to end'.$diff->days;
}
?>
<?php
echo 'Post Id'.$post_id;
$dateJoined=the_field('date_joined', $post_id );
$expiredate=the_field('expirey_date', $post_id );
//Convert them to timestamps.
$difference=(int)abs((strtotime($expiredate) - strtotime($dateJoined))); // 3
?>
<STYLE>
.myCheckbox input {
// display: none;
// Better than display: none for accessibility reasons
position: relative;
z-index: -9999;
}
.myCheckbox span {
width: 20px;
height: 20px;
display: block;
background: url("link_to_image");
}
.myCheckbox input:checked + span {
background: url("link_to_another_image");
}
</STYLE>
<div style="clear:both;">
Welcome this page allows you to opt out of our well being program. You have <?php echo $difference.'day(s) to opt out click opt out button below';?>
Do you wish to opt out of the well being program
</div>
<div class="form-group">
<form name="wellbeing" action="<?php echo get_permalink(); ?>" method="post">
<input type="submit" value="Opt Out"/>
</div>
</form>
<?php wp_reset_query(); // Restore global post data stomped by the_post(). ?>
<?php get_footer(); ?>

Resources