How to make popup on the WooCommerce listing page - php

I am making a WooCommerce website where I want to have a pop-up when someone clicks on apply now button. There I want to have two fields 1) All the class(custom field) that product has. 2) Kids that the current logged in user has.
And there would be Add to Cart button which would add the item inside the cart.
I have successfully been able to get those on my product page. I am using toolset https://toolset.com to create my product listing page and single product page.
This is my code for a single product list (Template View)
<div class="school">
<div class="top">
<div class="image">
[types field="logo"][/types]
</div>
<div class="city">
<img src="link_to_img">
[types field="city"][/types]
</div>
</div>
<div class="middle">
<p>[wpv-post-title]</p>
</div>
<div class="bottom">
[wpv-post-read-more]
<button class="applynow" href="#">Apply Now</button>
</div>
</div>
Also this is the code to render those fields 1 & 2 in the popup. I am using this in my single product page.
function iconic_output_engraving_field() {
global $product;
$classes = get_post_meta($product->get_id(),'wpcf-classes-opened-for-admission',array('show_name' => 'true'));
print_r("<label>Select Class</label>");
print_r("<select name='class'>");
print_r("<option disabled selected value> -- Select a Class -- </option>");
foreach ($classes as $class) {
print_r( "<option value='".$class[0]."'>".$class[0]."</option>");
}
print_r("</select>");
$args = array(
'id' => 1538,
);
echo render_view( $args );
}
add_action( 'woocommerce_before_add_to_cart_button', 'iconic_output_engraving_field', 10 );
How can I pass the id through the button, so that I can create a template which loads up with correct data and Add to Cart button.

https://wordpress.org/plugins/easy-login-woocommerce/
This plugin does what you're looking for, BUT it uses wp_user_login or some other function that you would need to change.
Basically, download, check the code of the plugin, your answer should be there.
Plugin is to create a popup when a button is clicked, plugin uses it to login/register, but you could edit to do whatever.

Related

How to alter css class once found in chrome console

Not sure how best to title this. I have a button that creates a modal popup for a job application form in WP Job Manager. I wish to duplicate this button on the same page which I have done, however my new button not only creates the modal but also loads the same application form on the page itself at the same time, this is not intended. The popup/modal is using Magnific Popup. Using Chrome console I found the issue that my new button is using a class without 'mfp-hide' at the end of it whereas the first button does have this.
By adding mfp-hide to the end of the class for that button in the Chrome console I solve the issue - the modal then loads correctly and the modal content does not load on the page. My issue is how/where to allocate a new class with mfp-hide at the end of it in my files. I am used to modifying class properties in child themes but not sure how to add this property/replace the class type. If you look here https://boolerang.co.uk/job/birch-creative-limited-permanent-full-stack-developer/ for example and right click inspect the top apply button then do the same with the lower apply button you can see the missing 'mfp-hide' on the lower. Clicking the lower button will show the problem.
In content-single-job_listing.php I added this to generate the second button:
<?php if ( candidates_can_apply() ) : ?>
<?php get_job_manager_template( 'job-application.php' ); ?>
<?php endif; ?>
job-application.php contains:
<?php if ( $apply = get_the_job_application_method() ) :
wp_enqueue_script( 'wp-job-manager-job-application' );
?>
<div class="job_application application">
<?php do_action( 'job_application_start', $apply ); ?>
<input type="button" class="application_button button" value="<?php
esc_attr_e( 'Apply for job', 'wp-job-manager' ); ?>" />
<div class="application_details">
<?php
/**
* job_manager_application_details_email or
job_manager_application_details_url hook
*/
do_action( 'job_manager_application_details_' . $apply->type,
$apply );
?>
</div>
<?php do_action( 'job_application_end', $apply ); ?>
</div>
<?php endif; ?>
The Chrome console for the original button shows:
<div class="application_details modal mfp-hide" id="apply-overlay"
style="display: block;">
<form class="job-manager-application-form job-manager-form" method="post"
enctype="multipart/form-data" action="https://boolerang.co.uk/job/birch-
creative-limited-permanent-full-stack-developer/">
I wish to change the class associated with the lower button to include the 'mfp-hide' which the Magnific Popup says is required in their documentation to have the desired effect. I don't know which file I need to alter to do this as it's not the button class which would be much easier. Any suggestions of where to edit to get this included would be much appreciated.

How to show more items on the click of 'View More Item..' link or button php

In my web application, user can buy the items online. They can see the list of items. When they click on any of the item, it will take them to that product page where they can see more details about the product. Also they can see the list of hardware parts that are used to make that products. I have limited to that hardware parts to show 6 at a time and then I have a button called 'Show More'. So when user clicks on 'show more', other hardware parts will be shown. How to do so that on button click, I can show remaining parts. Following is the glimpse of my code.
The below code is showing the hardware parts for that product and has a button 'Show More.'
index.php
<div class='item_display'>
<?
foreach ($model->hparts as $hp) {
?>
<div class="col item_grid">
<a class="itemGridContent">
<img src="<?= $hp->getImage() ?>" id="itemImg"/>
</a>
</div>
<?
}
?>
</div>
<button id="show_more">Show More...</button>
controller.php
$this->viewData->hparts = $item->getHParts()
Model.php
public function getHParts(){
$hp = Item_Parts::get_item_parts($this->id,6);
if($hp && count($hp)>0){
$hparts = [];
foreach ($hp as $parts){
$hparts[] = self::getItem($parts);
}
}
else{
}
return $hparts;
}
The above function limits the view of parts to show 6 at a time. Now how should I show more parts on button click ?

WordPress Admin Notice Dismissal

I'm currently building a WordPress Plugin, and in this plugin I need a WordPress admin notification. I was able to create the admin notification, however when I dismiss it, on the next reload of the page it shows up again. How do I get this to not display once a user has dismissed it?
function admin_notice_eagle_daily() {
$displayVar = '<b>EAGLE Display Reminder:</b>'; ?>
<div class="notice notice-success is-dismissible">
<p><?php _e($displayVar, 'sample-eagle-text-domain'); ?></p>
</div>
<?php
}
add_action( 'admin_notices', 'admin_notice_daily' );

Convert Bootstrap YAMM3 to WordPress using Menus Metabox

I seen many similar questions but no solution. I am trying to make yamm3 work with Wordpress.
I know there is plugins but they are extremely bloated.
I think it should be very simple just using a custom metabox.
This example adds a metabox but only allows links.
http://pastebin.com/hj1cxYQg
Here is the basic function:
/* Mega Menu */
function mynav_add_custom_box() {
add_meta_box(
'add-mynav',
'Mega Menu',
'mynav_show_custom_box',
'nav-menus',
'side',
'default');
}
add_action( 'admin_init', 'mynav_add_custom_box' );
//display nav menu meta box
function mynav_show_custom_box() {
// code to create mega menu
?>
<p class="button-controls">
<span class="add-to-menu">
<input type="submit" class="button-secondary submit-add-to-menu right" value="<?php esc_attr_e('Add to Menu'); ?>" name="add-custom-menu-item" id="submit-customlinkdiv" />
<span class="spinner"></span>
</span>
</p>
<?php
}
Metabox options:
The first option I would have would be 'how many columns?' using
bootstrap grid system for its width (up to 5).
The second option, you will choose to add menu item(s)/image(s) in the column(s) or use html w/builtin wp editor.
The li that has the mega menu dropdown should have a wrap div with class 'yamm-content', that is the only thing that makes yamm3 structure different.

Show comments with jquery

I need create a function like a facebook comment. for example if i will click to comment button, it will show me all comments just from same post. i tried to create with jquery, but if i click to button it shows me all comments in all posts. I need just comments where i have clicked not others.
there is show_com.js:
$(".com_but").click(function() {
$('.all_com').show();
});
there is style css:
.all_com{
display:none;
}
and there is index.php:
<button class='com_but' id="<php echo $post_id; ?>">add comment</button>
<script src="show_com.js"></script>
<div class='all_com' id="<php echo $post_id; ?>">
<input type='text'/>
</div>
$post_id is id from post(like a facebook post or twitter).
$('.all_com').show(); will show all divs with class 'all_com', wherever they are on the page. But you seem to intend that you want only to display the 'all_coms' that are children of the same parent as the button clicked. Right?
In that case you should have something like:
<script src="show_com.js"></script>
<div class="container">
<button class='com_but' id="<php echo $post_id; ?>">add comment</button>
<div class='all_com' id="<php echo $post_id; ?>">
<input type='text'/>
</div>
</div>
and your function would be something like:
$(".com_but").click(function() {
$('.all_com',$(this).parent()).show();
});
this will only show elements of class all_com that are contained within the parent of the clicked button.
Hope this helps.
If you just want to show the comments that are within the same hierarchy as the click, the general way of doing that is go from the location of the click (denoted by $(this)) up to a common parent in that section of the DOM (using .closest(selector)), then find all items of interest in that common parent (using .find()).
You don't show enough of your HTML for us to know what that common parent selector would be, but the general idea is like this:
$(".com_but").click(function() {
$(this).closest(common parent selector here).find('.all_com').show();
});

Categories