WooCommerce (WordPress module) integration
A free ecommerce plugin that allows you to sell anything.
How to integrate PostAffiliatePro with WooCommerce (WordPress module)
This integration with WooCommerce is really easy as you can connect the two using the WordPress plugin. When installed, configure it to define what do you want to track and how.
You can track per product commissions, order ID and coupons.
If you want to (or have to) integrate WooCommerce manually, here’s a guide.
Order tracking
To track whole order, use the following code. Edit file wp-content/plugins/woocommerce/templates/checkout/thankyou.php and place the code below line:
<?php do_action( 'woocommerce_thankyou', $order->id ); ?>
<script id="pap_x2s6df8d" src="https://URL_TO_PostAffiliatePro/scripts/trackjs.js" type="text/javascript"></script>
<script type="text/javascript">
PostAffTracker.setAccountId('Account_ID');
var sale = PostAffTracker.createSale();
sale.setTotalCost('<?php echo ($order->order_total - $order->order_shipping); ?>');
sale.setOrderID('<?php echo $order->id; ?>');
sale.setCurrency('<?php echo $order->get_order_currency(); ?>');
PostAffTracker.register();
</script>
Note:
In case you use a custom theme for WooCommerce and the thankyou.php file is located there as well (/themes/your_custom_theme/woocommerce/checkout/thankyou.php), you have to integrate it instead of the default one.
If you want more detailed tracking, follow the next step instead of this one.
If you wish to take use of Lifetime Commissions plugin then right above:
PostAffTracker.register();
add this:
sale.setData1('<?php echo $order->billing_email; ?>');
or this:
sale.setData1('<?php echo $order->user_id; ?>');
Per product integration
If you want to track commissions per product, use this code instead the one form step 1. You have to place it to the same file, at the same place:
wp-content/plugins/woocommerce/templates/checkout/thankyou.php
right below this line:
<?php do_action( 'woocommerce_thankyou', $order->id ); ?>
<script id="pap_x2s6df8d" src="https://URL_TO_PostAffiliatePro/scripts/trackjs.js" type="text/javascript"></script>
<script type="text/javascript">
PostAffTracker.setAccountId('Account_ID');
<?php
$i = 0;
foreach ($order->get_items() as $item) {
$itemprice = $item['line_total'];
$couponCode = '';
$_product = $order->get_product_from_item($item);
$p = $_product->id;
try { //if coupon has been used, set the last one in the setCoupon() parameter
$coupon = $order->get_used_coupons();
$couponToBeUsed = (count($coupon)>1 ? count($coupon)-1 : 0);
if (isset($coupon[$couponToBeUsed])) {
$itemcount = $order->get_item_count($type = '');
$orderdiscount = $order->get_order_discount();
if ($itemcount > 0) {
$discountperitem = $orderdiscount / $itemcount;
$itemprice = $item['line_total'] - $discountperitem;
}
$couponCode = $coupon[$couponToBeUsed];
}
}
catch (Exception $e) {
//echo "<!--Error: ".$e->getMessage()."-->";
}
if (!empty($_product->sku)) {
$p = $_product->sku;
}
echo "var sale".$i." = PostAffTracker.createSale();";
echo "sale".$i.".setTotalCost('".$itemprice."');";
echo "sale".$i.".setOrderID('".$order->id."($i)');";
echo "sale".$i.".setProductID('".$p."');";
echo "sale".$i.".setCurrency('".$order->get_order_currency()."');";
echo "sale".$i.".setCoupon('".$couponCode."');";
$i++;
}
?>
PostAffTracker.register();
</script>
Save your changes. That’s it, your shop has been integrated.
If you want to take use of Lifetime Commissions plugin, then right below:
echo "sale".$i.".setCoupon('".$couponCode."');";
add this:
echo "sale".$i.".setData1('".$order->billing_email."');";
or this:
echo "sale".$i.".setData1('".$order->user_id."');";
Integration of PayPal module in WooCommerce – part 1
Find and edit the following file:
- for WooCommerce 2.2.11 and lower: woocommerce/includes/gateways/paypal/class-wc-gateway-paypal.php
- for WooCommerce 2.3.3 and higher: woocommerce/includes/gateways/paypal/includes/class-wc-gateway-paypal-request.php
You can edit the plugin files either using the Plugin editor in WordPress or you can access the files of your WP installation via FTP.
In the above mentioned file find the function get_paypal_args() function and within it find a line with:
'return' =>
and a line with:
'notify_url' =>
Change the found lines by adding a special code:
'return' => esc_url( add_query_arg( 'utm_nooverride', '1', $this->get_return_url( $order ) ) ).'&paypal=1', // Post Affiliate Pro integration snippet
'notify_url' => $this->notify_url.'?pap_custom='.$_POST['pap_custom'], // Post Affiliate Pro integration snippet
Integration of PayPal module in WooCommerce – part 2
- for WooCommerce 2.2.11 and lower: in the same file (woocommerce/includes/gateways/paypal/class-wc-gateway-paypal.php), find function check_ipn_request_is_valid and into that function below the line of function check_ipn_request_is_valid add the code found in the box below
- for WooCommerce 2.3.3 and higher: find and edit the file of (woocommerce/includes/gateways/paypal/includes/class-wc-gateway-paypal-ipn-handler.php) and in that file find the validate_ipn() function. Within that function find the following line:
if ( ! is_wp_error( $response ) && $response['response']['code'] >= 200 && $response['response']['code'] < 300 && strstr( $response['body'], 'VERIFIED' ) ) {
and right below that line add the code found in the box below:
/* Post Affiliate Pro integration snippet */
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://URL_TO_PostAffiliatePro/plugins/PayPal/paypal.php?pap_custom='.$_GET['pap_custom']);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $_POST);
curl_exec($ch);
/* /Post Affiliate Pro integration snippet */
Save your work and continue with the next step.
Integration of PayPal module in WooCommerce – part 3
Edit the file: woocommerce/templates/checkout/form-checkout.php.
Find this line:
<?php do_action( 'woocommerce_checkout_order_review' ); ?>
and place this code below the line:
<!-- Post Affiliate Pro integration snippet -->
<input type="hidden" name="pap_custom" value="" id="pap_dx8vc2s5">
<script id="pap_x2s6df8d" src="https://URL_TO_PostAffiliatePro/scripts/notifysale.php" type="text/javascript">
</script>
<!-- /Post Affiliate Pro integration snippet -->
Integration of PayPal module in WooCommerce – part 4
If you only use PayPal as your payment integration, you can ignore this step.
To make sure the integration does not create duplicate orders (one from PayPal and one from the thank you page), we have to set the thank you page to ignore commissions for PayPal orders.
To do so, you have to modify the thank you page tracking code a little. First, edit the file woocommerce/templates/checkout/thankyou.php and find this line:
<?php do_action( 'woocommerce_thankyou', $order->id ); ?>
Place this code below that line:
<?php
if (empty($_GET['paypal'])) :
?>
Now, below the last integration lines:
PostAffTracker.register();
</script>
Add this code:
<?php endif; ?>
That’s it. Save your work and the very last step is to activate your PayPal IPN handling plugin in your Post Affiliate Pro.
Integration with Stripe
If you want to integrated Stripe recurring payments, you can do it in few small steps. First of all, you should have followed the step 1 or 2 and also using the customer email in data1:
sale.setData1('<?php echo $order->billing_email; ?>');
To make Stripe let your PAP know about a recurring payment, you have to add a new webhook in your Stripe account, Your Account (top right)> Account Settings> Webhooks … use this URL:
https://URL_TO_PostAffiliatePro/plugins/Stripe/stripe.php
Besides this, you have to enable (and configure) the Stripe plugin and Lifetime Commissions plugin.
Do not forget to insert the click tracking code to your WP header or footer file, using Appearance menu.
NOTE:
In case the sale tracking does not work for you event the sale tracking code is at it’s place, check if there is a special directory for woocommerce in your custom theme. If you found it, just integrate the /checkout/thankyou.php file there.
What is WooCommerce?
WooCommerce is a free, open-source eCommerce plugin designed specifically for WordPress, enabling users to transform their WordPress websites into fully functional online stores. Whether you’re selling physical products, digital goods, subscriptions, or memberships, WooCommerce provides a robust platform that supports a wide range of online retail operations. Highly extensible, it integrates seamlessly with WordPress and offers unparalleled flexibility and customization options for entrepreneurs and businesses looking to enhance their e-commerce capabilities.
Originally developed by WooThemes, WooCommerce has evolved significantly since its inception. In 2015, Automattic, the company behind WordPress.com, acquired WooCommerce, propelling its development to new heights. Over the years, WooCommerce has released several major updates and enhancements, solidifying its position as a dominant e-commerce platform within the WordPress ecosystem. Its journey is marked by continuous support and innovation driven by a global community of developers and users.
WooCommerce is tailored for individuals and businesses eager to establish online stores, ranging from small and medium-sized enterprises (SMEs) to entrepreneurs and large corporations already utilizing WordPress. It provides customizable and scalable solutions that convert WordPress websites into powerful e-commerce platforms. By leveraging WooCommerce, businesses can enhance their operations, improve scalability, and boost customer engagement through a feature-rich online store.
Main Features of WooCommerce
- Versatile Selling Options: Supports sales of physical and digital goods, as well as subscriptions and memberships.
- Customizable Store Setup: Offers a wide variety of themes and customization options to create a unique storefront that aligns with your brand.
- Supported Payments via 140+ Gateways: Integrates with major payment providers like PayPal, Stripe, and more, ensuring secure transactions.
- Order Management and Configurable Shipping: Provides efficient order management tools and flexible shipping options to meet customer needs.
- Extensions for Marketing, Taxation, and More: Access to a vast library of extensions to enhance functionality, including SEO, analytics, and customer engagement tools.
- Multi-Currency and Multilingual Support: Caters to a global audience by supporting multiple currencies and languages.
WooCommerce Pricing Options
- Core Plugin: Free to download and use.
- Hosting: Costs range from $3.99/month to $5,000/month, depending on the scale and needs of your store.
- Domain Name: Typically around $15/year.
- Themes and Plugins/Extensions: Variable price ranges depending on the specific themes and extensions you choose to enhance your store’s functionality.
- Additional Costs:
- Payment Gateway Fees: Transaction fees may apply depending on the payment gateway used.
- Optional Security/Enhancement Features: Additional expenses for advanced security measures or premium support services.
Key User Insights on WooCommerce
Pros:
- Highly Customizable and Flexible: Offers extensive options to tailor your online store to your specific needs.
- Robust Community Support: Backed by a large community of developers and users, providing ample resources and assistance.
Cons:
- Extensions May Incur Costs: While the core plugin is free, certain advanced features and extensions may require payment.
- Requires Hosting and Maintenance: Users are responsible for managing hosting services and performing maintenance beyond the capabilities of the core plugin.
YouTube Reviews of WooCommerce
- WooCommerce Review: The Best E-commerce Solution?: An in-depth analysis of WooCommerce’s features and usability.
- WooCommerce vs Shopify: Which One’s Best For You?: A comparative review highlighting the strengths and weaknesses of WooCommerce relative to Shopify.
- How To Use WooCommerce | eCommerce Tutorial for Beginners: A step-by-step guide for beginners on setting up and using WooCommerce.
Alternatives to WooCommerce
If WooCommerce doesn’t perfectly fit your needs, consider these alternatives:
- Shopify: A comprehensive e-commerce platform with hosting and easy setup.
- BigCommerce: Offers scalable solutions for growing businesses.
- Wix: Provides a user-friendly website builder with e-commerce capabilities.
- Adobe Commerce (Magento): Suitable for large enterprises requiring extensive customization.
- Shopify Buy Button: Embed products and a shopping cart on your website or blog.
- Ecwid: Adds an online store to any existing website.
- Easy Digital Downloads: Specializes in selling digital products.
- MemberPress: Ideal for creating membership sites and subscription-based services.
Explore seamless integrations with Post Affiliate Pro to enhance your affiliate marketing strategies. Discover solutions for e-commerce, email marketing, payments, and more, with easy integrations for platforms like 1&1 E-Shop, 2Checkout, Abicart, and many others. Optimize your affiliate network with these powerful tools.
Integrate Post Affiliate Pro with PrestaShop effortlessly using our free module. Enhance your online store with seamless tracking and PayPal integration, ensuring a smooth operation. Discover how to boost your e-commerce success with our easy-to-follow guide. Create your account for free and start optimizing today!