Changeset 3214574
- Timestamp:
- 12/30/2024 02:15:08 AM (15 months ago)
- Location:
- wpmktgengine-extension-woocommerce/trunk
- Files:
-
- 2 edited
-
readme.txt (modified) (1 diff)
-
wpmktgengine-woocommerce.php (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
wpmktgengine-extension-woocommerce/trunk/readme.txt
r3212782 r3214574 6 6 License: GPLv2 or later 7 7 License URI: http://www.gnu.org/licenses/gpl-2.0.html 8 Stable tag: 11 .7.498 Stable tag: 111.7.49 9 9 Understand how your leads and customers are participating with your ecommerce. 10 10 -
wpmktgengine-extension-woocommerce/trunk/wpmktgengine-woocommerce.php
r3212781 r3214574 1654 1654 $result = $WPME_API->callCustom('/wpmeorders', 'POST', $cartOrder->getPayload()); 1655 1655 error_log('cartOrder Payload: ' . json_encode($cartOrder->getPayload())); 1656 if($result->order_id!='') 1657 { 1656 if($result->result === 'success') { 1658 1657 update_post_meta($order_id, 'wpme_order_id', $result->order_id); 1659 1658 if (isset($subscription_id)) { … … 1661 1660 $result = $WPME_API->callCustom('/wpmeorders[S]', 'PUT', (array)$order_payload); 1662 1661 update_post_meta($subscription_id, 'wpme_order_id', $result->order_id); 1663 error_log('$result:' . $result);1662 //error_log('$result:' . $result); 1664 1663 } 1665 1664 } 1666 else 1667 {1668 apivalidate($order->id,1669 $cartOrder->action,1670 "0",1671 $order->date_created,1672 (array) $cartOrder->object,1673 (array) $cartOrder->getPayload(),1674 "0",1675 "API key not found",1676 $rand1677 );1665 else if ($result->result === 'failed') { 1666 apivalidate( 1667 $order->id, 1668 $cartOrder->action, 1669 $subscription_id, 1670 $order->date_created, 1671 (array) $cartOrder->object, 1672 (array) $cartOrder->getPayload(), 1673 "0", 1674 $result->message, 1675 $rand 1676 ); 1678 1677 } 1679 1678 1680 1679 } catch (\Exception $e) { 1681 apivalidate($order->id, 1682 $cartOrder->action, 1683 "0", 1684 $order->date_created, 1685 (array) $cartOrder->object, 1686 (array) $cartOrder->getPayload(), 1687 "0", 1688 "API key not found", 1689 $rand 1690 ); 1680 apivalidate( 1681 $order->id, 1682 $cartOrder->action, 1683 $subscription_id, 1684 $order->date_created, 1685 (array) $cartOrder->object, 1686 (array) $cartOrder->getPayload(), 1687 "0", 1688 "Exception happened.", 1689 $rand 1690 ); 1691 1691 } 1692 1692 }); 1693 1694 /** 1695 * Subscription Status Changed 1696 */ 1697 add_action( 1698 'woocommerce_subscription_status_updated', 1699 function ($subscription, $new_status, $old_status) { 1700 if ($new_status === 'active' && $old_status === 'pending') {//create a new subscription 1701 return; 1702 } 1703 1704 global $WPME_API; 1705 $rand = rand(); 1706 $subscription_id = $subscription->get_id(); 1707 $order_id = $subscription->get_parent_id(); 1708 $total_cost = $subscription->get_total(); 1709 $customer_email = $subscription->get_billing_email(); 1710 $datetime = new DateTime(); 1711 $activityDate = $datetime->format('c');// 'c' stands for ISO 8601 format 1712 1713 $activity = array( 1714 'email' => $customer_email, 1715 'activity_date' => $activityDate, // Dates should be in the format that the field is set to or ISO 8601 format. 1716 'activity_name' => '#' . $subscription_id . '; $' . $total_cost, 1717 'activity_description' => "", 1718 'url' => get_permalink($subscription_id) // url of post 1719 ); 1720 1721 if ($new_status == 'active') { 1722 $activity = array_merge($activity, ['activity_stream_type' => 'subscription activated']); 1723 } else if ($new_status == 'on-hold') { 1724 $activity = array_merge($activity, ['activity_stream_type' => 'subscription on hold']); 1725 } else if ($new_status == 'cancelled') { 1726 $activity = array_merge($activity, ['activity_stream_type' => 'subscription cancelled']); 1727 } else if ($new_status == 'expired') { 1728 $activity = array_merge($activity, ['activity_stream_type' => 'subscription expired']); 1729 } else if ($new_status == 'pending-cancel') { 1730 $activity = array_merge($activity, ['activity_stream_type' => 'subscription pending cancellation']); 1731 } 1732 1733 $result = $WPME_API->postActivities([$activity]); 1734 if (isset($result->process_results[0]) && $result->process_results[0]->result === "failed"){ 1735 apivalidate( 1736 $order_id, 1737 $activity['activity_stream_type'], 1738 $subscription_id, 1739 $activityDate, 1740 $activity, 1741 $activity, 1742 "0", 1743 $result->process_results[0]->error_message, 1744 $rand 1745 ); 1746 } 1747 }, 1748 10, 1749 3 1750 ); 1751 1752 /** 1753 * Subscription renewal 1754 */ 1755 add_action( 1756 'woocommerce_subscription_renewal_payment_complete', 1757 function ($subscription, $last_order) { 1758 global $WPME_API; 1759 $rand = rand(); 1760 $subscription_id = $subscription->get_id(); 1761 $total_cost = $subscription->get_total(); 1762 $customer_email = $subscription->get_billing_email(); 1763 $datetime = new DateTime(); 1764 $renewalDate = $datetime->format('c');// 'c' stands for ISO 8601 format 1765 $order_id = $last_order->id; 1766 1767 $activity = array( 1768 'email' => $customer_email, 1769 'activity_date' => $renewalDate, // Dates should be in the format that the field is set to or ISO 8601 format. 1770 'activity_name' => '#' . $order_id . '; $' . $total_cost, 1771 'activity_description' => "Subscription Renewal", 1772 'activity_stream_type' => 'Subscription Payment', 1773 'url' => get_permalink($order_id) // url of post 1774 ); 1775 1776 $result = $WPME_API->postActivities([$activity]); 1777 if (isset($result->process_results[0]) && $result->process_results[0]->result === "failed"){ 1778 apivalidate( 1779 $order_id, 1780 $activity['activity_stream_type'], 1781 $subscription_id, 1782 $renewalDate, 1783 $activity, 1784 $activity, 1785 "0", 1786 $result->process_results[0]->error_message, 1787 $rand 1788 ); 1789 } 1790 }, 1791 10, 1792 2 1793 ); 1693 1794 1694 1795 /**
Note: See TracChangeset
for help on using the changeset viewer.