XHTMLforum

XHTMLforum (http://xhtmlforum.de/index.php)
-   Serveradministration und serverseitige Scripte (http://xhtmlforum.de/forumdisplay.php?f=80)
-   -   PHP Funktion erweitern? (http://xhtmlforum.de/showthread.php?t=69826)

benzrecordings 13.08.2013 08:31

PHP Funktion erweitern?
 
Hallo liebe community,
ich habe mal eine Frage an alle Programmierer. Und zwar nutze ich Wordpress mit dem Plugin Woocommerce. Dort möchte ich intern zwei Zusätzliche Felder ausgeben, wovon dann eins auch auf der Produktseite zu sehen ist. Ich habe folgende Funktion gefunden und auch erfolgreich implementiert:

PHP-Code:

//Display Fields
add_action( 'woocommerce_product_after_variable_attributes', 'variable_fields', 10, 2 );
//JS to add fields for new variations
add_action( 'woocommerce_product_after_variable_attributes_js', 'variable_fields_js' );
//Save variation fields
add_action( 'woocommerce_process_product_meta_variable', 'variable_fields_process', 10, 1 );
 
function variable_fields( $loop, $variation_data ) {
?>
<tr>
<td>
<div>
<label><?php _e'My Custom Field''woocommerce' ); ?></label>
<input type="text" size="5" name="my_custom_field[<?php echo $loop?>]" value="<?php echo $variation_data['_my_custom_field'][0]; ?>"/>
</div>
</td>
</tr>
<?php
}
 
function 
variable_fields_js() {
?>
<tr>\
<td>\
<div>\
<label><?php _e'My Custom Field''woocommerce' ); ?></label>\
<input type="text" size="5" name="my_custom_field[' + loop + ']" />\
</div>\
</td>\
</tr>\
<?php
}
 
function 
variable_fields_process$post_id ) {
if (isset( 
$_POST['variable_sku'] ) ) :
$variable_sku $_POST['variable_sku'];
$variable_post_id $_POST['variable_post_id'];
$variable_custom_field $_POST['my_custom_field'];
for ( 
$i 0$i sizeof$variable_sku ); $i++ ) :
$variation_id = (int) $variable_post_id[$i];
if ( isset( 
$variable_custom_field[$i] ) ) {
update_post_meta$variation_id'_my_custom_field'stripslashes$variable_custom_field[$i] ) );
}
endfor;
endif;
}

Ich benötige allerdings ein weiteres Eingabefeld, welches zusätzlich noch auf der Produktseite ausgegeben wird. Ich schaffe es allerdings nicht noch ein Feld hinzuzufügen, da ich nur sehr bedingt Ahnung von PHP habe. Kann mir jemand behilflich sein?

Hier gibt's das Script übrigens auch im Netz:

https://gist.github.com/kloon/4228021

Vielen Dank!

David 16.08.2013 00:59

Zitat:

Zitat von benzrecordings (Beitrag 532052)
Ich schaffe es allerdings nicht noch ein Feld hinzuzufügen, da ich nur sehr bedingt Ahnung von PHP habe. Kann mir jemand behilflich sein?

Dann kannst Du entweder jemanden engagieren, der sich damit auskennt, oder du solltest dir wenigstens die Grundlagen aneignen. Hier z.B.: Quakenet/#php Tutorial - de - Einleitung

Wo hast Du denn den Code her, den du da gepostet hast? Was davon funktioniert, was nicht? Dein Controller (variable_fields_process() ) scheint auch irgendwie die falschen POST-Parameter auszuwerten. Deine eigenen Felder hast du ja alle in dem 'my_custom_field'-Array liegen.

Was genau willst du eigentlich tun? Also, was soll in den Feldern stehen, müssen die durchsuchbar sein, etc. pp.


Alle Zeitangaben in WEZ +2. Es ist jetzt 17:10 Uhr.

Powered by vBulletin® Version 3.8.11 (Deutsch)
Copyright ©2000 - 2024, vBulletin Solutions, Inc.

© Dirk H. 2003 - 2023