Changeset 3212781
- Timestamp:
- 12/24/2024 08:33:40 PM (15 months ago)
- Location:
- wpmktgengine-extension-woocommerce/trunk
- Files:
-
- 2 edited
-
readme.txt (modified) (1 diff)
-
wpmktgengine-woocommerce.php (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
wpmktgengine-extension-woocommerce/trunk/readme.txt
r3209418 r3212781 6 6 License: GPLv2 or later 7 7 License URI: http://www.gnu.org/licenses/gpl-2.0.html 8 Stable tag: 111 .7.488 Stable tag: 1111.7.48 9 9 Understand how your leads and customers are participating with your ecommerce. 10 10 -
wpmktgengine-extension-woocommerce/trunk/wpmktgengine-woocommerce.php
r3209418 r3212781 1472 1472 ); 1473 1473 1474 /**1474 /** 1475 1475 * Order furfilled 1476 1476 */ … … 1479 1479 1480 1480 global $WPME_API; 1481 $rand = rand();1481 $rand = rand(); 1482 1482 // Genoo order ID 1483 if (function_exists("wcs_get_subscriptions_for_order")):1483 if (function_exists("wcs_get_subscriptions_for_order")): 1484 1484 $subscriptions_ids = wcs_get_subscriptions_for_order( 1485 1485 $order_id, … … 1489 1489 ); 1490 1490 endif; 1491 1491 1492 $getrenewal = get_post_meta($order_id, "_subscription_renewal", true); 1492 1493 if(!empty($subscriptions_ids)): 1493 foreach($subscriptions_ids as $subscriptions_id) : 1494 $get_order = wc_get_order($subscriptions_id->id); 1495 foreach ($get_order->get_items() as $item) { 1496 1497 $changedItemData = $item->get_data(); 1498 // Let's see if this is in 1499 $id = (int) get_post_meta( 1500 $changedItemData["product_id"], 1501 WPMKTENGINE_PRODUCT_KEY, 1502 true 1503 ); 1504 if (is_numeric($id) && $id > 0) { 1505 $array["product_id"] = $id; 1506 $array["quantity"] = 1507 $changedItemData["quantity"]; 1508 $array["total_price"] = 1509 $changedItemData["total"]; 1510 $array["unit_price"] = 1511 $changedItemData["total"] / 1512 $changedItemData["quantity"]; 1513 $array["external_product_id"] = 1514 $changedItemData["product_id"]; 1515 $array["name"] = $changedItemData["name"]; 1516 $wpmeApiOrderItems[] = $array; 1517 } 1518 } 1519 endforeach; 1520 else: 1521 $get_order = wc_get_order($order_id); 1522 foreach ($get_order->get_items() as $item) { 1523 1524 $changedItemData = $item->get_data(); 1525 // Let's see if this is in 1526 $id = (int) get_post_meta( 1527 $changedItemData["product_id"], 1528 WPMKTENGINE_PRODUCT_KEY, 1529 true 1530 ); 1531 if (is_numeric($id) && $id > 0) { 1532 $array["product_id"] = $id; 1533 $array["quantity"] = 1534 $changedItemData["quantity"]; 1535 $array["total_price"] = 1536 $changedItemData["total"]; 1537 $array["unit_price"] = 1538 $changedItemData["total"] / 1539 $changedItemData["quantity"]; 1540 $array["external_product_id"] = 1541 $changedItemData["product_id"]; 1542 $array["name"] = $changedItemData["name"]; 1543 $wpmeApiOrderItems[] = $array; 1544 } 1545 } 1546 endif; 1494 foreach($subscriptions_ids as $subscriptions_id) : 1495 $subscription_id = $subscriptions_id->id; 1496 $get_order = wc_get_order($subscriptions_id->id); 1497 foreach ($get_order->get_items() as $item) { 1547 1498 1548 1549 $id = get_post_meta( 1550 $order_id, 1551 WPMKTENGINE_ORDER_KEY, 1499 $changedItemData = $item->get_data(); 1500 // Let's see if this is in 1501 $id = (int) get_post_meta( 1502 $changedItemData["product_id"], 1503 WPMKTENGINE_PRODUCT_KEY, 1552 1504 true 1553 1505 ); 1554 $order_genoo_id = $id; 1555 1556 $cartOrder = new \WPME\Ecommerce\CartOrder( 1557 $order_genoo_id 1558 ); 1559 $cartOrder->setApi($WPME_API); 1560 1561 $order = new \WC_Order($order_id); 1562 $cartOrder = new \WPME\Ecommerce\CartOrder(); 1563 $cartOrder->setApi($WPME_API); 1564 $cartOrder->total_price = $order->get_total(); 1565 $cartOrder->setUser($lead_id); 1566 $cartOrder->actionNewOrder(); 1567 $cartOrder->total_price = $order->get_total(); 1568 $cartAddress = $order->get_address("billing"); 1569 $cartAddress2 = $order->get_address("shipping"); 1570 $cartOrder = new \WPME\Ecommerce\CartOrder( 1571 $order_genoo_id 1572 ); 1573 $cartOrder->setApi($WPME_API); 1574 $cartOrder->setBillingAddress( 1575 $cartAddress["address_1"], 1576 $cartAddress["address_2"], 1577 $cartAddress["city"], 1578 $cartAddress["country"], 1579 $cartAddress["phone"], 1580 $cartAddress["postcode"], 1581 "", 1582 $cartAddress["state"] 1583 ); 1584 $cartOrder->setShippingAddress( 1585 $cartAddress2["address_1"], 1586 $cartAddress2["address_2"], 1587 $cartAddress2["city"], 1588 $cartAddress2["country"], 1589 $cartAddress2["phone"], 1590 $cartAddress2["postcode"], 1591 "", 1592 $cartAddress2["state"] 1593 ); 1594 $cartOrder->order_number = $order_id; 1595 $cartOrder->first_name = 1596 $order->get_billing_first_name; 1597 $cartOrder->last_name = 1598 $order->get_billing_last_name; 1599 $cartOrder->currency = $order->get_order_currency(); 1600 $cartOrder->setTotal($order->get_total()); 1601 $cartOrder->addItemsArray($wpmeApiOrderItems); 1602 // Add email and leadType 1603 //ec_lead_type_id = lead type ID 1604 //email_ordered_from = email address making the sale 1605 $leadTYpe = wpme_get_customer_lead_type(); 1606 $cartOrder->ec_lead_type_id = $leadTYpe; 1607 $cartOrder->changed->ec_lead_type_id = $leadTYpe; 1608 $cartOrder->email_ordered_from = $email; 1609 $cartOrder->changed->email_ordered_from = $email; 1610 $cartOrder->total_price = $order->get_total(); 1611 $cartOrder->tax_amount = $order->get_total_tax(); 1612 $cartOrder->changed->tax_amount = $order->get_total_tax(); 1613 $cartOrder->shipping_amount = $order->get_total_shipping(); 1614 $cartOrder->changed->shipping_amount = $order->get_total_shipping(); 1615 // From email 1616 $cartOrderEmail = \WPME\WooCommerce\Helper::getEmailFromOrder( 1617 $order_id 1618 ); 1619 if ($cartOrderEmail !== false) { 1620 $cartOrder->email_ordered_from = $cartOrderEmail; 1621 $cartOrder->changed->email_ordered_from = $cartOrderEmail; 1506 if (is_numeric($id) && $id > 0) { 1507 $array["product_id"] = $id; 1508 $array["quantity"] = 1509 $changedItemData["quantity"]; 1510 $array["total_price"] = 1511 $changedItemData["total"]; 1512 $array["unit_price"] = 1513 $changedItemData["total"] / 1514 $changedItemData["quantity"]; 1515 $array["external_product_id"] = 1516 $changedItemData["product_id"]; 1517 $array["name"] = $changedItemData["name"]; 1518 $wpmeApiOrderItems[] = $array; 1622 1519 } 1623 wpme_simple_log_2( 1624 "WPC-2 Payment Complete for order: " . $order_id 1625 ); 1626 wpme_simple_log_2( 1627 "WPC-3 Woocommerce order: " . $id 1628 ); 1520 } 1521 endforeach; 1522 else: 1523 $get_order = wc_get_order($order_id); 1524 foreach ($get_order->get_items() as $item) { 1525 1526 $changedItemData = $item->get_data(); 1527 // Let's see if this is in 1528 $id = (int) get_post_meta( 1529 $changedItemData["product_id"], 1530 WPMKTENGINE_PRODUCT_KEY, 1531 true 1532 ); 1533 if (is_numeric($id) && $id > 0) { 1534 $array["product_id"] = $id; 1535 $array["quantity"] = 1536 $changedItemData["quantity"]; 1537 $array["total_price"] = 1538 $changedItemData["total"]; 1539 $array["unit_price"] = 1540 $changedItemData["total"] / 1541 $changedItemData["quantity"]; 1542 $array["external_product_id"] = 1543 $changedItemData["product_id"]; 1544 $array["name"] = $changedItemData["name"]; 1545 $wpmeApiOrderItems[] = $array; 1546 } 1547 } 1548 endif; 1549 1550 $id = get_post_meta( 1551 $order_id, 1552 WPMKTENGINE_ORDER_KEY, 1553 true 1554 ); 1555 $order_genoo_id = $id; 1556 1557 $cartOrder = new \WPME\Ecommerce\CartOrder( 1558 $order_genoo_id 1559 ); 1560 $cartOrder->setApi($WPME_API); 1561 1562 $order = new \WC_Order($order_id); 1563 $cartOrder = new \WPME\Ecommerce\CartOrder(); 1564 $cartOrder->setApi($WPME_API); 1565 $cartOrder->total_price = $order->get_total(); 1566 $cartOrder->setUser($lead_id); 1567 $cartOrder->actionNewOrder(); 1568 $cartOrder->total_price = $order->get_total(); 1569 $cartAddress = $order->get_address("billing"); 1570 $cartAddress2 = $order->get_address("shipping"); 1571 $cartOrder = new \WPME\Ecommerce\CartOrder( 1572 $order_genoo_id 1573 ); 1574 $cartOrder->setApi($WPME_API); 1575 $cartOrder->setBillingAddress( 1576 $cartAddress["address_1"], 1577 $cartAddress["address_2"], 1578 $cartAddress["city"], 1579 $cartAddress["country"], 1580 $cartAddress["phone"], 1581 $cartAddress["postcode"], 1582 "", 1583 $cartAddress["state"] 1584 ); 1585 $cartOrder->setShippingAddress( 1586 $cartAddress2["address_1"], 1587 $cartAddress2["address_2"], 1588 $cartAddress2["city"], 1589 $cartAddress2["country"], 1590 $cartAddress2["phone"], 1591 $cartAddress2["postcode"], 1592 "", 1593 $cartAddress2["state"] 1594 ); 1595 $cartOrder->order_number = $order_id; 1596 $cartOrder->first_name = $order->get_billing_first_name; 1597 $cartOrder->last_name = $order->get_billing_last_name; 1598 $cartOrder->currency = $order->get_order_currency(); 1599 $cartOrder->setTotal($order->get_total()); 1600 $cartOrder->addItemsArray($wpmeApiOrderItems); 1601 // Add email and leadType 1602 //ec_lead_type_id = lead type ID 1603 //email_ordered_from = email address making the sale 1604 $leadTYpe = wpme_get_customer_lead_type(); 1605 $cartOrder->ec_lead_type_id = $leadTYpe; 1606 $cartOrder->changed->ec_lead_type_id = $leadTYpe; 1607 $cartOrder->email_ordered_from = $email; 1608 $cartOrder->changed->email_ordered_from = $email; 1609 $cartOrder->total_price = $order->get_total(); 1610 $cartOrder->tax_amount = $order->get_total_tax(); 1611 $cartOrder->changed->tax_amount = $order->get_total_tax(); 1612 $cartOrder->shipping_amount = $order->get_total_shipping(); 1613 $cartOrder->changed->shipping_amount = $order->get_total_shipping(); 1614 // From email 1615 $cartOrderEmail = \WPME\WooCommerce\Helper::getEmailFromOrder( 1616 $order_id 1617 ); 1618 if ($cartOrderEmail !== false) { 1619 $cartOrder->email_ordered_from = $cartOrderEmail; 1620 $cartOrder->changed->email_ordered_from = $cartOrderEmail; 1621 } 1622 wpme_simple_log_2( 1623 "WPC-2 Payment Complete for order: " . $order_id 1624 ); 1625 wpme_simple_log_2( 1626 "WPC-3 Woocommerce order: " . $id 1627 ); 1629 1628 1630 if (!empty($subscriptions_ids) && !$getrenewal) { 1631 1632 1633 $cartOrder->order_status = "subpayment"; 1634 1635 $cartOrder->financial_status = "paid"; 1636 1637 $cartOrder->changed->order_status = "subpayment"; 1638 $cartOrder->action = "subscription Started"; 1639 $cartOrder->changed->action = "subscription Started"; 1640 } 1641 1642 1643 elseif (!empty($subscriptions_ids) && $getrenewal!=''){ 1644 1645 1646 $cartOrder->order_status = "subrenewal"; 1647 $cartOrder->financial_status = "paid"; 1648 $cartOrder->changed->order_status = "subrenewal"; 1649 $cartOrder->action = "subscription Renewal"; 1650 $cartOrder->changed->action = "subscription Renewal"; 1651 } else { 1652 1653 $cartOrder->financial_status = "paid"; 1654 $cartOrder->action = "new order"; 1655 $cartOrder->changed->action = "new order"; 1656 $cartOrder->order_status = "order"; 1657 $cartOrder->changed->order_status = "order"; 1658 1659 } 1660 1661 try { 1662 $result = $WPME_API->callCustom('/wpmeorders', 'POST',$cartOrder->getPayload()); 1663 1664 if($result->order_id!='') 1665 { 1666 update_post_meta($order_id, 'wpme_order_id', $result->order_id); 1667 } 1668 else 1669 { 1670 apivalidate($order->id, 1671 $cartOrder->action, 1672 "0", 1673 $order->date_created, 1674 (array) $cartOrder->object, 1675 (array) $cartOrder->getPayload(), 1676 "0", 1677 "API key not found", 1678 $rand 1679 ); 1680 } 1681 1682 } catch (\Exception $e) { 1683 apivalidate($order->id, 1629 if (!empty($subscriptions_ids) && !$getrenewal) { 1630 $cartOrder->order_status = "subpayment"; 1631 $cartOrder->financial_status = "paid"; 1632 $cartOrder->changed->order_status = "subpayment"; 1633 $cartOrder->action = "subscription Started"; 1634 $cartOrder->changed->action = "subscription Started"; 1635 $cartOrder->subscription_id = $subscription_id; 1636 } 1637 elseif (!empty($subscriptions_ids) && $getrenewal!=''){ 1638 $cartOrder->order_status = "subrenewal"; 1639 $cartOrder->financial_status = "paid"; 1640 $cartOrder->changed->order_status = "subrenewal"; 1641 $cartOrder->action = "subscription Renewal"; 1642 $cartOrder->changed->action = "subscription Renewal"; 1643 $cartOrder->subscription_id = $subscription_id; 1644 } else { 1645 $cartOrder->financial_status = "paid"; 1646 $cartOrder->action = "new order"; 1647 $cartOrder->changed->action = "new order"; 1648 $cartOrder->order_status = "order"; 1649 $cartOrder->changed->order_status = "order"; 1650 $cartOrder->subscription_id = $subscription_id; 1651 } 1652 1653 try { 1654 $result = $WPME_API->callCustom('/wpmeorders', 'POST', $cartOrder->getPayload()); 1655 error_log('cartOrder Payload: ' . json_encode($cartOrder->getPayload())); 1656 if($result->order_id!='') 1657 { 1658 update_post_meta($order_id, 'wpme_order_id', $result->order_id); 1659 if (isset($subscription_id)) { 1660 $order_payload = $cartOrder->getPayload(); 1661 $result = $WPME_API->callCustom('/wpmeorders[S]', 'PUT', (array)$order_payload); 1662 update_post_meta($subscription_id, 'wpme_order_id', $result->order_id); 1663 error_log('$result:' . $result); 1664 } 1665 } 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 $rand 1677 ); 1678 } 1679 1680 } catch (\Exception $e) { 1681 apivalidate($order->id, 1684 1682 $cartOrder->action, 1685 1683 "0", … … 1691 1689 $rand 1692 1690 ); 1693 } 1694 1691 } 1695 1692 }); 1696 1693 … … 1698 1695 * Order Failed 1699 1696 */ 1700 1701 1697 add_action( 1702 1698 "woocommerce_order_status_pending",
Note: See TracChangeset
for help on using the changeset viewer.