I'm using the WordPress plugin "restrict content pro".
I would like to hide an element with selector li#wp-admin-bar-my-account-messages for a specific subscription id with PHP within my functions.php file.
I guess the PHP validation is rcp_is_active() && rcp_get_subscription_id() == 2 but don't know how to go on from here.
Thanks in advance
Assuming that rcp_is_active() && rcp_get_subscription_id() == 2 will validate to your specific use case and you just want to hide the element which has selector li#wp-admin-bar-my-account-messages you can do the following in your function.php
if ( rcp_is_active() && rcp_get_subscription_id() == 2 )
{
// for frontend
add_action( 'wp_head', function() {
echo '<style type="text/css">li#wp-admin-bar-my-account-messages{display:none !important}</style>';
} );
// for backend
add_action( 'admin_head', function() {
echo '<style type="text/css">li#wp-admin-bar-my-account-messages{display:none !important}</style>';
} );
}
Hope it helps :)
Related
How can I hide a specific button, based on the stock status of my product?
The plugin is creating this class:
function wdm_pefree_init() {
// phpcs:ignore WordPress.NamingConventions.ValidFunctionName.FunctionNameInvalid
if ( ! class_exists( 'Product_Enquiry_For_Woocommerce', false ) ) {
include_once WDM_PE_PLUGIN_PATH . '/includes/class-product-enquiry-for-woocommerce.php';
}
Product_Enquiry_For_Woocommerce::instance();
}
I only want to display this button the single product page of every product that is in backorder, but I can't get my code to work.
I'm not that great with PHP, so I'm trying to adapt some other code I have on my functions.php file, but without any luck.
Any help would be great, thanks!
I've tried this code:
add_filter('woocommerce_get_availability', 'wcs_custom_get_availability', 1, 2);
function wcs_custom_get_availability($availability, $_product) {
// Remove Enquiry Button
if (!$_product->is_in_stock()) {
remove_action('Product_Enquiry_For_Woocommerce');
}
return $availability;
}
I also see that the css class for the button is .pe-show-enq-modal, but I can't do a conditional "visibility: hidden" that only works for backorder products.
What you are looking for is this:
add_action( 'woocommerce_single_product_summary', 'remove_enquiry_button_if_out_of_stock', 30 );
function remove_enquiry_button_if_out_of_stock() {
global $product;
if ( ! $product->is_in_stock() ) {
remove_action( 'woocommerce_single_product_summary', array( Product_Enquiry_For_Woocommerce::instance(), 'enquiry_button' ), 25 );
}
}
Or Via CSS :
.product.out-of-stock .pe-show-enq-modal {
display: none;
}
The only way I got this (kinda) working was by using this JS:
function remove_enquiry() {
?>
<script type="text/javascript">
(function($){
$(document).ready(function(){
if($(".in-stock").length)
$(".pe-show-enq-modal").hide();
});
})(jQuery);
</script>
<?php
}
add_action('wp_head', 'remove_enquiry');
You can see it here.
But if you notice, it has a delay executing the JS, because when the page loads, the button still shows up for a brief moment (otherwise it seems to be working ok).
Hi,
i have a site that displays various projects as posts, each project has its own pdf file, uploaded via a file custom field for that post.
For the moment there's just a dynamic button as you can see in this example:
https://www.stefanomengoli.it/sm21/progetti/vivere-nelle-nuvole-progetto-di-bioarchitettura-per-un-loft-casa-sullalbero/
What i need is the user to be able to download or be redirected to the correct file after CF7 submission based on the project he/she is on.
I tried this code and it works with a specific url, but what i need is to put an acf url that dynamically shows the correct file as I said based on the project the visitor is on.
add_action( 'wp_footer', 'example_download' );
function example_download() {
?>
<script type="text/javascript">
document.addEventListener( 'wpcf7mailsent', function( event ) {
if ( '946' == event.detail.contactFormId ) {
window.open('https://www.example.com/wp-content/uploads/2021/05/my-document.php',
'_self');
}
}, false );
</script>
<?php
}
You just need to echo the custom field in the window.open
This should work. Just replace your_field with your ACF field name
add_action( 'wp_footer', 'example_download' );
function example_download() {
global $post;
?>
<script type="text/javascript">
document.addEventListener('wpcf7mailsent', function (event) {
if ('946' == event.detail.contactFormId) {
window.open('<?php the_field('your_field', $post->ID);?>',
'_self');
}
}, false);
</script>
<?php
}
Is it possible to remove "password protected" option from the visibility using a hook?
I found the following hook, but it seems I can only check the status of the post.
add_action( 'transition_post_status', 'my_function_to_check_status', 10, 3 );
I don't think that you can remove that option through a filter or an action (I stand to be corrected though), so you will probably have to action in either CSS or some jQuery to hide it for you.
You can do this with a hook in your functions file (see code below)
With jQuery you can fully remove the option, but CSS will only hide it.
The jQuery Route
//load jquery into footer to remove password protected option from visibility
add_action('admin_footer', 'hide_visibility_jquery');
function hide_visibility_jquery() {
//don't add this script if on any other post type:
if (get_post_type() != 'my-custom-post-type-slug') { return; }
//echo the jQuery to remove the input field and its label
echo '
<script type="text/javascript">
jQuery(\'input#visibility-radio-password\').remove();
jQuery(\'label[for="visibility-radio-password"]\').remove();
</script>
';
}
The CSS Route
//load CSS into the header to remove password protected option from visibility
add_action('admin_head', 'hide_visibility_css');
function hide_visibility_css() {
//don't add this CSS if on any other post type:
if (get_post_type() != 'my-custom-post-type-slug') { return; }
//echo the CSS to hide the input field and its label
echo '<style type="text/css">input#visibility-radio-password, label[for="visibility-radio-password"] {display: none;}</style>';
}
I'm facing a problem with my Woocemmerce mod and I would be glad if someone could help me.
my doubt is: how can I hide email at Woo setting/email tab? I would like to hide email from 3 specific fields.
Thanks a lot
Create a custom javascript file with the below code
document.addEventListener("DOMContentLoaded", function(event) {
function isValidEmailAddress(emailAddress) {
var pattern = /^([a-z\d!#$%&'*+\-\/=?^_`{|}~\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]+(\.[a-z\d!#$%&'*+\-\/=?^_`{|}~\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]+)*|"((([ \t]*\r\n)?[ \t]+)?([\x01-\x08\x0b\x0c\x0e-\x1f\x7f\x21\x23-\x5b\x5d-\x7e\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]|\\[\x01-\x09\x0b\x0c\x0d-\x7f\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))*(([ \t]*\r\n)?[ \t]+)?")#(([a-z\d\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]|[a-z\d\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF][a-z\d\-._~\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]*[a-z\d\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])\.)+([a-z\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]|[a-z\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF][a-z\d\-._~\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]*[a-z\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])\.?$/i;
return pattern.test(emailAddress);
}
var recipients= document.getElementsByClassName('wc-email-settings-table-recipient');
for(var i=0;i<recipients.length;i++){
if(isValidEmailAddress(recipients[i].innerText)){
recipients[i].innerText='This is hidden';// do what you want, fex. you can change the style instead of this
}
}
});
and enqueue the created js file on the admin page by applying below code into your functions.php file.
function my_enqueue() {
wp_enqueue_script( 'my_custom_script', get_template_directory_uri() . '/myscript.js' );
}
add_action( 'admin_enqueue_scripts', 'my_enqueue' );
also please note that the class name wc-email-settings-table-recipient may change for different versions of wooCommerce plugin.
Hope this helps.
I have created a plugin that adds a input box, 'Logo URL' on the Settings > General page in WordPress. This input can be called and works correctly. I have created another plugin that pulls the 'Logo URL' and applies the path to pull an image for the Login screen. Everything appears peachy.
The only issue I am having is that I would like to move the 'Logo URL' on the Settings > General page to up under 'Site Address (URL)'. I am at a loss on how to do this. I have scoured the web and been unable to find a helpful answer.
I am currently removing the original General page and adding a New General page but am unsure how to parse the correct options-general.php.
How to move the Logo_URL higher on the General Page?
/**
* This is the code to create the Settings box on the Settings > General
*/
$new_general_setting = new new_general_setting();
class new_general_setting {
function new_general_setting( ) {
add_filter( 'admin_init' , array( &$this , 'register_fields' ) );
}
function register_fields() {
register_setting( 'general', 'URL_logo', 'esc_attr' );
add_settings_field('URL_logo', '<label for="URL_logo">'.__('Website logo (URL)' , 'URL_logo' ).'</label>' , array(&$this, 'fields_html') , 'general' );
}
function fields_html() {
$value = get_option( 'URL_logo', '' );
echo '<input type="text" id="URL_logo" name="URL_logo" value="' . $value . '" />';
}
}
No, there's no way of ordering that natively. WordPress first prints its stuff then ours. It has to be done with jQuery.
add_action( 'admin_footer-options-general.php', function()
{
?>
<script type="text/javascript">
jQuery(document).ready( function($)
{
var son = $("label[for='URL_logo']").parent().parent(); // Our setting field
var father = $("label[for='home']").parent().parent(); // WordPress setting field
son.insertAfter(father);
});
</script>
<?php
});
The recommended way is to enqueue the JS inside an action call for "admin_print_scripts-$hookname". Note the hook name use in admin_footer and admin_head too.
As your field only changes after the page loaded, we can notice the "jump". To smooth it, we can use:
add_action( 'admin_head-options-general.php', function()
{
echo '<style>#wpbody .wrap form{display:none}</style>';
});
And add this jQuery after replaceWith():
$('#wpbody .wrap form').fadeIn('slow');