Advertisement
Guest User

Untitled

a guest
Mar 21st, 2018
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.10 KB | None | 0 0
  1. <?php
  2. /*
  3. Plugin Name: Site plugin for myexamplesite.com
  4. Description: Site specific code for myexamplesite.com
  5. */
  6. /* Begin Adding Functions Below This Line; Do not include an opening PHP tag as this sample code already includes one! */
  7. * @return void
  8. */
  9. function bc_ee_determine_whether_to_apply_surcharge() {
  10. // CHANGE $surcharge_QST_ID VALUE TO MATCH THE ID OF YOUR QUESTION
  11. $surcharge_QST_ID = 12;
  12. if ( isset( $_REQUEST[ 'ee_reg_qstn' ] ) ) {
  13. foreach ( $_REQUEST[ 'ee_reg_qstn' ] as $registrations ) {
  14. if ( ! empty( $registrations ) ) {
  15. foreach ( $registrations as $QST_ID => $response ) {
  16. if ( $QST_ID === $surcharge_QST_ID ) {
  17. switch ( $response ) {
  18. // CHANGE THESE TO EXACTLY MATCH THE ANSWER OPTIONS FOR YOUR QUESTION
  19. // THEN EDIT / ADD / DELETE THE FUNCTIONS BELOW
  20. // WHOSE NAMES MATCH THESE OPTIONS
  21. // YOU CAN ADD NEW OPTIONS, JUST MAKE SURE TO HAVE A CORRESPONDING
  22. // FUNCTION FOR SETTING THE SURCHARGE DETAILS
  23. case 'you print tickets at home' :
  24. // apply the surcharge
  25. add_filter( 'FHEE__bc_ee_apply_transaction_surcharge__apply_surcharge', '__return_true' );
  26. // hook into function below to set surcharge details
  27. add_filter( 'FHEE__bc_ee_apply_transaction_surcharge__surcharge_details', 'bc_ee_print_at_home_fee_surcharge_details' );
  28. break;
  29. case 'we print and ship tickets' :
  30. // apply the surcharge
  31. add_filter( 'FHEE__bc_ee_apply_transaction_surcharge__apply_surcharge', '__return_true' );
  32. // hook into function below to set surcharge details
  33. add_filter( 'FHEE__bc_ee_apply_transaction_surcharge__surcharge_details', 'bc_ee_ticket_shipping_fee_surcharge_details' );
  34. break;
  35. }
  36. }
  37. }
  38. }
  39. }
  40. }
  41. }
  42. add_action( 'AHEE__EE_System__core_loaded_and_ready', 'bc_ee_determine_whether_to_apply_surcharge', 1 );
  43. /**
  44. * EDIT THIS TO HOLD THE DETAILS FOR ONE OF YOUR ANSWER OPTIONS
  45. * @return array
  46. */
  47. function bc_ee_print_at_home_fee_surcharge_details() {
  48. return array(
  49. 'name' => 'transaction fee',
  50. 'code' => 'print-at-home-fee',
  51. 'description' => 'convenience fee for online tickets',
  52. 'unit_price' => 0.00,
  53. 'taxable' => false,
  54. );
  55. }
  56. /**
  57. * EDIT THIS TO HOLD THE DETAILS FOR ONE OF YOUR ANSWER OPTIONS
  58. * @return array
  59. */
  60. function bc_ee_ticket_shipping_fee_surcharge_details() {
  61. return array(
  62. 'name' => 'shipping fee',
  63. 'code' => 'ticket-shipping-fee',
  64. 'description' => 'postal fee for shipping tickets',
  65. 'unit_price' => 2.90,
  66. 'taxable' => false,
  67. );
  68. }
  69. /**
  70. * DO NOT EDIT ANYTHING EXCEPT DEFAULT SURCHARGE DETAILS
  71. *
  72. * bc_ee_apply_transaction_surcharge
  73. *
  74. * @param \EE_Checkout $checkout
  75. * @return \EE_Checkout
  76. */
  77. function bc_ee_apply_transaction_surcharge( EE_Checkout $checkout ) {
  78. // DEFAULT SURCHARGE DETAILS - EDIT THIS
  79. $surcharge_details = apply_filters(
  80. 'FHEE__bc_ee_apply_transaction_surcharge__surcharge_details',
  81. array(
  82. // name for surcharge that will be displayed, ie: 'printing fee'
  83. 'name' => 'shipping fee',
  84. // unique code used to identify surcharge in the db, ie: 'print-at-home-fee'
  85. 'code' => 'ticket-shipping-fee',
  86. // 'fee for printing tickets'
  87. 'description' => 'postal fee for shipping tickets',
  88. // surcharge amount
  89. 'unit_price' => 2.50,
  90. // whether or not tax is applied on top of the surcharge
  91. 'taxable' => false,
  92. )
  93. );
  94. // STOP EDITING
  95. // apply the surcharge ?
  96. if ( ! apply_filters( 'FHEE__bc_ee_apply_transaction_surcharge__apply_surcharge', true ) ) {
  97. return $checkout;
  98. }
  99. // verify checkout
  100. if ( ! $checkout instanceof EE_Checkout ) {
  101. return $checkout;
  102. }
  103. // verify cart
  104. $cart = $checkout->cart;
  105. if ( ! $cart instanceof EE_Cart ) {
  106. return $checkout;
  107. }
  108. // verify grand total line item
  109. $grand_total = $cart->get_grand_total();
  110. if ( ! $grand_total instanceof EE_Line_Item ) {
  111. return $checkout;
  112. }
  113. // has surcharge already been applied ?
  114. $existing_surcharge = $grand_total->get_child_line_item( $surcharge_details[ 'code' ] );
  115. if ( $existing_surcharge instanceof EE_Line_Item ) {
  116. return $checkout;
  117. }
  118. EE_Registry::instance()->load_helper( 'Line_Item' );
  119. $pre_tax_subtotal = EEH_Line_Item::get_pre_tax_subtotal( $grand_total );
  120. $pre_tax_subtotal->add_child_line_item(
  121. EE_Line_Item::new_instance( array(
  122. 'LIN_name' => $surcharge_details[ 'name' ],
  123. 'LIN_desc' => $surcharge_details[ 'description' ],
  124. 'LIN_unit_price' => (float) $surcharge_details[ 'unit_price' ],
  125. 'LIN_quantity' => 1,
  126. 'LIN_is_taxable' => $surcharge_details[ 'taxable' ],
  127. 'LIN_order' => 0,
  128. 'LIN_total' => (float) $surcharge_details[ 'unit_price' ],
  129. 'LIN_type' => EEM_Line_Item::type_line_item,
  130. 'LIN_code' => $surcharge_details[ 'code' ],
  131. ) )
  132. );
  133. $grand_total->recalculate_total_including_taxes();
  134. return $checkout;
  135. }
  136. add_filter( 'FHEE__EED_Single_Page_Checkout___initialize_checkout__checkout', 'bc_ee_apply_transaction_surcharge' );
  137. // End of file bc_ee_apply_transaction_surcharge.php
  138. /* Stop Adding Functions */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement