How can i give different/custom IDs to the photo gallery of the woocommerce products?
My products get their photo gallery from a different plugin and i have the array of IDs and urls coming from it. like:
Array ( [0] => 4046 [1] => 4047 [2] => 4048 [3] => 4049 )
I just need to tell woocommerce to use these ids instead of its default.
I also tried to copy the original product-image.php and product-thumbnails.php files in to my child theme like this:
werkstatt-child/woocommerce/single-product/product-image.php
but even without modifying them the photo gallery stops working, it seems like that it does not use .js and .css files anymore.
Can you please tell me what is the right way to tell the woocommerce product photo gallery to use a different array of IDs ?
See also questions close to this topic
-
In feed ads in Wordpress Woocommerce
I need in feed ads in product thumbnails of my website gforgadget.com which is using wordpress. I have edited my woocommerce-teplate.php as
if ( ! function_exists( 'woocommerce_content' ) ) { /** * Output WooCommerce content. * * This function is only used in the optional 'woocommerce.php' template. * which people can add to their themes to add basic woocommerce support. * without hooks or modifying core templates. */ function woocommerce_content() { $i=1; if ( is_singular( 'product' ) ) { while ( have_posts() ) : the_post(); if($i==5||$i==7||$i==10){?> #my adsense code <?php } wc_get_template_part( 'content', 'single-product' ); $i++; endwhile; } else { ?> <?php if ( apply_filters( 'woocommerce_show_page_title', true ) ) : ?> <h1 class="page-title"><?php woocommerce_page_title(); ?></h1> <?php endif; ?> <?php do_action( 'woocommerce_archive_description' ); ?> <?php if ( woocommerce_product_loop() ) : ?> <?php do_action( 'woocommerce_before_shop_loop' ); ?> <?php woocommerce_product_loop_start(); ?> <?php if ( wc_get_loop_prop( 'total' ) ) : ?> <?php $i++; while ( have_posts() ) : ?> <?php the_post(); ?> <?php if($i==5||$i==7||$i==10){?> #my adsense code <?php }?> <?php wc_get_template_part( 'content', 'product' ); ?> <?php $i++;?> <?php endwhile; ?>
There is no error and website is running fine. But No ads has been comeup in my website. How to achieve this in feed ads in woocommerce product thumbnail.
-
woocommerce clear 1 value after complete order
if anyone can help me on this. I use below snippet in functions.php to create a tip in the checkout as an addon. but the tip/value selected is not clear after complete order. the default setting would be $0 when first visit the site. also even with the $0, it is still showing at the subtotal section with tip $0.00 2 things I want to achieve. 1. Clear the tip/value putting in to be clear after complete the ordee. 2. hide the "tip $0" in the cart when there is no tip added. Thank you for helping. here is the code in functions.php
// Part 3 // Refresh Checkout if Radio Changes // Uses jQuery add_action( 'wp_footer', 'bbloomer_checkout_radio_choice_refresh' ); function bbloomer_checkout_radio_choice_refresh() { if ( ! is_checkout() ) return; ?> <script type="text/javascript"> jQuery( function($){ $('form.checkout').on('change', 'input[name=radio_choice]', function(e){ e.preventDefault(); var p = $(this).val(); $.ajax({ type: 'POST', url: wc_checkout_params.ajax_url, data: { 'action': 'woo_get_ajax_data', 'radio': p, }, success: function (result) { $('body').trigger('update_checkout'); } }); }); }); </script> <?php } // Part 4 // Add Radio Choice to Session // Uses Ajax add_action( 'wp_ajax_woo_get_ajax_data', 'bbloomer_checkout_radio_choice_set_session' ); add_action( 'wp_ajax_nopriv_woo_get_ajax_data', 'bbloomer_checkout_radio_choice_set_session' ); function bbloomer_checkout_radio_choice_set_session() { if ( isset($_POST['radio']) ){ $radio = sanitize_key( $_POST['radio'] ); WC()->session->set('radio_chosen', $radio ); echo json_encode( $radio ); } die(); }
<?php // Part 1 // Display Radio Buttons // Uses woocommerce_form_field() add_action( 'woocommerce_review_order_before_payment', 'bbloomer_checkout_radio_choice' ); function bbloomer_checkout_radio_choice() { $chosen = WC()->session->get('radio_chosen'); $chosen = empty( $chosen ) ? WC()->checkout->get_value('radio_choice') : $chosen; $chosen = empty( $chosen ) ? 'show_option_none' : $chosen; $args = array( 'type' => 'radio', 'class' => array( 'form-row-wide' ), 'options' => array( 'option_1' => '$2', 'option_2' => '$3', 'option_3' => '$4', 'option_4' => '$5', 'option_5' => '$6', 'option_6' => '$7', 'option_7' => '$8', 'option_8' => '$9', 'option_9' => '$10', 'option_10' => '$11', 'option_11' => '$12', 'no_option' => 'Remove', ), 'default' => $chosen ); echo '<div class="radiotip" id="checkout-radio">'; echo '<h3>Add tip here</h3>'; woocommerce_form_field( 'radio_choice', $args, $chosen ); echo '</div>'; } // Part 2 // Add Fee and Calculate Total // Based on session's "radio_chosen" #2 Calculate New Total add_action( 'woocommerce_cart_calculate_fees', 'bbloomer_checkout_radio_choice_fee', 20, 1 ); function bbloomer_checkout_radio_choice_fee( $cart ) { if ( is_admin() && ! defined( 'DOING_AJAX' ) ) return; $radio = WC()->session->get( 'radio_chosen' ); if ( "option_1" == $radio ) { $fee = 2; } elseif ( "option_2" == $radio ) { $fee = 3; } elseif ( "option_3" == $radio ) { $fee = 4; } elseif ( "option_4" == $radio ) { $fee = 5; } elseif ( "option_5" == $radio ) { $fee = 6; } elseif ( "option_6" == $radio ) { $fee = 7; } elseif ( "option_7" == $radio ) { $fee = 8; } elseif ( "option_8" == $radio ) { $fee = 9; } elseif ( "option_9" == $radio ) { $fee = 10; } elseif ( "option_10" == $radio ) { $fee = 11; } elseif ( "option_11" == $radio ) { $fee = 12; } $cart->add_fee( __('Tip', 'woocommerce'), $fee ); }
-
WooCommerce deduct order total from coupon value
I would like to ask if there's any way to deduct order total from woocommerce coupon amount value?
For example, if someone completes an order of $500 and apply coupon of value $1000. It should change the coupon value to $500 which can be used later.
Any help would be really appreciate. Thanks!
-
Dynamically populate a custom form in Woocommerce products
I have the following code that puts a basic hidden form on my woocommerce product page with a button (it is part of a plugin that I am trying to write that adds some custom options entered in the backend.
myplugin_option_name
is one of these strings.)I basically want this form populated dynamically based on the current product details and the method I've tried to use below (from what I've manage to pickup/learn) just doesn't work and I'm not sure how to proceed. I've tried various other methods of dynamically populating fields based on other solutions to other questions but none of them worked in my instance.
add_action( 'woocommerce_single_product_summary', 'my_extra_button_on_product_page', 30 ); function my_extra_button_on_product_page() { global $product; $url_part = get_option('myplugin_option_name'); $id = $product->get_id(); $url = home_url; echo '<form action="https://example.com/transactions" method="POST">'; echo '<input type="hidden" name="locationId" value="{$id}" />'; echo '<input type="hidden" name="workflow" value="{$url_part}" />'; echo '<input type="hidden" name="callbackUrl" value="{$url}" />'; echo '<input type="submit" value= "Customise Product"></input>'; echo '</form>'; }
Maybe it is something fairly simple that I'm missing because I've had very little sleep in the last few days trying to teach my self php in order to get this working, so I apologize in advance if it is a minor (stupid) error.
-
Restrict displayed products by author in WooCommerce backend
I want to show the WooCommerce products by a user who added those products from admin.
For example:
- user1 logs into the wp-admin and add product A, B, C into a system.
- user2 logs into the wp-admin and add product D, E, F into a system.
Then at current user1 is able to see user2 products in wp-admin and user2 can see user1 products.
I want to customize the product list in admin in such a way that Admin can see all the products and user1 can see only his products and user2 can see his products.
I am new to WooCommerce, so please help.
-
How to grab item data from WooCommerce order
I need to take data from order of customer
Need to take item ID and quantity.
Tried with but not working
$item_data = $item_values->get_data(); foreach ($item_data as $item) { $product_id = $item['product_id']; $quantity = $item['quantity']; }
-
Display New Badge Woocommerce If In New Category
I need to display a 'new' badge to product on the archive page but only for products in the 'New' category
add_action( 'woocommerce_after_shop_loop_item_title', 'lottie_new_badge', 40 ); function lottie_new_badge($badge) { global $product; if (has_term ('new')) { echo '<p>New</p>'; } return $badge; }
Got this code but not working, mixed few bits of code together to try get it to work but no luck.
-
Change product button based on product category in Woocommerce archive pages
I have a jQuery script which successfully retrieves data from local storage and then returns to a PHP function (within a child theme). Within this function I have an if/else block which I want to use in order to change all buttons on all shop pages and linked product pages when opened. depending on the result obtained from the jQuery script.
There are 3 options : default "check coverage", standard "add to cart" and finally "register your interest"
I have 3 categories and want to exclude the 'hardware category
How can I apply a filter to all product pages matching a tag? The code below applies this to all the shop pages items on the store, but not the linked product page for the current customer without overwriting other customers views.
add_filter( 'woocommerce_loop_add_to_cart_link', 'replacing_add_to_cart_button', 10, 2 ); function replacing_add_to_cart_button( $button, $product ) { $button_text = __("Check Coverage", "woocommerce"); $button = '<a class="button" href="******/coverage">' . $button_text . '</a>'; return $button; }
Any guidance, criticisms or thoughts are appreciated.
EDIT - The Ajax code that I use:
jQuery script enqueued from functions.php in child theme:
jQuery.ajax({ type: "POST", url: "/wp-admin/admin-ajax.php", data: { action: 'dynamic_product_links', // add your parameters here cat1: localStorage.getItem("cat1"), cat2: localStorage.getItem("cat2"), }, success: function (output) { console.log(output); } });
functions.php
add_action('wp_enqueue_scripts', 'woocommerce_ajax_check_coverage_js', 99); function woocommerce_ajax_check_coverage_js(){ //echo "<script type='text/javascript'>alert('called woocommerce_ajax_check_coverage_js ');</script>"; wp_register_script( 'woocommerce-ajax-check-coverage-js', get_stylesheet_directory_uri() . "/assets/ajax-check-coverage.js", array('jquery'), null, true ); wp_enqueue_script('woocommerce-ajax-check-coverage-js'); } // register the ajax action for authenticated users add_action('wp_ajax_dynamic_product_links', 'dynamic_product_links'); // register the ajax action for unauthenticated users add_action('wp_ajax_nopriv_dynamic_product_links', 'dynamic_product_links'); function dynamic_product_links() { // ajax data received from jQuery script which retrieves data from local storage $cat1_speed = $_REQUEST['cat1']; // can be either 'Check Coverage','No Coverage' or a number linked to a custom atttribute $cat2_speed = $_REQUEST['cat2']; if ($cat1_speed == 'check ooverage' || $cat2_speed == 'check coverage') { // set all matching categories except hardware to check coverage } if ($cat1_speed == 'No Coverage' ) { // remove this catogory item set from the store (hide?) -> change any product/* pages add to cart button to "register your interest" } if ($cat1_speed == '20' || $cat2_speed == 'check coverage') { // remove this catogory item set from the store (hide?) if the products atttribute is greater than the number } // in the end, returns success json data wp_send_json_success([/* some data here */$wireless_speed ,$fusion_fibre_speed]); // or, on error, return error json data wp_send_json_error([/* some data here */]); }
- How can I use the Secondary Images Upload Metabox from Woocommerce on a Custom post type?
-
Portfolio gallery with responsive grid, filter function and onclick lightbox with HTML description
I'm searching for a portfolio gallery script with a responsive grid layout, a filter function and an onclick lightbox function with the possibility to add a HTML description.
Does someone of you know where I can get a free template with this functions?
Thaaaanks. <3
-
Adding Javascript Gallery and Lightbox to Wordpress
I've made a Galley and Lightbox using Vanilla Javascript and CSS and would like to add it to WordPress.
The functionality that I want is to allow my friend (who will own the website) to add his own images into the gallery. So if he creates a page, say X's Wedding he should be able to add his images and these should respect the markup I have in HTML/CSS.
I don't know how complicated this is or where to go to read more.
I looked at the gallery wp function but didn't manage to find anything there.
I'll appreciate any help!
-
SAS - Find and assign an ID base on all possible combinations of more variables
I need to assign the same ID to every combination of same values in three variables and i really have no clue of what can I do to spot combination of the same three letters among the three variables (A-B-C should match with B-C-A) Here's my input data:
data HAVE; input ID VAR1 VAR2 VAR3 $; DATALINES; 001 A B C 002 A C B 003 B C A 004 A B 005 B A 006 D E F 007 E F D 008 F E D 009 E F 010 F E ; RUN;
And the resulting ID_NEW should be:
data HAVE; input ID VAR1 VAR2 VAR3 $ ID_NEW; DATALINES; 001 A B C 1 002 A C B 1 003 B C A 1 004 A B 2 005 B A 2 006 D E F 3 007 E F D 3 008 F E D 3 009 E F 4 010 F E 4 ; RUN;
I am able to spot combination of two by proc sql and performing a left join with keys t1.var1=t2.var2 and t1.var2=t2.var1 but it comes to spot the three letters combinations, I want to avoid the join because I could have 6 possible combinations and I feel that there's a smart way to so, without repeating the join 6 times! Perhaps with a combination of catt and scan functions?
Thank you in advance for your help :) !
-
How should DB entity IDs be managed to avoid security risks in a performant way?
Let's suppose I have a small website where users can public book reviews. So, in the server code we have somewhere something like this:
// Get user's read books. public IHttpActionResult GetBooks() { var user = GetLoggedUser(); var userBooks = BooksRepository.GetByUserId(user.Id); return Ok({ Name: user.Name, Books: userBooks.ToDtoList() }); } public IHttpActionResult GetReviews(int bookId) { var reviews = ReviewsRepository.GetByBookId(bookId); return Ok({ Reviews: reviews.ToDtoList() }); }
Among other things, the review objects have an ID property (integer), that's their ID in the database. Now let's suppose I'm a malicious user, I log in and then, I start doing something like:
let limit = 100; for (let id = someStart; id < (someStart + limit); id++) { fetch(URL + '/reviews?bookId=' + id) .then( /* getting other users' reviews... */ ); }
In order to avoid that situation, instead of using integers, I have seen people using GUIDs as the primary key of their tables. Do databases order GUIDs somehow internally so they can create an index? If not, isn't it a slow approach? Is there a better way to deal with IDs sent to the browser?
-
creating unique ID to assign to duplicate addresses in file
I am working to create a household ID when people in my file have the same address but assigned to different people. I need it to be the same ID for each person with the same address not a sequential ID and I am using a program called Alpine so I need to use Sql or version of pig syntax.