Year End Sale -2o% Off On All Products - Coupon: FMADEC2017

Top 5 Questions and Answers Regarding Magento and WordPress Programming Issues Part - 2

Coding of any website is getting harder with the passage of time, especially on a WooCommerce or Magento website. Because website owners demand unique functionality on their websites to beat their competitors.  That is why many programmers ask coding related questions on the different platform when they are unable to build the code or get issues while coding any website. FMEAddons have chosen most asked questions regarding Magento and WordPress Programming issues asked by programmers and have mentioned in this article with their solutions. The answers mentioned in this article are given by top community members and do not represent us.

Question No. 1

A user enables the two radio buttons on a WooCommerce product page and wants to surcharge customer if he chooses one option and not for other option. Plus, he also wants to update the checkout accordingly.

He has used this code to achieve this but got issues.

add_action( 'woocommerce_cart_calculate_fees','woocommerce_custom_surcharge' );

function woocommerce_custom_surcharge() {

global $woocommerce;

$surcharge = 5.32;

$woocommerce->cart->add_fee( 'Surcharge', $surcharge, true, '' );

}

Answer

Please create an Ajax which will handle these radio buttons and add action in a surcharge function. Then add the right cart->add_fee.

Or you can simply download WooCommerce product options addon by FMEAddons which allows you to create product options and charge the price accordingly. It also displays the additional fields on checkout page as well.

Question No. 2

A user has WordPress website and wants to display different header for single post page. He tried a lot but failed to change the header of a single page.

Answer

You can use this code if you want to change the header of a single post page.

<?php get_header(‘single’); ?>

Question No. 3

A user want to add cart button to the web pages of WooCommerce website and he has the following code.

<?php woocommerce_product_loop_start(); ?>

<?php woocommerce_product_subcategories(); ?>

<?php while ( have_posts() ) : the_post(); ?>

<div id="product-image1">

<a href="<?php echo esc_url( get_permalink( $product->id ) ); ?>" title="<?php echo esc_attr( $product->get_title() ); ?>">

<?php echo $product->get_image(); ?>

</a>

</div>

<div id="product-description-container">

<ul>

<a href="<?php echo esc_url( get_permalink( $product->id ) ); ?>" title="<?php echo esc_attr( $product->get_title() ); ?>">

<li><h4><?php echo $product->get_title(); ?></h4></li></a>

<li><?php echo apply_filters( 'woocommerce_short_description', $post->post_excerpt )?></li>

<li><h6><?php echo $product->get_price_html(); ?>  **MISSING CODE TO ADD TO CART BUTTON HERE**</h6></li>

</ul>

</div>

<?php endwhile; // end of the loop. ?>

Answer

Please use this code in place of (**MISSING CODE TO ADD TO CART BUTTON HERE**) to enable add to cart button.

global $product;

echo apply_filters( 'woocommerce_loop_add_to_cart_link',

sprintf( '<a href="%s" rel="nofollow" data-product_id="%s" data-product_sku="%s" class="button %s product_type_%s">%s</a>',

esc_url( $product->add_to_cart_url() ),

esc_attr( $product->id ),

esc_attr( $product->get_sku() ),

$product->is_purchasable() ? 'add_to_cart_button' : '',

esc_attr( $product->product_type ),

esc_html( $product->add_to_cart_text() )

),

$product );

Question No. 4

A user is using Magento on his website and facing an issue that product review form and product reviews are not showing up on the product page. He is facing this issue since he changed his Magento theme.

Answer

Please check the product/view.phtml if it is missing and the code should be like this

<?php echo $this->getChildHtml('product_additional_data') ?>

Or you can just download Magento product review extension by FMEAddons to enable review form on product pages for your customers. With the help of this extension, customers can also rate price, quality, and value of a product.

Question No. 5

A Magento user is unable to find the upload picture button at the back office and he is using Mozilla Firefox on his Mac book.

Answer

Please install latest flash version on your laptop or you can use Chrome browser to make the upload button appeared at the back-end of your Magento website.

Leave a Reply