Showing posts with label WooCommerce. Show all posts
Showing posts with label WooCommerce. Show all posts

Wednesday, 20 April 2022

How to Removing product _ product-category _ or shop from the URLs in WordPress, WooCommerce?

Here, Removing /product/, /product-category/, or /shop/ from the URLs is not advisable due to the way WordPress resolves its URLs. It uses the product-category (or any other text for that matter) base of an URL to detect that it is an URL leading to a product category.

There are SEO plugins that allow you to remove this base, but that can lead to a number of problems with performance and duplicate URLs.


Try following Plugins:-
1> Remove slug from custom post type
https://wordpress.org/support/plugin/remove-slug-from-custom-post-type
Just install & activate this plugin/remove-slug-from-custom-post-type

2> SEO Ultimate
https://wordpress.org/plugins/seo-ultimate/
In SEO Ultimate settings under 'Permalink Tweaker' check the 'Product Categories' and save.


For more Interesting, Useful Article & codes visit IT New Code.

On logged in user can view WP site? How to Make Member only site?

Add following code in theme "functions.php"  file




/*************************************************************************************************************
 * Only logged in user can view site except Login, Register, Password-Recovery & successful Registration pages
 *************************************************************************************************************/
add_action( 'wp', 'members_only' );
function members_only() {
    // Restrict unlogged user
    if( !is_user_logged_in() ) {
        // id specified page then execute
        // 789 is page id for "Registration" page.
        // 792 is page id for "Login" page is also Home page.
        // 796 is page id for "Password Recovery" page.
        // 868 is page id for "Successful Registration" page.
        // is_front_page() for website main page.
        if (is_page(789) || is_page(792) || is_page(796) || is_page(868) || is_front_page() ) {
           // echo "This is current page";
        }
        else {
            // Redirect to Home page.
            //wp_redirect( get_home_url() );
            wp_redirect( 'https://www.example.com/wp-login.php' );
            exit;
        }
    }
}

Monday, 31 October 2016

How to hide Coupon form in WooCommerce, WordPress?

In case you're not utilizing coupons by any stretch of the imagination, you can conceal the structure on the truck and checkout page by unchecking "coupons checkbox" from WooCommerce > Settings > General, yet most times you'll need to leave coupons empowered on the off chance that you have to give a client a rebate for reasons unknown.

Or Can Disable it by adding following code.


Add following code in "functions.php" file.

<?php
// hide coupon form everywhere in woocommerce site
function hide_coupon_field( $enabled ) {
if ( is_cart() || is_checkout() ) {
$enabled = false;
}

return $enabled;
}
add_filter( 'woocommerce_coupons_enabled', 'hide_coupon_field' );
?>



For more Interesting, Useful Article & codes visit IT New Code.

Woocommerce add to cart button redirect to checkout Learn

Method 1 for manual link:-

Try WooCommerce default method for add to cart button redirect to checkout. You can find the option in the WooCommerce -> Settings -> Products -> Display area. When the option “Redirect to the cart page after successful addition” is checked it will redirect all users to the cart after adding a product to the cart.
Uncheck it.



Then directly use following code:-
<a href="/checkout/?add-to-cart=2817&amp;quantity=1">Add to Cart</a>
2817 is procuct id.
1 is number of products add in cart.

Method 2:-

1. You can find the option in the WooCommerce -> Settings -> Products -> Display area. When the option “Redirect to the cart page after successful addition” is checked it will redirect all users to the cart after adding a product to the cart.
Uncheck it.



2. Woocommerce > Settings > Checkout (Tab) - where you should select pages for cart and checkout.
Selcect Cart Page as Checkout option from drop down menu.


Just it.
Now, Add to cart button will redirect to checkout page.


For more Interesting, Useful Article & codes visit IT New Code.




Saturday, 8 October 2016

How to hide other Shipping methods When free Shipping is available in WooCommerce, WordPress?


Some times there are many methods use for diffident need & conditions in WooCommerce. In it one comman condition is like "Hide other Shipping methods When free Shipping is available". Below is given solution of this condition.

First create Free Shipping method with condition.Then,

Add following code in functions.php file


Snippets for WooCommerce 2.5
<?php
/**
 * woocommerce_package_rates is a 2.1+ hook
 */
add_filter( 'woocommerce_package_rates', 'hide_shipping_when_free_is_available', 10, 2 );

/**
 * Hide shipping rates when free shipping is available
 *
 * @param array $rates Array of rates found for the package
 * @param array $package The package array/object being shipped
 * @return array of modified rates
 */
function hide_shipping_when_free_is_available( $rates, $package ) {
 
  // Only modify rates if free_shipping is present
  if ( isset( $rates['free_shipping'] ) ) {
 
  // To unset a single rate/method, do the following. This example unsets flat_rate shipping
  unset( $rates['flat_rate'] );
 
  // To unset all methods except for free_shipping, do the following
  $free_shipping          = $rates['free_shipping'];
  $rates                  = array();
  $rates['free_shipping'] = $free_shipping;
}

return $rates;
}
?>



Snippets for WooCommerce Version 2.6+
<?php
/**
 * Hide shipping rates when free shipping is available.
 * Updated to support WooCommerce 2.6 Shipping Zones.
 *
 * @param array $rates Array of rates found for the package.
 * @return array
 */
function my_hide_shipping_when_free_is_available( $rates ) {
$free = array();
foreach ( $rates as $rate_id => $rate ) {
if ( 'free_shipping' === $rate->method_id ) {
$free[ $rate_id ] = $rate;
break;
}
}
return ! empty( $free ) ? $free : $rates;
}
add_filter( 'woocommerce_package_rates', 'my_hide_shipping_when_free_is_available', 100 );
?>





For more Interesting, Useful Article & codes visit IT New Code.


Wednesday, 27 July 2016

How to Rename Coupon Code fields with WooCommerce, WordPress?


Just renaming the coupon field to something else can likewise diminish the quantity of clients that leave your site amid checkout to discover coupon codes. Clients that as of now have the code will comprehend what name to search for whatever length of time that you're steady. For instance, on the off chance that you email out "Offer Codes" or "Promo Codes", then clients will search for this field, yet those without coupons won't get occupied by the words "coupon" or 'rebate'.

Simply following the steps of code changing for rename the coupon code fields.

Add following code in "functions.php" file.


<?php
/************************************************
 * rename the coupon field on the cart page
 ************************************************/
function woocommerce_rename_coupon_field_on_cart( $translated_text, $text, $text_domain ) {
// bail if not modifying frontend woocommerce text
if ( is_admin() || 'woocommerce' !== $text_domain ) {
return $translated_text;
}
if ( 'Apply Coupon' === $text ) {
$translated_text = 'Apply Promo Code';
}
return $translated_text;
}
add_filter( 'gettext', 'woocommerce_rename_coupon_field_on_cart', 10, 3 );



/************************************************
 * rename the "Have a Coupon?" message on the checkout page
 ************************************************/
function woocommerce_rename_coupon_message_on_checkout() {
return 'Have a Promo Code?' . ' <a href="#" class="showcoupon">' . __( 'Click here to enter your code', 'woocommerce' ) . '</a>';
}
add_filter( 'woocommerce_checkout_coupon_message', 'woocommerce_rename_coupon_message_on_checkout' );
// rename the coupon field on the checkout page
function woocommerce_rename_coupon_field_on_checkout( $translated_text, $text, $text_domain ) {
// bail if not modifying frontend woocommerce text
if ( is_admin() || 'woocommerce' !== $text_domain ) {
return $translated_text;
}
if ( 'Coupon code' === $text ) {
$translated_text = 'Promo Code';

} elseif ( 'Apply Coupon' === $text ) {
$translated_text = 'Apply Promo Code';
}
return $translated_text;
}
add_filter( 'gettext', 'woocommerce_rename_coupon_field_on_checkout', 10, 3 );

?>

Above bold text place do rename as you need.



For more Interesting, Useful Article & codes visit IT New Code.

Sunday, 19 June 2016

How to change Product page structure in WordPress, WooCommerce?

1> Create folder "woocommerce" in your theme.
2> your product page templte at following address:
   "/public_html/wp-content/plugins/woocommerce/templates"
3> download "content-single-product.php" file & put in theme "woocommerce" folder
4> "content-single-product.php" code Under standing below:
<?php
/**
* woocommerce_single_product_summary hook
*
* @hooked woocommerce_template_single_title - 5
* @hooked woocommerce_template_single_rating - 10
* @hooked woocommerce_template_single_price - 10
* @hooked woocommerce_template_single_excerpt - 20
* @hooked woocommerce_template_single_add_to_cart - 30
* @hooked woocommerce_template_single_meta - 40
* @hooked woocommerce_template_single_sharing - 50
*/

do_action( 'woocommerce_single_product_summary' );
?>
Above code can be print product title,Price,short discription etc.
To change it go follwing path
"/public_html/wp-content/plugins/woocommerce/includes/wc-template-hooks.php" file.

You can see follwing code:
/**
* Product Summary Box.
*
* @see woocommerce_template_single_title()
* @see woocommerce_template_single_rating()
* @see woocommerce_template_single_price()
* @see woocommerce_template_single_excerpt()
* @see woocommerce_template_single_meta()
* @see woocommerce_template_single_sharing()
*/
add_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_title', 5 );
add_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_rating', 10 );
add_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_price', 10 );
add_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_excerpt', 20 );
add_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_meta', 40 );
add_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_sharing', 50 );

From here it comes output.

5> for remove any function copy following code in your "functions.php" file in your theme.
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_title', 5 );
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_rating', 10 );
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_price', 10 );
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_excerpt', 20 );
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_meta', 40 );
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_sharing', 50 );

Code for Product Title:-
<?php if( mfn_opts_get('shop-product-title') != 'sub' ): ?>
<center><h1 itemprop="name" class="product_title entry-title product_title"><?php the_title(); ?></h1></center>
<?php endif; ?>

Code for Short discription:-
<div itemprop="description" class="wooshortdiscription">
<?php echo apply_filters( 'woocommerce_short_description', $post->post_excerpt ) ?>
</div>

Take code from "/public_html/wp-content/plugins/woocommerce/templates/single-product" files & put in Your "content-single-product.php" as you need.

6> Never change original file because when its update your modified code will be lost.


    
For more Interesting, Useful Article & codes visit IT New Code.

How to Remove Tabs in product page in WordPress, WooCommerce?

Open Theme "function.php" then enter following code.


add_filter( 'woocommerce_product_tabs', 'woo_remove_product_tabs', 98 );

function woo_remove_product_tabs( $tabs ) {

    unset( $tabs['description'] );       // Remove the description tab
    unset( $tabs['reviews'] ); // Remove the reviews tab
    unset( $tabs['additional_information'] );   // Remove the additional information tab

    return $tabs;

}


For more Interesting, Useful Article & codes visit IT New Code.

How to remove some type sorting in WordPress, WooCommerce?

Open "function.php" file in your theme.
then enter following code.


// Modify the default WooCommerce orderby dropdown
//
// Options: menu_order, popularity, rating, date, price, price-desc

function my_woocommerce_catalog_orderby( $orderby ) {
    unset($orderby["price"]);
    unset($orderby["price-desc"]);
    return $orderby;
}
add_filter( "woocommerce_catalog_orderby", "my_woocommerce_catalog_orderby", 20 );



For more Interesting, Useful Article & codes visit IT New Code.

How to set Product image as use original Image in WordPress, WooCommerce?

1> Open WooCommerce Plugin in Plugins > woocommerce

2> Following templete for Product Image code
      templates/single-product/product-image.php

3> Following is "Product-image.php" code.
<?php

/**
 * Single Product Image
 *
 * @author WooThemes
 * @package WooCommerce/Templates
 * @version     2.0.14
 */

if ( ! defined( 'ABSPATH' ) ) {
  exit; // Exit if accessed directly
}

global $post, $woocommerce, $product;

?>
<div class="images">

<?php
    if ( has_post_thumbnail() ) {

      $image_title   = esc_attr( get_the_title( get_post_thumbnail_id() ) );
      $image_caption   = get_post( get_post_thumbnail_id() )->post_excerpt;
      $image_link    = wp_get_attachment_url( get_post_thumbnail_id() );
      $image         = get_the_post_thumbnail( $post->ID, apply_filters( 'single_product_large_thumbnail_size', 'shop_single' ), array(
        'title'  => $image_title,
        'alt'  => $image_title
        ) );

      $attachment_count = count( $product->get_gallery_attachment_ids() );

      if ( $attachment_count > 0 ) {
        $gallery = '[product-gallery]';
      } else {
        $gallery = '';
      }

      echo apply_filters( 'woocommerce_single_product_image_html', sprintf( '<a href="%s" itemprop="image" class="woocommerce-main-image zoom" title="%s" data-rel="prettyPhoto' . $gallery . '">%s</a>', $image_link, $image_caption, $image ), $post->ID );

    } else {

      echo apply_filters( 'woocommerce_single_product_image_html', sprintf( '<img src="%s" alt="%s" />', wc_placeholder_img_src(), __( 'Placeholder', 'woocommerce' ) ), $post->ID );

    }
  ?>

<?php do_action( 'woocommerce_product_thumbnails' ); ?>

</div>


4> Replace Following code by "$image = the_post_thumbnail( 'large','style=max-width:100%;height:auto;');".

Code:-
    $image = get_the_post_thumbnail( $post->ID, apply_filters( 'single_product_large_thumbnail_size', 'shop_single' ), array(
        'title'  => $image_title,
        'alt'  => $image_title
        ) );

5> SAVE and Check on front.


For more Interesting, Useful Article & codes visit IT New Code.

How to Empty Price display on cart button WordPress, WooCommerce?

Add Following code to "function.php" file


function custom_woocommerce_is_purchasable( $purchasable, $product ){
    if( $product->get_price() == 0 ||  $product->get_price() == '')
        $purchasable = true;
    return $purchasable;
}
add_filter( 'woocommerce_is_purchasable', 'custom_woocommerce_is_purchasable', 10, 2 );



For more Interesting, Useful Article & codes visit IT New Code.

Saturday, 18 June 2016

How to Disable payment Getway in WordPress, WooCommerce Plugin?

Add following code in "function.php" file.


Code:-
<?php
add_filter('woocommerce_cart_needs_payment', '__return_false');
?>



For more Interesting, Useful Article & codes visit IT New Code.

How to create Product "Add to Cart" type Button manually in WordPress, WooCommerce?

First create product in WooCommerce.

Then Where You want to put button Put following code:


Button anchor tag:-
----------------------------------------
<a href="/test_new_guided/?add-to-cart=2526">Add to Bag</a>


Add direct 5 product in cart:-
----------------------------------------
<a href="/test_new_guided/?add-to-cart=2526&quantity=5">Add to Bag</a>


Here, 2526 is product id.



For more Interesting, Useful Article & codes visit IT New Code.

How to Add new tab with contact form, Product form, Product Inquiry Form in Wordpress, WooCommerce?

1>  Install Contact form 7 plugin first.
    then create new form in it with following code:

 <p>Your Name (required)<br />
        [text* your-name] </p>

    <p>Your Email (required)<br />
        [email* your-email] </p>

    <p class="product_subject">Subject<br />
        [text your-subject class:product_name] </p>

    <p>Your Message<br />
        [textarea your-message] </p>

    <p>[submit "Send"]</p>


2>  Then open themes "function.php" file & put follwing code in it:

add_filter( 'woocommerce_product_tabs', 'product_enquiry_tab' );
function product_enquiry_tab( $tabs ) {

    $tabs['test_tab'] = array(
        'title'     => __( 'Enquire about Product', 'woocommerce' ),
        'priority'  => 50,
        'callback'  => 'product_enquiry_tab_form'
    );

    return $tabs;

}
function product_enquiry_tab_form() {
    global $product;
    //If you want to have product ID also
    //$product_id = $product->id;
    $subject    =   "Enquire about ".$product->post->post_title;

    echo "<h3>".$subject."</h3>";
    echo do_shortcode('[contact-form-7 id="19" title="Contact form 1_copy"]'); //add your contact form shortcode here ..

    ?>

    <script>
    (function($){
        $(".product_name").val("<?php echo $subject; ?>");
    })(jQuery);
    </script>
    <?php
}
    ?>


Its Done.



For more Interesting, Useful Article & codes visit IT New Code.

How to add new checkbox for terms & condition in checkout page for WordPress, WooCommerce Plugin?

Below given all code is single code, Put following code in theme "function.php" file:


/**
 * Add checkbox field to the checkout
 **/
add_action('woocommerce_after_order_notes', 'my_custom_checkout_field');

function my_custom_checkout_field( $checkout ) {

    echo '<div id="my-new-field"><h3>'.__('Terms & Condition: ').'</h3>';
echo '<span class="mustcheck"><p>'.__('Must Check terms & condition *').'</p></span>';
    woocommerce_form_field( 'my_checkbox', array(
        'type'          => 'checkbox',
        'class'         => array('input-checkbox'),
        'label'         => __('Terms of Policy'),
        'required'  => true,
        ), $checkout->get_value( 'my_checkbox' ));

 
woocommerce_form_field( 'my_checkbox1', array(
        'type'          => 'checkbox',
        'class'         => array('input-checkbox'),
        'label'         => __('Terms of Use'),
        'required'  => true,
        ), $checkout->get_value( 'my_checkbox1' ));

 
woocommerce_form_field( 'my_checkbox2', array(
        'type'          => 'checkbox',
        'class'         => array('input-checkbox'),
        'label'         => __('Refund Policy'),
        'required'  => true,
        ), $checkout->get_value( 'my_checkbox2' ));

    echo '</div>';
}



/**
 * Process the checkout
 **/
add_action('woocommerce_checkout_process', 'my_custom_checkout_field_process');

function my_custom_checkout_field_process() {
    global $woocommerce;

    // Check if set, if its not set add an error.
    if (!$_POST['my_checkbox'])
         $woocommerce->add_error( __('Please agree to Terms of Policy.') );

if (!$_POST['my_checkbox1'])
         $woocommerce->add_error( __('Please agree to Terms of Use.') );

if (!$_POST['my_checkbox2'])
         $woocommerce->add_error( __('Please agree to Refund Policy.') );
}



/**
 * Update the order meta with field value
 **/
add_action('woocommerce_checkout_update_order_meta', 'my_custom_checkout_field_update_order_meta');

function my_custom_checkout_field_update_order_meta( $order_id ) {
    if ($_POST['my_checkbox']) update_post_meta( $order_id, 'My Checkbox', esc_attr($_POST['my_checkbox']));
if ($_POST['my_checkbox1']) update_post_meta( $order_id, 'My Checkbox1', esc_attr($_POST['my_checkbox1']));
if ($_POST['my_checkbox2']) update_post_meta( $order_id, 'My Checkbox2', esc_attr($_POST['my_checkbox2']));
}


Save it & Now Check Your checkout page.


For more Interesting, Useful Article & codes visit IT New Code.

 

Copyright @ 2016 IT New Code | Developing Code | Designing Code.

Designed by: Ankit Shah