Ich muss den Code ändern, um den Textbereich nicht auf allen meinen WooCommerce-Produkten anzuzeigen, sondern nur auf 2, dies ist auf meinem untergeordneten WordPress-Theme unter functions.php
Datei.
Ich habe $product_id in geändert $product_id = 2130
(meine spezifische Produkt-ID)bin mir nicht sicher, ob ich das alles ändern soll $product_id
oder $_POST
damit dieser Code nur auf 2 Produkten angezeigt wird
Es ist für ein bestimmtes Produkt oder Produkte, die mit einem Namen personalisiert werden. Ich habe versucht, den Code $product_id auf zahlreiche andere Erweiterungen ohne Erfolg zu ändern. Ich bin mir nicht sicher, ob ich die gesamte $product_id durch welchen Code ersetzen soll, oder sollte es bei sein $_POST
und alle ersetzen.
add_action( 'woocommerce_before_add_to_cart_button', 'custom_product_add_on', 9 );
function custom_product_add_on() {
$value = isset( $_POST['_custom_text_add_on'] ) ? sanitize_text_field( $_POST['_custom_text_add_on'] ) : '';
echo '<div>
<label>Custom Text Add-On <abbr class="required" title="required">*</abbr></label>
<p>
<input name="_custom_text_add_on" value="' . $value . '">
</p>
</div>';
}
add_filter( 'woocommerce_add_to_cart_validation', 'custom_product_add_on_validation', 10, 3 );
function custom_product_add_on_validation( $passed, $product_id, $qty ){
if( isset( $_POST['_custom_text_add_on'] ) && sanitize_text_field(
$_POST['_custom_text_add_on'] ) == '' ) {
wc_add_notice( 'Custom Text Add-On is a required field', 'error' );
$passed = false;
}
return $passed;
}
add_filter( 'woocommerce_add_cart_item_data', 'custom_product_add_on_cart_item_data', 10, 2 );
function custom_product_add_on_cart_item_data( $cart_item, $product_id ){
if( isset( $_POST['_custom_text_add_on'] ) ) {
$cart_item['custom_text_add_on'] = sanitize_text_field(
$_POST['_custom_text_add_on'] );
}
return $cart_item;
}
add_filter( 'woocommerce_get_item_data', 'custom_product_add_on_display_cart', 10, 2 );
function custom_product_add_on_display_cart( $_data, $cart_item ) {
if ( isset( $cart_item['custom_text_add_on'] ) ){
$data[] = array(
'name' => 'Custom Text Add-On',
'value' => sanitize_text_field( $cart_item['custom_text_add_on'] )
);
}
return $data;
}
add_action( 'woocommerce_add_order_item_meta', 'custom_product_add_on_order_item_meta', 10, 2 );
function custom_product_add_on_order_item_meta( $item_id, $values ) {
if ( ! empty( $values['custom_text_add_on'] ) ) {
wc_add_order_item_meta( $item_id, 'Custom Text Add-On',
$values['custom_text_add_on'], true );
}
}
add_filter( 'woocommerce_order_item_product', 'custom_product_add_on_display_order', 10, 2 );
function custom_product_add_on_display_order( $cart_item, $order_item ){
if( isset( $order_item['custom_text_add_on'] ) ){
$cart_item_meta['custom_text_add_on'] =
$order_item['custom_text_add_on'];
}
return $cart_item;
}
add_filter( 'woocommerce_email_order_meta_fields', 'custom_product_add_on_display_emails' );
function custom_product_add_on_display_emails( $fields ) {
$fields['custom_text_add_on'] = 'Custom Text Add-On';
return $fields;
}
Warum fügen Sie so viele Kommentare hinzu, anstatt die Frage selbst zu ändern?
– Amarnasan
20. Mai 2019 um 11:38 Uhr
Es tut mir leid, ich bin neu in Foren, ich entschuldige mich, werde herausfinden, wie das jetzt geht.
– RompelStompel
20. Mai 2019 um 11:40 Uhr
Entschuldigung, ich habe die Kommentare gelöscht und meine Frage bearbeitet.
– RompelStompel
20. Mai 2019 um 12:01 Uhr