I created a custom checkout page.
I wanted to put the coupon code anywhere and it worked.
Unfortunately after clicking on the "apply coupon" button, instead of validating the coupon and adding it to the order, the system responds as per clicking the "order and pay" button Code used in form-checkout.php:
<?php do_action('woocommerce_checkout_coupon_form', $checkout); ?>
<form name="checkout" method="post" class="checkout woocommerce-checkout" action="<?php echo esc_url( wc_get_checkout_url() ); ?>" enctype="multipart/form-data">
<div class="checkout-form-container">
<?php if ( sizeof( $checkout->checkout_fields ) > 0 ) : ?>
<?php do_action( 'woocommerce_checkout_before_customer_details' ); ?>
<div class="col2-set" id="customer_details">
<div class="col-1">
<?php do_action( 'woocommerce_checkout_billing' ); ?>
</div>
</div>
<?php do_action( 'woocommerce_checkout_after_customer_details'); ?>
<p class="form-row form-row-first">
<label for="coupon_code">Coupon?</label>
<input type="text" name="coupon_code" class="custom-coupon-code-input input-text" placeholder="<?php esc_attr_e( 'Wprowadż kod', 'woocommerce' ); ?>" id="coupon_code" value="" />
</p>
<p class="form-row form-row-last">
<input type="submit"button class="button custom-apply-coupon-btn">
<?php esc_attr_e( 'Apply', 'woocommerce' ); ?>
</button>
</p>
<?php endif; ?>
</div>
Check your checkout page HTML. You are actually putting your coupon form inside checkout form. HTML forms doesn't support nested forms.
Put the form outside of checkout form. If you really need to show them there then take those values by javascript with the click of 'Apply Coupon' button and do the validation. But A form tag inside another form is not the correct way.
The submit button is submitting parent form also. That's why you are getting that.
I know where is the problem. Everything works perfectly on woo 2.6.8 but after update to min 3.0.4 its crash as I described above.
Related
I had added three buttons to the cart page, one for each payment method. Clicking on one of the buttons led to the checkout page where the corresponding payment method used to be pre-selected. It used to work, but somehow has stopped working after updating to the latest Woocommerce version. Any other way of doing this?
Here is the code in cart.php template for the buttons:
<form action="<?php echo esc_url( WC()->cart->get_cart_url() ); ?>" method="post">
<input type="submit" class="checkout-button button alt wc-forward" name="proceed" value="<?php _e( 'Order with Purchase Order', 'woocommerce' ); ?>" />
<input type="submit" class="checkout-button button alt wc-forward" name="proceed" value="<?php _e( 'Order with PayPal', 'woocommerce' ); ?>" />
<input type="submit" class="checkout-button button alt wc-forward" name="proceed" value="<?php _e( 'Order with Credit Card', 'woocommerce' ); ?>" />
<?php /*do_action( 'woocommerce_proceed_to_checkout' );*/ ?>
<?php wp_nonce_field( 'woocommerce-cart' ); ?>
</form>
I have to change the input type of a password field.
When I click on a button, it toggled from show to hide value. Also, input type changed from password to text.
How can I implement the same functionality in Laravel as defined in WordPress -
wordpress/wp-admin/install.php?
Can any one help me in understanding this piece of code:
<label for="pass1">
<?php _e( 'Password' ); ?>
</label>
</th>
<td>
<div class="">
<?php $initial_password = isset( $_POST['admin_password'] ) ? stripslashes( $_POST['admin_password'] ) : wp_generate_password( 18 ); ?>
Please, explain the below code:
<input type="password" name="admin_password" id="pass1" class="regular-text" autocomplete="off" data-reveal="1" data-pw="<?php echo esc_attr( $initial_password ); ?>" aria-describedby="pass-strength-result" />
<button type="button" class="button wp-hide-pw hide-if-no-js" data-start-masked="<?php echo (int) isset( $_POST['admin_password'] ); ?>" data-toggle="0" aria-label="<?php esc_attr_e( 'Hide password' ); ?>">
<span class="dashicons dashicons-hidden"></span>
<span class="text"><?php _e( 'Hide' ); ?></span>
</button>
Please, explain these terms:
data-reveal="1"
data-pw
aria-describedby="pass-strength-result"
data-start-masked
Are these HTML or Bootstrap attributes?
Please, tell me, what files are related to this code & where.
aria-describedby is an attribute from JavaScript.
https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/ARIA_Techniques/Using_the_aria-describedby_attribute
data-toggle is an attribute from Bootstrap. Example
aria-label is an attribute from JavaScript. https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/ARIA_Techniques/Using_the_aria-label_attribute
data-reveal is an attribute from Foundation. https://foundation.zurb.com/sites/docs/v/5.5.3/components/reveal.html
I'd like to give another html element the function of 'add to cart'. Is this possible? I have added some html code into single-product.php and want one of these elements to function as 'add to cart' when you click on them :)
I hope that I've been able to explain myself :P
The following will work as an add to cart button within a product loop, where $product is the post object -
<?php if( $product->is_purchasable() ):?>
<form class="cart" method="post" enctype='multipart/form-data'>
<?php do_action( 'woocommerce_before_add_to_cart_button' ); ?>
<input type="hidden" name="add-to-cart" value="<?php echo esc_attr( $product->id ); ?>" />
<button type="submit">Add to Cart</button>
<?php do_action( 'woocommerce_after_add_to_cart_button' ); ?>
</form>
<?php endif; ?>
How I search my WordPress site pages with search box I placed in my site?
Currently I am using this code.
<form id="searchform" method="get" action="<?php bloginfo('siteurl')?>/" style="margin-left: -43px;">
<input type="text" name="" id="s" class="textbox" placeholder="Search" required/>
<input id="btnSearch" type="submit" name="submit" value="<?php _e('Search'); ?>" />
</form>
I used name="s" but it not do search properly. I want that if user right page1 name search box take it to siteurl/page1 and so for page2 and remaining page.
Thanks in advance
Try this :
function redirect_search() {
if (is_search() && !empty($_GET['s'])) {
wp_redirect(home_url("/").urlencode($_GET['s']));
exit();
}
}
add_action('template_redirect', 'redirect_search' );
Add above code in your functions.php file.
So now when you type something, it will redirect it to that page.
NOTE:If you type something related to the published post, it will redirect to that POST instead of what have you entered.
For example : If I type hello in search box, then it will redirect you to hello world(which is default post that comes during installation of wordpress).
This is what have for you.
<div id="content" class="textbox <?php echo of_get_option('blog_sidebar_pos') ?>">
<?php _e('Search for:',''); ?> "<?php the_search_query(); ?>"
<?php
if (have_posts()) : while (have_posts()) : the_post();
$format = get_post_format();
get_template_part( 'include/'.$format );
if($format == '')
get_template_part( 'include/standard' );
endwhile; else:
?>
<?php echo '<p><strong>' . __('There has been an error.', '') . '</strong></p>'; ?>
<p> <?php _e('return to home page', ''); ?> <?php _e('use the search .', ''); ?></p>
<?php get_search_form(); ?>
</div><!--no-results-->
<?php endif; ?>
<?php get_template_part('include/post'); ?>
im trying to put add to cart on content-product.php but without success.
I need a button that when the person clicks add to cart automatically.
I tried to put this:
<form class="cart" method="post" enctype='multipart/form-data'>
<?php do_action( 'woocommerce_before_add_to_cart_button' ); ?>
<input type="hidden" name="add-to-cart" value="<?php echo esc_attr( $product->id ); ?>" />
<button type="submit" class="single_add_to_cart_button button alt"><?php echo $product->single_add_to_cart_text(); ?></button>
<?php do_action( 'woocommerce_after_add_to_cart_button' ); ?>
</form>
The button looks ok but dont add to cart...
Someone can help me?
Im using Woocommerce 2.1.5
Thanks so much
Adding:
do_action( 'woocommerce_after_shop_loop_item' );
to the content-product.php file should add the "Add to cart" button.