Importing hard coded custom field into acf field

First off, you should know that get_post_meta() doesn’t create any custom fields (or metadata), it only retrieves the custom field’s value. But the WordPress functions that do create custom fields (for posts) are add_post_meta() and update_post_meta(). So that get_post_meta($post->ID, “mt_post_subtitle”, true) simply retrieves the value of the meta/field named mt_post_subtitle for the post (referenced by … Read more

How to get the POST TITLE using the POST ID?

WordPress has a ton of the get_the_*() functions which you can pass an ID and return a value you’re looking for. In this case you can call get_the_title() which returns the title of a post. An example could look like: echo get_the_title( 3249 );

Function set default image when image not present

You’d want to put the <img/> tag and all the necessary content for the default image after the final colon in the following line: $my_image = ( $image[0] != ” ) ? ‘ <img alt=”‘ . esc_attr( sprintf( the_title_attribute( ‘echo=0’ ) ) ) . ‘” title=”‘ . esc_attr( sprintf( the_title_attribute( ‘echo=0’ ) ) ) . … Read more

Woocommerce add to cart quantity buttons with AJAX

I fixed it with some IDs add in function.php add_filter( ‘woocommerce_loop_add_to_cart_link’, ‘quantity_inputs_for_loop_ajax_add_to_cart’, 10, 2 ); function quantity_inputs_for_loop_ajax_add_to_cart( $html, $product ) { if ( $product && $product->is_type( ‘simple’ ) && $product->is_purchasable() && $product->is_in_stock() && ! $product->is_sold_individually() ) { // Get the necessary classes $class = implode( ‘ ‘, array_filter( array( ‘button’, ‘product_type_’ . $product->get_type(), $product->is_purchasable() && … Read more

Change sign up fee in cart for subscription products WooCommerce

add_action( ‘woocommerce_before_calculate_totals’, ‘change_subscription_signup_fee’, 1000, 1 ); function change_subscription_signup_fee( $cart ) { if (is_admin() && !defined(‘DOING_AJAX’)) return; if ( did_action( ‘woocommerce_before_calculate_totals’ ) >= 2 ) return; // Loop through cart items foreach ( $cart->get_cart() as $cart_item ) { // Check that product custom cart item data “alredy_have_number” exist and is true if( isset($cart_item[‘alredy_have_number’]) && $cart_item[‘alredy_have_number’] ) … Read more

Prevent a plugin from being automatically activated

You might want to add your own plugin to deactivate their plugin (silently). First open their main plugin file and see where the plugin hooks (or filters) in. Then unhook their plugin … and your’s as well. <?php /** Plugin Name: Deactivate other plugin */ add_action( ‘the_same_hook’, ‘removeOtherPlugin’, PHP_INT_MAX -1 ); function removeOtherPlugin() { remove_filter( current_filter(), … Read more

How to get specific image in media library with php

There’s a few functions: wp_get_attachment_image_url( $attachment_id, $size ) – Gets the URL to specified size of the image. wp_get_attachment_image_src( $attachment_id, $size ) – Gets an array of the image URL, width, and height for the specified size of the image. wp_get_attachment_image( $attachment_id, $size ) – Gets the full HTML for an image, including width, height, … Read more