WooCommerce – Display variation custom field value [closed]

Ok, I’ve managed to solve this. This is how i finally created variations custom field: add_action( ‘woocommerce_product_after_variable_attributes’, ‘variation_settings_fields’, 10, 3 ); add_action( ‘woocommerce_save_product_variation’, ‘save_variation_settings_fields’, 10, 2 ); function variation_settings_fields( $loop, $variation_data, $variation ) { woocommerce_wp_text_input( array( ‘id’ => ‘price_1_50[‘ . $variation->ID . ‘]’, ‘class’ => ‘price_1_50’, ‘type’ => ‘text’, ‘label’ => __( ‘Price | Product … Read more

Get WooCommerce shipping methods programmatically

You need to use something different as following (commented): // Loop through shipping packages from WC_Session (They can be multiple in some cases) foreach ( WC()->cart->get_shipping_packages() as $package_id => $package ) { // Check if a shipping for the current package exist if ( WC()->session->__isset( ‘shipping_for_package_’.$package_id ) ) { // Loop through shipping rates for … Read more

Change message given when deleting post from custom post type

There’s no hook named post_trashed_messages, but there is the bulk_post_updated_messages hook which you can use to change the bulk action updated messages: add_filter( ‘bulk_post_updated_messages’, function ( $bulk_messages, $bulk_counts ) { $bulk_messages[‘post’][‘trashed’] = _n( ‘%s post successfully deleted.’, ‘%s posts successfully deleted.’, $bulk_counts[‘trashed’] ); return $bulk_messages; }, 10, 2 ); Or to target a specific post … Read more

Submitting form via admin-post.php and handling errors

Am I supposed to just do normal redirects back to my form page? Something like wp_redirect( ‘/my-page/’, 302 );? Yes. How do I display my errors on the page that has the form? Well, there are various ways, including: Passing an error code as a query string in the redirect URL: example.com/my-page/?my_form_error=tos_agree_empty. Then in your … Read more

How to allow “Add New” capability of CPT when links to its UI are placed as a submenu?

The problem is that when the special subscriber tries to Add New a sub-cpt post, it is denied permission. However, when the CPT menu is a top-admin-menu, then everything works out fine. The issue is related to the placement of the CPT’s UI menu in the back-end: if it’s top-level (show_in_menu=TRUE), all is well; if … Read more

Show ACF field from custom taxonomy and display on the single template

I would try something like this… // Assume there is only one category. $product_category = get_the_terms($post, ‘product-category’)[0]; $cat_fields = get_fields(“term_$product_category”); $color = $cat_fields[‘category_colour_primary’]; You could also do this… // Assume there is only one category. $product_category = get_the_terms($post, ‘product-category’)[0]; $color = get_field(‘category_colour_primary’, “term_$product_category”);