Overwrite $wp_customize from wordpress plugin - php

I am using a simple theme in WordPress, that pulls it's customizers sections from the plugin ThemeHunk Customizer.
I want to hide certain sections in the customizer section, but when using $wp_customize, it isn't working.
This is what I am trying to hide:
$wp_customize->add_section('section_home_ordering', array(
'title' => __('Section Ordering', 'featuredlite'),
'priority' => 3,
));
This is located in the /wp-content/plugins/themehunk-customizer/featuredlite/customizer/customizer.php file.
I have added this to my functions.php file in my child theme directory:
function customize_register_init( $wp_customize ){
$wp_customize->remove_section('section_default_home');
$wp_customize->remove_section('pro_button');
$wp_customize->remove_section('Docs_button');
$wp_customize->remove_section('section_home_ordering'); - THIS IS THE SECTION I would like removed from the /plugin/ file
}
add_action( 'customize_register', 'customize_register_init', 99 );
It doesn't seem to remove though, like it would if you were removing a section from a parent theme.
Is there another method to do this, or is this not possible to remove from a plugin rather than a parent theme?
Thank you in advance.
SOLVED I use the customize_controls_enqueue_scripts hook to input custom CSS within the wordpress customizer, so I can display certain elements as hidden!

In theme your code works fine. Maybe it depends on action hooks order.
Have you tried?
add_action( 'plugins_loaded', 'customize_register_init', 99 );

You can simply go with these documentation as it shows you can disable particular section of Home Page (FrontPage). You can change order of appearance also from the Appearance > Frontpage Section > Section Ordering.
Reference Link: https://themehunk.com/docs/shopline-theme/#frontpage-section
https://themehunk.com/product/shopline-free-shopping-theme/

Related

Woocommerce conditionally load a custom product template

I am creating a custom theme and I have copied the file content-product.php to my theme folder. There I have made changes to the html structure and css. I can load of list of products and see the changes working via the short code [products].
However elsewhere on the site I want to display another list of products but from a different category. I would use the shortcode [products category="special category"] These products should be displayed using a different template.
My question is: Where can I inspect the shortcode query? and how can I conditionally load a different template depending on which products are being displayed?
In my themes functions.php file I have started to extend the [products] shortcode like this:
function my_wc_shortcode_product_query_args($args, $atts){
if ( isset( $args['category'] ) && $args['category'] == "Daoine Óga") {
var_dump($args);
// Tell Woocommerce to load my custom template instead of the my-theme/woocommerce/content-product.php
}
return $args;
}
But I'm not sure how I can return or get woocommerce to display my custom template at this point.
The woocommerce file that creates the [products] shortcode can be found at plugins/woocommerce/includes/shortcodes/class-wc-shortcode-products.php
Make a folder in plugins folder called custom-product-templates and make a copy of the woocommerce file class-wc-shortcode-products.php to that folder.
Add the plugin comments to the top of that file:
/*
Plugin name: Custom Product Template
Plugin URI: https://anirishwebdesigner.com
Description: Display custom product templates in woocommerce loop
Author: Linda Keating
Author URI: http://anirishwebdesigner.com
Version: 1.0
*/
Navigate to localhost/wp-admin in browser and to the plugins and activate newly created plugin
I can now safely edit that file so that the shortcode behaviour loads the template I want based on certain criteria.
First extend the class so that it accepts a template attribute
In the parse attributes function add
'template' => '',
Then search for wc_get_template_part('content', 'product'); and modify the code here to load different templates in an if..else statement. Something like:
`if($this->attributes['template'] == 'Daoine Óga') {
wc_get_template_part( 'content', 'childrenproduct' );
} else {
wc_get_template_part( 'content', 'product' );
}`
If there are simpler / better solutions please let me know.

Trying to overwrite / append editor-style.css from parent theme in child theme

I am using the good old twenty eleven for a simple job and overwrite styles using a child.
The Problem is, that editor styles are not overwritten when i add an editor-child.css in the child theme folder.
Adding add_editor_style in the child themes functions.php (wrapped in after_setup_theme) doesn't seem to work. Can't I load multiple editor styles or what is the problem here? I can't figure out how I can overwrite this ugly twenty eleven editor css in gutenberg. It might even be better to disable it, but even that doesn't work using remove_editor_style. And I can't find anything on the subject using google or stackoverflow.
<?php
// In the child theme functions.php. I simply want to use the style.css by the child theme as an extra editor style
function wysiwyg_styles() {
add_editor_style( get_stylesheet_uri() );
}
add_action( 'after_setup_theme', 'wysiwyg_styles');
?>
No css is loaded in the admin (after deleting chache AND cookies)
What happen is that you're using the wrong action hook... you should be using the admin_enqueue_scripts hook.
Try doing it like this.. and check if it works for you:
add_action('admin_enqueue_scripts', function () {
wp_enqueue_style('admin-styles', get_stylesheet_directory_uri().'/pathToYour.css');
});
// If the above does not work change get_stylesheet_directory_uri() for get_template_directory_uri()
Hope this can help, good luck.
You can try instead:
add_theme_support( 'editor-styles' );
add_editor_style( 'style-editor.css' );
in your functions.php. Haven’t checked if it works with a child theme though.
More information here:
https://developer.wordpress.org/block-editor/developers/themes/theme-support/

Remove "Custom fields" metabox in Woocommerce order edit pages

I'm trying to remove the 'postcustom' meta box from the order details for a simple wooCommerce shop. The div #postcustom appears in Orders--->Click on single order --> bottom of page as 'Custom Fields'. I want to get rid of it. There are loads of examples of how to do this by calling the following function:
function remove_custom_field_meta_box()
{
remove_meta_box('postcustom', 'page', 'normal');
}
I've hooked it (currently) into:
//Remove postcustom meta box
add_action('admin_menu', 'remove_custom_field_meta_box');
I've also tried 'dashboard' and 'post' as $context to no avail.
I've also tried hooking to remove_meta_boxes, admin_init, and a few others.
I'm working in a child themes functions.php and using the default wooCommerce theme. Any thoughts on why this isn't firing? That pesky #postcustom div is still there in the admin menu! Is my context incorrect? I also tried 'orders'. Thanks#
Updated: For orders in Woocommerce the post type is 'shop_order', so your code should be:
add_action( 'add_meta_boxes', 'remove_shop_order_meta_boxe', 90 );
function remove_shop_order_meta_boxe() {
remove_meta_box( 'postcustom', 'shop_order', 'normal' );
}
Code goes in function.php file of your active child theme (or active theme). Tested and works.
Or you can hide it hitting the "screen options" tab and unchecking "Custom Fields" checkbox:

Woocommerce shop page custom template

As I understand by default Woocommerce shop page uses product archive template. What I am looking for, is to use a custom template for shop page.
Here is what I did:
Create template "my-shop"
Create page "My shop" -> choose template "my-shop"
Choose "My shop" as Woocommerce shop page
But none of the changes I made to "my-shop" template are present on the shop page.
What am I missing here? I would not like to change product archive itself, just the shop page.
Is there a way to disable product archive from being a default for shop page?
Thanks
I know it's too late and you may have figured it out by now. In any case, the changes that you would like to make to the WooCommerce Shop Page need to be done in the archive-product.php and it would be safer to create a child theme and do these changes. Making enhancements and customizations in a Child theme is best practice so that you can update the parent theme at any time and it won't affect your store.
I hope this helps, for more information on how you can use WooCommerce short-codes to customize your store can be found here.
To add to Silver Ringvee's answer - he used is_page but that only works on wordpress pages. For woocommerce you need to use something like is_woocommerce() . See Woocommerce conditional tags page.
My example code uses the is_shop conditional tag as that was the page you wanted to change. the code get_template_part( 'content', 'shop' ); will call the file content-shop.php in your theme root folder. This code is to be added at the top of wp-content\themes\*theme*\woocommerce\archive-product.php that you can copy from wp-content\plugins\woocommerce\templates\archive-product.php
You can add it just before get_header( 'shop' ); line 23 in my file - and the entire page will be drawn from your template. If you want to keep the header of the shop page, then put this code after the get_header code. Remember to include a footer in your file as well
if (is_shop()) {
get_template_part( 'content', 'shop' );
} else {
#normal archive-product code here
}
The solution (not perfect) that I figured to work best, until someone finds a way to actually change the template from dashboard:
Adding:
<?php
if (is_page( 'Page Title' ) ):
# Do your stuff
endif;
?>
to content-product.php in my theme's woocommerce folder.
If you prefer to go with code, you can create a redirect from the original shop page to your page via wp_redirect.
add_action('template_redirect', 'bc_010101_redirect_woo_pages');
function bc_010101_redirect_woo_pages()
{
if (is_shop())
{
wp_redirect('your_shop_url_here');
exit;
}
}
More detailed tutorial can be found here
This is not possible to create custom template for shop page , just copy and paste woocommerce Templates into you theme folder and Try to work in content-product.php template .

How to add a new header menu in wordpress?

How to add a new header menu in wordpress?
You may add a function to wordpress (well anywhere in your theme) using the wp_nav_menu(). This requires that you add the code below to your functions.php file (if you do not have one in your theme directory then create one):
add_action( 'init', 'register_my_menus' );
function register_my_menus() {
register_nav_menus(
array(
'menu-1' => __( 'Top menu' ),
'menu-2' => __( 'Bottom menu' )
)
);
}
Change the "Top menu" and "Bottom menu" to what ever you want the names to be. Basically you are just telling wordpress (wp 3.+) to make reservations for these menu in your theme. If you want more you just need to define the names in a new line. Save that.
That done you will need to add the menu in your site template. Usually I define the arguments first before I call the wp_nav_menu() function. Read up on the arguments here http://codex.wordpress.org/Function_Reference/wp_nav_menu
Hope that helps.
You can manage the menus in your WordPress dashboard under "Appearance => Menus". Here is a tutorial: http://en.support.wordpress.com/menus/

Categories