Skip to content

Instantly share code, notes, and snippets.

Avatar

Shopify Partners shopifypartners

View GitHub Profile
View shopify-buy-button-and-wordpress-wp-enqueue-script.php
function theme_scripts() {
wp_enqueue_script( 'buy-button', 'http://sdks.shopifycdn.com/buy-button/0.1.34/buybutton.min.js', array( ), '', true );
wp_enqueue_script( 'shopify-product', '/assets/js/custom.js', array('buy-button' ), '', true );
}
add_action( 'wp_enqueue_scripts', 'theme_scripts' );
View shopify-buy-button-and-wordpress-initialize-the-client.js
var client = ShopifyBuy.buildClient({
apiKey: 'your-api-key',
domain: 'my-shop.myshopify.com',
appId: '6'
});
View shopify-buy-button-and-wordpress-fetch-product-information.js
var productNodes = document.querySelectorAll('[data-shopify-product]');
Array.prototype.slice.call(productNodes).forEach(function (node) {
var productId = node.dataset.shopifyProduct;
ui.createComponent('product', {
id: productId,
node: node,
});
});
View shopify-buy-button-and-wordpress-iframeless-embeds.js
ui.createComponent('product', {
id: productId,
options: {
product: {
iframe: false
},
cart: {
iframe: false
}
}
View shopify-buy-button-and-wordpress-css-styles.php
wp_enqueue_style( 'buy-button','http://sdks.shopifycdn.com/buy-button/0.1.34/buybutton.css' );
View shopify-buy-button-and-wordpress-shortcode.php
function shopify_shortcode ($atts) {
$a = shortcode_atts(array(
'id' => ''
), $atts);
return '<div data-shopify-product="' . $a['id'] . '"></div>';
}
add_shortcode( 'shopify_product', 'shopify_shortcode' );
View shopify-buy-button-and-wordpress-wp-enqueue-script-js-buy-sdk.php
function enqueue_shopify_buy() {
wp_enqueue_script('shopify-buy', 'http://sdks.shopifycdn.com/js-buy-sdk/v0/latest/shopify-buy.umd.polyfilled.min.js');
}
add_action( 'admin_enqueue_scripts', 'enqueue_shopify_buy' );
You can’t perform that action at this time.