Display ACF fields on WooCommerce single product page via hook - woocommerce

This method works fine
Display ACF fields on WooCommerce single product page
but what if I want to use this code below. How do I have to format the code so that it works with the functions.php
$my_title = get_field('the_subtitle');
<?php if($my_title):?>
<span id="product-subtitle" class="product-subtitle subtitle"><?php echo $my_title;?></span>
<?php endif;?>

Related

Add dropdown list to woocommerce cart and retrieve value on checkout?

I'd like to modify cart.php to contain a dropdown list of "checkout agents" and then retrieve that data when checking out to redirect to the correct agent (different URLs).
I already have cart.php in the child theme. I have created a cart-custom-checkout.php page to handle retrieving the cart contents and redirecting (wp_redirect) to an agents URL (I tested a single agent by building the URL from the cart contents and it works great).
I enabled the custom checkout via modifying the child theme functions.php as follows:
// enable custom checkout for woocommerce
add_shortcode( 'cart_custom_checkout', 'cart_custom_checkout_function' );
function cart_custom_checkout_function() {
wc_get_template('cart/cart-custom-checkout.php');
}
Then used that shortcode on the checkout page.
Now that everything works like I want in concept, the final step is to create the dropdown list in the cart.php so one of several agents can be chosen. From there I then need to somehow retrieve that in the cart-custom-checkout.php page. If it were part of the WC() cart data or something like that would be great.
Can someone help explain how I can do what I'm wanting to do?
TIA!!
Update: I've gone a little further and added my dropddown list as follows:
add_action('woocommerce_after_cart_totals', 'woocommerce_cart_add_resellers');
function woocommerce_cart_add_resellers() {
wc_get_template('cart/cart-add-reseller.php');
}
The cart-add-reseller.php contents are:
<div style="margin-top:5px">
<select name="agent">
<option value="Agent1">Use Agent1</option>
<option value="Agent2">Use Agent2</option>
</select>
</div>
Now just need to get what agent value is in the cart-custom-checkout.php page. How do I do that?
Update2: I am not getting any $_POST data when clicking the proceeded to checkout button.
// enable custom checkout for woocommerce
add_shortcode( 'cart_custom_checkout', 'cart_custom_checkout_function' );
function cart_custom_checkout_function() {
var_dump($_POST);
wc_get_template('cart/cart-custom-checkout.php');
}
It's empty.
Update 3: I've check $post which just gives me the checkout page itself with the shortcode in it, $_POST is empty, $_SESSIONS is empty, $_GET is empty. I'm not sure where the $_POST data went, maybe some javascript or something like that which I know nothing about. If I could just know a filter or action or something to give me the $_POST data, it will have the value I need. So I give up for now.
Any help would be appreciated.
If I fully understand what you have, if you were to add the following in functions.php, it will add the required field to the cart page and allow it to be accessible via $_POST on the checkout page. This essential replaces the default Proceed to Checkout button, with a new one that includes the select field and a post action.
add_action( 'woocommerce_proceed_to_checkout', 'add_agent_before_proceed_to_checkout', 15 );
function add_agent_before_proceed_to_checkout() {
remove_action( 'woocommerce_proceed_to_checkout', 'woocommerce_button_proceed_to_checkout', 20 );
?>
<form id="checkout_form" method="POST" action="<?php echo esc_url ( wc_get_checkout_url() ); ?>">
<div style="margin-top:5px">
<select name="agent">
<option value selected="selected">-- Select an Agent --</option>
<option value="Agent1">Use Agent1</option>
<option value="Agent2">Use Agent2</option>
</select>
</div>
<button type="submit" class="checkout-button button alt wc-forward" style="width:100%;"><?php
esc_html_e( 'Proceed to checkout', 'woocommerce' ) ?></button>
</form>
<?php
}
The reason what you had added to cart didn't work, is the Proceed to Checkout button (woocommerce\templates\cart\proceed-to-checkout-button.php) by default doesn't do a post action, it is actually a link. Also the spot you were adding your input was not within a form so wouldn't have posted the value.

How to design a php page theme template in wordpress using either html or css?

<?php
/*
Template Name: isbn
*/
?>
<form action="" method="post" name="myForm">
Filter <input id="isbn" type="text" name="isbn" />
<input type="submit" name="submit" value="Submit" /></form>
<?php get_header(); ?>
<?php
if(isset($_POST['submit']))
{
global $wpdb;
$table_name = "isbn"; // change this to your table name
$field = $_POST['isbn']; // change this to your isbn field $_POST['ISBN'];
$retrieve_data = $wpdb->get_results( "SELECT * FROM $table_name where isbn = '".$field."'");
foreach ($retrieve_data as $retrieved_data) {
echo $retrieved_data->title;
// echo $retrieved_data->image; // for image
}
}
?>
This is a search form which i want to design. I have created this form in a page template named isbn. But when i am opening that page for editing i am unable to do this. I am using divi theme in wordpress.
So divi theme is not allowing me to edit this page. Due to which this page is looking very bad in look wise.
Can anyone help me for designing this page by giving their codes or simply by giving their suggestions?
I am facing one more problem whenever i am writing css code in above code i am not getting anything. So i am totally blank that how to deal with this
Just create a WordPress page and add shortcode which you added in functions.php before. Don't create template for this page just use your shortcode only.
First, you have to create a page using divi theme, then create shortcode for this form in functions.php and then use this shortcode in your page.
you are inserting the form above the get_header(); function, so it will be outside of the html tag and outside of the body tag. Move it into the body, then it should at least appear on the page, and you'll see what you need to do next.

How to show multiple Google Maps with different locations created in Advance Custom Fields Wordpress plugin?

I have created two Maps fields in Advanced Custom Fields (ACF) Plugin in its field group area, please check the screenshot
But on the front end when I try to add the code as per Google Maps custom field code only one Map is showing not the second one https://www.advancedcustomfields.com/resources/google-map/
Ah yes, I'm able to figure this out. There has no need of any other different settings, just need to add one more field in ACF fields group area and show that field in the front end by doing the same settings as did on the first field but just change the location variable name and pass the second field value in it. Below is the complete code example to show the first and second map in different HTML elements.
First Map:
<?php
$location = get_field('map');
if( !empty($location) ):
?>
<div class="acf-map">
<div class="marker" data-lat="<?php echo $location['lat']; ?>" data-lng="<?php echo $location['lng']; ?>"></div>
</div>
<?php endif; ?>
Second Map:
<?php
$location_second = get_field('map_second');
if( !empty($location_second) ):
?>
<div class="acf-map">
<div class="marker" data-lat="<?php echo $location_second['lat']; ?>" data-lng="<?php echo $location_second['lng']; ?>"></div>
</div>
<?php endif; ?>
As I have created two map fields in ACF plugin, first map field's name is Map and Second map field name is Map Second, so these will be used as map and map_second in code as given above.
I hope you have ACF Pro version :)
then you can use repeater field
Create repeater field "locations" then inside only one field with name "location" and use code from example "Render multiple markers onto a map"

Woocommerce Cart - parsing shortcode within cart output

Bit of an unusual customisation in WooCommerce that I require...
I've modified the standard WooCommerce cart.php so that the customer can't edit the quantity or remove items from cart. Basically, the customer first visits a seating plan page, selects their seat, and this then adds the relevant ticket (which is just a WC product) to their cart, and displays the cart page.
I want a column in the cart output, which has a button next to every row (every ticket) directing the customer back to the relevant seating plan for that ticket.
I've stored the seating plan shortcode in the WooCommerce product details, and I'm able to recall this in cart.php, and it displays in the right place as text using this line of code:
<td class="product-seating" data-title="<?php esc_attr_e( 'Seating Plan', 'woocommerce' ); ?>">
<?php echo the_field('wccaf_seating_plan_link', $product_id) ; ?>
</td>
This returns the following text nicely under a Seating Plan column in the cart for every ticket:
[tc_seat_chart id="3818" show_legend="true" button_title="Select your seat(s)" subtotal_title="Subtotal" cart_title="Continue to Checkout"]
However, what I actually want it to do is parse this shortcode, which should create a nice button with a link to the correct seating plan.
How would I make it parse the shortcode and not just display it as text? I tried playing around with do_shortcode but didn't have any luck.
Try this:
<td class="product-seating" data-title="<?php esc_attr_e( 'Seating Plan', 'woocommerce' ); ?>">
<?php $seating_plan = get_field('wccaf_seating_plan_link', $product_id) ;
echo do_shortcode($seating_plan);
?>
</td>

Data/Content Architecture in WordPress 3.1

Update
I solved it in that way:
What you need:
Custom Post Type
Enabled Plugin "Posts 2 Posts" (see comments below)
Enabled Plugin "Allow numeric stubs"
You'll need the Plugin "Posts 2 Posts" to assign posts tp pages. "Allow numeric stubs" is a plugin that will allow you to have numeric slugs for pages. If try to add pages named to 2011 or 2012 you'll get Page-Slugs like 2011-2 or 2012-2 because it is not possible to have a page slug that is a number.
First you have to add some Pages. For Example 2011, Nominees and Actors. Now you arrange the Pages as childs to your needs.
2011
-Nominees
--Actors
Your Url will now look like http://example.com/2011/nominees/actors
Now you have to add a Custom Post Type which contains your nominees. Add some nominees to your Post Type (should work with Articles too).
Register a connection type in your functions.php
function my_connection_types() {
// Make sure the Posts 2 Posts plugin is active.
if ( !function_exists( 'p2p_register_connection_type' ) )
return;
p2p_register_connection_type( array(
'id' => 'posts_pages',
'from' => 'page',
'to' => 'nominees' // Your Post-Type
) );
}
add_action( 'init', 'my_connection_types', 100 );
Now go to your Actor-Page, look for a MetaBox named "Connected Nominees" and add your nominees.
Edit your page.php
<article class="single entry">
<header class="post post-header">
<h1><?php the_title(); ?></h1>
</header>
<section class="post post-content">
<?php the_content(); ?>
<?php
// Find connected pages
$connected = p2p_type( 'posts_pages' )->get_connected( get_queried_object_id() );
// Display connected pages
if ( $connected->have_posts() ) :
?>
<?php while ( $connected->have_posts() ) : $connected->the_post(); ?>
<h2><?php the_title(); ?></h2>
<?php the_content(); ?>
<?php endwhile; ?>
<?php
// Prevent weirdness
wp_reset_postdata();
endif;
?>
</section>
</article>
Now you should be able to see you asigned Posts (nominees) on your Page Actors.
The solution is easy to understand for authors since they are working with default wordpress behaviors and the content connection process feels really native.
I'm looking for some data architecture best practices in WordPress 3.1.n
Here are the facts:
It is some kind of award
The Award has **n** different categories
People could be nominated
Each nominee could be asscociated with 1 category
Each category is grouped by year
Each category can contain up to 3 or 5 nominees
Categories/Terms(?)
2011
actor
special-effects
story
2012
actor
special-effects
story
For Example:
http://example.com/nominees/2011/actor/all-nominees-in-actor-cat-in-2011.html
http://example.com/nominees/2011/special-effects/all-nominees-in-special-effects-cat-in-2011.html
http://example.com/nominees/2012/special-effects/all-nominees-in-special-effects-cat-in-2012.html
Note: Custom Post-Types and Custom Taxonomies are fine but i can't get hirachical Taxonomy-Terms work.
Does anyone have some suggestions to solve this with WordPress?
You might consider creating an "Award" post type with categories being the types of awards... Best Actor, Special Effects, etc. Also you could tag each award post by what year it is. I like tagging the year vs a year as a category because it gives you the option to build and scale content by year as the site grows. However a category would work as well.
Then, perhaps create an Actor post type with each actors name, this would have the added benefit of being scaleable should you want to expand on actor profiles down the road. Then consider connecting them using something like the "Posts 2 Posts" plugin. Plugin here
This plugin is great for associating posts with other posts like a "review" post with a "product" post. You will essentially be doing the same thing except "review" would be substituted with "award" and "product" would be associated with "actor".

Resources