Guest User

Untitled

a guest
Mar 21st, 2018
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.83 KB | None | 0 0
  1. add_filter( 'cybersource_add_signed_field_names', 'cybersource_add_mdd_fields' );
  2.  
  3. global $woocommerce;
  4.  
  5. $consumer_id = get_current_user_id();
  6. $previous_customer = ( $consumer_id == 0 ? 'NO' : 'YES' );
  7.  
  8.  
  9. // Get Cart Items
  10. $cart_items = $woocommerce->cart->get_cart();
  11.  
  12. $cb_items = array();
  13.  
  14. if( ! empty( $cart_items ) ){
  15.  
  16. if( count($cart_items) == 1 ){
  17.  
  18. $x = 0;
  19. foreach( $cart_items as $values ){
  20.  
  21. if( $values[ 'product_id' ] ){
  22. $product = new WC_Product( $values['product_id']);
  23. $products_cats = $product->get_category_ids();
  24. } else {
  25. $product = new WC_Product( $values['variation_id']);
  26. $products_cats = $product->get_category_ids();
  27. }
  28.  
  29.  
  30. $_product = $values['data']->post;
  31.  
  32. $cb_items[ 'merchant_defined_data3' ] = substr($_product->post_title,0,100);
  33.  
  34. if( is_array($products_cats) && ! empty($products_cats)){
  35. $c = array();
  36. foreach ($products_cats as $value) {
  37. $c[] = get_cat_name( $value );
  38. }
  39.  
  40. $products_cats = implode( ',', $c );
  41. } else {
  42. $products_cats = '';
  43. }
  44.  
  45. $cb_items[ 'merchant_defined_data4' ] = $products_cats;
  46.  
  47. $x++;
  48. }
  49.  
  50. } else {
  51.  
  52.  
  53. $x = 0;
  54. foreach( $cart_items as $values ){
  55.  
  56. if( $values[ 'product_id' ] ){
  57. $product = new WC_Product( $values['product_id']);
  58. $products_cats = $product->get_category_ids();
  59. } else {
  60. $product = new WC_Product( $values['variation_id']);
  61. $products_cats = $product->get_category_ids();
  62. }
  63.  
  64.  
  65. $_product = $values['data']->post;
  66.  
  67. $mdd_product[ 'name' ][] = substr($_product->post_title,0,100);
  68.  
  69. if( ! empty($products_cats) && is_array($products_cats)){
  70. foreach ( $products_cats as $key => $value) {
  71. $mdd_product[ 'cats' ][] = $value;
  72. }
  73. } else {
  74. $mdd_product[ 'cats' ] = $products_cats;
  75. }
  76.  
  77.  
  78. $x++;
  79. }
  80.  
  81.  
  82.  
  83. if( ! empty( $mdd_product[ 'name' ] ) && is_array($mdd_product[ 'name' ])){
  84. $cb_items[ 'merchant_defined_data3' ] = implode( ',', $mdd_product[ 'name' ] );
  85. }
  86.  
  87. if( ! empty($mdd_product[ 'cats' ]) && is_array($mdd_product[ 'cats' ] )){
  88. $c = array();
  89.  
  90. foreach ($mdd_product[ 'cats' ] as $value) {
  91. $c[] = get_cat_name( $value );
  92. }
  93. $cb_items[ 'merchant_defined_data4' ] = implode( ',', $c);
  94. }
  95.  
  96. }
  97.  
  98. }
  99.  
  100.  
  101. $shipping_class = array_values($cart_items);
  102.  
  103.  
  104. if( ! empty( $shipping_class)){
  105. $shipping_class = $shipping_class[0]['data']->get_shipping_class();
  106.  
  107. if( empty($shipping_class) ){
  108. $shipping_class = WC()->session->get('chosen_shipping_methods');
  109. $shipping_class = $shipping_class[0];
  110. }
  111.  
  112.  
  113.  
  114. } else {
  115. $shipping_class = 'No shipping method available';
  116. }
  117.  
  118. $mdd1 = array(
  119. 'consumer_id' => $consumer_id, // Consumer ID
  120. 'merchant_defined_data1' => __( 'WC', 'woocommerce' ), // Chanel of Operation
  121. 'merchant_defined_data2' => __( 'YES', 'woocommerce' ), // 3D secure registration
  122. 'merchant_defined_data5' => $previous_customer, // Previous Customer
  123. 'merchant_defined_data6' => $shipping_class, // Shipping Method
  124. 'merchant_defined_data7' => WC()->cart->get_cart_contents_count(), // Number of Items Sold
  125. 'merchant_defined_data8' => $woocommerce->customer->get_country(), // Product Shipping Country
  126. 'merchant_defined_data20' => __( 'NO', 'woocommerce' ), // VIP Customer
  127.  
  128. );
  129.  
  130. $mdd = array_merge( $mdd1, $cb_items );
  131.  
  132. return $mdd;
Add Comment
Please, Sign In to add comment