can you help me with wordpress code editing - wordpress

how can I replace these codes?
I want to take the h1 tag into the price span
enter image description here

You have to add a snippet to your functions.php like this to remove the title:
remove_action( 'woocommerce_shop_loop_item_title', 'woocommerce_template_loop_product_title', 10 );
After that, you have to add a file price.php to your theme in the following folder (you need to create that folder in your theme root):
woocommerce/loop/
With this content
<?php
/**
* Loop Price
*
* This template can be overridden by copying it to yourtheme/woocommerce/loop/price.php.
*
* HOWEVER, on occasion WooCommerce will need to update template files and you
* (the theme developer) will need to copy the new files to your theme to
* maintain compatibility. We try to do this as little as possible, but it does
* happen. When this occurs the version of the template file will be bumped and
* the readme will list any important changes.
*
* #see https://docs.woocommerce.com/document/template-structure/
* #package WooCommerce\Templates
* #version 1.6.4
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
global $product;
?>
<?php if ( $price_html = $product->get_price_html() ) : ?>
<span class="price">
<h1 class="woocommerce-loop-product__title">
<?php echo get_the_title(); ?>
</h1>
<?php echo $price_html; ?>
</span>
<?php endif; ?>

Related

Wordpress, Restrict page & content access to logged in users with a specific role

I'm looking to restrict a page content to a specific role, subscriber, AND redirect all other to the Wordpress registration form.
I've tried to do it, but I was getting an error "content is private" and was getting automatically disconnected.
Could anyone be of assistance?
This is a basic page template using conditional statements to restrict users from viewing specific contents pages. That's probably somewhat what you're looking for, at least you will be close, and you can do some research on your own for the rest. I've commented pretty much everything used. Modify it and have fun.
<?php
if ( ! defined( 'ABSPATH' ) ):
exit;
endif;
/**
* is_user_logged_in
* Determines whether the current visitor is a logged in user.
* #link https://developer.wordpress.org/reference/functions/is_user_logged_in/
*
* wp_get_current_user
* Retrieve the current user object.
* #link https://developer.wordpress.org/reference/functions/wp_get_current_user/
* #link https://wordpress.org/support/article/roles-and-capabilities/
*/
$users = wp_get_current_user();
$roles = array( 'administrator', 'editor', 'author', 'subscriber' );
if ( ! is_user_logged_in() || ! array_intersect( $roles, $users->roles ) ):
/**
* wp_logout
* Log the current user out.
* #link https://developer.wordpress.org/reference/functions/wp_logout/
*/
wp_logout();
/**
* wp_redirect
* Redirects to another page.
* #link https://developer.wordpress.org/reference/functions/wp_redirect/
*
* wp_registration_url
* Returns the URL that allows the user to register on the site.
* #link https://developer.wordpress.org/reference/functions/wp_registration_url/
*/
wp_redirect( esc_url( wp_registration_url() ) );
exit;
endif;
/**
* get_header
* Load header template.
* #link https://developer.wordpress.org/reference/functions/get_header/
*/
get_header();
/**
* The Loop
* #link https://developer.wordpress.org/themes/basics/the-loop/
*/
if( have_posts() ):
while( have_posts() ): the_post();
/**
* get_the_title
* Retrieve post title.
* #link https://developer.wordpress.org/reference/functions/get_the_title/
*
* the_title
* Display or retrieve the current post title with optional markup.
* #link https://developer.wordpress.org/reference/functions/the_title/
*/
if( get_the_title() !== '' ):
esc_attr( the_title() );
endif;
/**
* get_the_content
* Retrieve the post content.
* #link https://developer.wordpress.org/reference/functions/get_the_content/
*
* the_content
* Display the post content.
* #link https://developer.wordpress.org/reference/functions/the_content/
*/
if( get_the_content() !== '' ):
esc_attr( the_content() );
endif;
endwhile;
endif;
/**
* get_footer
* Load footer template.
* #link https://developer.wordpress.org/reference/functions/get_footer/
*/
get_footer(); ?>
Learn more
wp_logout # https://developer.wordpress.org/reference/functions/wp_logout/
wp_redirect # https://developer.wordpress.org/reference/functions/wp_redirect/
wp_registration_url # https://developer.wordpress.org/reference/functions/wp_registration_url/

Wordpress: Advanced Custom Fields not showing up on posts in front end after modifying theme configuration

I installed Advanced Custom Fields and created a field group called "Apps", that shows up whenever a post is made under the apps category. IN that group is a "description" field. The field shows up without fail, or doesn't when the conditions aren't met, while making the post. However, after modifying the singular.php file in the twentytwenty theme to show the field on the front end, nothing changes. I am using the the_field function, like so:
contents of singular.php
<?php
/**
* The template for displaying single posts and pages.
*
* #link https://developer.wordpress.org/themes/basics/template-hierarchy/
*
* #package WordPress
* #subpackage Twenty_Twenty
* #since Twenty Twenty 1.0
*/
get_header();
?>
<main id="site-content" role="main">
<?php
if ( have_posts() ) {
while ( have_posts() ) {
the_post();
get_template_part( 'template-parts/content', get_post_type() );
the_field('Apps_description');
}
}
?>
</main><!-- #site-content -->
<?php get_template_part( 'template-parts/footer-menus-widgets' ); ?>
<?php get_footer(); ?>
I tried putting the the_field function as individual php outside the while loop as well; same result.
Is there something I'm missing? This appears to be what was laid out in the ACF function reference.
Thanks!

how to display only subcategory on the category page without using the taxonomy-product_cat page in woocommerce

<?php
/**
* The Template for displaying products in a product category. Simply includes the archive template
*
* This template can be overridden by copying it to yourtheme/woocommerce/taxonomy-product_cat.php.
*
* HOWEVER, on occasion WooCommerce will need to update template files and you (the theme developer).
* will need to copy the new files to your theme to maintain compatibility. We try to do this.
* as little as possible, but it does happen. When this occurs the version of the template file will.
* be bumped and the readme will list any important changes.
*
* #see http://docs.woothemes.com/document/template-structure/
* #package WooCommerce/Templates
* #version 1.6.4
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
wc_get_template( 'archive-category.php' );
i am developing a E-commerce website in that i want to show only subcategories with their image and name and then after clicking on the subcategory name it should visit to the subcategory products page without affecting the taxonomy-product_cat page what to do please anyone can help ?
it is my code - both taxonomy-product_cat.php and archive-category.php
<?php
/**
* The Template for displaying product archives, including the main shop page which is a post type archive
*
* This template can be overridden by copying it to yourtheme/woocommerce/archive-product.php.
*
* HOWEVER, on occasion WooCommerce will need to update template files and you (the theme developer).
* will need to copy the new files to your theme to maintain compatibility. We try to do this.
* as little as possible, but it does happen. When this occurs the version of the template file will.
* be bumped and the readme will list any important changes.
*
* #see http://docs.woothemes.com/document/template-structure/
* #author WooThemes
* #package WooCommerce/Templates
* #version 2.0.0
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
get_header(); ?>
<div class="container-fluid"><div class="row">
<div class="col-md-10 col-md-offset-2">
<?php
$terms = get_the_terms( $post->ID, 'product_cat' );
foreach ( $terms as $term ){
$category_name = $term->name;
$category_id = $term->term_id;
$category_thumbnail = get_woocommerce_term_meta($term->term_id, 'thumbnail_id', true);
$image = wp_get_attachment_url($category_thumbnail); ?>
<div class="col-lg-3 col-md-4 col-sm-6 col-xs-12">
<div class="hovereffect">
<?php echo '<img class="img-responsive" src="'.$image.'">'; ?>
<div class="overlay">
<h2><?php echo '' . $category_name . ''; ?></h2>
</div>
</div>
</div>
<?php }
?>
</div></div></div>
<?php get_footer(); ?>

How to override Woocommerce Single Product template page with Avada child-theme

I need to redesign the default woocommerce template of a product page.
I have tried this with copying the structure of avada to child-theme.
/theme/avada/woocommerce/single-product/* to /theme/avada-child-theme/woocommerce/single-product/
But I can not find a template that displays the whole page. Only title.php does change the title. But can not find the rest of the page.
I need to delete these parts:
- short description
- sku
- social media buttons
How can I redesign a complete product page is new for me.
May be someone can give me a start where to find the templates.
Thanks in advance.
Herman
<?php
/**
* The template for displaying product content in the single-product.php template
*
* This template can be overridden by copying it to yourtheme/woocommerce/content-single-product.php.
*
* HOWEVER, on occasion WooCommerce will need to update template files and you (the theme developer).
* will need to copy the new files to your theme to maintain compatibility. We try to do this.
* as little as possible, but it does happen. When this occurs the version of the template file will.
* be bumped and the readme will list any important changes.
*
* #see http://docs.woothemes.com/document/template-structure/
* #author WooThemes
* #package WooCommerce/Templates
* #version 1.6.4
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
?>
<?php
/**
* woocommerce_before_single_product hook.
*
* #hooked wc_print_notices - 10
*/
do_action( 'woocommerce_before_single_product' );
if ( post_password_required() ) {
echo get_the_password_form();
return;
}
?>
<div itemscope itemtype="<?php echo woocommerce_get_product_schema(); ?>" id="product-<?php the_ID(); ?>" <?php post_class(); ?>>
<?php
/**
* woocommerce_before_single_product_summary hook.
*
* #hooked woocommerce_show_product_sale_flash - 10
* #hooked woocommerce_show_product_images - 20
*/
do_action( 'woocommerce_before_single_product_summary' );
?>
<div class="summary entry-summary">
<?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
*/
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_excerpt', 20);
do_action( 'woocommerce_single_product_summary' );
?>
</div><!-- .summary -->
<?php
/**
* woocommerce_after_single_product_summary hook.
*
* #hooked woocommerce_output_product_data_tabs - 10
* #hooked woocommerce_upsell_display - 15
* #hooked woocommerce_output_related_products - 20
*/
do_action( 'woocommerce_after_single_product_summary' );
?>
<meta itemprop="url" content="<?php the_permalink(); ?>" />
</div><!-- #product-<?php the_ID(); ?> -->
<?php do_action( 'woocommerce_after_single_product' ); ?>
I don't know about the Avada theme, but in default WooCommerce you can see in the content-single-product.php template that short description and social buttons are added via hook. So to remove them you'd need to use remove_action() from your theme's functions.php.
If this doesn't work as is, please review remove_action() because you just need to make sure that the parameters match up to what the Avada theme is doing.
function so_35252579_remove_hooks(){
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_excerpt', 20 );
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_sharing', 50 );
}
add_action( 'woocommerce_before_single_product', 'so_35252579_remove_hooks' );
To remove the SKU, you could either disable skus, or if you need them but don't want to display them on the front end then you would need to override single-product/meta.php
Here is the code. You can write it as a plugin or simply copy paste to functions.php. Note the following
locate_template function is first look at active theme root directory for the file. If the file is present there then it will use. otherwise plugin folder will be check.
First if condition simply checking whether the current page is showing is single product page. you can add more conditional tags based on you requirement.
add_filter( 'wc_get_template_part', 'so_29984159_custom_content_template_part', 10, 3 );
function so_29984159_custom_content_template_part( $template, $slug, $name ){
if ( $slug == 'content' && $name == 'single-product') {
if( locate_template('content-single-product-custom.php') ) {
$template = locate_template( $file_name );
} else {
// Template not found in theme's folder, use plugin's template as a fallback
$template = dirname( __FILE__ ) . '/content-single-product-custom.php';
}
}
return $template;
}

WooCommerce: List Variations Available

I'm trying to display the variations of a products in the category page, something like
"Product Image"
"Product Title"
from $107 - $ 200 (I got this done)
Available in: 5lb / 10lb / 20lb (I'm trying to achieve this)
I read online and found this function but i couldn't get it to work, keep saying function does not exist.
<?php
/**
* Loop Price
*
* #author WooThemes
* #package WooCommerce/Templates
* #version 1.6.4
*/
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
global $product;
?>
<?php if ( $price_html = $product->get_price_html() ) : ?>
<span class="price"><?php echo $price_html; ?></span>
<?php endif; ?>
<?php
**if ($product->get_variation_attributes(size)) {
echo $product->get_variation_attributes(size);
}**
?>
What i wish to achieve is fairly simple, I just need to let customers know that there are different bag size of my products available, however a simple "From $100" as per custom woocommerce template does not let novice online shopper know that means there are other variations.
I've added Size attribute under each of my variation products like 5KG, 6KG, 7Lb, and hope to display them in front page in red.
I do not need sophiscated solutions like drop down list or whatsoever, just plain display if variation is available.
Hope Someone can point me to some direction.
Update: This is my current solution, however, If i can list down the variation available it will be a bonus.
if ( $product->max_variation_price && $product->max_variation_price !== $product->min_variation_price ) {
echo "<span style='font-size:75%; color: red; display: block;'>Available in Various Sizes</span>";
}

Resources