Episode #125 of the Stack Overflow podcast is here. We talk Tilde Club and mechanical keyboards. Listen now

New answers tagged

0

This is how I solved it: /** * Force currency change */ add_filter( 'wcml_client_currency', function($current) { if(isset($_GET['currency']) && $_GET['currency']) return $_GET['currency']; if(isset($_POST['currency']) && $_POST['currency']) return $_POST['currency']; return $current; ...


0

I got it. Im developing a plugin for woocommerce, so i was adding my Function to my plugin page instead of my include of the functions. Just put it on the functions and it works.


0

You can put you code in functions.php where you define the string, for example: <?php function get_banner_text() { $url = $_SERVER["REQUEST_URI"]; if (strpos($url, "bob.")) { $banner_text = "Welcome to Agent Bob's Portal!"; } else { $banner_text = "Default text here"; } return $banner_text; } ?> Afterwards for example in header....


0

Why not just use? get_permalink(get_the_ID());


0

You have a number of problems that have to be corrected for this to work. Shortcodes should return content - not echo/print it to the screen. You should sanitize your retrieved $_POST values before use. You can't query the db for a plain text password. Passwords are hashed. Don't do your form processing outside of a function. Setup a function for it and ...


1

One is When I use the shortcode of the form in the page or post, showing the form in the WP backend 5.2.3 version. That happens because your shortcode is echoing the output. A shortcode should always return the output, but if you need to echo it, then you should use output buffering: public function ajaxrf_shortcode(){ // Turn on output buffering. ...


0

If you don't want to call the class method statically you can do the following add_shortcode('RSSjb', [new RSSjbClass, 'RSSjb_funct']);


0

Try using some API from WordPress itself - https://codex.wordpress.org/Function_Reference/wp_localize_script


0

WooCommerce already saves a custom metadata called _stock_status. This metadata can have these values: instock outofstock onbackorder You don't need to create your own metadata as that would be redundant and more difficult to keep in sync with WooCommerce data.


1

You are able to change texts using a translation file. By default, plugin texts are in the English language. Even your site language is English, You are able to generate a new language file and change texts on it. Imagine that the plugin folder name (plugin slug, plugin text domain) is my-plugin and Your site language is set to English (UK) in Admin ...


0

You can change text using filter. add below code in active theme's functions.php file to change text form join waitlist message. Here is a documentation where you can take reference. : https://docs.woocommerce.com/document/woocommerce-waitlist/ add_filter( 'wcwl_join_waitlist_message_text', 'change_string_from_woo_wait_list',10,1 ); function ...


1

I guess the reason is you have not added post title and added post id $my_post = array( 'post_id' => 1, 'post_status' => 'pending', 'post_type' => 'post' ); Ideally if should be $my_post = array( 'post_title' => wp_strip_all_tags( $_POST['post_title'] ), 'post_content' => $...


0

The reason this was happening, is metabox.io for some reason triggers a page refresh before saving the option. This meant that after the page refresh, the new options did not have time to take effect. My workaround for now is to use header("refresh:0") which accomplishes what I was trying to do in my original post but without causing a refresh loop like the ...


0

To reset quantity input field to 1 when variation changes on product detail page use below code. you can set default quantity from jQuery("[name='quantity']").val(1);. i have tested and it is working fine for me. add_action( 'wp_footer', 'variation_change_update_qty' ); function variation_change_update_qty() { if (is_product()) { ?> ...


0

You access the file direct link this way: <?php echo (wpdm_get_package(get_the_ID()))['download_url']; ?>


0

I solved this problem with: function hide_product_title_part( $title, $id ) { if ( ( is_front_page() || is_shop() || is_product_tag() || is_product_category() ) && get_post_type( $id ) === 'product' ) { if (strstr($title, ":")) { $new_title = explode(":", $title); return $new_title[1]; } else { return $title; } } ...


0

After research I've found a way to get POST data from a form. Thanks to this article, I've successfully managed to get the data from the my WP_List_Table through admin_post mechanism.


1

IFTTT works from RSS feed, simply including your post in wordpress RSS feed can do the trick... function add_cpt_to_loop_and_feed( $query ) { if ( is_home() && $query->is_main_query() || is_feed() ) $query->set( 'post_type', array( 'post', 'download' ) ); return $query; }


0

I had quite a bit more wrong than i thought, but i was able to figure out what i needed. I completely removed wp_localize_script() it wasnt necessary(this is for an admin tab). I added include 'my-ajax.php'; to the main plugin.php fixed the Jquery and ended up with this include 'my-ajax.php'; function admin_scripts() { if (is_admin()) { ...


0

This code will do it: global $post; $user = get_user_by( 'ID', $post->post_author ); if ( in_array( 'author', $user->roles ) ) {echo "Author";} You don't even need global $post; if you are if a query loop.


0

WordPress provides a way to access PHP variable into .js file using the wp_localize_script so if your follow that it's standard practice (standard practices are always advisable). Your next question is my-ajax.php and plugin URL. All ajax in WordPress process through admin-ajax.php (Standard one) that file could be found in wp-admin so wp_localize_script ...


-1

Use woocommerce_email_customer_details. function email_order_user_meta( $order, $sent_to_admin, $plain_text ) { $meta = get_post_meta($order->ID, 'OIB'); if($meta){ /*** whatever format you like here ***/ echo '<tr>' . $meta '</tr>'; } } add_action('woocommerce_email_customer_details', 'email_order_user_meta', 30, 3 );


0

// add body class for that. add_filter( 'body_class', 'custom_class' ); function custom_class( $classes ) { if ( is_single() && 'post' == get_post_type() ) { $classes[] = 'article-page'; } else{ if(!is_page('library')) $classes[] = 'home'; } if(is_page('contact-page')){ $classes[] = 'contact-page'; } if(...


0

You want to add different CSS class on different page. You can do it by checking it by page or page id. It's going to bit long work for you. However, you can do it two way. (May be more ways are there but I suggest you these two) For both you should have added following code into active theme's header file where you render body tag <body <?php ...


1

In your functions.php: function my_body_class($classes) { if(is_page()){ global $page; $title = get_the_title( $page ); $classes[] = $title; } return $classes; } add_filter('body_class', 'my_body_class'); That will add the page title as a class to each page.


2

Couple of options for you. Option 1: Use the body_class() function to add the page slug to the class. function add_slug_body_class( $classes ) { global $post; if ( isset( $post ) ) { $classes[] = $post->post_name; } return $classes; } add_filter( 'body_class', 'add_slug_body_class' ); Then whatever the url is, say "yourdomainpage.com/...


0

You are missing multiple single quotes around $a[url], so after src=" there should be a ' and after $a[url] there should be another single quote, and you also need to quote the array key, so the whole return line should be return '<audio class="listen" preload="none" data-size="250" src="' . $a['url'] . '"></audio></div></div>';


1

To query a second database you can use the wpdb object like explained here. This can be a local or extern database. You don't need to create a plugin.


0

This won't affect your existing scheduled Cron events, as they already have a schedule interval set. It will only add a new custom schedule interval that will be available for new ones. So long as you are adding to the $schedules array and returning it (which you are) then it will all be fine.


0

I have modified code of https://stackoverflow.com/a/54722971/10183871 which you have provided. i have made some changes according your requirement. you can take reference below code and make changes as per your requirement. i have tested code and it is working for me https://prnt.sc/pgwwvq. // Set the defined product attribute taxonomy function ...


0

Here is a plugin that does this in case someone else needs it. Just save this in <?php /* Plugin Name: WC Split Cart Backorders Plugin URI: https://www.creativemonarchy.com Description: A simple plugin that helps you split the WooCommerce in stock and backorder stock items for the same product in your cart. Author: Sohrab Iravani Version: 1.0 Author ...


1

in while($row = $result->fetch_assoc()); semicolon occored issue. replace ; with : <?php while($row = $result->fetch_assoc()): ?> <tr> <td><?php echo $row['name']; ?></td> <td><?php echo $row['location']; ?></td> <td></td> </tr> <?php ...


0

This is the off topic question. But the answer is yes it is possible. In IFTTT we can use the Feed applet like "Feed to Tweet". So, Just create the the Feed applet with your custom post type feed URL. WordPress generates the feed URL for each post type. You can get it as below: https://yourwebsite.com/feed/?post_type={post-type-slug} E.g. Feed URL of ...


0

Without more context from you, I can only assume and show you what I have done that works for me using PSR4 Autoloading. Example: Assuming that all my custom class directories and files is in ./inc folder In your composer.json, add this "autoload": { "psr-4": { "Inc\\": "./inc" } } Inc is the vendor name of your application, use this ...


0

is_author() is not for determining current user, it checks whether the Author archive page is in display or not. Your call would be to use wp_get_current_user() or get_current_user_id() (if you are comfortable with user ID) or any similar function WP have. Example of using wp_get_current_user() <?php $current_user = wp_get_current_user(); if ( 'ritesh'...


0

You're not far off. is_author() returns a boolean meaning if you are on the archive page for Ritesh it will return true, and your code will execute. Based on your post, I think you need to look up the page author based on the current post object and check against that instead. So your total code might look like this: $id = get_queried_object()->...


0

Easier one-liner with less bash: wp site list --field=url | xargs -i -n1 wp cron event run --due-now --url="{}" You can either run it manually or put it in a script and call it from cron as in the other answers.


0

Although you might have already managed to solve the problem you faced, here's few thoughts. You could use register_activation_hook(), register_deactivation_hook() and register_uninstall_hook() functions to trigger a wp_remote_post() call to your (custom) API endpoint to count the times when your plugin is activated, deactivated or deleted. If the ...


1

So the issue has already been resolved via the comments and the current state of the question already includes the corrected code. But I thought I should post this answer as a reminder for you, me and everyone reading this. :) So first off, here's a helpful excerpt from an article on WP Engine: The “unexpected end of file” error is not specific to ...


0

Ok, I found this thread: It partially resolves my problem but breaks the gutenberg blocks, rendering some of them unusable. I would greatly appriciate help with this...


0

There's a number of way to do the thing you're asking. If your php function just spits out an array of options, you could consider adding the array to your site's footer with wp_localize_script() and then get the data out of by referencing the js object in your script. E.g. // theme functions.php or a plugin file function dropdown_options() { // modify ...


0

Your problem involves a technique called REST API. WordPress supports it. All you need is to make a plugin → register_rest_field → pass your data through it. What you want to do may seems simple but it is still lot of works. Also, remember to tighten plugin security.


0

As majick suggested on a comment you could use a shortcode to create the accordion markup. If you want to manually define the tab titles and content, you could add something like this to your functions.php. add_shortcode( 'accordion', 'accordion_callback' ); function accordion_callback( $args, $content ) { $defaults = array( 'id' => '...


1

if you use any hooks, filters or shortcodes with class methods, you have two options. either declare it INSIDE an instance of a class, in which case, you can refer to the instance of the class. class myClass { function __construct() { add_shortcode('my_shortcode_name', [ $this, 'shortcode' ]); } function shortcode() { //your code here ...


1

Here’s one way to solve this: sort both arrays loop through them and compare them item by item (they should be equal, because arrays are sorted) . sort( $evaltypesReq ); sort( $evaltypesSch ); $containsAllValues = true; foreach ( $evaltypesReq as $k => $v ) { if ( $evaltypesSch[$k] !== $v ) $containsAllValues = false; }


1

In it's current state you would directly get the value from the associative PHP array by directly referencing the key like so: var_dump( $form_data['key'] ); It's wise to note that when you dump variables using var_dump you get information on the value type, and length. So in this case you get string(33) which indicates the value is a string and is 33 ...


0

Move the $make_new['term_id'] inside the block that runs when there is no error. Do you have your WP_DEBUG on? What is the error message?


0

I decided to go with wp_ajax instead


0

public function start(){ add_action('init', array($this, 'knp_supplier_endpoint')); //Add endpoint urls add_action('woocommerce_account_product-submissions_endpoint', array($this, 'knp_product_submissions_content')); add_action('woocommerce_account_submission-form_endpoint', array($this, 'knp_submission_form_content')); add_action('...


1

Follow this flow: Define an empty array $nav_img = array(); outside the loop. Inside the loop while you fetch the featured image, push the URL to the array too like this $nav_img[]='your_image_here' ; Then inside <div class="slider-nav-thumbnails"></div> you can simply do a for each loop to set the images as thumb. UPDATE: Here I added ...


Top 50 recent answers are included