ご質問は
少し不明確であるあなたがお店やアーカイブWooCommerceページにアドオン・ツー・カートボタンを表示loop/add-to-cart.php
WooCommerceテンプレートを編集することを最初に指定する必要があります。それはのようなhref
<a>
タグでGET URLを設定したよう
例えば:
http://www.myshop.com/shop/?add-to-cart=208&gclid=601
この:
http://www.myshop.com/shop/?add-to-cart=208
が、それはあなたのような何かを追加する必要があります動作させるために追加を行います&
+ gclid=
+(ここでは例601
用)gclid
の値...
ので次のコードは、完全に(this test server上のアクションでそれを参照してください)動作します:
<?php
/**
* Loop Add to Cart
*
* This template can be overridden by copying it to yourtheme/woocommerce/loop/add-to-cart.php.
*
* HOWEVER, on occasion WooCommerce will need to update template files and you
* (the theme developer) will need to copy the new files to your theme to
* maintain compatibility. We try to do this as little as possible, but it does
* happen. When this occurs the version of the template file will be bumped and
* the readme will list any important changes.
*
* @see https://docs.woocommerce.com/document/template-structure/
* @author WooThemes
* @package WooCommerce/Templates
* @version 2.5.0
*/
if (! defined('ABSPATH')) {
exit;
}
global $product;
// Just for testing (replace after with $gclid=$_GET['gclid'];)
$gclid = '&gclid=120';
// $gclid=$_GET['gclid'];
echo apply_filters('woocommerce_loop_add_to_cart_link',
sprintf('<a rel="nofollow" href="%s" data-quantity="%s" data-product_id="%s" data-product_sku="%s" class="%s">%s</a>',
esc_url($product->add_to_cart_url().$gclid),
esc_attr(isset($quantity) ? $quantity : 1),
esc_attr($product->id),
esc_attr($product->get_sku()),
esc_attr(isset($class) ? $class : 'button'),
esc_html($product->add_to_cart_text())
),
$product);
// Checking that you get 'gclid' value (just for test)
// (will display normally the 'gclid' value after the button add-to-cart)
echo '<p>gclid value: '. $_GET['gclid'] .</p>;
問題は確かにあなたの$gclid=$_GET['gclid'];
から来ています。
'gclid'
の値を取得していることを確認する必要があります。
$gclid= '&gclid=' . $_GET['gclid'];
これは動作するはずです...
すべてのエラー:あなたは
'gclid'
値を取得していることを確認したらは、あなたはそれを少し、この方法を変更する必要がありますか? 'apply_filters(X、sprintf(X、esc_url(X)')は、閉じかっこで囲まれていますか? –
'code'global $ product; $ gclid = $ _GET ['gclid'] ; //読み取りGCLIDと$ GCLID はapply_filters( 'woocommerce_loop_add_to_cart_link'、 \tのsprintf( '%s'、 \t \t esc_url($製品 - > add_to_cart_url()の$ GCLID)、 \t \t esc_attr(ISSETをエコーそれを格納します。 ($数量)?$数量:1)、 \t \t esc_attr($製品 - > ID)、 \t \t esc_attr($製品 - > get_sku())、 \t \t esc_attr(ISSET($クラス)$クラス:? 'ボタン') 、 \t \t esc_html($ product-> add_to_cart_text()) \t)、 $ product); –
エラーはありませんが、動作しません。私はちょうどリンクを作成しようとしていますhref = "%s" include $ gclid。そのリンクと私はURLからgclidを引っ張り、リンクの最後に配置しています。これはコード全体ですが、短縮するためにコード全体を渡すことはありませんでした。ありがとう。 –