Webekir adlı üyeden alıntı:
mesajı görüntüle
Woocommerce işinize yarayabilecek kodlar
29
●2.268
- 21-01-2024, 13:17:33@Webekir;
Whatsapp butonu ekliyor(hemen al) müşteri butona tıkladığında seçtigi varyasyon ürün seçenek - fiyat bilgisi tüm detaylar ilk mesajda yer alıyor.
add_action('woocommerce_after_add_to_cart_button', 'ecommercehints_content_after_add_to_cart_form', 30); function ecommercehints_content_after_add_to_cart_form() { global $product; if( ! is_a('WC_Product', $product) ) { $product = wc_get_product( get_the_id() ); } // Not for variable products if( ! $product || 'variable' === $product->get_type() ) return; // Get the product name $product_title = $product->get_name(); // Get the product URL $product_url = $product->get_permalink(); // Get the product price $product_price = strip_tags( wc_price( wc_get_price_to_display( $product, array( 'price' => $product->get_price() ) ) ) ); // Button CSS ?> <style> .order_on_whatsapp { display: flex; justify-content: center; align-items: center; height: 60px; border-radius: 3px; background-color: #fff; color: #131313; padding: 10px; vtext-decoration: none; font-weight: 700; border: 2px solid #5e51b6; font-size: 115%; } .order_on_whatsapp:hover{ background-color: #6051BA; color: #fff; } .order_on_whatsapp img { margin-right: 10px; width: 14px; } </style> <?php // Output the WhatsApp button with the product's title and URL in the pre-filled message echo '<a href="https://api.whatsapp.com/send?phone=+905003007245&text=Merhaba,%20Bu%20ürünü%20almak%20istiyorum:%20' . $product_title . '%20-%20' . $product_price . '%20(' . $product_url . ')" class="order_on_whatsapp"> <img src="https://woo.cdesksolutions.com/wp-content/uploads/2022/11/whatsapp.webp" width="14px"> Hemen AL </a>'; } // Add variation custom field data to single variable product form add_filter( 'woocommerce_available_variation', 'add_variation_custom_field_to_variable_form', 10, 3 ); function add_variation_custom_field_to_variable_form( $variation_data, $product, $variation ) { $variation_data['name'] = $variation->get_name(); // Product Variation name $variation_data['url'] = $variation->get_permalink(); // Product Variation URL $variation_data['main_url'] = $product->get_permalink(); // Parent Variable Product URL return $variation_data; } // For variable products add_action( 'woocommerce_after_variations_form', 'display_selected_variation_custom_field_js' ); function display_selected_variation_custom_field_js(){ // Button CSS ?> <style> .order_on_whatsapp { display: flex; justify-content: center; align-items: center; height: 60px; border-radius: 3px; background-color: #fff; color: #131313; padding: 10px; vtext-decoration: none; font-weight: 700; border: 2px solid #5e51b6; font-size: 115%; } .order_on_whatsapp:hover{ background-color: #6051BA; color: #fff; } .order_on_whatsapp img { margin-right: 10px; width: 14px; } .order_on_whatsapp.disabled { opacity: .5 !important; cursor: not-allowed; } .order_on_whatsapp.disabled:hover { background-color: #fff; color: #131313; } </style> <?php // Javascript ?> <script type="text/javascript"> (function($){ var href = 'https://api.whatsapp.com/send?phone=+905003570045&text=Merhaba,%20Bu%20urunu%20almak%20istiyorum:%20'; $('form.cart').on('show_variation', function(event, data) { $('.order_on_whatsapp').removeClass('disabled').attr( 'href', href + data.name + '%20-%20TL' + data.display_price + '%20(' + data.url + ')' ); }).on('hide_variation', function(event) { $('.order_on_whatsapp').removeAttr('href').addClass('disabled'); }); })(jQuery); </script> <?php // Display button echo '<a class="order_on_whatsapp"> <img src="https://woo.cdesksolutions.com/wp-content/uploads/2022/11/whatsapp.webp" width="14px"> Hemen AL </a>'; }@Lazo61;
temanızın functions.php dosyasına ekleniyor. denemeden önce yedek alınız - 21-01-2024, 18:54:56Teşekkürler, temanızın özel functions.php dosyasına ekliyorsunuz güncellemelerden etkilenmez.Frekans adlı üyeden alıntı: mesajı görüntüle
- 21-01-2024, 19:14:25PhoenixTR adlı üyeden alıntı: mesajı görüntüle
Bu değerli ve normalin çok daha ötesinde çalışan kod için çok teşekkür ederiz...

