HTML5 validation on quantity in woocommerce, change error message - html

I am creating my first online shop.
Problem: I want to show, error message for quantity validation.
Stock quantity is not showing in product detail page but it is showing in cart page. I have share both pages screenshot below.
Product Detail: http://prntscr.com/93ajnj
Cart: http://prntscr.com/93ajuk
I have use below code in woocommerce > single-product > add-to-cart > variable.php
<div class="quantity"><strong>Quantity </strong>
<input type="number" step="<?php echo esc_attr( $step ); ?>" <?php if ( is_numeric( $min_value ) ) : ?>min="<?php echo esc_attr( $min_value ); ?>"<?php endif; ?> <?php if ( is_numeric( $max_value ) ) : ?>max="<?php echo esc_attr( $max_value ); ?>"<?php endif; ?> name="<?php echo esc_attr( $input_name ); ?>" value="<?php echo esc_attr( $input_value ); ?>" class="input-text qty text" size="4" oninvalid="setCustomValidity('Sorry! we have only <?php echo esc_attr( $max_value ); ?> shirts in your selected size.')"
onchange="try{setCustomValidity('')}catch(e){}" />
</div>
Any help in this regards will be highly appreciated. Thanks in advance.
P.S. link of website.

Related

I would like to put search bar beside a page selector

I'm newbie and I would like to know the way to put search bar beside page selector.
Here's a screenshot now :
https://imgur.com/a/S9X3sIc
My desire layout :
https://imgur.com/a/0zx3rfl
How can I make it? I need your help. Thanks in advance. I love you guys. :D
<div class="wpf-navi <?php echo esc_attr($class) ?>">
<div class="wpf-navi-wrap">
<div id="wpf-widget-search" class="wpforo-widget-wrap"><form action="<?php echo wpforo_home_url() ?>" method="get">
<?php wpforo_make_hidden_fields_from_url( wpforo_home_url() ) ?>
<input type="text" placeholder="<?php wpforo_phrase('Search...') ?>" name="wpfs" class="wpfw-70" value="<?php echo isset($_GET['wpfs']) ? esc_attr(sanitize_text_field($_GET['wpfs'])) : '' ?>" ><input type="submit" class="wpfw-20" value="ยป">
</form></div>
<span class="wpf-page-info">
<?php wpforo_phrase('Page') ?> <?php echo intval($paged) ?> / <?php echo intval($pages_count) ?>
</span>
<?php if( $paged - 1 > 0 ): $prev_url = ( ($paged - 1) == 1 ? $sanitized_current_url : sprintf($url, $paged - 1) ); ?>
<a href="<?php echo esc_url( WPF()->user_trailingslashit($prev_url) ) ?>" class="wpf-prev-button" rel="prev">
<i class="fas fa-chevron-left fa-sx"></i> <?php wpforo_phrase('prev') ?>
</a>
<?php endif ?>
<select class="wpf-navi-dropdown" onchange="if (this.value) window.location.assign(this.value)" title="<?php esc_attr( wpforo_phrase('Select Page') ) ?>">
<option value="<?php echo esc_url( WPF()->user_trailingslashit($sanitized_current_url) ) ?>" <?php wpfo_check($paged, 1, 'selected') ?>>1</option>
<?php for($i = 2; $i <= $pages_count; $i++) : ?>
<option value="<?php echo esc_url( WPF()->user_trailingslashit( sprintf($url, $i) ) ) ?>" <?php wpfo_check($paged, $i, 'selected') ?>>
<?php echo $i ?>
</option>
<?php endfor; ?>
</select>
<?php if( $paged + 1 <= $pages_count ): ?>
<a href="<?php echo esc_url( WPF()->user_trailingslashit(sprintf($url, $paged + 1) ) ) ?>" class="wpf-next-button" rel="next">
<?php wpforo_phrase('next') ?> <i class="fas fa-chevron-right fa-sx"></i>
</a>
<?php endif ?>
</div>
</div>

Wordpress custom widget that allows html codes

I just need a widget with a textarea where I can paste an embed code. Right now, whenever I save the widget, it auto removes the html codes.
<label for="<?php echo $this->get_field_id( 'embed' ); ?>"><?php _e( 'Embed:' ); ?></label>
<input class="widefat" id="<?php echo $this->get_field_id( 'embed' ); ?>" name="<?php echo $this->get_field_name( 'embed' ); ?>" type="text" value="<?php echo esc_attr( $embed ); ?>" />
It should work like the default text-widget where it runs HTML. Any way I can put a certain code to retain and run the HTML in my custom widget?
Please use the default textwidget, it will serve your purposes.

How to Display a custom value like customer number in order Email

I am working on a solution for the task to display a customer number in the order confirmation email.
There is already a custom attribute customer_number which is displayed in the register form and the customers back-end.
It seems to get displayed by calling a helper.
This is how it is displayed in the register form:
<input type="number"
name="<?php echo Company_Helper_Data :: CUSTOMER_NUMBER_FIELD ?>"
id="<?php echo Company_Helper_Data :: CUSTOMER_NUMBER_FIELD . "id" ?>"
value="<?php echo $this->escapeHtml($this->getFormData()->getData( Company_Helper_Data :: CUSTOMER_NUMBER_FIELD ) ) ?>"
title="<?php echo $this->__('Customer Number') ?>" class="input-text" />
This is how it gets called in the customer back-end
<input type="text"
name="customer_number"
id="customer_number"
value="<?php echo $this->getCustomer()->getCustomerNumber() ?>"
title="<?php echo $this->__(' Customer Number') ?>"
class="input-text" />
So I simply tried to put this code into the order/default.phmtl:
<?php echo $this->getCustomer()->getCustomerNumber()?>
Which does not work. The Order cannot be set.
I am rookie to programming. Does anyone has an idea how to call the customer-data in the order email-template and display it in the order confirmation?
For this in Magento, you'll have to go in magento backend admin panel,
next go to
system=>Transactional Emails
Here you'll find your email template.
After this open the email template and then place this where you would like
{{ var customer_number }}

From dropdown to table in Magento

I am using Magento Community in order to develop a webshop. I am creating products with a dropdown custom option. I have been trying to change the display (HTML) of this information. Basically, I would like to display a table instead of the dropdown menu that appears currently, but I do not know how to do it. The file I have tried to edit is located in app/design/frontend/base/default/template/bundle/catalog/product/view/type/bundle/option. What I understood is that the information is inserted using the following code:
<?php endif; ?>
<input type="hidden" name="bundle_option[<?php echo $_option->getId() ?>]" value="<?php echo $_selections[0]->getSelectionId() ?>"/>
<?php else:?>
<select onchange="bundle.changeSelection(this)" id="bundle-option-<?php echo $_option->getId() ?>" name="bundle_option[<?php echo $_option->getId() ?>]" class="bundle-option-<?php echo $_option->getId() ?><?php if ($_option->getRequired()) echo ' required-entry' ?> bundle-option-select change-container-classname">
<option value=""><?php echo $this->__('Choose a selection...') ?></option>
<?php foreach ($_selections as $_selection): ?>
<?php if ($_selection->getSelectionCanChangeQty() && $this->_isSelected($_selection)): ?>
<?php $tierPriceHtml = $this->getTierPriceHtml($_selection); ?>
<?php endif; ?>
<option value="<?php echo $_selection->getSelectionId() ?>"<?php if ($this->_isSelected($_selection)) echo ' selected="selected"' ?><?php if (!$_selection->isSaleable()) echo ' disabled="disabled"' ?>><?php echo $this->getSelectionTitlePrice($_selection, false) ?></option>
<?php endforeach; ?>
</select>
What I tried to do is to get the information while building a table, so I added some lines at the end of the tag in order to see a table under the dropdown, with all the information, something as basic as the following lines:
<table class="probapifa">
<?php foreach ($_selections as $_selection1): ?>
<tr id="rowpifa" value="<?php echo $_selection1->getSelectionId() ?>"><?php echo $this->getSelectionTitlePrice($_selection1, false) ?></tr>
<?php endforeach; ?>
</table>
The result is unappreciated, as I can see nothing even if I select a new option from the dropdown. Also, I can see that in the code above, it says Choose a product for the initial selected option, when in the product site the text that appears is Please select. (I read it should be edited in the CSV file, right?). So my guess is that I am not editing the right file, what should I do? I really need your help.

I am creating a recent posts widgets for practice but I need help correctly making it so admin can adjust the category displayed

So like I said in the title, I am creating a recent posts widget for practice. It includes different features and the one that I am having problems with it is allowing admin to choose the category they want to display. I currently have it set up so that in the form it has a text field in which the admin can input the category manually but I need it to be such that it has a drop down menu that already has the category there, so the admin can just select it. I am not sure how to do this at all so if I could get some help that would be great. Sorry if I am being vague, I am new to this. I am posting my code below.
<?php
/*
Plugin Name: News Recent Posts Widget
Plugin URI:
Description: A recent post widget with extra functions that allow admin to make changes to certain values
Author: Kevin Ullyott
Version: 1.0
Author URI: http://modmacro.com/
*/
class recentpost extends WP_Widget {
public function __construct() {
parent::WP_Widget(
// or parent::__construct(
false,
'Kevin - Recent Posts Widget',
array(
'description' => __('A recent post widget with extra functions that allow admin to make changes to certain values')
)
);
;
}
public function widget( $args, $instance ) {
extract( $args );
$headline = $instance['headline'];
$category = $instance['category'];
$numberposts = $instance['numberposts'];
$readmore = $instance['readmore'];
echo $before_widget;
echo $before_title;
echo "<p class=\"headline\">$headline</p>";
echo $after_title;
$args = array( 'numberposts' => $numberposts, 'category_name' => $category );
$recent_posts = wp_get_recent_posts( $args );
foreach( $recent_posts as $recent ){
setup_postdata(get_post($recent['ID']));
echo '<a href="' . get_permalink($recent['ID']) . '" title=" '.esc_attr(get_the_title($recent['ID'])).'" >' . get_the_title($recent['ID']).'</a> ';
echo get_the_time('F j, Y', $recent['ID']);
the_excerpt();
}
wp_reset_postdata();
echo $after_widget;
}
public function update( $new_instance, $old_instance ) {
$instance = array();
$instance['headline'] = ( $new_instance['headline'] );
$instance['category'] = ( $new_instance['category'] );
$instance['numberposts'] = ( $new_instance['numberposts'] );
$instance['readmore'] = ( $new_instance['readmore'] );
return $instance;
}
public function form( $instance ) {
$headline = $instance[ 'headline' ];
$category = $instance[ 'category' ];
$numberposts = $instance[ 'numberposts' ];
$readmore = $instance[ 'readmore' ];
?>
<p>
<label for="<?php echo $this->get_field_id( 'headline' ); ?>">
<?php _e( 'Headline:' ); ?>
</label>
<input class="widefat" id="<?php echo $this->get_field_id( 'headline' ); ?>" name="<?php echo $this->get_field_name( 'headline' ); ?>" type="text" value="<?php echo esc_attr( $headline ); ?>" />
</p>
<label for="<?php echo $this->get_field_id( 'category' ); ?>">
<?php _e( 'Category:' ); ?>
</label>
<input class="widefat" id="<?php echo $this->get_field_id( 'category' ); ?>" name="<?php echo $this->get_field_name( 'category' ); ?>" type="text" value="<?php echo esc_attr( $category ); ?>" />
</p>
<label for="<?php echo $this->get_field_id( 'numberposts' ); ?>">
<?php _e( 'Number of posts:' ); ?>
</label>
<input class="widefat" id="<?php echo $this->get_field_id( 'numberposts' ); ?>" name="<?php echo $this->get_field_name( 'numberposts' ); ?>" type="text" value="<?php echo esc_attr( $numberposts ); ?>" />
</p>
<label for="<?php echo $this->get_field_id( 'readmore' ); ?>">
<?php _e( 'Read More:' ); ?>
</label>
<input class="widefat" id="<?php echo $this->get_field_id( 'readmore' ); ?>" name="<?php echo $this->get_field_name( 'readmore' ); ?>" type="text" value="<?php echo esc_attr( $readmore ); ?>" />
</p>
<?php
}
}
add_action( 'widgets_init', create_function('', 'return register_widget("recentpost");') );
?>
The function wp_dropdown_categories will bring in the categories but adding the function alone wont save or retrieve the selected category. You'll need to add the name selected and id arguments. This should work I think:
<?php wp_dropdown_categories(array('name' => $this->get_field_name('category'), 'selected' => $category, 'id' => $this->get_field_id('category'), 'class' => 'widefat')); ?>
I added class widefat as well but its only for presentation. Hope that helps.
The function wp_dropdown_categories displays a dropdown menu that pulls in all of the categories used in the site. Here is the documentation on it: http://codex.wordpress.org/Function_Reference/wp_dropdown_categories
So you can replace
get_field_id( 'category' ); ?>" name="get_field_name( 'category' ); ?>" type="text" value="" />
with a call to the wp_dropdown_categories function.