Search

הוספת קוד מעקב משלכם בעמוד ״תודה״ של ווקומרס

הקוד שלפניכם מאפשר להוסיף קוד מעקב כלשהו בעמוד התודה (Thank You Page) של ווקומרס לאחר רכישה. המשתנה $order יכיל את כל המידע הרלוונטי של אותה הזמנה שבוצעה כך שתוכלו לשלוח את הפרטים לאותו שירות בו אתם משתמש למעקב.

שימו לב להסברים המופיעים בקוד בכדי להבין היכן להוסיף את קוד המעקב וכיצד להשתמש במשתנה זה:

/**
 * Add custom tracking code to the thank-you page
 */

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 );
	}
}
add_action( 'woocommerce_thankyou', 'my_custom_tracking' );
מצאתם טעות בקוד? הסניפט לא עובד לכם? רישמו לי בתגובות ואני מבטיח לטפל בכך במהרה ולספק סניפט תקין...
4 תגובות...
  • דניאל 23 ספטמבר 2020, 22:14

    היי, תודה רבה על הקוד המפורט! רוצה להבין באיזה קובץ בוורדפרס לשים את הקוד? מה שאני מחפש זה להתקין קוד המרה של גוגל בעט רכישה באתר. יש את הקוד הגנרי מהספריית קודים של גוגל – השאלה איך לשים אותו בצורה תקינה וכך שכל הנתונים יהיו גנריים – דינמיים בהתאם לכל הזמנה.

    
    // Send transaction data with a pageview if available
    // when the page loads. Otherwise, use an event when the transaction
    // data becomes available.
    dataLayer.push({
        'ecommerce': {
            'purchase': {
                'actionField': {
                    'id': 'T12345',                         // Transaction ID. Required for purchases and refunds.
                    'affiliation': 'Online Store',
                    'revenue': '35.43',                     // Total transaction value (incl. tax and shipping)
                    'tax':'4.90',
                    'shipping': '5.99',
                    'coupon': 'SUMMER_SALE'
                },
                'products': [{                            // List of productFieldObjects.
                    'name': 'Triblend Android T-Shirt',     // Name or ID is required.
                    'id': '12345',
                    'price': '15.25',
                    'brand': 'Google',
                    'category': 'Apparel',
                    'variant': 'Gray',
                    'quantity': 1,
                    'coupon': ''                            // Optional fields may be omitted or set to empty string.
                },
                    {
                        'name': 'Donut Friday Scented T-Shirt',
                        'id': '67890',
                        'price': '33.75',
                        'brand': 'Google',
                        'category': 'Apparel',
                        'variant': 'Black',
                        'quantity': 1
                    }]
            }
        }
    });
    

    אשמח לקבל עזרה בנושא, תודה רבה!

    • רועי יוסף 24 ספטמבר 2020, 4:06

      היי דניאל,

      לצערי לא אוכל להסביר כאן כיצד לעשות – זה מורכב מדי בכדי שאוכל להסביר זאת בתגובות. מציע לך להעזר במתכנת. כן – הקוד צריך להיות ב functions.php…

      בהצלחה 🙂

  • עדי 26 דצמבר 2022, 8:26

    תודה רבה!
    האם יש לך קוד כזה שמשנה גם את העמוד עצמו?
    בנוסף, הקוד מתאים לפיקסל של פייסבוק? מנסה למצוא את הדרך הנכונה ביותר בשביל שהמחיר שהלקוח בסופו של דבר שילם יעבור לפייסבוק וכך אוכל למדוד תוצאות.
    שוב תודה,
    עדי

    • רועי יוסף 26 דצמבר 2022, 12:43

      מה זה ״קוד המשנה את העמוד עצמו?״ הקוד מתאים לכל קוד מעקב שתרצי..

תגובה חדשה

Up!
לבלוג