Home / Woo-Commerce / WooCommerce Products Custom Fields with Discount price

WooCommerce Products Custom Fields with Discount price

WooCommerce Products Custom Fields with Discount price.

/***********************my custom code******************/

// Add save percent next to sale item prices.
add_filter( ‘woocommerce_sale_price_html’, ‘woocommerce_custom_sales_price’, 10, 2 );
function woocommerce_custom_sales_price( $price, $product ) {

$percentage = round( ( ( $product->regular_price – $product->sale_price ) / $product->regular_price ) * 100 );

echo $price . sprintf( __(‘<span style=”color:#fff; font-size:20px; margin: 10px;”>|</span> Discount <span style=”color:#fff; font-size:20px; margin: 3px;”>:</span>  %s ‘, ‘woocommerce’ ), $percentage . ‘%’ );

// Display Custom Field Value
//echo get_post_meta( $post->ID, ‘_text_field’, true );
//echo ‘<span style=”color:#fff; font-size:20px; margin: 10px;”>’;
// echo “|”;
// echo ‘</span>’;

// You can also use
//echo get_post_meta( get_the_ID(), ‘_discount_text_field’, true );

echo ‘<span style=”color:#fff; font-size:20px; margin: 10px;”>’;
echo “|”;
echo ‘</span>’;

echo get_post_meta( get_the_ID(), ‘_bought_text_field’, true );

return ;
}

// Display Fields
add_action( ‘woocommerce_product_options_general_product_data’, ‘woo_add_custom_general_fields’ );

// Save Fields
add_action( ‘woocommerce_process_product_meta’, ‘woo_add_custom_general_fields_save’ );
function woo_add_custom_general_fields() {

global $woocommerce, $post;
echo ‘<div class=”options_group”>’;

woocommerce_wp_text_input(
array(
‘id’ => ‘_discount_text_field’,
‘label’ => __( ‘Discount’, ‘woocommerce’ ),
‘placeholder’ => ‘http://’,
‘desc_tip’ => ‘true’,
‘description’ => __( ‘Enter the custom value here.’, ‘woocommerce’ )
)
);
woocommerce_wp_text_input(
array(
‘id’ => ‘_bought_text_field’,
‘label’ => __( ‘Bought’, ‘woocommerce’ ),
‘placeholder’ => ‘http://’,
‘desc_tip’ => ‘true’,
‘description’ => __( ‘Enter the custom value here.’, ‘woocommerce’ )
)
);
echo ‘</div>’;
}

function woo_add_custom_general_fields_save( $post_id ){
// Text Field
$woocommerce_text_field = $_POST[‘_discount_text_field’];
if( !empty( $woocommerce_text_field ) )
update_post_meta( $post_id, ‘_discount_text_field’, esc_attr( $woocommerce_text_field ) );

$woocommerce_text_field = $_POST[‘_bought_text_field’];
if( !empty( $woocommerce_text_field ) )
update_post_meta( $post_id, ‘_bought_text_field’, esc_attr( $woocommerce_text_field ) );

}

add_action( ‘woocommerce_product_write_panel_tabs’, ‘woo_add_custom_admin_product_tab’ );

function woo_add_custom_admin_product_tab() {
?>
<li class=”custom_tab”><a href=”#custom_tab_data”><?php _e(‘_discount_text_field’, ‘woocommerce’); ?></a></li>
<?php
}

/************************end my custom code******************/

 

// Display Fields
add_action( ‘woocommerce_product_options_general_product_data’, ‘woo_add_custom_general_fields’ );

// Save Fields
add_action( ‘woocommerce_process_product_meta’, ‘woo_add_custom_general_fields_save’ );

/**
Fields Container
**/
function woo_add_custom_general_fields() {

global $woocommerce, $post;

echo ‘<div class=”options_group”>’;

// Textarea
woocommerce_wp_textarea_input(
array(
‘id’ => ‘_isbntextarea’,
‘label’ => __( ‘ISBN’, ‘woocommerce’ ),
‘placeholder’ => ”,
‘description’ => __( ‘ISBN.’, ‘woocommerce’ )
)
);

// Textarea
woocommerce_wp_textarea_input(
array(
‘id’ => ‘_pagestextarea’,
‘label’ => __( ‘Pages’, ‘woocommerce’ ),
‘placeholder’ => ”,
‘description’ => __( ‘Pages.’, ‘woocommerce’ )
)
);

// Textarea
woocommerce_wp_textarea_input(
array(
‘id’ => ‘_sizetextarea’,
‘label’ => __( ‘Size’, ‘woocommerce’ ),
‘placeholder’ => ”,
‘description’ => __( ‘Size.’, ‘woocommerce’ )
)
);
// Textarea
woocommerce_wp_textarea_input(
array(
‘id’ => ‘_copyrighttextarea’,
‘label’ => __( ‘Copyright’, ‘woocommerce’ ),
‘placeholder’ => ”,
‘description’ => __( ‘Copyright.’, ‘woocommerce’ )
)
);

// END Textarea

echo ‘</div>’;

}

function woo_add_custom_general_fields_save( $post_d ){

// Textarea
$woocommerce_textarea = $_POST[‘_isbntextarea’];
if( !empty( $woocommerce_textarea ) )
update_post_meta( $post_id, ‘_isbntextarea’, esc_html( $woocommerce_textarea ) );

// Textarea
$woocommerce_textarea = $_POST[‘_pagestextarea’];
if( !empty( $woocommerce_textarea ) )
update_post_meta( $post_id, ‘_pagestextarea’, esc_html( $woocommerce_textarea ) );

// Textarea
$woocommerce_textarea = $_POST[‘_sizetextarea’];
if( !empty( $woocommerce_textarea ) )
update_post_meta( $post_id, ‘_sizetextarea’, esc_html( $woocommerce_textarea ) );

// Textarea
$woocommerce_textarea = $_POST[‘_copyrighttextarea’];
if( !empty( $woocommerce_textarea ) )
update_post_meta( $post_id, ‘_copyrighttextarea’, esc_html( $woocommerce_textarea ) );
}
?>
<div itemprop=”description”>
<?php echo apply_filters( ‘woocommerce_short_description’, $post->post_excerpt ) ?>
</div>
<p>&nbsp;<p>&nbsp;<p>
<span itemprop=”productID” class=”sku_wrapper”><b><?php _e( ‘ISBN:’, ‘woocommerce’ ); ?></b> <span class=”sku”>
<?php
// Display Custom Field Value
echo get_post_meta( get_the_ID(), ‘_isbntextarea’, true );
?></span></span>
<br>
<span itemprop=”productID” class=”sku_wrapper”><b><?php _e( ‘Pages:’, ‘woocommerce’ ); ?> </b><span class=”sku”>
<?php
// Display Custom Field Value
echo get_post_meta( get_the_ID(), ‘_pagestextarea’, true );
?></span></span>
<br>
<span itemprop=”productID” class=”sku_wrapper”><b><?php _e( ‘Size:’, ‘woocommerce’ ); ?> </b><span class=”sku”>
<?php
// Display Custom Field Value
echo get_post_meta( get_the_ID(), ‘_sizetextarea’, true );
?></span></span>
<br>

<span itemprop=”productID” class=”sku_wrapper”><b><?php _e( ‘Copyright: &copy;’, ‘woocommerce’ ); ?> </b><span class=”sku”>
<?php
// Display Custom Field Value
echo get_post_meta( get_the_ID(), ‘_copyrighttextarea’, true );
?></span></span>

About Sushil_kumar

Check Also

aws

how to setting WordPress on Amazon EC2

Step 1: Create an AWS Account Step 2: Create an Instance To create a new …

Leave a Reply

Your email address will not be published. Required fields are marked *

0

December 10, 2016

Clear all