How will i add an option under customizer woocommerce section? - wordpress

What is the customizer section name? I want to add a field option under customizer woocommerce section. Or how will I add a field under woocommerce option? Can someone help me with that?
$wp_customize->add_section( 'woocommerce_secction_name' , array(
'title' => __( 'My Section Name', 'starter' ),
'priority' => 30
) );
$wp_customize->add_setting( 'starter_new_setting_name' , array(
'default' => '#000000',
'transport' => 'refresh',
) );
$wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'link_color', array(
'label' => __( 'Header Color', 'starter' ),
'section' => 'woocommerce_secction_name',
'settings' => 'starter_new_setting_name',
) ) );

// Add section to WooCommerce Panel
$wp_customize->add_section( 'SECTION_NAME',
array(
'title' => __( 'SECTION TITLE'),
'panel' => 'woocommerce',
'capability' => '',
'priority' => 500,
)
);
The important part is the panel name as you can see selecting woocommerce it will add to the woocomerce panel

Related

Wordpress How Can I Display skill1_logo in View

Hi Im practically a newbie and would like to kindly ask how can I display skill1_logo,skill1_title,skill1_description on a page that I want. I was trying to do a 1 page website using wordpress to practice my wordpress.
function theme_skills_customizer($wp_customize){
//adding section in wordpress customizer
$wp_customize->add_section('skills_settings_section', array(
'title' => 'Skills Section'
));
$wp_customize->add_setting('skill1_logo');
$wp_customize->add_setting('skill1_title');
$wp_customize->add_setting('skill1_description');
$wp_customize->add_control( new WP_Customize_Image_Control( $wp_customize, 'skill1_logo', array(
'label' => __( 'Skill 1 Logo', 'themeslug' ),
'width' => 400,
'height' => 400,
'flex-width' => true,
'flex-height' => true,
'section' => 'skills_settings_section',
'settings' => 'skill1_logo',
)));
$wp_customize->add_control( 'skill1_title', array(
'label' => __( 'Skill 1 Title' ),
'section' => 'skills_settings_section', // Add a default or your own section
'type' => 'text',
));
$wp_customize->add_control( 'skill1_description', array(
'label' => __( 'Skill 1 Description' ),
'section' => 'skills_settings_section', // Add a default or your own section
'type' => 'textarea',
));
}
add_action( 'customize_register', 'theme_skills_customizer' );
You can use get_theme_mod function to echo those settings.
e.g.
$s_title = get_theme_mod('skill1_title');

How to add a custom field in woocommerce product category using meta box plugin

I just want to add a custom field in the product category page in admin using the metabox plugin https://metabox.io/
This is in woocommerce and this is what I have
add_filter( 'rwmb_meta_boxes', 'product_register_meta_boxes' );
function product_register_meta_boxes( $meta_boxes )
{
$prefix = 'product_';
$meta_boxes[] = array(
'id' => 'product_cat_keywords_search',
'title' => __( 'Searchable keywords', 'your-prefix' ),
'post_types' => array( 'product'),
'taxonomy' => array( 'product_cat'),
'context' => 'normal',
'priority' => 'low',
'fields' => array(
array(
'name' => __( 'Product Category Keywords', 'your-prefix' ),
'id' => "{$prefix}pcat_keywords",
'desc' => __( 'Category Keywords', 'your-prefix' ),
'type' => 'text',
'std' => __( '', 'your-prefix' ),
'clone' => true,
'clone-group' => 'my-clone-group2',
),
)
);
return $meta_boxes;
}
This code only appears in product page and not in product category page.
I need to use metabox since I will be using the clone feature, thanks

WordPress customizer multiple add_control 's in section

Quick question.
I'm trying to add multiple controls within a WordPress customizer section.
$wp_customize->add_section( 'lr_panel2', array(
'title' => esc_html__( 'Panel 2', 'lr' ),
'active_callback' => 'is_front_page',
'panel' => 'lr_theme_options',
'description' => esc_html__( 'Add a background image to your panel by setting a featured image in the page editor. If you don’t select a page, this panel will not be displayed.', 'lr' ),
) );
$wp_customize->add_setting( 'lr_panel2', array(
'default' => false,
'sanitize_callback' => 'lr_sanitize_numeric_value',
) );
$wp_customize->add_control( 'lr_panel2', array(
'label' => esc_html__( 'Panel Content', 'lr' ),
'section' => 'lr_panel2',
'type' => 'dropdown-pages',
) );
So this one is working fine and dandy. I try to add a second one and neither render. I assumed I could just repeat the add_control class, something like:
$wp_customize->add_control( 'lodestar_panel2', array(
'label' => esc_html__( 'Panel Layout', 'lr' ),
'section' => 'lr',
'type' => 'select',
'choices' => array(
),
) );
But that's not working how I want it too, Has anyone done this before?
Thanks!
You are adding the control in another section. Section should be same
'section' => 'lr_panel2',
This is the section of first control you've added and
'section' => 'lr',
This is the section of second control you've added
Also a control wouldn't show unless you've added somethings in it.

Implementing A WordPress Settings Class for Options Pages

I'm trying to implement this class: A WordPress Settings Class for Options Pages
What I tried:
function add_wp_page(){
require_once( TEMPLATEPATH."/folder_admin/wm-settings.php" );
// A top level page
$my_top_page = create_settings_page(
'my_top_level_page',
__( 'My Top Level Page' ),
array(
'parent' => false,
'title' => __( 'Top Level Menu' ),
'icon_url' => 'dashicons-admin-generic',
'position' => '63.3'
),
array(
'my_standard_section' => array(
'title' => __( 'Standard' ),
'description' => __( 'My section description.' ),
'fields' => array(
'my_input' => array(
'label' => __( 'Input example' )
),
'my_checkbox' => array(
'type' => 'checkbox',
'label' => __( 'Checkbox example' )
),
'my_textarea' => array(
'type' => 'textarea',
'label' => __( 'Textarea example' )
)
)
)
),
array(
'tabs' => true,
'submit' => __( 'My Submit' ),
'reset' => __( 'My reset' ),
'description' => __( 'My page description.' ),
'updated' => __( 'My success message !')
)
);
// And a sub-page
$my_sub_page = create_settings_page(
'my_sub_page',
__( 'My Sub Page' ),
array(
'parent' => 'my_top_level_page',
'title' => __( 'Sub Level Menu' )
)
);
}
add_action( 'admin_init', 'add_wp_page' );
The TEMPLATEPATH is it ok. If I echo something in wp-settings.php it will print it.
The rest of the code it is from that website. It is from an example.
The menu doesn't show.
Am I missing something?
Thanks
The settings need to be registered before 'admin_init'.
Replace the last line with add_action( 'init', 'add_wp_page' );.
Also, avoid wrapping the require_once in an action or you won't be able to access get_setting() outside your hook.
Oh, and the position can be a string. And it is actually recommended to use a decimal number to prevent possible conflicts for these menu positions with other plugins or themes.
Please set a 'position' => '63.3' to integer.
or use positions of core menu:
2 Dashboard
4 Separator
5 Posts
10 Media
15 Links
20 Pages
25 Comments
59 Separator
60 Appearance
65 Plugins
70 Users
75 Tools
80 Settings
99 Separator
The position in the menu order this menu should appear.
Hope it solves your problems :)

Fatal error when adding setting to customizer in wordpress

I am trying to add an extra setting in the Wordpress customizer. Can you add extra settings in the site title & tagline section or do you have to create your own section? This is the code I have so far in my functions.php file:
function mytheme_customize_register( $wp_customize )
{
$wp_customize->add_control(
new WP_Customize_Control(
$wp_customize,
'your_setting_id',
array(
'label' => __( 'Your Label Name', 'theme_name' ),
'section' => 'title_tagline',
'settings' => 'your_setting_id',
'type' => 'text'
)
)
);
}
add_action( 'customize_register', 'mytheme_customize_register' );
If I try to go to the customize theme page in the admin area though I get the following error:
Fatal error: Call to a member function check_capabilities() on a non-object in C:\xampp\htdocs\one-gas\wp-includes\class-wp-customize-control.php on line 161
Yes, you can add to the title and tagline section. Try using this code:
$wp_customize->add_control(
new WP_Customize_Control(
$wp_customize,
'your_setting_id',
array(
'label' => __( 'Your Label Name', 'theme_name' ),
'section' => 'title_tagline',
'settings' => 'your_setting_id',
'type' => 'text'
)
)
)
);
Read more about the Theme Customization API at the WordPress Codex.
I fixed it in the end it's because I had to define a setting first so this is the working code:
function mytheme_customize_register( $wp_customize )
{
$wp_customize->add_setting('subtagline', array(
'default' => 0,
'type' => 'option'
));
$wp_customize->add_control(
new WP_Customize_Control(
$wp_customize,
'subtagline',
array(
'label' => __( 'Sub Tagline', 'One Gas' ),
'section' => 'title_tagline',
'settings' => 'subtagline',
'type' => 'text'
)
)
);
}
add_action( 'customize_register', 'mytheme_customize_register' );

Resources