I tried modifying this plug-in for WordPress:
https://easydigitaldownloads.com/downloads/custom-prices/?utm_campaign=documentation&utm_source=helpscout&utm_medium=doc&utm_term=1975-custom-prices-overview
What I'm trying to achieve is moving the $ sign next to the custom price field or alternatively removing it completely.
/*
* Hook into add to cart post
*/
function edd_cp_purchase_link_top( $download_id ) {
global $edd_options;
$default_price = get_post_meta( $download_id, 'edd_cp_default_price', true );
$min_price = edd_format_amount ( get_post_meta( $download_id, 'edd_cp_min', true ) );
$custom_price = isset( $_GET ['cp_price'] ) ? edd_format_amount( $_GET ['cp_price'] ) : '';
$button_text = get_post_meta( $download_id, 'cp_button_text', true );
if ( empty( $custom_price ) && ! empty( $default_price ) ) {
$custom_price = edd_format_amount( $default_price );
}
if ( edd_cp_has_custom_pricing( $download_id ) && ! edd_single_price_option_mode( $download_id ) ) {
$wrapper_display = '';
$download = new EDD_Download( $download_id );
if ( edd_item_in_cart( $download_id, array() ) && ( ! $download->has_variable_prices() || ! $download->is_single_price_mode() ) ) {
$wrapper_display = 'style="display:none;"';
} ?>
<p class="edd-cp-container" <?php echo $wrapper_display; ?>>
<?php
echo __( 'Name your price', 'edd_cp' );
if ( ! isset( $edd_options['currency_position'] ) || $edd_options['currency_position'] == 'before' ) : ?>
<?php echo edd_currency_filter( '' ); ?> <input type="text" name="edd_cp_price" class="edd_cp_price" value="<?php echo esc_attr( $custom_price ); ?>" size="30" data-min="<?php echo $min_price; ?>" style="width: 40px;" data-default-text="<?php echo esc_attr( $button_text ); ?>" />
<?php else : ?>
<input type="text" name="edd_cp_price" class="edd_cp_price" value="<?php echo esc_attr( $custom_price ); ?>" size="30" data-min="<?php echo $min_price; ?>" style="width: 80px;" data-default-text="<?php echo esc_attr( $button_text ); ?>" /><?php echo edd_currency_filter( '' );
endif;
$min_no_format = floatval( $min_price );
if( !empty( $min_no_format ) ) {
echo ' <small>(min '.edd_currency_filter( ( $min_price ) ).')</small>';
} ?>
</p>
<?php
}
}
add_filter( 'edd_purchase_link_top', 'edd_cp_purchase_link_top' );
/*
* Add additional list item if variable pricing is enabled
*/
function edd_cp_after_price_options_list( $key, $price, $download_id ) {
if( ! edd_cp_has_custom_pricing( $download_id ) ) {
return;
}
if ( ! edd_single_price_option_mode( $download_id ) ) {
return;
}
global $edd_options;
$default_price_option = edd_get_default_variable_price( $download_id );
$display = 'none';
if ( $key === $default_price_option ) {
$display = 'block';
} ?>
<div class="edd-cp-price-option-wrapper" style="display: <?php echo esc_attr( $display ); ?>;">
<?php
echo __( 'Name your price', 'edd_cp' );
if ( ! isset( $edd_options['currency_position'] ) || $edd_options['currency_position'] == 'before' ) : ?>
<?php echo edd_currency_filter( '' ); ?> <input type="text" name="edd_cp_price[<?php echo esc_attr( $key ); ?>]" class="edd_cp_price" value="<?php echo esc_attr( $price['amount'] ); ?>" size="30" data-min="" />
<?php else : ?>
<input type="text" name="edd_cp_price[<?php echo esc_attr( $key ); ?>]" class="edd_cp_price" value="<?php echo esc_attr( $price['amount'] ); ?>" size="30" data-min="" data-default-text="<?php echo esc_attr( $button_text ); ?>" /><?php echo edd_currency_filter( '' );
endif; ?>
</div>
<?php }
add_action( 'edd_after_price_option', 'edd_cp_after_price_options_list', 10, 3 );
See the attached image. This is how it currently looks.
I really appreciate your help!
Related
this codes diplay prodcuts checkbox and load them in template
but i want to display the value of the checked items only in backend admin new column
so i can know exactly which items the customer has selected
product displying with quantity and name i just want to display those values in my admin dashbord
new column
codes:
<tr>
<td class="row_head" valign="top">
<?php echo esc_html__( 'Produits:', 'woocommerce-smart-refunder' ); ?>
</td>
<td class="row_headxx">
<label for="refund_type_prd">
<?php
if ( sizeof( $products ) > 0 ) {
foreach( $products as $item ) { ?>
<input type="checkbox" name="wc_products" class="wc_products" id="wc_products<?php echo ($item['name']); ?>" value="<?php echo $product_id;?>"<?php if(in_array($product_id,$data) ){echo "checked";} ?>><span class="gdjhd57djk3"><?php echo __(esc_html($item['name']), 'woocommerce-smart-refunder'); ?><?php if ( isset ( $checkboxMeta['wc_products'] ) ) checked( $checkboxMeta['wc_products'][0], 'yes' ); ?></span>
<?php echo apply_filters( 'woocommerce_order_item_quantity_html', ' <strong class="product-quantity">' . sprintf( '× %s', $item['qty'] ) . '</strong></p>', $item );?>
<?php echo apply_filters( 'woocommerce_order_item_name', $product_permalink ? sprintf( '<div class="hhdjdk654b">'.'<span>Réf:<span>'. '<a class=hhsjdh533H" href="%s">%s</a>'.'</div>', $product_permalink, $item->get_id() ) : $item->get_id(), $item, $is_visible ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped;?>
<div class="quantity">
<input class="minus" type="button" value="-">
<input type="number" step="<?php echo esc_attr( $step ); ?>" <?php if ( is_numeric( $min_value ) ) : ?>min="<?php echo esc_attr( $min_value ); ?>"<?php endif; ?> <?php if ( is_numeric( $max_value ) ) : ?>max="<?php echo esc_attr( $max_value ); ?>"<?php endif; ?> name="<?php echo esc_attr( $input_name ); ?>" value="<?php echo esc_attr( $item['qty']); ?>" title="<?php _ex( 'Qty', 'Product quantity input tooltip', 'woocommerce' ) ?>" class="input-text qty text" size="4" />
<input class="plus" type="button" value="+">
</div> <?php
//echo $product->get_id();
?>
<script type="text/javascript">
jQuery(document).ready(function($){
$('form.cart').on( 'click', 'button.plus, button.minus', function() {
// Get current quantity values
var qty = $( this ).closest( 'form.cart' ).find( '.qty' );
var val = parseFloat(qty.val());
var max = parseFloat(qty.attr( 'max' ));
var min = parseFloat(qty.attr( 'min' ));
var step = parseFloat(qty.attr( 'step' ));
// Change the value if plus or minus
if ( $( this ).is( '.plus' ) ) {
if ( max && ( max <= val ) ) {
qty.val( max );
} else {
qty.val( val + step );
}
} else {
if ( min && ( min >= val ) ) {
qty.val( min );
} else if ( val > 1 ) {
qty.val( val - step );
}
}
});
});
</script>
<?php
}
}
?>
</label>
<br>
</td>
</tr>
I am working on an e-commerce site, which I want to add different custom quantities for each single product separately. For example, I want business cards page with quantities goes as 250,500,1000,1200, 1500 etc.. and Magnets page quantities goes as 15,25,50,75 etc.. I found the following code, which I can add the different quantities, But It is common to all the products. Please help
<?php
if ( ! defined( 'ABSPATH' ) ) exit;
if ( $max_value && $min_value === $max_value ) {
?><div class="quantity hidden"><input type="hidden" id="<?php echo esc_attr( $input_id ); ?>"
class="qty" name="<?php echo esc_attr( $input_name ); ?>" value="<?php echo esc_attr( $min_value ); ?>"
/></div><?php
} elseif ( isset ( $dropdown_steps ) ) {
?><div class="quantity">
<label class="screen-reader-text" for="<?php echo esc_attr( $input_id ); ?>"><?php esc_html_e( 'Quantity', 'woocommerce' ); ?></label>
<select name="<?php echo esc_attr( $input_name ); ?>" class="quantity" id="<?php echo esc_attr( $input_id ); ?>"><?php
foreach ( $dropdown_steps as $i ) :
?><option value="<?php echo absint( $i ); ?>"><?php echo sprintf( _n( '%d Item', '%d Items', $i, 'woocommerce' ), $i ); ?></option><?php
endforeach
?></select>
</div><?php
} else {
?><div class="quantity">
<label class="screen-reader-text" for="<?php echo esc_attr( $input_id ); ?>"><?php esc_html_e( 'Quantity', 'woocommerce' ); ?></label>
<input type="number" id="<?php echo esc_attr( $input_id ); ?>" class="input-text qty text" step="
<?php echo esc_attr( $step ); ?>" min="<?php echo esc_attr( $min_value ); ?>" max="<?php echo esc_attr( 0
< $max_value ? $max_value : '' ); ?>" name="<?php echo esc_attr( $input_name ); ?>" value="<?php echo
esc_attr( $input_value ); ?>" title="<?php echo esc_attr_x( 'Qty', 'Product quantity input tooltip',
'woocommerce' ) ?>" size="4" pattern="<?php echo esc_attr( $pattern ); ?>" inputmode="<?php echo
esc_attr( $inputmode ); ?>" aria-labelledby="<?php echo ! empty( $args['product_name'] ) ? sprintf(
esc_attr__( '%s quantity', 'woocommerce' ), $args['product_name'] ) : ''; ?>" />
</div><?php
}
In cart page
/**
* Add additional quantity input field args.
*
* #param WC_Product $product
*/
function ace_quantity_input_field_args( $args, $product ) {
if ( ! $product->is_sold_individually() ) {
$args['dropdown_steps'] = array( 1, 5, 25, 100, 250, 500, 2500 );
}
return $args;
}
add_filter( 'woocommerce_quantity_input_args', 'ace_quantity_input_field_args', 10, 2 );
I am using the Avada Wordpress theme. I'd like to switch out the logo depending on the page. I found this thread on stackoverflow and found it very useful
The latest Avada theme has different coding for standard, mobile and sticky header logos. On top of that, each has a retina option. That is where I am having the problem. It is not clear to me how to allow this for the retina options, too. The coding in the logo.php file is different than in the example I sited.
You'll see the section. The "standard" string works, but not the mobile, sticky, or retina. Any thoughts? Here's the full logo.pho code I am using.
<?php
/**
* Logo template.
*
* #author ThemeFusion
* #copyright (c) Copyright by ThemeFusion
* #link http://theme-fusion.com
* #package Avada
* #subpackage Core
*/
// Do not allow directly accessing this file.
if ( ! defined( 'ABSPATH' ) ) {
exit( 'Direct script access denied.' );
}
$logo_opening_markup = '<div class="';
$logo_closing_markup = '</div>';
if ( 'v7' === Avada()->settings->get( 'header_layout' ) && ! Avada()->settings->get( 'logo_background' ) ) {
$logo_opening_markup = '<li class="fusion-middle-logo-menu-logo ';
$logo_closing_markup = '</li>';
} elseif ( 'v7' === Avada()->settings->get( 'header_layout' ) && Avada()->settings->get( 'logo_background' ) && 'Top' === Avada()->settings->get( 'header_position' ) ) {
$logo_opening_markup = '<li class="fusion-logo-background fusion-middle-logo-menu-logo"><div class="';
$logo_closing_markup = '</div></li>';
} elseif ( Avada()->settings->get( 'logo_background' ) && 'v4' !== Avada()->settings->get( 'header_layout' ) && 'v5' !== Avada()->settings->get( 'header_layout' ) && 'Top' === Avada()->settings->get( 'header_position' ) ) {
$logo_opening_markup = '<div class="fusion-logo-background"><div class="';
$logo_closing_markup = '</div></div>';
}
?>
<?php if ( '' !== Avada()->settings->get( 'logo', 'url' ) || '' !== Avada()->settings->get( 'logo_retina', 'url' ) ) : ?>
<?php echo $logo_opening_markup; // WPCS: XSS ok. ?>fusion-logo" data-margin-top="<?php echo esc_attr( Avada()->settings->get( 'logo_margin', 'top' ) ); ?>" data-margin-bottom="<?php echo esc_attr( Avada()->settings->get( 'logo_margin', 'bottom' ) ); ?>" data-margin-left="<?php echo esc_attr( Avada()->settings->get( 'logo_margin', 'left' ) ); ?>" data-margin-right="<?php echo esc_attr( Avada()->settings->get( 'logo_margin', 'right' ) ); ?>">
<?php elseif ( 'v7' !== Avada()->settings->get( 'header_layout' ) ) : ?>
<?php echo $logo_opening_markup; // WPCS: XSS ok. ?>fusion-logo" data-margin-top="0px" data-margin-bottom="0px" data-margin-left="0px" data-margin-right="0px">
<?php endif; ?>
<?php
/**
* The avada_logo_prepend hook.
*/
do_action( 'avada_logo_prepend' );
$logo_anchor_tag_attributes = '';
$logo_anchor_tag_attributes_array = apply_filters(
'avada_logo_anchor_tag_attributes',
array(
'class' => 'fusion-logo-link',
'href' => ( $custom_link = Avada()->settings->get( 'logo_custom_link' ) ) ? esc_url( $custom_link ) : esc_url( home_url( '/' ) ),
)
);
foreach ( $logo_anchor_tag_attributes_array as $attribute => $value ) {
if ( 'href' === $attribute ) {
$value = esc_url( $value );
} else {
$value = esc_attr( $value );
}
$logo_anchor_tag_attributes .= ' ' . $attribute . '="' . $value . '" ';
}
$logo_alt_attribute = apply_filters( 'avada_logo_alt_tag', get_bloginfo( 'name', 'display' ) . ' ' . __( 'Logo', 'Avada' ) );
?>
<?php if ( ( Avada()->settings->get( 'logo', 'url' ) && '' !== Avada()->settings->get( 'logo', 'url' ) ) || ( Avada()->settings->get( 'logo_retina', 'url' ) && '' !== Avada()->settings->get( 'logo_retina', 'url' ) ) ) : ?>
<a<?php echo $logo_anchor_tag_attributes; // WPCS: XSS ok. ?>>
<?php $standard_logo = Avada()->images->get_logo_image_srcset( 'logo', 'logo_retina' ); ?>
<!-- custom logo -->
<?php
//Movie
if (is_page( 'movie' ))
{
$standard_logo['srcset'] = '/wp-content/uploads/2018/08/SRSM-Logo-Default-01.png';
$standard_logo['url'] = $standard_logo['srcset'];
$retina_logo['srcset'] = '/wp-content/uploads/2018/08/SRSM-Logo-Retina-01.png';
$retina_logo['url'] = $retina_logo['srcset'];
$mobile_logo['srcset'] = '/wp-content/uploads/2018/08/SRSM-Logo-Mobile-01.png';
$mobile_logo['url'] = $mobile_logo['srcset'];
$sticky_logo['srcset'] = '/wp-content/uploads/2018/08/SRSM-Logo-Sticky-01.png';
$sticky_logo['url'] = $sticky_logo['srcset'];
}
?>
<!-- standard logo -->
<img src="<?php echo esc_url_raw( $standard_logo['url'] ); ?>" srcset="<?php echo esc_attr( $standard_logo['srcset'] ); ?>" width="<?php echo esc_attr( $standard_logo['width'] ); ?>" height="<?php echo esc_attr( $standard_logo['height'] ); ?>"<?php echo $standard_logo['style']; // WPCS: XSS ok. ?> alt="<?php echo esc_attr( $logo_alt_attribute ); ?>" retina_logo_url="<?php echo esc_url_raw( $standard_logo['is_retina'] ); ?>" class="fusion-standard-logo" />
<?php
if ( Avada()->settings->get( 'mobile_logo', 'url' ) && '' !== Avada()->settings->get( 'mobile_logo', 'url' ) ) {
$mobile_logo = Avada()->images->get_logo_image_srcset( 'mobile_logo', 'mobile_logo_retina' );
?>
<!-- mobile logo -->
<img src="<?php echo esc_url_raw( $mobile_logo['url'] ); ?>" srcset="<?php echo esc_attr( $mobile_logo['srcset'] ); ?>" width="<?php echo esc_attr( $mobile_logo['width'] ); ?>" height="<?php echo esc_attr( $mobile_logo['height'] ); ?>"<?php echo $mobile_logo['style']; // WPCS: XSS ok. ?> alt="<?php echo esc_attr( $logo_alt_attribute ); ?>" retina_logo_url="<?php echo esc_url_raw( $mobile_logo['is_retina'] ); ?>" class="fusion-mobile-logo" />
<?php } ?>
<?php
if ( Avada()->settings->get( 'sticky_header_logo', 'url' ) && '' !== Avada()->settings->get( 'sticky_header_logo', 'url' ) && ( in_array( Avada()->settings->get( 'header_layout' ), array( 'v1', 'v2', 'v3', 'v6', 'v7' ) ) || ( ( in_array( Avada()->settings->get( 'header_layout' ), array( 'v4', 'v5' ) ) && 'menu_and_logo' === Avada()->settings->get( 'header_sticky_type2_layout' ) ) ) ) ) {
$sticky_logo = Avada()->images->get_logo_image_srcset( 'sticky_header_logo', 'sticky_header_logo_retina' );
?>
<!-- sticky header logo -->
<img src="<?php echo esc_url_raw( $sticky_logo['url'] ); ?>" srcset="<?php echo esc_attr( $sticky_logo['srcset'] ); ?>" width="<?php echo esc_attr( $sticky_logo['width'] ); ?>" height="<?php echo esc_attr( $sticky_logo['height'] ); ?>"<?php echo $sticky_logo['style']; // WPCS: XSS ok. ?> alt="<?php echo esc_attr( $logo_alt_attribute ); ?>" retina_logo_url="<?php echo esc_url_raw( $sticky_logo['is_retina'] ); ?>" class="fusion-sticky-logo" />
<?php } ?>
</a>
<?php endif; ?>
<?php
/**
* The avada_logo_append hook.
*
* #hooked avada_header_content_3 - 10.
*/
do_action( 'avada_logo_append' );
?>
<?php
echo $logo_closing_markup; // WPCS: XSS ok.
/* Omit closing PHP tag to avoid "Headers already sent" issues. */
how to query woocommerce shipping method tax price ?
Porblem i don't tax + prive query!
Price query:
<?php if($method->cost > 0) : ?>+<span style="font-weight: normal"><?= $method->cost ?> Ft</span><?php endif; ?>
</label>
</div>
My code is:
<h2>Átvételi mód</h2>
<?php
$packages = WC()->shipping->get_packages();
$first = true;
foreach ($packages as $i => $package) {
$chosen_method = isset(WC()->session->chosen_shipping_methods[$i]) ? WC()->session->chosen_shipping_methods[$i] : '';
$product_names = array();
if (sizeof($packages) > 1) {
foreach ($package['contents'] as $item_id => $values) {
$product_names[$item_id] = $values['data']->get_name() . ' ×' . $values['quantity'];
}
$product_names = apply_filters('woocommerce_shipping_package_details_array', $product_names, $package);
}
/** #var WC_Shipping_Rate[] $available_methods */
$available_methods = $package['rates'];
$show_package_details = sizeof( $packages ) > 1;
$package_name = apply_filters( 'woocommerce_shipping_package_name', sprintf( _nx( 'Shipping', 'Shipping %d', ( $i + 1 ), 'shipping packages', 'woocommerce' ), ( $i + 1 ) ), $i, $package );
?>
<div class="shipping atvetelimod">
<td data-title="<?php echo esc_attr( $package_name ); ?>">
<?php if ( 1 < count( $available_methods ) ) : ?>
<div id="shipping_method row">
<?php
foreach ( $available_methods as $method ) : ?>
<div class="col-lg-6 balraszoveg">
<div class="jobbelvalaszto">
<label class="checkjel">
<input class="legyenelottefeher" type="radio" name="shipping_method[<?= $i ?>]" data-index="<?= $i ?>" id="shipping_method_<?= $i ?>_<?= sanitize_title( $method->id ) ?>" value="<?= esc_attr( $method->id ) ?>" class="shipping_method" <?= checked( $method->id, $chosen_method, false ) ?> />
</label>
</div>
<label class="jobboldaliszoveg" for="shipping_method_<?= $i ?>_<?= sanitize_title( $method->id ) ?>">
<strong><?= $method->get_label() ?></strong><br />
<?php if($method->cost > 0) : ?>+<span style="font-weight: normal"><?= $method->cost ?> Ft</span><?php endif; ?>
</label>
</div>
<?php endforeach; ?>
</div>
<?php elseif ( 1 === count( $available_methods ) ) : ?>
<?php
$method = current( $available_methods );
printf( '%3$s <input type="hidden" name="shipping_method[%1$d]" data-index="%1$d" id="shipping_method_%1$d" value="%2$s" class="shipping_method" />', $index, esc_attr( $method->id ), wc_cart_totals_shipping_method_label( $method ) );
do_action( 'woocommerce_after_shipping_rate', $method, $index );
?>
<?php elseif ( WC()->customer->has_calculated_shipping() ) : ?>
<?php echo apply_filters( is_cart() ? 'woocommerce_cart_no_shipping_available_html' : 'woocommerce_no_shipping_available_html', wpautop( __( 'There are no shipping methods available. Please ensure that your address has been entered correctly, or contact us if you need any help.', 'woocommerce' ) ) ); ?>
<?php elseif ( ! is_cart() ) : ?>
<?php echo wpautop( __( 'Enter your full address to see shipping costs.', 'woocommerce' ) ); ?>
<?php endif; ?>
<?php if ( $show_package_details ) : ?>
<?php echo '<p class="woocommerce-shipping-contents"><small>' . esc_html( $package_details ) . '</small></p>'; ?>
<?php endif; ?>
<?php if ( ! empty( $show_shipping_calculator ) ) : ?>
<?php woocommerce_shipping_calculator(); ?>
<?php endif; ?>
</td>
</div>
<?php }; ?>
I've created this code, it is supposed to use wordpress metabox functionality to save additional data of posts in DB.
//Price list meta boxes
add_action( 'add_meta_boxes', 'cd_meta_box_add' );
function cd_meta_box_add() {add_meta_box( 'price-list-id', 'Price List', 'cd_meta_box_cb', 'post', 'normal', 'high' );}
function cd_meta_box_cb()
{
// $post is already set, and contains an object: the WordPress post
global $post;
$values = get_post_custom( $post->ID );
//
$plheading = isset( $values['price_list_heading'] ) ? esc_attr( $values['price_list_heading'][0] ) : '';
$plcategory1 = isset( $values['price_list_category1'] ) ? esc_attr( $values['price_list_category1'][0] ) : '';
$plcategoryitems1 = isset( $values['price_list_items_category1'] ) ? esc_attr( $values['price_list_items_category1'][0] ) : '';
$plcategory2 = isset( $values['price_list_category2'] ) ? esc_attr( $values['price_list_category2'][0] ) : '';
$plcategoryitems2 = isset( $values['price_list_items_category2'] ) ? esc_attr( $values['price_list_items_category2'][0] ) : '';
$plcategory3 = isset( $values['price_list_category3'] ) ? esc_attr( $values['price_list_category3'][0] ) : '';
$plcategoryitems3 = isset( $values['price_list_items_category3'] ) ? esc_attr( $values['price_list_items_category3'][0] ) : '';
// We'll use this nonce field later on when saving.
wp_nonce_field( 'my_meta_box_nonce', 'meta_box_nonce' );
?>
<p>
<label for="price_list_heading">Price list heading:</label>
<input type="text" name="price_list_heading" id="price_list_heading" value="<?php echo $plheading; ?>" />
</p>
<p>
<label for="price_list_category1">Category1 Title:</label>
<input type="text" name="price_list_category1" id="price_list_category1" value="<?php echo $plcategory1; ?>" />
<textarea style="width: 100%;" rows="3" name="price_list_items_category1" id="price_list_items_category1"><?php echo $plcategoryitems1; ?></textarea>
<span style="display: block; font-weight: bold; text-align: right;">Example: Rhine Riesling1|0,75 l|9,50 €</span>
</p>
<p>
<label for="price_list_category2">Category2 Title:</label>
<input type="text" name="price_list_category2" id="price_list_category2" value="<?php echo $plcategory2; ?>" />
<textarea style="width: 100%;" rows="3" name="price_list_items_category2" id="price_list_items_category2"><?php echo $plcategoryitems2; ?></textarea>
<span style="display: block; font-weight: bold; text-align: right;">Example: Rhine Riesling1|0,75 l|9,50 €</span>
</p>
<p>
<label for="price_list_category3">Category3 Title:</label>
<input type="text" name="price_list_category3" id="price_list_category3" value="<?php echo $plcategory3; ?>" />
<textarea style="width: 100%;" rows="3" name="price_list_items_category3" id="price_list_items_category3"><?php echo $plcategoryitems3; ?></textarea>
<span style="display: block; font-weight: bold; text-align: right;">Example: Rhine Riesling1|0,75 l|9,50 €</span>
</p>
<?php
}
//Saving price list
add_action( 'save_post', 'cd_meta_box_save' );
function cd_meta_box_save( $post_id )
{
// Bail if we're doing an auto save
if( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) return;
// if our nonce isn't there, or we can't verify it, bail
if( !isset( $_POST['meta_box_nonce'] ) || !wp_verify_nonce( $_POST['meta_box_nonce'], 'my_meta_box_nonce' ) ) return;
// if our current user can't edit this post, bail
if( !current_user_can( 'edit_post' ) ) return;
// Make sure your data is set before trying to save it
if( isset( $_POST['price_list_heading'] ) )
update_post_meta( $post_id, 'price_list_heading', esc_attr( $_POST['price_list_heading'] ) );
//
if( isset( $_POST['price_list_category1'] ) )
update_post_meta( $post_id, 'price_list_category1', esc_attr( $_POST['price_list_category1'] ) );
if( isset( $_POST['price_list_items_category1'] ) )
update_post_meta( $post_id, 'price_list_items_category1', esc_attr( $_POST['price_list_items_category1'] ) );
//
if( isset( $_POST['price_list_category2'] ) )
update_post_meta( $post_id, 'price_list_category2', esc_attr( $_POST['price_list_category2'] ) );
if( isset( $_POST['price_list_items_category2'] ) )
update_post_meta( $post_id, 'price_list_items_category2', esc_attr( $_POST['price_list_items_category2'] ) );
//
if( isset( $_POST['price_list_category3'] ) )
update_post_meta( $post_id, 'price_list_category3', esc_attr( $_POST['price_list_category3'] ) );
if( isset( $_POST['price_list_items_category3'] ) )
update_post_meta( $post_id, 'price_list_items_category3', esc_attr( $_POST['price_list_items_category3'] ) );
}
Instead of saving what I write in textboxes and inputs in DB I find "Array" on all fields! What is going on? What did I miss?
figured it out $plheading = isset( $values['price_list_heading'] ) ? esc_attr( $values['price_list_heading'][0] ) : '';
I was missing [0]
btw, in that tutorial in some examples [0] is missing :)
Please have a look at the steps and see if you missed anything, here is the link http://www.farinspace.com/how-to-create-custom-wordpress-meta-box/