Hallo
Ich hab ein Problem und ich finde den Fehler nicht entweder ich steh voll auf dem Schlauch oder ich hab was Wichtiges übersehen, ich hoffe jemand kann mir bitte helfen.
Weil der Code relativ umfangreich ist, habe ich die Zeilen Kommentiert um es leicher/schneller nachvolziehen zu können.Ganz unten ist der Fehler wo keine Aktion ausgeführt wird alles andere funktioniert, nur der Wert (_max_tickets) sollte bei dem Formular unten überschrieben werden.
Ich hab ein Problem und ich finde den Fehler nicht entweder ich steh voll auf dem Schlauch oder ich hab was Wichtiges übersehen, ich hoffe jemand kann mir bitte helfen.
Weil der Code relativ umfangreich ist, habe ich die Zeilen Kommentiert um es leicher/schneller nachvolziehen zu können.Ganz unten ist der Fehler wo keine Aktion ausgeführt wird alles andere funktioniert, nur der Wert (_max_tickets) sollte bei dem Formular unten überschrieben werden.
PHP-Code:
<?php
/**
* Adds the panel to the Product Data postbox in the product interface
*
* @return void
*
*/
public function product_write_panel(){
global $post;
echo '<div id="lottery_tab" class="panel woocommerce_options_panel">';
woocommerce_wp_text_input(
array(
'id' => '_max_tickets', //Hier wird der Wert Normalerweise eingetragen
'class' => 'input_text',
'size' => '6',
'label' => __( 'Available tickets', 'wc_lottery' ),
'type' => 'number',
'custom_attributes' => array('step' => 'any', 'min' => '0'),
'desc_tip' => 'true',
'description' => __( 'Minimum tickets to be sold', 'wc_lottery' )
) );
[...]
do_action( 'woocommerce_product_options_lottery' );
echo "</div>";
}
/**
* Saves the data inputed into the product boxes, as post meta data
*
*
* @param int $post_id the post (product) identifier
* @param stdClass $post the post (product)
*
*/
public function product_save_data($post_id, $post){
$product_type = empty( $_POST['product-type'] ) ? 'simple' : sanitize_title( wc_clean( $_POST['product-type'] ) );
if (
$product_type == 'lottery' ) {
if (isset($_POST['_max_tickets'] ) && !empty($_POST['_max_tickets']) && !empty($_POST['_lottery_price'])){
update_post_meta( $post_id, '_manage_stock', 'yes' );
if(get_post_meta( $post_id, '_lottery_participants_count',TRUE )){
update_post_meta( $post_id, '_stock', intval(wc_clean( $_POST['_max_tickets'])) - intval(get_post_meta( $post_id, '_lottery_participants_count',TRUE )) );
} else {
update_post_meta( $post_id, '_stock', wc_clean( $_POST['_max_tickets']) );
}
update_post_meta( $post_id, '_backorders', 'no' );
}
else{
update_post_meta( $post_id, '_manage_stock', 'no' );
update_post_meta( $post_id, '_backorders', 'no' );
update_post_meta( $post_id, '_stock_status', 'instock' );
}
if (isset($_POST['_lottery_price'] ) && !empty($_POST['_lottery_price'])){
$lottey_price = wc_format_decimal( wc_clean( $_POST['_lottery_price'] ) );
update_post_meta( $post_id, '_lottery_price', $lottey_price );
update_post_meta( $post_id, '_regular_price', $lottey_price );
update_post_meta( $post_id, '_price', $lottey_price );
} else{
update_post_meta( $post_id, '_lottery_price', '0' );
update_post_meta( $post_id, '_regular_price', '0' );
update_post_meta( $post_id, '_price', '0' );
}
if(($_POST['_lottery_price'] == 0 || !isset($_POST['_lottery_price'])) && (!isset($_POST['_max_tickets_per_user']) or empty($_POST['_max_tickets_per_user']) )){
update_post_meta( $post_id, '_sold_individually', 'yes' );
}
if (isset($_POST['_max_tickets_per_user'] ) && !empty($_POST['_max_tickets_per_user']) ){
update_post_meta( $post_id, '_max_tickets_per_user', wc_clean( $_POST['_max_tickets_per_user'] ) );
if ($_POST['_max_tickets_per_user'] <= 1){
update_post_meta( $post_id, '_sold_individually', 'yes' );
} else {
update_post_meta( $post_id, '_sold_individually', 'no' );
}
}
if (isset($_POST['_lottery_num_winners'] ) && !empty($_POST['_lottery_num_winners']) ){
update_post_meta( $post_id, '_lottery_num_winners', wc_clean( $_POST['_lottery_num_winners'] ) );
if ($_POST['_lottery_num_winners'] <= 1){
update_post_meta( $post_id, '_lottery_multiple_winner_per_user', 'no' );
} else {
if(isset($_POST['_lottery_multiple_winner_per_user']) && !empty($_POST['_lottery_multiple_winner_per_user']) ){
update_post_meta( $post_id, '_lottery_multiple_winner_per_user', 'yes' );
} else{
update_post_meta( $post_id, '_lottery_multiple_winner_per_user', 'no' );
}
}
}
if (isset($_POST['_max_tickets'] ))
update_post_meta( $post_id, '_max_tickets', wc_clean( $_POST['_max_tickets'] ) ); //Hier wird der Wert gespeichert
[...]
}
}
/**
* Add lottery icons in product list in wp-admin
*
* @access public
* @param string, string
* @return void
*
*/
function woocommerce_simple_lottery_order_column_lottery_content($column_name, $post_ID) {
global $product, $post;
if ($column_name == 'lottery') {
$class ='';
$product_data = wc_get_product( $post_ID );
if( is_object($product_data) && $product_data->product_type == 'lottery'){
if($product_data->is_closed()){ echo "Closed";
}
else{
if(isset($_POST['submit']))
{
update_post_meta( $post_id, '_max_tickets', wc_clean( $_POST['_max_tickets'] ) ); //hier wird der Wert _max_tickets via submit Button überschrieben Hier ist auch der Fehler
}
else{?>
<form action="" method="POST">
<input type="submit" id="submit" name="submit" />
<input name="fe" type="text" id="_max_tickets" value="<?php echo !empty($product->lottery_participants_count) ? $product->lottery_participants_count : '0' ;?>" />
</form>
<?php
echo "Sold<br/>";
echo !empty($product->lottery_participants_count) ? $product->lottery_participants_count : '0' ;
printf( __( " / %s", 'wc_lottery' ),$product->max_tickets ) ;
}}
if($product_data->is_closed())
$class .= ' finished ';
// echo "<img src='".plugin_dir_url( __FILE__ ) .'images/lottery.png'."' alt='".__('Lottery','wc_lottery')."' class='$class' />";
}
if ( get_post_meta( $post_ID , '_lottery' , TRUE)){
// echo "<img src='".plugin_dir_url( __FILE__ ) .'images/lottery.png'."' alt='".__('Lottery','wc_lottery')."' class='order' />";
}
}
}

Kommentar