-
WooCommerce Get Order Product Details Before Payment in Plugin
The woocommerce_checkout_process hook is very useful when you want to validate anything before the order is processed. add_action(‘woocommerce_checkout_process’, ‘woocommerce_get_data’, 10); function woocommerce_get_data(){ $cart = array(); $items = WC()->cart->get_cart(); foreach($items as $i=>$fetch){ $item = $fetch[‘data’]->post; $cart[]=array( ‘code’ => $fetch[‘product_id’], ‘name’ => $item->post_title, ‘description’ => $item->post_content, ‘quantity’ => $fetch[‘quantity’], ‘amount’ => get_post_meta($fetch[‘product_id’], ‘_price’, true) ); } $user = wp_get_current_user(); $data = array( ‘total’ => WC()->cart->total, ‘cart’ => $cart, ‘user’ => array( ‘id’ => $user->ID, ‘name’ => join(‘ ‘,array_filter(array($user->user_firstname, $user->user_lastname))), ‘mail’ => $user->user_email, ) ); $_SESSION[‘woo_data’]=json_encode($data); } https://stackoverflow.com/questions/42784075/woocommerce-get-order-product-details-before-payment-in-plugin
-
Add Privacy Policy Acceptance Checkbox @ WooCommerce Checkout
/** * @snippet Add privacy policy tick box at checkout * @how-to Watch tutorial @ https://businessbloomer.com/?p=19055 * @sourcecode https://businessbloomer.com/?p=19854 * @author Rodolfo Melogli * @testedwith WooCommerce 3.3.4 */ add_action( ‘woocommerce_review_order_before_submit’, ‘bbloomer_add_checkout_privacy_policy’, 9 ); function bbloomer_add_checkout_privacy_policy() { woocommerce_form_field( ‘privacy_policy’, array( ‘type’ => ‘checkbox’, ‘class’ => array(‘form-row privacy’), ‘label_class’ => array(‘woocommerce-form__label woocommerce-form__label-for-checkbox checkbox’), ‘input_class’ => array(‘woocommerce-form__input woocommerce-form__input-checkbox input-checkbox’), ‘required’ => true, ‘label’ => ‘I\’ve read and accept the <a href=”/privacy-policy”>Privacy Policy</a>’, )); } // Show notice if customer does not tick add_action( ‘woocommerce_checkout_process’, ‘bbloomer_not_approved_privacy’ ); function bbloomer_not_approved_privacy() { if ( ! (int) isset( $_POST[‘privacy_policy’] ) ) { wc_add_notice( __( ‘Please acknowledge the Privacy Policy’ ), ‘error’ ); } } https://businessbloomer.com/woocommerce-additional-acceptance-checkbox-checkout/