Woocommerce product variations layout change - woocommerce

I want to make a small change on the single-product page about displaying variations.
Normally variations are displayed like this as html.
<table class="variations" cellspacing="0">
<tbody>
<tr>
<td class="label"><label for="group-size">Group Size</label></td>
<td class="value">
<select id="group-size" class="" name="attribute_group-size" data-attribute_name="attribute_group-size">
<option value="">Chose an options</option>
<option value="1 Person" >1 Person</option>
<option value="2 persons" >2 persons</option>
</select>
</td>
</tr>
<tr>
<td class="label"><label for="type-of-activity">Type of Activity</label></td>
<td class="value">
<select id="tipo-de-actividad" class="" name="attribute_tipo-de-actividad" data-attribute_name="attribute_type-of-activity">
<option value="">Chose an option</option>
<option value="Walking" >Walking</option>
<option value="With car" >with car</option>
</select>
<a class="reset_variations" href="#">Clean the selections</a>
</td>
</tr>
</tbody>
</table>
But I want to have like this
<table class="variations" cellspacing="0">
<tbody>
<tr>
<td class="label"><label for="group-size">Group Size</label></td>
</tr>
<tr>
<td class="value">
<select id="group-size" class="" name="attribute_group-size" data-attribute_name="attribute_group-size">
<option value="">Chose an options</option>
<option value="1 Person" >1 Person</option>
<option value="2 persons" >2 persons</option>
</select>
</td>
</tr>
<tr>
<td class="label"><label for="type-of-activity">Type of Activity</label></td>
</tr>
<tr>
<td class="value">
<select id="tipo-de-actividad" class="" name="attribute_tipo-de-actividad" data-attribute_name="attribute_type-of-activity">
<option value="">Chose an option</option>
<option value="Walking" >Walking</option>
<option value="With car" >with car</option>
</select>
<a class="reset_variations" href="#">Clean the selections</a>
</td>
</tr>
</tbody>
</table>
Means that i wantto have the labels inside a row just above the options.
How we can do that?

I got the solution myself.
There is variable.php in
wp-content/plugins/woocommerce/templates/single-product/add-to-cart
I opened that file
ı have changed
<table class="variations" cellspacing="0">
<tbody>
<?php foreach ( $attributes as $attribute_name => $options ) : ?>
<tr>
<td class="label"><label for="<?php echo sanitize_title( $attribute_name ); ?>"><?php echo wc_attribute_label( $attribute_name ); ?></label></td>
<td class="value">
<?php
$selected = isset( $_REQUEST[ 'attribute_' . sanitize_title( $attribute_name ) ] ) ? wc_clean( $_REQUEST[ 'attribute_' . sanitize_title( $attribute_name ) ] ) : $product->get_variation_default_attribute( $attribute_name );
wc_dropdown_variation_attribute_options( array( 'options' => $options, 'attribute' => $attribute_name, 'product' => $product, 'selected' => $selected ) );
echo end( $attribute_keys ) === $attribute_name ? '<a class="reset_variations" href="#">' . __( 'Clear selection', 'woocommerce' ) . '</a>' : '';
?>
</td>
</tr>
<?php endforeach;?>
</tbody>
</table>
to
<table class="variations" cellspacing="0">
<tbody>
<?php foreach ( $attributes as $attribute_name => $options ) : ?>
<tr>
<td class="label"><label for="<?php echo sanitize_title( $attribute_name ); ?>"><?php echo wc_attribute_label( $attribute_name ); ?></label></td>
</tr>
<tr>
<td class="value">
<?php
$selected = isset( $_REQUEST[ 'attribute_' . sanitize_title( $attribute_name ) ] ) ? wc_clean( $_REQUEST[ 'attribute_' . sanitize_title( $attribute_name ) ] ) : $product->get_variation_default_attribute( $attribute_name );
wc_dropdown_variation_attribute_options( array( 'options' => $options, 'attribute' => $attribute_name, 'product' => $product, 'selected' => $selected ) );
echo end( $attribute_keys ) === $attribute_name ? '<a class="reset_variations" href="#">' . __( 'Clear selection', 'woocommerce' ) . '</a>' : '';
?>
</td>
</tr>
<?php endforeach;?>
</tbody>
</table>
Result was as i like.
Sorry for disturbing you.

Related

Fatal error: Call to undefined function _e() in ---- Wordpress plugin error

I'm following a tutorial in Wordpress for Developers. I started to debug the code and I am getting stuck here.
I think it might be a semi-colon? I'm not exactly sure.
The code is as follows:
<div class="wrap">
<h2><?php _e( 'Halloween Store Options', 'halloween-plugin' ) ?></h2>
<form method="post" action="options.php">
<?php settings_fields ( 'halloween-settings-group' ); ?>
<table class="form-table">
<tr valign="top">
<th scope="row"><?php _e( 'Show Product Inventory', 'halloween-plugin' ); ?></th>
<td><input type="checkbox" name="halloween_options[show_inventory]"
<?php echo checked( $hs_inventory, 'on' ); ?> /></td>
</tr>
<tr valign="top">
<th scope="row"><?php _e( 'Currency Sign', 'halloween-plugin' ) ?></th>
<td><input type="text" name="halloween_options[currency_sign]"
value="<?php echo esc_attr( $hs_currency_sign ); ?>"
size="1" maxlength="1" /></td>
</tr>
</table>
<p class="submit">
<input type="submit" class="button-primary"
value="<?php _e( 'Save Changes', 'halloween-plugin' ); ?>" />
</p>
</form>
</div>
If anyone could help me out, I'd greatly appreciate it.
Try to load the file wp-load.php, before you use the function _e().
require_once('../../../wp-load.php');

How do I make table rows the same height?

I'm doing a contact merge sort of page, and therefore need two tables side by side where you can select which data you want from each contact, but I need the rows to line up so it's easy for the user to select appropriate data. I'm using boostrap
<div class="col-sm-10 col-sm-offset-1">
<form method="post" class="form-inline">
<?php foreach($contacts as $contact): ?>
<div class="col-sm-6">
<table class="table table-bordered table-container">
<thead>
<tr>
<th colspan="3" class="text-center">Contact <?php echo $counter == 1 ? '1':'2'; ?></th>
</tr>
</thead>
<tbody>
<tr>
<div class="input-group">
<td class="td_attr">Main Type:</td>
<td class="text-center td_data"><?php echo $main_type_array[$contact->contact_main_type]; ?></td>
<td class="text-center"><input value="1" type="radio" name="main_type"></td>
</div>
</tr>
<tr>
<div class="input-group">
<td class="td_attr">Title:</td>
<td class="text-center td_data"><?php echo $contact->contact_title; ?></td>
<td class="text-center"><input value="1" type="radio" name="title"></td>
</div>
</tr>
<tr>
<div class="input-group">
<td class="td_attr">First Name:</td>
<td class="text-center td_data"><?php echo $contact->contact_fname; ?></td>
<td class="text-center"><input value="1" type="radio" name="first_name"></td>
</div>
</tr>
<tr>
<div class="input-group">
<td class="td_attr">Last Name:</td>
<td class="text-center td_data"><?php echo $contact->contact_sname; ?></td>
<td class="text-center"><input value="1" type="radio" name="last_name"></td>
</div>
</tr>
<tr>
<div class="input-group">
<td class="td_attr">Salutation:</td>
<td class="text-center td_data"><?php echo $contact->contact_salu; ?></td>
<td class="text-center"><input value="1" type="radio" name="salu"></td>
</div>
</tr>
<tr>
<div class="input-group">
<td class="td_attr">Position:</td>
<td class="text-center td_data"><?php echo $contact->contact_position; ?></td>
<td class="text-center"><input value="1" type="radio" name="position"></td>
</div>
</tr>
<tr>
<div class="input-group">
<td class="td_attr">Email Address:</td>
<td class="text-center td_data"><?php echo $contact->contact_email; ?></td>
<td class="text-center"><input value="1" type="radio" name="email"></td>
</div>
</tr>
<tr>
<div class="input-group">
<td class="td_attr">Alt. Email:</td>
<td class="text-center td_data"><?php echo $contact->contact_alt_email; ?></td>
<td class="text-center"><input value="1" type="radio" name="alt_email"></td>
</div>
</tr>
<tr>
<div class="input-group">
<td class="td_attr">Phone Number:</td>
<td class="text-center td_data"><?php echo $contact->contact_phone; ?></td>
<td class="text-center"><input value="1" type="radio" name="phone"></td>
</div>
</tr>
<tr>
<div class="input-group">
<td class="td_attr">Mobile Number:</td>
<td class="text-center td_data"><?php echo $contact->contact_mobile; ?></td>
<td class="text-center"><input value="1" type="radio" name="mobile"></td>
</div>
</tr>
<tr>
<div class="input-group">
<td class="td_attr">PA Name:</td>
<td class="text-center td_data"><?php echo $contact->contact_pa_name; ?></td>
<td class="text-center"><input value="1" type="radio" name="pa_name"></td>
</div>
</tr>
<tr>
<div class="input-group">
<td class="td_attr">PA Email:</td>
<td class="text-center td_data"><?php echo $contact->contact_pa_email; ?></td>
<td class="text-center"><input value="1" type="radio" name="pa_email"></td>
</div>
</tr>
<tr>
<div class="input-group">
<td class="td_attr">Type:</td>
<td class="text-center td_data"><?php echo $contact->old_type_new; ?></td>
<td class="text-center"><input value="1" type="radio" name="old_type_new"></td>
</div>
</tr>
<tr>
<div class="input-group">
<td class="td_attr">Interest Area 1:</td>
<td class="text-center td_data"><?php echo $contact->contact_interest_area; ?></td>
<td class="text-center"><input value="1" type="radio" name="ia1"></td>
</div>
</tr>
<tr>
<div class="input-group">
<td class="td_attr">Interest Area 2:</td>
<td class="text-center td_data"><?php echo $contact->contact_interest_area2; ?></td>
<td class="text-center"><input value="1" type="radio" name="ia2"></td>
</div>
</tr>
<tr>
<div class="input-group">
<td class="td_attr">Affilliation:</td>
<td class="text-center td_data"><?php echo $contact->contact_affiliation; ?></td>
<td class="text-center"><input value="1" type="radio" name="affiliation"></td>
</div>
</tr>
<tr>
<div class="input-group">
<td class="td_attr">Source:</td>
<td class="text-center td_data"><?php echo $contact->contact_source; ?></td>
<td class="text-center"><input value="1" type="radio" name="source"></td>
</div>
</tr>
<tr>
<div class="input-group">
<td class="td_attr">Location:</td>
<td class="text-center td_data"><?php echo $contact->contact_location; ?></td>
<td class="text-center"><input value="1" type="radio" name="location"></td>
</div>
</tr>
<tr>
<div class="input-group">
<td class="td_attr">Forum Interests:</td>
<td class="text-center td_data">
<?php
foreach($contact->forum_interests as $forum) {
echo "$forum->forum_1word <br/>";
}
?>
</td>
<td class="text-center vert-align"><input value="1" type="radio" name="forum_interests"></td>
</div>
</tr>
</tbody>
</table>
</div>
<?php $counter++; ?>
<?php endforeach; ?>
<?php for($i = 0; $i < 2; $i++): ?>
<div class="col-sm-6">
<table class="table table-bordered">
<thead>
<tr>
<th colspan="3" class="text-center">Events</th>
</tr>
<tr>
<th>Event Date</th>
<th>Event Title</th>
<th>Invite Status</th>
</tr>
</thead>
<tbody>
<?php foreach($events[$i] as $event): ?>
<tr>
<td><?php echo $event->event_date ?></td>
<td><?php echo $event->event_title; ?></td>
<Td><?php echo $contacts[$i]->invites[$event->event_id]; ?></Td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
<?php endfor; ?>
</form>
</div>
have you tried adding a
div class="row"
to wrap your for loop?

Why are my settings not being saved on wordpress admin?

I am new to wordpress, and I have build a plugin that just saves settings on the admin menu.
But when I click on the save button it just takes me to the options.php page and doesn't do anything. I have looked over my code a couple of times, and I can't seem to find why its not saving, and just stays at the options.php page.
Any help would be really appreciated!! Thanks
function fflOptionsMenuLink(){
add_options_page("Facebook Footer Link Options", "Facebook Footer Link","manage_options","ffl-options","fflOptionsContent" );
}
function fflOptionsContent(){
$opt = get_option("ffl_settings");
$output = "<div class='wrap'>
<h2>Facebook footer link settings </h2>
<form method='post' action='options.php' id='ffl_settings_group'>";
settings_fields('ffl_settings_group');
$output .= "<table class='form-table'>
<tbody>
<tr>
<th scope='row'><label for='ffl_settings[enable]'>Enable</label> </th>
<td><input name='ffl_settings[enable]' type='checkbox' id='ffl_settings[enable]' value='1' ></td>
</tr>
<tr>
<th scope='row'><label for='ffl_settings[facebook_url]'>Facebook Profile </label> </th>
<td><input name='ffl_settings[facebook_url]' type='text' id='ffl_settings[facebook_url]' value='{$opt["ffl_settings"]}' class='regular-text' ></td>
</tr>
<tr>
<th scope='row'><label for='ffl_settings[link_color]'>Enter color or hex value</label> </th>
<td><input name='ffl_settings[link_color]' type='text' id='ffl_settings[link_color]' value='{$opt["link_color"]}' class='regular-text' ></td>
</tr>
<tr>
<th scope='row'><label for='ffl_settings[show_in_feed]'>Show in feed</label> </th>
<td><input name='ffl_settings[show_in_feed]' type='checkbox' id='ffl_settings[show_in_feed]' value='1' ></td>
</tr>
</tbody>
</table>
<p class='submit'><input type='submit' name='submit' id='submit' class='button button-primary' value='Submit'> </p>
";
$output .= "</form>";
$output.="</div>";
echo $output;
}
add_action("admin_menu","fflOptionsMenuLink");
//Register Settings
function fflRegisterSetting(){
register_setting("ffl_settings_group","ffl_settings");
}
add_action("admin_init","ffl_register_setting");
Few Things...
ISSUE - Your function name for registering settings fflRegisterSetting not ffl_register_setting as in your hook.
ISSUE - You are not outputting submit button by wp function
Reminder - facebook_url field has value wrong $opt["link_color"], but since checkboxes are not ready either so I'll consider this a WIP ;)
So your code should look something like this -
function fflOptionsMenuLink(){
add_options_page("Facebook Footer Link Options", "Facebook Footer Link","manage_options","ffl-options","fflOptionsContent" );
}
function fflOptionsContent(){
$opt = get_option("ffl_settings");
echo "<div class='wrap'>
<h2>Facebook footer link settings </h2>
<form method='post' action='options.php' id='ffl_settings_group'>";
settings_fields('ffl_settings_group');
echo "<table class='form-table'>
<tbody>
<tr>
<th scope='row'><label for='ffl_settings[enable]'>Enable</label> </th>
<td><input name='ffl_settings[enable]' type='checkbox' id='ffl_settings[enable]' value='1' ></td>
</tr>
<tr>
<th scope='row'><label for='ffl_settings[facebook_url]'>Facebook Profile </label> </th>
<td><input name='ffl_settings[facebook_url]' type='text' id='ffl_settings[facebook_url]' value='{$opt["facebook_url"]}' class='regular-text' ></td>
</tr>
<tr>
<th scope='row'><label for='ffl_settings[link_color]'>Enter color or hex value</label> </th>
<td><input name='ffl_settings[link_color]' type='text' id='ffl_settings[link_color]' value='{$opt["link_color"]}' class='regular-text' ></td>
</tr>
<tr>
<th scope='row'><label for='ffl_settings[show_in_feed]'>Show in feed</label> </th>
<td><input name='ffl_settings[show_in_feed]' type='checkbox' id='ffl_settings[show_in_feed]' value='1' ></td>
</tr>
</tbody>
</table>
";
submit_button(); // Get the submit button from this function
echo "</form>";
echo "</div>";
}
add_action("admin_menu","fflOptionsMenuLink");
//Register Settings
function fflRegisterSetting(){
register_setting("ffl_settings_group","ffl_settings");
}
add_action("admin_init","fflRegisterSetting");

WooCommerce working with variable pricing issues

I am working with WooCommerce and have my page where I display a single product and it's single pricing. I am changing everything over to be rated at a variable price (Licensing model).
Here is the Single Product Markup:
<?php
/**
* Template Name: Featured Tracks
*/
get_header(); ?>
<div id="content">
<?php while ( have_posts() ) : the_post(); ?>
<div id="post-<?php the_ID(); ?>" <?php post_class('page'); ?>>
<h1><?php the_title(); ?></h1>
<?php echo do_shortcode( '[audio file="'.get_post_meta( get_the_ID(), '_track_preview_file', true ).'" desc="'. get_the_title() .'"]' ); ?>
<table width="100%" border="0" cellspacing="0" cellpadding="0" class="table table-border table-hover">
<tr>
<th scope="row">Price:</th>
<td><span class="middle"><?php global $product, $woocommerce; $product = get_product( get_the_ID() ); echo $product->get_price_html(); ?></span>
</td>
</tr>
<tr>
<th scope="row">Buy Now:</th>
<td><span class="middle">Add To Cart</span></td>
</tr>
<tr>
<th scope="row">Try It Out:</th>
<td><span class="middle">Download Preview</span></td>
</tr>
<th scope="row">Description:</th>
<td><?php the_excerpt(); ?></td>
</tr>
<tr>
<th scope="row">Catalog:</th>
<td><?php the_terms( get_the_ID(), 'product_catalog', '', ', ', '' ); ?></td>
</tr>
<tr>
<th scope="row">Composer:</th>
<td><?php echo get_post_meta( get_the_ID(), '_track_composer', true ); ?></td>
</tr>
<tr>
<th scope="row">Publisher:</th>
<td><?php echo get_post_meta( get_the_ID(), '_track_publisher', true ); ?></td>
</tr>
<tr>
<th scope="row">Keywords:</th>
<td><?php echo $product->get_tags( ', ', '<span class="tagged_as">', '</span>' ); ?></td>
</tr>
<tr>
<th scope="row">Tempo:</th>
<td><?php echo get_post_meta( get_the_ID(), '_track_temp', true ); ?></td>
</tr>
<tr>
<th scope="row">BPM:</th>
<td><?php echo get_post_meta( get_the_ID(), '_track_bpm', true ); ?></td>
</tr>
<tr>
<th scope="row">Length:</th>
<td><?php echo get_post_meta( get_the_ID(), '_track_length', true ); ?></td>
</tr>
</table>
</div><!-- .catalog-item -->
<?php endwhile; wp_reset_query(); ?>
</div><!--#content-->
<?php get_footer(); ?>
The line that prints out the single price is where I am going to include two different links to add the item to your cart depending on the license you want. I am just not too familiar with WooCommerce enough to make that happen
You don't need to add the two links yourself, that's what WooCommerce Product Variations is designed to do.
Once configured, it will include a dropdown menu and automatically adjust the price for the user based on their selection.

WordPress Plugin: How to add a separate page for editing a form

OK so i have a plugin which has its own settings page and all. In the settings i have a form that will display data from a custom table. It looks like this:
<form method="post" action="">
<table>
<tbody>
<tr>
<th>StringVal1</th>
<th>Checked</th>
<th>StringVal2</th>
<th>StringVal3</th>
<th>Configurations</th>
</tr>
<tr>
<td>
<?php echo "Value from table"; ?>
</td>
<td>
<?php
if ($row["Checked"] == 1) {
$checked = ' checked="checked" ';
}
echo "<input name='Checked' type='checkbox' " . $checked . " />";
?>
</td>
<td>
<?php echo "Another value from table"; ?>
</td>
<td>
<?php echo "More value from table"; ?>
</td>
<th>
<div align="center">
<input name="EditButton" type="submit" class="edit-secondary" value="Edit">
</div>
</th>
</tr>
</tbody>
</table>
</form>
When the "Edit" Button is clicked i want to link to another page (for ex. /wp-admin/plugins.php?page=myplugin-settings/edit-form) in order to edit and insert delete rows from the table. So how can i add that extra page i need?

Resources