Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prefix was not added when a variation was selected #298

Merged
merged 1 commit into from
Oct 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion assets/integration/woocommerce.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ Yes! Pagespeed is one of our main focus points, and we strive to make the plugin
Enhancements:

Bugfixes:
* The product ID Prefix was not added when a product variation was selected.

Other:

Expand Down
3 changes: 2 additions & 1 deletion src/Integration/WooCommerce.php
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,7 @@ public function enqueue_scripts(): void {
public function get_global_settings( array $global_settings ): array {

$global_settings['wc']['use_sku'] = (bool) $this->options->get( 'integrations', 'woocommerce_use_sku' );
$global_settings['wc']['pid_prefix'] = $this->prefix_item_id();
$global_settings['wc']['add_shipping_info']['config'] = (int) Options::init()->get( 'integrations', 'woocommerce_shipping_info' );
$global_settings['wc']['add_payment_info']['config'] = (int) Options::init()->get( 'integrations', 'woocommerce_payment_info' );
$global_settings['wc']['view_item']['config'] = (int) Options::init()->get( 'integrations', 'woocommerce_variable_product_tracking' );
Expand Down Expand Up @@ -988,7 +989,7 @@ public function cart_item_remove_link( string $woocommerce_cart_item_remove_link
*
* @return string
*/
public function prefix_item_id( string $item_id ): string {
public function prefix_item_id( string $item_id = '' ): string {
return Options::init()->get( 'integrations', 'woocommerce_product_id_prefix' ) . $item_id;
}

Expand Down
3 changes: 2 additions & 1 deletion src/js/woocommerce.js
Original file line number Diff line number Diff line change
Expand Up @@ -352,14 +352,15 @@ function gtmkitLoad() {
);

productVariationData.id = productVariationData.item_id =
window.gtmkit_settings.wc.pid_prefix +
productVariation.variation_id;
if (
window.gtmkit_settings.wc.use_sku &&
productVariation.sku &&
'' !== productVariation.sku
) {
productVariationData.id = productVariationData.item_id =
productVariation.sku;
window.gtmkit_settings.wc.pid_prefix + productVariation.sku;
}

productVariationData.price = productVariation.display_price;
Expand Down