junkpad92
Forum Replies Created
Viewing 4 replies - 1 through 4 (of 4 total)
-
Forum: Plugins
In reply to: [WooCommerce] Add fee dynamically depending on textfieldHere is my current code:
/** * Add the field to the checkout */ add_action( 'woocommerce_after_order_notes', 'datepicker_checkout_field' ); function datepicker_checkout_field( $checkout ) { echo '<div id="datepicker_checkout_field"><h2>' . __('Lieferdatum') . '</h2>'; woocommerce_form_field( 'order_datepicker', array( 'type' => 'text', 'required' => true, 'class' => array('my-field-class form-row-wide'), 'id' => 'order_datepicker', 'label' => __('W?hlen Sie Ihr Lieferdatum aus'), 'placeholder' => __('Datum ausw?hlen'), 'custom_attributes' => array( 'readonly' => 'true' ) ), $checkout->get_value( 'order_datepicker' )); echo '</div>'; } /** * Process the checkout */ add_action('woocommerce_checkout_process', 'my_custom_checkout_field_process'); function my_custom_checkout_field_process() { // Check if set, if its not set add an error. if ( ! $_POST['order_datepicker'] ) { wc_add_notice( __( 'Bitte geben Sie ein Lieferdatum an.' ), 'error' ); } } /** * Update the order meta with field value */ add_action( 'woocommerce_checkout_update_order_meta', 'my_custom_checkout_field_update_order_meta' ); function my_custom_checkout_field_update_order_meta( $order_id ) { if ( ! empty( $_POST['order_datepicker'] ) ) { update_post_meta( $order_id, 'Lieferdatum', sanitize_text_field( $_POST['order_datepicker'] ) ); } } /** * Display field value on the order edit page */ add_action( 'woocommerce_admin_order_data_after_billing_address', 'my_custom_checkout_field_display_admin_order_meta', 10, 1 ); function my_custom_checkout_field_display_admin_order_meta($order){ echo '<p><strong>'.__('Lieferdatum').':</strong> ' . get_post_meta( $order->id, 'Lieferdatum', true ) . '</p>'; } /** * Add the field to order emails **/ add_filter('woocommerce_email_order_meta_keys', 'my_custom_checkout_field_order_meta_keys'); function my_custom_checkout_field_order_meta_keys( $keys ) { $keys[] = "Lieferdatum"; return $keys; } /* ----------- MINIMUM ORDER AMOUNT ------------- */ add_action( 'woocommerce_checkout_process', 'wc_minimum_order_amount' ); add_action( 'woocommerce_before_cart' , 'wc_minimum_order_amount' ); function wc_minimum_order_amount() { // Which shipping method is chosen? if ( is_admin() && ! defined( 'DOING_AJAX' ) ) return; $chosen_methods = WC()->session->get( 'chosen_shipping_methods' ); $chosen_shipping = $chosen_methods[0]; // Set this variable to specify a minimum order value if( $chosen_shipping == 'local_pickup' ) { $minimum = 45; } else { $minimum = 150; } if ( WC()->cart->total < $minimum ) { if( is_cart() ) { wc_print_notice( sprintf( 'Der Mindestbestellwert betr?gt %s. Derzeit betr?gt Ihr Bestellwert %s.' , wc_price( $minimum ), wc_price( WC()->cart->total ) ), 'error' ); } else { wc_add_notice( sprintf( 'Der Mindestbestellwert betr?gt %s. Derzeit betr?gt Ihr Bestellwert %s.' , wc_price( $minimum ), wc_price( WC()->cart->total ) ), 'error' ); } } } /* ----------------------------------------------- */ /* ---------- CUSTOM SURCHARGE ----------- */ function woocommerce_custom_surcharge() { global $woocommerce; if ( is_admin() && ! defined( 'DOING_AJAX' ) ) return; $country = array('AT', 'US'); $percentage = 0.1; if ( in_array( $woocommerce->customer->get_shipping_country(), $country ) ) : $surcharge = ( $woocommerce->cart->cart_contents_total + $woocommerce->cart->shipping_total ) * $percentage; $woocommerce->cart->add_fee( 'Feiertagszuschlag 10 %', $surcharge, true, 'standard' ); endif; } add_action( 'woocommerce_cart_calculate_fees','woocommerce_custom_surcharge' ); /* --------------------------------------- */
Thank you very much for helping!
Hey,
thanks for your answer!
Yes, there is a bug in WordPress: https://core.trac.www.ads-software.com/ticket/12061 – for 5 years!
I fixed it by added the posted function to my functions.php.
Fixed it by adding this to my functions.php
function shortcode_empty_paragraph_fix( $content ) { $array = array ( '<p>[' => '[', ']</p>' => ']', ']<br />' => ']' ); $content = strtr( $content, $array ); return $content; } add_filter( 'the_content', 'shortcode_empty_paragraph_fix' );
Forum: Plugins
In reply to: [Paginated Effects Gallery] If too many pictures, page loads extremely slowThank you! ??
No, I use your plugin. ?? It is really great! But if you would release this feature in the next version, I would be really happy.
Thanks!
Viewing 4 replies - 1 through 4 (of 4 total)