Skip to content

Instantly share code, notes, and snippets.

@NateWr
Last active June 3, 2019 07:42
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save NateWr/414b3a325c42f5369f76 to your computer and use it in GitHub Desktop.
Save NateWr/414b3a325c42f5369f76 to your computer and use it in GitHub Desktop.
Output Google Adwords tracking code when a booking request is made.
<?php
/**
* Plugin Name: Google Adwords Tracking for Restaurant Reservations
* Plugin URI: http://themeofthecrop.com
* Description: Insert a Google Adwords Campaign conversion tracking snippet when a new booking request has been made.
* Version: 0.0.1
* Author: Theme of the Crop
* Author URI: http://themeofthecrop.com
* License: GNU General Public License v2.0 or later
* License URI: http://www.gnu.org/licenses/gpl-2.0.html
*
* This program is free software; you can redistribute it and/or modify it under the terms of the GNU
* General Public License as published by the Free Software Foundation; either version 2 of the License,
* or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
* even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*
* You should have received a copy of the GNU General Public License along with this program; if not, write
* to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
if ( ! defined( 'ABSPATH' ) )
exit;
/**
* Check the status of a booking request after it's been added to the database
*/
add_action( 'rtb_insert_booking', 'gatrtb_check_booking_request' );
if ( !function_exists( 'gatrtb_check_booking_request' ) ) {
function gatrtb_check_booking_request( $booking ) {
if ( $booking->request_inserted === true ) {
add_action( 'wp_footer', 'gatrtb_add_adwords_conversion_code' );
}
}
} // endif;
/**
* Output the conversion tracking code in the footer
*/
if ( !function_exists( 'gatrtb_add_adwords_conversion_code' ) ) {
function gatrtb_add_adwords_conversion_code( $booking ) {
?>
<!-- Add your tracking snippet here -->
<?php
}
} // endif;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment