Skip to content

Instantly share code, notes, and snippets.

@jrick1229
Last active November 29, 2018 17:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jrick1229/6c7fa8edee71727253b6cc3fb61680ea to your computer and use it in GitHub Desktop.
Save jrick1229/6c7fa8edee71727253b6cc3fb61680ea to your computer and use it in GitHub Desktop.
Auto-add product to cart on page visit
<?php
add_action( 'wp', 'auto_add_to_cart_OPC' );
function auto_add_to_cart_OPC() {
$product_id = 561;
$page_id = 332;
if ( is_page( $page_id ) ) {
WC()->cart->empty_cart();
WC()->cart->add_to_cart( $product_id );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment