📄 محتوای کامل
محدوده پشتیبانی :
ما نمی توانیم طبق سیاست پشتیبانی خود، پشتیبانی برای سفارشیسازیها ارائه دهیم . اگر نیاز به سفارشیسازی یک قطعه کد یا گسترش قابلیتهای آن دارید، توصیه میکنیم با یک شریک آژانس Woo یا یک توسعهدهنده WooCommerce در Codeable همکاری کنید .
این قطعه کد برای اضافه کردن قابلیت ردیابی برای یک نرمافزار تحلیلی جداگانه است که ممکن است نصب کرده باشید. شیء سفارش شامل تمام دادههای سفارش مورد نیاز شما، از جمله ردیفهای سفارش، است.
شما باید این کد را به functions.phpفایل قالب فرزند خود یا از طریق افزونهای که امکان اضافه کردن توابع سفارشی را فراهم میکند، مانند افزونه Code snippets، اضافه کنید . لطفاً کد سفارشی را مستقیماً به فایل قالب والد خود اضافه نکنید functions.phpزیرا هنگام بهروزرسانی قالب، این کد به طور کامل پاک میشود.
| /** |
| * Add custom tracking code to the thank-you page |
| */ |
| add_action( ‘woocommerce_thankyou’, ‘my_custom_tracking’ ); |
| function my_custom_tracking( $order_id ) { |
| // Lets grab the order |
| $order = wc_get_order( $order_id ); |
| /** |
| * Put your tracking code here |
| * You can get the order total etc e.g. $order->get_total(); |
| */ |
| // This is the order total |
| $order->get_total(); |
| // This is how to grab line items from the order |
| $line_items = $order->get_items(); |
| // This loops over line items |
| foreach ( $line_items as $item ) { |
| // This will be a product |
| $product = $order->get_product_from_item( $item ); |
| // This is the products SKU |
| $sku = $product->get_sku(); |
| // This is the qty purchased |
| $qty = $item[‘qty’]; |
| // Line item total cost including taxes and rounded |
| $total = $order->get_line_total( $item, true, true ); |
| // Line item subtotal (before discounts) |
| $subtotal = $order->get_line_subtotal( $item, true, true ); |
| } |
| } |