wmaraci reklam

Woocommerce Ürüne İSİM SOYİSİM ekleme

4 Mesajlar 739 Okunma
pst.net
wmaraci reklam

sergennaslan sergennaslan Razer Gold %80 Kullanıcı
  • Üyelik 17.01.2016
  • Yaş/Cinsiyet 26 / E
  • Meslek Girişimci
  • Konum Ankara
  • Ad Soyad S** A**
  • Mesajlar 784
  • Beğeniler 251 / 253
  • Ticaret 102, (%100)
Merhabalar,

Woocommerce altyapısını kullanan web sitemde ürünleri sepete eklemeden önce "Bardağın üzerine ne yazılacak" şeklinde bir bölüm olmasını istiyorum nasıl ekleyebilirim bu kısmı?

Örnekte ki gibi

 

 

wmaraci
reklam

forces forces WM Aracı Kullanıcı
  • Üyelik 23.01.2016
  • Yaş/Cinsiyet 45 / E
  • Meslek bilgisayar mühendisi
  • Konum İstanbul Avrupa
  • Ad Soyad M** E**
  • Mesajlar 1366
  • Beğeniler 9 / 379
  • Ticaret 0, (%0)
woocommerce_after_cart_item_name hook olarak kullanılacak ;

woocommerce-cart-input.php oluşturun ve içerisine aşağıdaki kodları yapıştırın

/**
* Add a text field to each cart item
*/
function prefix_after_cart_item_name( $cart_item, $cart_item_key ) {
$notes = isset( $cart_item['notes'] ) ? $cart_item['notes'] : '';
printf(
'
',
'prefix-cart-notes',
$cart_item_key,
$cart_item_key,
$notes
);
}
add_action( 'woocommerce_after_cart_item_name', 'prefix_after_cart_item_name', 10, 2 );
/**
* Enqueue our JS file
*/
function prefix_enqueue_scripts() {
wp_register_script( 'prefix-script', trailingslashit( plugin_dir_url( __FILE__ ) ) . 'update-cart-item-ajax.js', array( 'jquery-blockui' ), time(), true );
wp_localize_script(
'prefix-script',
'prefix_vars',
array(
'ajaxurl' => admin_url( 'admin-ajax.php' )
)
);
wp_enqueue_script( 'prefix-script' );
}
add_action( 'wp_enqueue_scripts', 'prefix_enqueue_scripts' );





Yukarıdaki kodları ekleyince aşağıdaki gibi bir görüntü çıkacak







kullanıcı oluşturduğumuz kutucuğa metin girebiliyor ancak henüz kayıt işlemi yapılmadı .
update-cart-item-ajax.js adında bir dosya oluşturun ve içerisine aşağıdkai kodları yapıştırın

(function($){
$(document).ready(function(){
$('.prefix-cart-notes').on('change keyup paste',function(){
$('.cart_totals').block({
message: null,
overlayCSS: {
background: '#fff',
opacity: 0.6
}
});
var cart_id = $(this).data('cart-id');
$.ajax(
{
type: 'POST',
url: prefix_vars.ajaxurl,
data: {
action: 'prefix_update_cart_notes',
security: $('#woocommerce-cart-nonce').val(),
notes: $('#cart_notes_' + cart_id).val(),
cart_id: cart_id
},
success: function( response ) {
$('.cart_totals').unblock();
}
}
)
});
});
})(jQuery);





şimdi kullanıcının yazdıkları meta data olarak sunucuya gitti .

update-cart-meta-data.php adında dosya oluşturun ve içerisine aşağıdaki kodları yapıştırın

/**
* Update cart item notes
*/
function prefix_update_cart_notes() {
// Do a nonce check
if( ! isset( $_POST['security'] ) || ! wp_verify_nonce( $_POST['security'], 'woocommerce-cart' ) ) {
wp_send_json( array( 'nonce_fail' => 1 ) );
exit;
}
// Save the notes to the cart meta
$cart = WC()->cart->cart_contents;
$cart_id = $_POST['cart_id'];
$notes = $_POST['notes'];
$cart_item = $cart[$cart_id];
$cart_item['notes'] = $notes;
WC()->cart->cart_contents[$cart_id] = $cart_item;
WC()->cart->set_session();
wp_send_json( array( 'success' => 1 ) );
exit;
}
add_action( 'wp_ajax_prefix_update_cart_notes', 'prefix_update_cart_notes' );
function prefix_checkout_create_order_line_item( $item, $cart_item_key, $values, $order ) {
foreach( $item as $cart_item_key=>$cart_item ) {
if( isset( $cart_item['notes'] ) ) {
$item->add_meta_data( 'notes', $cart_item['notes'], true );
}
}
}
add_action( 'woocommerce_checkout_create_order_line_item', 'raa_add_custom_data_to_order', 10, 4 );




Artık kullanıcının yazdığı isimi sipariş ile birlikte görebilirsiniz .
sergennaslan

kişi bu mesajı beğendi.

forces forces WM Aracı Kullanıcı
  • Üyelik 23.01.2016
  • Yaş/Cinsiyet 45 / E
  • Meslek bilgisayar mühendisi
  • Konum İstanbul Avrupa
  • Ad Soyad M** E**
  • Mesajlar 1366
  • Beğeniler 9 / 379
  • Ticaret 0, (%0)
alternatif olarak kodlar ile ben uğraşmayayım derseniz aşağıdaki eklenti ile olur

https://tr.wordpress.org/plugins/product-input-fields-for-woocommerce/
 

 

sergennaslan sergennaslan Razer Gold %80 Kullanıcı
  • Üyelik 17.01.2016
  • Yaş/Cinsiyet 26 / E
  • Meslek Girişimci
  • Konum Ankara
  • Ad Soyad S** A**
  • Mesajlar 784
  • Beğeniler 251 / 253
  • Ticaret 102, (%100)
forces sağolun hocam
 

 

wmaraci
Mersin evden eve nakliyat
wmaraci
Konuyu toplam 1 kişi okuyor. (0 kullanıcı ve 1 misafir)
Site Ayarları
  • Tema Seçeneği
  • Site Sesleri
  • Bildirimler
  • Özel Mesaj Al