Skip to content

Instantly share code, notes, and snippets.

View yojance's full-sized avatar
🏠
Working from home

Yojance Rabelo yojance

🏠
Working from home
View GitHub Profile
<?php
/*
Plugin Name: Authorize.net AIM - WooCommerce Gateway
Plugin URI: http://www.sitepoint.com/
Description: Extends WooCommerce by Adding the Authorize.net AIM Gateway.
Version: 1
Author: Yojance Rabelo, SitePoint
Author URI: http://www.sitepoint.com/
*/
@yojance
yojance / woocommerce-authorizenet-aim-gateway.php
Created August 2, 2014 15:31
Complete code for the first file
<?php
/*
Plugin Name: Authorize.net AIM - WooCommerce Gateway
Plugin URI: http://www.sitepoint.com/
Description: Extends WooCommerce by Adding the Authorize.net AIM Gateway.
Version: 1.0
Author: Yojance Rabelo, SitePoint
Author URI: http://www.sitepoint.com/
*/
@yojance
yojance / woocommerce-authorizenet-aim.php
Created August 2, 2014 16:04
SPYR_AuthorizeNet_AIM __construct()
// Setup our Gateway's id, description and other values
function __construct() {
// The global ID for this Payment method
$this->id = "spyr_authorizenet_aim";
// The Title shown on the top of the Payment Gateways Page next to all the other Payment Gateways
$this->method_title = __( "Authorize.net AIM", 'spyr-authorizenet-aim' );
// The description for this Payment Gateway, shown on the actual Payment options page on the backend
@yojance
yojance / woocommerce-authorizenet-aim.php
Created August 2, 2014 16:51
Build the administration fields for this specific Gateway
// Build the administration fields for this specific Gateway
public function init_form_fields() {
$this->form_fields = array(
'enabled' => array(
'title' => __( 'Enable / Disable', 'spyr-authorizenet-aim' ),
'label' => __( 'Enable this payment gateway', 'spyr-authorizenet-aim' ),
'type' => 'checkbox',
'default' => 'no',
),
'title' => array(
@yojance
yojance / woocommerce-authorizenet.php
Created August 2, 2014 18:23
Processing the Payment
// Submit payment and handle response
public function process_payment( $order_id ) {
global $woocommerce;
// Get this Order's information so that we know
// who to charge and how much
$customer_order = new WC_Order( $order_id );
// Are we testing right now or is it a real transaction
$environment = ( $this->environment == "yes" ) ? 'TRUE' : 'FALSE';
@yojance
yojance / functions.php
Created September 28, 2014 13:24
Custom Hook/Function for WordPress Cron (Recurring Events)
<?php
// delete_post_revisions will be call when the Cron is executed
add_action( 'delete_post_revisions', 'delete_all_post_revisions' );
// This function will run once the 'delete_post_revisions' is called
function delete_all_post_revisions() {
$args = array(
'post_type' => 'post',
'posts_per_page' => -1,
@yojance
yojance / functions.php
Created September 28, 2014 13:35
WordPress Cron (Recurring Events)
<?php
// Make sure this event hasn't been scheduled
if( !wp_next_scheduled( 'delete_post_revisions' ) ) {
// Schedule the event
wp_schedule_event( time(), 'daily', 'delete_post_revisions' );
}
@yojance
yojance / page-coupon-redeem.php
Created November 16, 2014 20:30
Coupon Redeem HTML
<div class="redeem-coupon">
<form id="ajax-coupon-redeem">
<p>
<input type="text" name="coupon" id="coupon">
<input type="submit" name="redeem-coupon" value="Redeem Offer" />
</p>
<p class="result"></p>
</form><!-- #ajax-coupon-redeem -->
</div><!-- .redeem-coupon -->
@yojance
yojance / functions.php
Created November 16, 2014 20:37
Ajax Call Handler
add_action( 'wp_ajax_spyr_coupon_redeem_handler', 'spyr_coupon_redeem_handler' );
add_action( 'wp_ajax_nopriv_spyr_coupon_redeem_handler', 'spyr_coupon_redeem_handler' );
@yojance
yojance / functions.php
Created November 16, 2014 21:34
Ajax Handler
<?php
function spyr_coupon_redeem_handler() {
// Get the value of the coupon code
$code = $_REQUEST['coupon_code'];
// Check coupon code to make sure is not empty
if( empty( $code ) || !isset( $code ) ) {
// Build our response
$response = array(